Setup basic discord session
This commit is contained in:
parent
571aa3650e
commit
4b62347d5d
5 changed files with 80 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bot.token
|
||||
bingobot
|
||||
11
go.mod
Normal file
11
go.mod
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module gitlab.com/whom/bingobot
|
||||
|
||||
go 1.23.2
|
||||
|
||||
require 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
|
||||
)
|
||||
12
go.sum
Normal file
12
go.sum
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
|
||||
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
45
main.go
Normal file
45
main.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var (
|
||||
Token = flag.String("token", "", "Bot authentication token")
|
||||
App = flag.String("app", "", "Application ID")
|
||||
Guild = flag.String("guild", "", "Guild ID") // Do we want it to be tied to one server?
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *App == "" {
|
||||
log.Fatal("application id is not set")
|
||||
}
|
||||
|
||||
startBot()
|
||||
}
|
||||
|
||||
func startBot() {
|
||||
session, _ := discordgo.New("Bot " + *Token)
|
||||
|
||||
err := session.Open()
|
||||
if err != nil {
|
||||
log.Fatalf("could not open session: %s", err)
|
||||
}
|
||||
|
||||
sigch := make(chan os.Signal, 1)
|
||||
signal.Notify(sigch, os.Interrupt)
|
||||
<-sigch
|
||||
|
||||
log.Printf("shutting down gracefully...")
|
||||
|
||||
err = session.Close()
|
||||
if err != nil {
|
||||
log.Printf("could not close session gracefully: %s", err)
|
||||
}
|
||||
}
|
||||
10
start.sh
Executable file
10
start.sh
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
APP_ID=1303795224857804851
|
||||
|
||||
if [ ! -f "bot.token" ]; then
|
||||
echo "can't startup: bot.token file missing"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
BOT_TOKEN=$(cat bot.token)
|
||||
|
||||
./bingobot --app ${APP_ID} --token ${BOT_TOKEN}
|
||||
Loading…
Add table
Add a link
Reference in a new issue