ImplMessageMonitor #1
5
go.mod
5
go.mod
@ -2,7 +2,10 @@ module git.directme.in/Joren/SolMonitor
|
||||
|
||||
go 1.22.4
|
||||
|
||||
require github.com/bwmarrin/discordgo v0.28.1
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0
|
||||
github.com/bwmarrin/discordgo v0.28.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
|
47
main.go
47
main.go
@ -4,18 +4,36 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var (
|
||||
Token string
|
||||
Token string
|
||||
ServerID string
|
||||
)
|
||||
|
||||
func init() {
|
||||
Token = os.Getenv("DISCORD_BOT_TOKEN")
|
||||
var config struct {
|
||||
Token string `toml:"DISCORD_BOT_TOKEN"`
|
||||
ServerID string `toml:"DISCORD_SERVER_ID"`
|
||||
}
|
||||
|
||||
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
|
||||
fmt.Println("Error loading config:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
Token = config.Token
|
||||
ServerID = config.ServerID
|
||||
|
||||
if Token == "" {
|
||||
fmt.Println("No token provided. Please set DISCORD_BOT_TOKEN environment variable.")
|
||||
fmt.Println("No token provided in config.toml.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if ServerID == "" {
|
||||
fmt.Println("No server ID provided in config.toml.")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@ -28,6 +46,7 @@ func main() {
|
||||
}
|
||||
|
||||
dg.AddHandler(ready)
|
||||
dg.AddHandler(messageCreate)
|
||||
|
||||
dg.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildMessages
|
||||
|
||||
@ -42,6 +61,24 @@ func main() {
|
||||
}
|
||||
|
||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||
s.UpdateGameStatus(0, "Monitoring addresses")
|
||||
s.UpdateGameStatus(0, "Monitoring messages")
|
||||
}
|
||||
|
||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := s.State.Channel(m.ChannelID)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting channel:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.GuildID != ServerID {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Message from %s: %s\n", m.Author.Username, m.Content)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user