Allow usernames
This commit is contained in:
37
main.go
37
main.go
@ -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) {
|
func findVerification(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
parts := strings.Split(m.Content, " ")
|
parts := strings.Split(m.Content, " ")
|
||||||
discordId := parts[1]
|
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))
|
matches, err := filepath.Glob(fmt.Sprintf("./verifications/*%+v*", discordId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
@ -429,10 +460,6 @@ func findVerification(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := s.GuildMember(config.GuildID, discordId)
|
msg := fmt.Sprintf("```%+v\nJoined: %+v\n```", user.User.Username, user.JoinedAt)
|
||||||
if err != nil {
|
|
||||||
log.LogErrorType(err)
|
|
||||||
}
|
|
||||||
msg := fmt.Sprintf("```%+v\nJoined: %+v\n", user.User.Username, user.JoinedAt)
|
|
||||||
s.ChannelFileSendWithMessage(m.ChannelID, msg, fmt.Sprintf("%+v Verification", discordId), verificationImage)
|
s.ChannelFileSendWithMessage(m.ChannelID, msg, fmt.Sprintf("%+v Verification", discordId), verificationImage)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user