Compare commits
	
		
			3 Commits
		
	
	
		
			fba7d2c8d4
			...
			7d8a2db77b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						7d8a2db77b
	
				 | 
					
					
						|||
| 
						
						
							
						
						b63a368c35
	
				 | 
					
					
						|||
| 
						
						
							
						
						6cf715e620
	
				 | 
					
					
						
							
								
								
									
										11
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,3 +1,14 @@
 | 
				
			|||||||
module HwidBot
 | 
					module HwidBot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.22.4
 | 
					go 1.22.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require (
 | 
				
			||||||
 | 
						github.com/BurntSushi/toml v1.4.0
 | 
				
			||||||
 | 
						github.com/bwmarrin/discordgo v0.28.1
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require (
 | 
				
			||||||
 | 
						github.com/gorilla/websocket v1.4.2 // indirect
 | 
				
			||||||
 | 
						golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
 | 
				
			||||||
 | 
						golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										74
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								main.go
									
									
									
									
									
								
							@@ -2,8 +2,78 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"os/signal"
 | 
				
			||||||
 | 
						"syscall"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/BurntSushi/toml"
 | 
				
			||||||
 | 
						"github.com/bwmarrin/discordgo"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main(){
 | 
					var client *discordgo.Session
 | 
				
			||||||
	fmt.Println("Initial")
 | 
					
 | 
				
			||||||
 | 
					type Config struct {
 | 
				
			||||||
 | 
						Discord  Discord  `toml:"discord"`
 | 
				
			||||||
 | 
						Database Database `toml:"database"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Discord struct {
 | 
				
			||||||
 | 
						Token   string `toml:"client"`
 | 
				
			||||||
 | 
						GuildID string `toml:"guildid"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Database struct {
 | 
				
			||||||
 | 
						Host     string `toml:"host"`
 | 
				
			||||||
 | 
						Port     int    `toml:"port"`
 | 
				
			||||||
 | 
						Name     string `toml:"name"`
 | 
				
			||||||
 | 
						Username string `toml:"username"`
 | 
				
			||||||
 | 
						Password string `toml:"password"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func loadConfig(filename string) (Config, error) {
 | 
				
			||||||
 | 
						var config Config
 | 
				
			||||||
 | 
						_, err := toml.DecodeFile(filename, &config)
 | 
				
			||||||
 | 
						return config, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						config, err := loadConfig("config.toml")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error occurred whilst trying to load config:", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client, err = discordgo.New("Bot " + config.Discord.Token)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error initializing bot:", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						if client == nil {
 | 
				
			||||||
 | 
							fmt.Println("Bot client is not initialized")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client.AddHandler(func(client *discordgo.Session, r *discordgo.Ready) {
 | 
				
			||||||
 | 
							fmt.Println("Bot is online")
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := client.Open()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error opening connection:", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						stop := make(chan os.Signal, 1)
 | 
				
			||||||
 | 
						signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
 | 
				
			||||||
 | 
						<-stop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Println("Gracefully shutting down.")
 | 
				
			||||||
 | 
						client.Close()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user