First commit

This commit is contained in:
Alex Thomassen 2020-02-17 12:43:21 +01:00
commit aab9fb30f7
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
8 changed files with 116 additions and 0 deletions

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
# http://editorconfig.org
root = true
[*]
end_of_line = lf
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

2
.env.example Normal file
View File

@ -0,0 +1,2 @@
DISCORD_BOT_TOKEN=Your-Discord-Bot-Token-Here
REACT_USER_ID="81332863928119296"

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text eol=lf

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.env
# Ignore binary files
moyaireactbot
moyaireactbot.exe

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# MoyaiReactBot
1. Copy file `.env.example` to `.env`
2. Add your Discord bot token to `.env`
3. Run `go build`
4. Run `./moyaireactbot`
5. Hopefully it runs idk.

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module moyaireactbot
go 1.13
require (
github.com/bwmarrin/discordgo v0.20.2
github.com/joho/godotenv v1.3.0
)

8
go.sum Normal file
View File

@ -0,0 +1,8 @@
github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20=
github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
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=

72
main.go Normal file
View File

@ -0,0 +1,72 @@
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
var (
token string
reactUserID string
)
func init() {
err := godotenv.Load()
if err != nil {
fmt.Println("Could not load .env file: ", err)
os.Exit(1)
}
token = os.Getenv("DISCORD_BOT_TOKEN")
reactUserID = os.Getenv("REACT_USER_ID")
if token == "" || reactUserID == "" {
fmt.Println("DISCORD_BOT_TOKEN and REACT_USER_ID variables have to be set.")
os.Exit(1)
}
}
func main() {
bot, err := discordgo.New("Bot " + token)
if err != nil {
fmt.Println("Could not create Discord bot instance:", err)
return
}
bot.AddHandler(messageCreate)
err = bot.Open()
if err != nil {
fmt.Println("Error opening connection to Discord:", err)
return
}
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
bot.Close()
}
func messageCreate(sess *discordgo.Session, msg *discordgo.MessageCreate) {
if msg.Author.ID != reactUserID {
return
}
channelID := msg.ChannelID
msgID := msg.ID
err := sess.MessageReactionAdd(channelID, msgID, "🗿")
if err != nil {
fmt.Println("Error occurred reacting to message ID: "+msgID, err)
}
}