Add ability to send the id of the channel the message is found in

This commit is contained in:
Joren 2024-06-27 11:52:31 +02:00
parent c0076759a4
commit 95a05eef25
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 13 additions and 4 deletions

View File

@ -5,6 +5,8 @@
SERVER_ID = "" SERVER_ID = ""
OUTPUT_CHANNEL_ID = "" OUTPUT_CHANNEL_ID = ""
PREFIX_ENABLED = true PREFIX_ENABLED = true
SERVER_ID_ENABLED = false
CHANNEL_ID_ENABLED = true
[SERVERS.COIN_REGEXES] [SERVERS.COIN_REGEXES]
Bitcoin = "[13][a-km-zA-HJ-NP-Z1-9]{25,34}" Bitcoin = "[13][a-km-zA-HJ-NP-Z1-9]{25,34}"
Ethereum = "0x[a-fA-F0-9]{40}" Ethereum = "0x[a-fA-F0-9]{40}"
@ -15,6 +17,8 @@
SERVER_ID = "" SERVER_ID = ""
OUTPUT_CHANNEL_ID = "" OUTPUT_CHANNEL_ID = ""
PREFIX_ENABLED = false PREFIX_ENABLED = false
SERVER_ID_ENABLED = false
CHANNEL_ID_ENABLED = true
[SERVERS.COIN_REGEXES] [SERVERS.COIN_REGEXES]
Ethereum = "0x[a-fA-F0-9]{40}" Ethereum = "0x[a-fA-F0-9]{40}"
Solana = "[1-9A-HJ-NP-Za-km-z]{32,44}" Solana = "[1-9A-HJ-NP-Za-km-z]{32,44}"

13
main.go
View File

@ -27,7 +27,8 @@ type ServerConfig struct {
} `toml:"CHANNEL_BLACKLIST"` } `toml:"CHANNEL_BLACKLIST"`
PrefixEnabled bool `toml:"PREFIX_ENABLED"` PrefixEnabled bool `toml:"PREFIX_ENABLED"`
AllowDuplicates bool `toml:"ALLOW_DUPLICATES"` AllowDuplicates bool `toml:"ALLOW_DUPLICATES"`
ServerIDEnabled bool `toml:"SERVER_ID_ENABLED"` ServerIDEnabled bool `toml:"SERVER_ID_ENABLED"`
ChannelIDEnabled bool `toml:"CHANNEL_ID_ENABLED"`
} }
func init() { func init() {
@ -127,7 +128,7 @@ func checkMessageContent(s *discordgo.Session, server ServerConfig, m *discordgo
match := regex.FindStringSubmatch(m.Content) match := regex.FindStringSubmatch(m.Content)
if len(match) > 0 { if len(match) > 0 {
matchedAddress := match[0] matchedAddress := match[0]
message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName) message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName, m)
if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) { if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) {
return return
@ -146,7 +147,7 @@ func checkEmbeds(s *discordgo.Session, server ServerConfig, m *discordgo.Message
match := regex.FindStringSubmatch(embed.Description) match := regex.FindStringSubmatch(embed.Description)
if len(match) > 0 { if len(match) > 0 {
matchedAddress := match[0] matchedAddress := match[0]
message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName) message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName, m)
if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) { if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) {
return return
@ -160,7 +161,7 @@ func checkEmbeds(s *discordgo.Session, server ServerConfig, m *discordgo.Message
} }
} }
func formatMessage(server ServerConfig, coin, username, address, serverName string) string { func formatMessage(server ServerConfig, coin, username, address, serverName string, m *discordgo.MessageCreate) string {
message := address message := address
if server.PrefixEnabled { if server.PrefixEnabled {
@ -171,6 +172,10 @@ func formatMessage(server ServerConfig, coin, username, address, serverName stri
message = fmt.Sprintf("%s (Server: %s)", message, serverName) message = fmt.Sprintf("%s (Server: %s)", message, serverName)
} }
if server.ChannelIDEnabled {
message = fmt.Sprintf("%s (From: <#%s>)", message, m.ChannelID)
}
return message return message
} }