CookieMod - v0.0.2

This commit is contained in:
Jann Pächnatz 2023-12-01 22:40:08 +01:00
parent 34e4ead4ff
commit 8ea26d88d0
7 changed files with 138 additions and 3 deletions

1
PERMISSIONS.md Normal file
View File

@ -0,0 +1 @@
# Permissions

View File

@ -4,11 +4,63 @@
### Installation
Please don't touch the db folder
Installation files explanation
|Path |Description |
|----------------|-----------------------|
|db/* |Database (Badger DB) |
|data/* |Configuration, etc.. |
|data/config.json|Main configuration file|
#### ⚠️ **Warning** ⚠️
Don't touch the db folder or the included files if you don't know what you are doing. The whole user data is stored in there and can be corrupted if you modify the database.
#### Example config.json
```json
{
"token": "YOUR_TOKEN123456789",
"guildID": "YOUR_GUILDID123456789"
}
```
#### Example perms.json
```json
{
"roles": [
{
"roleID": "YOUR_ROLE_ID123456789",
"perms": [
"cookiebot.mod.ban",
"cookiebot.mod.kick",
"cookiebot.mod.mute",
"cookiebot.mod.timeout",
"cookiebot.mod.tempban",
"cookiebot.user.send.files",
"cookiebot.user.send.content",
"cookiebot.user.send.urls",
"cookiebot.admin",
]
},
{
"roleID": "YOUR_ROLE_ID123456789",
"perms": [
"cookiebot.user.report",
"cookiebot.user.stats",
]
}
]
}
```
### Features
- Chat Moderation
- Polls
- User Bot Prevention
- Twitch / YouTube integration (Notifications)
- Twitch / YouTube integration (Notifications)

64
bot.go
View File

@ -3,7 +3,11 @@ package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
)
func CheckInstallationFolder(path string) {
@ -26,5 +30,65 @@ func main() {
log.Info("Starting CookieMod 🍪")
CheckInstallationFolder("db")
CheckInstallationFolder("data")
session, err := discordgo.New("Bot " + "TOKEN")
if err != nil {
log.Fatal(err)
}
// Register the messageCreate func as a callback for MessageCreate events.
session.AddHandler(messageCreate)
// In this example, we only care about receiving message events.
session.Identify.Intents = discordgo.IntentsGuildMessages
// Open a websocket connection to Discord and begin listening.
err = session.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
// Wait here until CTRL-C or other term signal is received.
log.Info("CookieMod 🍪 is running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
// Cleanly close down the Discord session.
log.Info("CookieMod 🍪 is stopping.")
session.Close()
}
// This function will be called (due to AddHandler above) every time a new
// message is created on any channel that the authenticated bot has access to.
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
// This isn't required in this specific example but it's a good practice.
if m.Author.ID == s.State.User.ID {
return
}
log.Info(fmt.Sprintf("Neue Nachricht: %s", m.Content))
// If the message is "ping" reply with "Pong!"
if m.Content == "!time" {
now := time.Now()
hour, min, sec := now.Hour(), now.Minute(), now.Second()
hourStr := fmt.Sprint(int(hour))
minStr := fmt.Sprint(int(min))
secStr := fmt.Sprint(int(sec))
if len(hourStr) < 2 {
hourStr = "0" + hourStr
}
if len(minStr) < 2 {
minStr = "0" + minStr
}
if len(secStr) < 2 {
secStr = "0" + secStr
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s:%s:%s", hourStr, minStr, secStr))
}
// If the message is "pong" reply with "Ping!"
if m.Content == "pong" {
s.ChannelMessageSend(m.ChannelID, "Ping!")
}
}

1
cmds.go Normal file
View File

@ -0,0 +1 @@
package main

7
go.mod
View File

@ -2,10 +2,15 @@ module git.capy.sh/jann/cookiemod
go 1.21.1
require github.com/fatih/color v1.16.0
require (
github.com/bwmarrin/discordgo v0.27.1
github.com/fatih/color v1.16.0
)
require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.14.0 // indirect
)

11
go.sum
View File

@ -1,11 +1,22 @@
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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=

1
translations.csv Normal file
View File

@ -0,0 +1 @@
de-DE,cookiemod.time,
1 de-DE cookiemod.time