Skip to content

Commit

Permalink
Merge pull request #12 from Tobio89/feat/improved-nick-logging
Browse files Browse the repository at this point in the history
Improve user nick/username log msg
  • Loading branch information
Tobio89 authored Mar 19, 2023
2 parents 219e266 + 1c3485b commit 50d3531
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (c *Commands) DeleteMultipleMessages(eraseFromStartingPostID, eraseUntilPos
func (c *Commands) ManualVerify(i *discordgo.InteractionCreate, user *discordgo.User) {

var responseContent string
var userNick string = c.bot.Utils.GetUserNickOrUsername(user)
var userNick string = c.bot.Utils.MakeUserNickLogString(user)

// Get member from server's member list
member, err := c.bot.Utils.GetMemberByID(user.ID)
Expand Down Expand Up @@ -576,7 +576,7 @@ func (c *Commands) ManualVerify(i *discordgo.InteractionCreate, user *discordgo.
func (c *Commands) ManualDeVerify(i *discordgo.InteractionCreate, user *discordgo.User) {

var responseContent string
var userNick string = c.bot.Utils.GetUserNickOrUsername(user)
var userNick string = c.bot.Utils.MakeUserNickLogString(user)

// Get member from server's member list
member, err := c.bot.Utils.GetMemberByID(user.ID)
Expand Down
27 changes: 20 additions & 7 deletions app/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (e *Events) onNewMember(s *discordgo.Session, memberJoinEvent *discordgo.Gu
botWelcomeScript := fmt.Sprintf("%s, %s! Welcome to FCC Korea's discord server!\n*You'll need to introduce yourself here to complete your verification and get access to the full server :)*\n*여기서 자기소개하면 사용자 검증을 완료 될 겁니다*\nWe'd love to get to know you and find out where you are on your coding journey!\nOnce you're verified, %s check out the react-for-roles channel and let us know where you're based!\n%s", greeting, memberJoinEvent.Mention(), suggestion, closing)

e.bot.Session.ChannelMessageSend(e.bot.Cfg.server.intros, botWelcomeScript)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User {nick \"%s\", username \"%s\"} joined the server", memberJoinEvent.Member.Nick, memberJoinEvent.User.Username))

userNick := e.bot.Utils.MakeUserNickLogString(memberJoinEvent.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s joined the server", userNick))
}

func (e *Events) onMessageSent(s *discordgo.Session, m *discordgo.MessageCreate) {
Expand Down Expand Up @@ -74,7 +76,9 @@ func (e *Events) handleIntroductionVerification(m *discordgo.MessageCreate) {
}

e.bot.Session.GuildMemberRoleAdd(e.bot.Cfg.server.guild, member.User.ID, e.bot.Cfg.roles.verified)
e.bot.SendLog(msg.LogVerification, fmt.Sprintf("User {nick \"%s\", username \"%s\"} became verified", member.Nick, member.User.Username))

userNick := e.bot.Utils.MakeUserNickLogString(member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s became verified", userNick))
}

func (e *Events) parseReactionAdded(m *discordgo.MessageReactionAdd) {
Expand Down Expand Up @@ -150,7 +154,9 @@ func (e *Events) rfrAdd(member *discordgo.Member, emojiUsed string) {
}
}
e.bot.Session.GuildMemberRoleAdd(e.bot.Cfg.server.guild, member.User.ID, role.ID)
e.bot.SendLog(msg.LogRFR, fmt.Sprintf("User {nick \"%s\", username \"%s\"} receives role %s", member.Nick, member.User.Username, RFRRoleSelected))

userNick := e.bot.Utils.MakeUserNickLogString(member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s gains role %s", userNick, RFRRoleSelected))
}
}

Expand Down Expand Up @@ -185,7 +191,9 @@ func (e *Events) rfrRemove(member *discordgo.Member, emojiUsed string) {
e.bot.SendLog(msg.LogError, err.Error())
return
}
e.bot.SendLog(msg.LogRFR, fmt.Sprintf("User {nick \"%s\", username \"%s\"} loses role %s", member.Nick, member.User.Username, RFRRoleSelected))

userNick := e.bot.Utils.MakeUserNickLogString(member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s loses role %s", userNick, RFRRoleSelected))
}
}
}
Expand All @@ -206,7 +214,9 @@ func (e *Events) onlineChatRoleAdd(member *discordgo.Member) {
e.bot.SendLog(msg.LogError, "Whilst adding Gather role:")
e.bot.SendLog(msg.LogError, err.Error())
} else {
e.bot.SendLog(msg.LogRFR, fmt.Sprintf("User {nick \"%s\", username \"%s\"} subscribes to Gather updates", member.Nick, member.User.Username))

userNick := e.bot.Utils.MakeUserNickLogString(member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s subscribes to Online Meetup updates", userNick))
}
}

Expand All @@ -232,7 +242,8 @@ func (e *Events) onlineChatRoleRemove(member *discordgo.Member) {
e.bot.SendLog(msg.LogError, err.Error())
return
}
e.bot.SendLog(msg.LogRFR, fmt.Sprintf("User {nick \"%s\", username \"%s\"} unsubscribes from Gather updates", member.Nick, member.User.Username))
userNick := e.bot.Utils.MakeUserNickLogString(member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s unsubscribes from Online Meetup updates", userNick))
}

func (e *Events) learningResourcePost(m *discordgo.MessageReactionAdd, learningDiscussionChannel *discordgo.Channel, learningResourcesChannel *discordgo.Channel) {
Expand All @@ -253,7 +264,9 @@ func (e *Events) learningResourcePost(m *discordgo.MessageReactionAdd, learningD
messageContents := fmt.Sprintf("%s\nThanks, %s, who posted this resource: \n"+message.Content, e.makeMessageLink(message.Reference()), message.Author.Mention())
e.bot.Session.ChannelMessageSend(learningResourcesChannel.ID, messageContents)
e.bot.Session.MessageReactionAdd(learningDiscussionChannel.ID, message.ID, BotProcessedEmoji)
e.bot.SendLog(msg.LogLearning, fmt.Sprintf("%s's (%s) post was added to Learning Resources", m.Member.Nick, m.Member.User.Username))

userNick := e.bot.Utils.MakeUserNickLogString(m.Member.User)
e.bot.SendLog(msg.LogNewMember, fmt.Sprintf("User %s's post was added to Learning Resources", userNick))
}
}

Expand Down
9 changes: 9 additions & 0 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ func (u *Utils) GetUserNickOrUsername(user *discordgo.User) string {
}
return member.User.Username
}

func (u *Utils) MakeUserNickLogString(user *discordgo.User) string {
member, _ := u.GetMemberByID(user.ID)

if member.Nick != "" {
return member.Nick + " (n)"
}
return member.User.Username + " (u)"
}

0 comments on commit 50d3531

Please sign in to comment.