Add monitor
This commit is contained in:
parent
74ddfb5b52
commit
1b9cbd88c4
18
main.go
18
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@ -11,12 +12,14 @@ import (
|
|||||||
var (
|
var (
|
||||||
Token string
|
Token string
|
||||||
ServerID string
|
ServerID string
|
||||||
|
OutputChannelID string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var config struct {
|
var config struct {
|
||||||
Token string `toml:"DISCORD_BOT_TOKEN"`
|
Token string `toml:"DISCORD_BOT_TOKEN"`
|
||||||
ServerID string `toml:"DISCORD_SERVER_ID"`
|
ServerID string `toml:"DISCORD_SERVER_ID"`
|
||||||
|
OutputChannelID string `toml:"OUTPUT_CHANNEL_ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
|
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
|
||||||
@ -26,6 +29,7 @@ func init() {
|
|||||||
|
|
||||||
Token = config.Token
|
Token = config.Token
|
||||||
ServerID = config.ServerID
|
ServerID = config.ServerID
|
||||||
|
OutputChannelID = config.OutputChannelID
|
||||||
|
|
||||||
if Token == "" {
|
if Token == "" {
|
||||||
fmt.Println("No token provided in config.toml.")
|
fmt.Println("No token provided in config.toml.")
|
||||||
@ -36,6 +40,11 @@ func init() {
|
|||||||
fmt.Println("No server ID provided in config.toml.")
|
fmt.Println("No server ID provided in config.toml.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if OutputChannelID == "" {
|
||||||
|
fmt.Println("No output channel ID in config.toml")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -80,5 +89,14 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Message from %s: %s\n", m.Author.Username, m.Content)
|
fmt.Printf("Message from %s: %s\n", m.Author.Username, m.Content)
|
||||||
|
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`\b\w{36,44}\b`)
|
||||||
|
match := re.FindStringSubmatch(m.Content)
|
||||||
|
if len(match) > 0 {
|
||||||
|
matchedWord := match[0]
|
||||||
|
message := fmt.Sprintf("%s", matchedWord)
|
||||||
|
s.ChannelMessageSend(OutputChannelID, message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user