Skip to content

Commit

Permalink
Server/Channel naming
Browse files Browse the repository at this point in the history
  • Loading branch information
get-got committed Dec 20, 2020
1 parent 6015c73 commit 84f66bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func getUserIdentifier(usr discordgo.User) string {
}

func getGuildName(guildID string) string {
sourceGuildName := "Server Name Unknown"
sourceGuildName := "UNKNOWN"
sourceGuild, _ := bot.State.Guild(guildID)
if sourceGuild != nil && sourceGuild.Name != "" {
sourceGuildName = sourceGuild.Name
Expand All @@ -274,14 +274,32 @@ func getGuildName(guildID string) string {
}

func getChannelName(channelID string) string {
sourceChannelName := "Channel Name Unknown"
sourceChannelName := "unknown"
sourceChannel, _ := bot.State.Channel(channelID)
if sourceChannel != nil && sourceChannel.Name != "" {
sourceChannelName = sourceChannel.Name
if sourceChannel != nil {
if sourceChannel.Name != "" {
sourceChannelName = sourceChannel.Name
} else {
switch sourceChannel.Type {
case discordgo.ChannelTypeDM:
sourceChannelName = "dm"
case discordgo.ChannelTypeGroupDM:
sourceChannelName = "group-dm"
}
}
}
return sourceChannelName
}

func getSourceName(guildID string, channelID string) string {
guildName := getGuildName(guildID)
channelName := getChannelName(channelID)
if channelName == "dm" || channelName == "group-dm" {
return channelName
}
return fmt.Sprintf("\"%s\"#%s", guildName, channelName)
}

//#endregion

// For command case-insensitivity
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func handleMessage(m *discordgo.Message, edited bool) {
if config.DebugOutput {
sendLabel = fmt.Sprintf("%s/%s/%s", m.GuildID, m.ChannelID, m.Author.ID)
} else {
sendLabel = fmt.Sprintf("%s in \"%s\"#%s", getUserIdentifier(*m.Author), getGuildName(m.GuildID), getChannelName(m.ChannelID))
sendLabel = fmt.Sprintf("%s in %s", getUserIdentifier(*m.Author), getSourceName(m.GuildID, m.ChannelID))
}
content := m.Content
if len(m.Attachments) > 0 {
Expand Down

0 comments on commit 84f66bb

Please sign in to comment.