|
|
|
@@ -5,13 +5,11 @@ import (
|
|
|
|
|
"os"
|
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
"git.directme.in/Joren/SmsHook/ringbuffer"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
Token string
|
|
|
|
|
Servers []ServerConfig
|
|
|
|
@@ -21,14 +19,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,19 +111,25 @@ 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)
|
|
|
|
|
message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName, m)
|
|
|
|
|
|
|
|
|
|
if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) {
|
|
|
|
|
return
|
|
|
|
@@ -134,14 +141,14 @@ func checkMessageContent(s *discordgo.Session, server ServerConfig, m *discordgo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
message := formatMessage(server, coin, m.Author.Username, matchedAddress, serverName, m)
|
|
|
|
|
|
|
|
|
|
if !server.AllowDuplicates && MessageHistory[server.ServerID].ContainsItem(message) {
|
|
|
|
|
return
|
|
|
|
@@ -155,11 +162,26 @@ func checkEmbeds(s *discordgo.Session, server ServerConfig, m *discordgo.Message
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|