Browse Source

Allow usernames

BotCommandStruct
Gregory Rudolph 3 years ago
parent
commit
4caeade581
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 37
      main.go

37
main.go

@ -411,9 +411,40 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -411,9 +411,40 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
}
func idFromUsername(username string) string {
userID := ""
g, err := dg.GuildMembers(config.GuildID, "", 1000)
log.LogInfo("reqPass guild is %+v.", config.GuildID)
if err == nil {
for _, m := range g {
if strings.ToUpper(m.Nick) == strings.ToUpper(username) {
userID = m.User.ID
log.LogInfo("User ID found for %+v as %+v", username, userID)
}
}
} else {
log.LogError("Unable to find user ID for %+v", username)
}
return userID
}
func findVerification(s *discordgo.Session, m *discordgo.MessageCreate) {
parts := strings.Split(m.Content, " ")
discordId := parts[1]
user, err := s.GuildMember(config.GuildID, discordId)
uidFound := true
if err != nil {
log.LogErrorType(err)
uidFound = false
}
if !uidFound {
discordId = idFromUsername(discordId)
user, err = s.GuildMember(config.GuildID, discordId)
uidFound = true
if err != nil {
log.LogErrorType(err)
}
}
matches, err := filepath.Glob(fmt.Sprintf("./verifications/*%+v*", discordId))
if err != nil {
log.LogErrorType(err)
@ -429,10 +460,6 @@ func findVerification(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -429,10 +460,6 @@ func findVerification(s *discordgo.Session, m *discordgo.MessageCreate) {
log.LogErrorType(err)
return
}
user, err := s.GuildMember(config.GuildID, discordId)
if err != nil {
log.LogErrorType(err)
}
msg := fmt.Sprintf("```%+v\nJoined: %+v\n", user.User.Username, user.JoinedAt)
msg := fmt.Sprintf("```%+v\nJoined: %+v\n```", user.User.Username, user.JoinedAt)
s.ChannelFileSendWithMessage(m.ChannelID, msg, fmt.Sprintf("%+v Verification", discordId), verificationImage)
}

Loading…
Cancel
Save