From 366e6a1e3fbf7512a7be0ef57d96162a7e524943 Mon Sep 17 00:00:00 2001 From: adminoo Date: Sat, 5 Dec 2020 18:10:27 +0100 Subject: [PATCH] initial commit --- .gitignore | 17 +++++++++++++++++ config.example.yaml | 0 core/config.go | 25 +++++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 10 ++++++++++ main.go | 38 ++++++++++++++++++++++++++++++++++++++ readme.md | 5 +++++ 7 files changed, 103 insertions(+) create mode 100644 .gitignore create mode 100644 config.example.yaml create mode 100644 core/config.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ab9e5c --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +config.yaml \ No newline at end of file diff --git a/config.example.yaml b/config.example.yaml new file mode 100644 index 0000000..e69de29 diff --git a/core/config.go b/core/config.go new file mode 100644 index 0000000..01bc599 --- /dev/null +++ b/core/config.go @@ -0,0 +1,25 @@ +package config + +import ( + "io/ioutil" + "log" + "gopkg.in/yaml.v2" +) + +type Config struct { + Token string `yaml:"token"` + Name string `yaml:"name"` +} + +func (c *Config) LoadConf() *Config { + yamlFile, err := ioutil.ReadFile("config.yaml") + if err != nil { + log.Printf("yamlFile.Get err #%v ", err) + } + err = yaml.Unmarshal(yamlFile, c) + if err != nil { + log.Fatalf("Unmarshal: %v", err) + } + return c +} + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fc1d87a --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module ariona.fr/git/gator/gogodisco + +go 1.15 + +require ( + github.com/bwmarrin/discordgo v0.22.0 + gopkg.in/yaml.v2 v2.4.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e04061b --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM= +github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= +github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= +golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..6c43719 --- /dev/null +++ b/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "ariona.fr/git/gator/gogodisco/core" + + "fmt" + "os" + "os/signal" + "syscall" + + "github.com/bwmarrin/discordgo" +) + +func main() { + var c config.Config + c.LoadConf() + + discord, err := discordgo.New("Bot " + c.Token) + if err != nil { + fmt.Println("error creating Discord session, ", err) + return + } + + err = discord.Open() + if err != nil { + fmt.Println("error opening connection, ", err) + return + } + + // Wait here until CTRL-C or other term signal is received. + fmt.Println("Bot is now running. Press CTRL-C to exit.") + sc := make(chan os.Signal, 1) + signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) + <-sc + + // Cleanly close down the Discord session. + discord.Close() +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4e289c1 --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +# Gogodisco + +## About +This is a simple bot in Go for the Discord messaging service, created for learning purpose and to quickly experiment with features discussed in different Discord channels I frequent. +