Compare commits
9 Commits
0f3db80465
...
main
Author | SHA1 | Date | |
---|---|---|---|
2df3f1c0b3
|
|||
c1da0b7a3b
|
|||
23a3ff1da2 | |||
8b5448312b | |||
7da090badf | |||
32987927f8
|
|||
3fe974d3c3
|
|||
95a05eef25
|
|||
c0076759a4
|
38
README.md
38
README.md
@ -15,7 +15,9 @@ This setting should be enabled for the bot in the discord developer panel for it
|
||||
SERVER_ID = "1050204101826334999"
|
||||
OUTPUT_CHANNEL_ID = "1250585834726621999"
|
||||
PREFIX_ENABLED = true
|
||||
ALLOW_DUPLICATES = false
|
||||
SERVER_ID_ENABLED = false
|
||||
CHANNEL_ID_ENABLED = true
|
||||
MESSAGE_LINK_ENABLED = false
|
||||
[SERVERS.COIN_REGEXES]
|
||||
Bitcoin = "[13][a-km-zA-HJ-NP-Z1-9]{25,34}"
|
||||
Ethereum = "0x[a-fA-F0-9]{40}"
|
||||
@ -25,11 +27,41 @@ This setting should be enabled for the bot in the discord developer panel for it
|
||||
[[SERVERS]]
|
||||
SERVER_ID = "1250885747062345999"
|
||||
OUTPUT_CHANNEL_ID = "1250585834726621999"
|
||||
PREFIX_ENABLED = true
|
||||
ALLOW_DUPLICATES = false
|
||||
PREFIX_ENABLED = false
|
||||
SERVER_ID_ENABLED = false
|
||||
CHANNEL_ID_ENABLED = true
|
||||
MESSAGE_LINK_ENABLED = false
|
||||
[SERVERS.COIN_REGEXES]
|
||||
Ethereum = "0x[a-fA-F0-9]{40}"
|
||||
Solana = "[1-9A-HJ-NP-Za-km-z]{32,44}"
|
||||
[SERVERS.CHANNEL_BLACKLIST]
|
||||
CHANNELS = []
|
||||
```
|
||||
|
||||
### Explaination
|
||||
|
||||
```toml
|
||||
[DISCORD]
|
||||
BOT_TOKEN = ""
|
||||
|
||||
[[SERVERS]]
|
||||
# ID of the server in which all the channels should be monitored
|
||||
SERVER_ID = "1050204101826334999"
|
||||
# Channel where everything should be send to
|
||||
OUTPUT_CHANNEL_ID = "1250585834726621999"
|
||||
# Wether to show the coin prefix or not
|
||||
PREFIX_ENABLED = true
|
||||
# Display name of server a message has been send in
|
||||
SERVER_ID_ENABLED = false
|
||||
# Display clickable channel object of server a message has been send in
|
||||
CHANNEL_ID_ENABLED = true
|
||||
# Provides a link to the message where the regex has been matched
|
||||
MESSAGE_LINK_ENABLED = false
|
||||
[SERVERS.COIN_REGEXES]
|
||||
# Prefix = Regex pair of the coin(s) to be matched; can theoretically be used for other stuff
|
||||
Bitcoin = "[13][a-km-zA-HJ-NP-Z1-9]{25,34}"
|
||||
Ethereum = "0x[a-fA-F0-9]{40}"
|
||||
[SERVERS.CHANNEL_BLACKLIST]
|
||||
# IDs of the channels that should NOT be monitored
|
||||
CHANNELS = ["1250537334550827078"]
|
||||
```
|
@ -4,7 +4,11 @@
|
||||
[[SERVERS]]
|
||||
SERVER_ID = ""
|
||||
OUTPUT_CHANNEL_ID = ""
|
||||
ALLOW_DUPLICATES = false
|
||||
PREFIX_ENABLED = true
|
||||
SERVER_ID_ENABLED = false
|
||||
CHANNEL_ID_ENABLED = true
|
||||
MESSAGE_LINK_ENABLED = false
|
||||
[SERVERS.COIN_REGEXES]
|
||||
Bitcoin = "[13][a-km-zA-HJ-NP-Z1-9]{25,34}"
|
||||
Ethereum = "0x[a-fA-F0-9]{40}"
|
||||
@ -15,6 +19,10 @@
|
||||
SERVER_ID = ""
|
||||
OUTPUT_CHANNEL_ID = ""
|
||||
PREFIX_ENABLED = false
|
||||
ALLOW_DUPLICATES = false
|
||||
SERVER_ID_ENABLED = false
|
||||
CHANNEL_ID_ENABLED = true
|
||||
MESSAGE_LINK_ENABLED = false
|
||||
[SERVERS.COIN_REGEXES]
|
||||
Ethereum = "0x[a-fA-F0-9]{40}"
|
||||
Solana = "[1-9A-HJ-NP-Za-km-z]{32,44}"
|
||||
|
65
main.go
65
main.go
@ -4,14 +4,13 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"git.directme.in/Joren/SmsHook/ringbuffer"
|
||||
)
|
||||
|
||||
|
||||
var (
|
||||
Token string
|
||||
Servers []ServerConfig
|
||||
@ -21,14 +20,17 @@ var (
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
ServerID string `toml:"SERVER_ID"`
|
||||
OutputChannelID string `toml:"OUTPUT_CHANNEL_ID"`
|
||||
CoinRegexes map[string]string `toml:"COIN_REGEXES"`
|
||||
ServerID string `toml:"SERVER_ID"`
|
||||
OutputChannelID string `toml:"OUTPUT_CHANNEL_ID"`
|
||||
CoinRegexes map[string]string `toml:"COIN_REGEXES"`
|
||||
ChannelBlacklist struct {
|
||||
Channels []string `toml:"CHANNELS"`
|
||||
} `toml:"CHANNEL_BLACKLIST"`
|
||||
PrefixEnabled bool `toml:"PREFIX_ENABLED"`
|
||||
AllowDuplicates bool `toml:"ALLOW_DUPLICATES"`
|
||||
PrefixEnabled bool `toml:"PREFIX_ENABLED"`
|
||||
AllowDuplicates bool `toml:"ALLOW_DUPLICATES"`
|
||||
ServerIDEnabled bool `toml:"SERVER_ID_ENABLED"`
|
||||
ChannelIDEnabled bool `toml:"CHANNEL_ID_ENABLED"`
|
||||
MessageLinkEnabled bool `toml:"MESSAGE_LINK_ENABLED"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -110,56 +112,79 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
return
|
||||
}
|
||||
|
||||
checkMessageContent(s, server, m)
|
||||
checkEmbeds(s, server, m)
|
||||
guild, err := s.Guild(m.GuildID)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting guild:", err)
|
||||
return
|
||||
}
|
||||
|
||||
checkMessageContent(s, server, m, guild.Name)
|
||||
checkEmbeds(s, server, m, guild.Name)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkMessageContent(s *discordgo.Session, server ServerConfig, m *discordgo.MessageCreate) {
|
||||
func checkMessageContent(s *discordgo.Session, server ServerConfig, m *discordgo.MessageCreate, serverName string) {
|
||||
for coin, regex := range CoinRegexes {
|
||||
match := regex.FindStringSubmatch(m.Content)
|
||||
if len(match) > 0 {
|
||||
matchedAddress := match[0]
|
||||
message := formatMessage(server, coin, m.Author.Username, matchedAddress)
|
||||
matchedAddress = strings.TrimSpace(matchedAddress)
|
||||
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(matchedAddress) {
|
||||
return
|
||||
}
|
||||
|
||||
s.ChannelMessageSend(server.OutputChannelID, message)
|
||||
MessageHistory[server.ServerID].Add(message)
|
||||
MessageHistory[server.ServerID].Add(matchedAddress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkEmbeds(s *discordgo.Session, server ServerConfig, m *discordgo.MessageCreate) {
|
||||
func checkEmbeds(s *discordgo.Session, server ServerConfig, m *discordgo.MessageCreate, serverName string) {
|
||||
for _, embed := range m.Message.Embeds {
|
||||
if embed.Type == "rich" && embed.Description != "" {
|
||||
for coin, regex := range CoinRegexes {
|
||||
match := regex.FindStringSubmatch(embed.Description)
|
||||
if len(match) > 0 {
|
||||
matchedAddress := match[0]
|
||||
message := formatMessage(server, coin, m.Author.Username, matchedAddress)
|
||||
matchedAddress = strings.TrimSpace(matchedAddress)
|
||||
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(matchedAddress) {
|
||||
return
|
||||
}
|
||||
|
||||
s.ChannelMessageSend(server.OutputChannelID, message)
|
||||
MessageHistory[server.ServerID].Add(message)
|
||||
MessageHistory[server.ServerID].Add(matchedAddress)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func formatMessage(server ServerConfig, coin, username, address string) string {
|
||||
func formatMessage(server ServerConfig, coin, username, address, serverName string, m *discordgo.MessageCreate) string {
|
||||
message := address
|
||||
|
||||
if server.PrefixEnabled {
|
||||
return fmt.Sprintf("%s: %s", coin, address)
|
||||
message = fmt.Sprintf("%s: %s", coin, address)
|
||||
}
|
||||
return address
|
||||
|
||||
if server.ServerIDEnabled {
|
||||
message = fmt.Sprintf("%s (Server: %s)", message, serverName)
|
||||
}
|
||||
|
||||
if server.ChannelIDEnabled {
|
||||
message = fmt.Sprintf("%s (From: <#%s>)", message, m.ChannelID)
|
||||
}
|
||||
|
||||
if server.MessageLinkEnabled {
|
||||
message = fmt.Sprintf("%s ([Link](<https://discord.com/channels/%s/%s/%s>))", message, m.GuildID, m.ChannelID, m.ID)
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
||||
func isChannelBlacklisted(serverID, channelID string) bool {
|
||||
|
Reference in New Issue
Block a user