aa
This commit is contained in:
		
							
								
								
									
										5
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								go.mod
									
									
									
									
									
								
							| @@ -2,7 +2,10 @@ module git.directme.in/Joren/SolMonitor | |||||||
|  |  | ||||||
| go 1.22.4 | 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 ( | require ( | ||||||
| 	github.com/gorilla/websocket v1.4.2 // indirect | 	github.com/gorilla/websocket v1.4.2 // indirect | ||||||
|   | |||||||
							
								
								
									
										45
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								main.go
									
									
									
									
									
								
							| @@ -4,18 +4,36 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
|  | 	"github.com/BurntSushi/toml" | ||||||
| 	"github.com/bwmarrin/discordgo" | 	"github.com/bwmarrin/discordgo" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	Token    string | 	Token    string | ||||||
|  | 	ServerID string | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func init() { | 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 == "" { | 	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) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -28,6 +46,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	dg.AddHandler(ready) | 	dg.AddHandler(ready) | ||||||
|  | 	dg.AddHandler(messageCreate) | ||||||
|  |  | ||||||
| 	dg.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildMessages | 	dg.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildMessages | ||||||
|  |  | ||||||
| @@ -42,6 +61,24 @@ func main() { | |||||||
| } | } | ||||||
|  |  | ||||||
| func ready(s *discordgo.Session, event *discordgo.Ready) { | 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) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user