/
lookup.go
49 lines (39 loc) · 1.56 KB
/
lookup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package handlers
import (
"strings"
"discord-dero-bot/utils/dero"
"github.com/bwmarrin/discordgo"
)
func HandleWalletName(session *discordgo.Session, message *discordgo.MessageCreate) {
content := message.Content
// fmt.Println("CONTENT: %s", content)
if !strings.HasPrefix(content, "!lookup ") {
session.ChannelMessageSend(message.ChannelID, "To lookup a DERO address, use the format: `!lookup <@user_mention or wallet_name>`")
return
}
userInput := strings.TrimPrefix(message.Content, "!lookup ")
// log.Printf("User Input: " + userInput)
// Check if the input matches the format of a user mention
if strings.HasPrefix(userInput, "<@") && strings.HasSuffix(userInput, ">") {
userID := strings.TrimPrefix(userInput, "<@")
userID = strings.TrimSuffix(userID, ">")
userMappingsMutex.Lock()
mappedAddress, exists := userMappings[userID]
userMappingsMutex.Unlock()
if exists {
session.ChannelMessageSend(message.ChannelID, "DERO Address (from registered user): ```"+mappedAddress+"```")
} else {
// Ping the user with the mention
userMention := "<@" + userID + ">"
session.ChannelMessageSend(message.ChannelID, userMention+" is not registered or invalid input. \n\n To register, please use `!register`")
}
} else {
// Perform a wallet name lookup for non-user mention inputs
deroAddress := dero.WalletNameToAddress(userInput)
if deroAddress != "" {
session.ChannelMessageSend(message.ChannelID, "DERO Address: ```"+deroAddress+"```")
} else {
session.ChannelMessageSend(message.ChannelID, "Wallet name not found or invalid.")
}
}
}