discord-selphybot/main.go

104 lines
4.7 KiB
Go
Raw Permalink Normal View History

2018-05-17 16:30:29 +02:00
package main
import (
2019-01-10 00:16:39 +01:00
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/deckarep/golang-set"
2019-01-10 00:16:39 +01:00
"log"
"os"
"os/signal"
"syscall"
2018-05-17 16:30:29 +02:00
)
var config = readConfig()
var commands []*Command
var state *discordgo.State
2018-05-17 16:30:29 +02:00
func main() {
session, err := discordgo.New("Bot " + config.Token)
2019-01-10 00:16:39 +01:00
if err != nil {
fmt.Println("error: ", err)
return
}
defer session.Close()
2018-06-11 18:05:47 +02:00
session.AddHandler(evaluateMessage)
session.AddHandler(onJoin)
err = session.Open()
2019-01-10 00:16:39 +01:00
if err != nil {
fmt.Println("No connection:\n", err)
return
}
2018-06-11 18:05:47 +02:00
2019-01-10 00:16:39 +01:00
f, err := os.OpenFile("selphybot.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Println("Error opening log file:\n", err)
}
defer f.Close()
log.SetOutput(f)
session.UpdateStatus(0, "!help")
state = discordgo.NewState()
server, err := session.Guild(config.ServerID)
if err != nil {
fmt.Println("Guild incorrectly configured. Exiting...")
return
}
state.GuildAdd(server)
go checkAndDeleteUnusedChannels(session)
2019-01-10 00:16:39 +01:00
addCommands()
2018-06-04 02:32:40 +02:00
2019-01-10 00:16:39 +01:00
fmt.Println("Bot running. selphyWoo")
log.Println("Bot running. selphyWoo")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
2018-06-05 14:05:09 +02:00
for _, channel := range tempChannels {
session.ChannelDelete(channel.ID)
}
2019-01-10 00:16:39 +01:00
fmt.Println("Exiting...")
log.Println("Exiting...")
}
2018-06-05 14:05:09 +02:00
// I’ll just put all of the commands here for now.
func addCommands() {
2019-01-10 00:16:39 +01:00
// Moderation
registerCommand(Command{Trigger: "^[^`]*([()|DoOvVcC][-=^']?;|;[-=^']?[()|DoOpPvVcC3]|:wink:|😉)[^`]*$", Output: "<@%s> Oboe!", DeleteInput: true, OutputIsReply: true, Type: CommandTypeRegex})
registerCommand(Command{Trigger: "(\\s|\n|^)[nN][hH]([ ?.,\n]|$)", Output: "<@%s> „nh“ ist kein Wort, du Oboe!", DeleteInput: true, OutputIsReply: true, Type: CommandTypeRegex})
registerCommand(Command{Trigger: "einzigste", Output: "<@%s> Es heißt „einzige“, du Tuba.", DeleteInput: true, OutputIsReply: true, Type: CommandTypeContains})
registerCommand(Command{Trigger: "!complain", Type: CommandTypePrefix, DMOnly: true, Function: modComplain})
registerCommand(Command{Trigger: "!scomplain", Type: CommandTypePrefix, DMOnly: true, Function: selphyComplain})
registerCommand(Command{Trigger: "!beschwerde", Type: CommandTypePrefix, DMOnly: true, Function: modComplain})
2018-06-05 14:05:09 +02:00
2019-01-10 00:16:39 +01:00
for comm, _ := range config.RoleCommands {
registerCommand(Command{Trigger: comm, Type: CommandTypeFullMatch, DMOnly: true, Function: giveAgeRole})
}
2018-06-04 02:32:40 +02:00
// Fluff
2019-01-10 00:16:39 +01:00
registerCommand(Command{Trigger: "o/", Output: "\\o", Type: CommandTypeFullMatch, Cooldown: 10})
registerCommand(Command{Trigger: "\\o", Output: "o/", Type: CommandTypeFullMatch, Cooldown: 10})
registerCommand(Command{Trigger: "\\o/", Output: "/o\\", Type: CommandTypeFullMatch, Cooldown: 10})
registerCommand(Command{Trigger: "/o\\", Output: "\\o/", Type: CommandTypeFullMatch, Cooldown: 10})
registerCommand(Command{Trigger: "!heil", Output: "(ノ・ェ・)ノ Selphy (ノ・ェ・)ノ", Type: CommandTypeFullMatch, Cooldown: 30})
registerCommand(Command{Trigger: "ayy", Output: "lmao", Type: CommandTypeFullMatch, Cooldown: 0})
registerCommand(Command{Trigger: "<:selphyDango:531594585424527370>", Output: "<:dango:430669469799677953> :notes: Dango Daikazoku :notes: <:dango:430669469799677953>", Type: CommandTypeFullMatch, Cooldown: 10800})
registerCommand(Command{Trigger: "praise the sun", Output: "If only I could be so grossly incandescent \\\\[T]/", Type: CommandTypeContains, IgnoreCase: true, Cooldown: 85600})
2018-06-04 02:32:40 +02:00
2019-01-10 00:16:39 +01:00
// Information
registerCommand(Command{Trigger: "!welcome", OutputEmbed: getWelcomeEmbed(), Type: CommandTypeFullMatch, DMOnly: true})
registerCommand(Command{Trigger: "!mods", Output: "Bei Fragen, Problemen und Beschwerden wende dich bitte an die Moderatoren oder schick mir eine Nachricht beginnend mit !complain, um dich anonym zu beschweren.\nAktuell anwesende Mods werden dir rechts mit dem Rang „Maid“ angezeigt.", Type: CommandTypeFullMatch})
2018-06-04 02:32:40 +02:00
// Features :Pog:
registerCommand(Command{Trigger: "!vc ", Type: CommandTypePrefix, Function: parseVoiceChannelCommand, AllowedChannels: mapset.NewSetWith("525852491976278016")})
2019-01-10 00:16:39 +01:00
// Admin and/or debug
registerCommand(Command{Trigger: "<@%s> <3", Output: "<@%s> <3", Type: CommandTypeFullMatch, AdminOnly: true, OutputIsReply: true, RequiresMention: true})
registerCommand(Command{Trigger: "echo", Type: CommandTypePrefix, Function: echoMessage, AdminOnly: true})
2019-01-10 00:16:39 +01:00
// This needs to be the last command because getHelpEmbed is evaluated here once, not on every function call. Putting it too early will result in missing commands in the output.
registerCommand(Command{Trigger: "!help", OutputEmbed: getHelpEmbed(), Type: CommandTypeFullMatch})
2018-07-22 15:43:46 +02:00
2019-01-10 00:16:39 +01:00
fmt.Printf("Successfully initialized %d commands\n", len(commands))
log.Printf("Successfully initialized %d commands", len(commands))
2018-05-17 16:30:29 +02:00
}