2019-08-05 22:33:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"github.com/bwmarrin/disgord/x/mux"
|
2020-10-10 19:34:17 +00:00
|
|
|
"io/ioutil"
|
2019-08-05 22:33:07 +00:00
|
|
|
"log"
|
2019-08-07 02:52:10 +00:00
|
|
|
"math/rand"
|
2019-08-05 22:33:07 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2019-08-07 02:52:10 +00:00
|
|
|
"time"
|
2019-08-05 22:33:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var Session, _ = discordgo.New()
|
|
|
|
var bot_token string
|
|
|
|
var bot_channel string
|
2020-04-26 06:57:21 +00:00
|
|
|
var bot_admin_role string
|
2019-08-05 22:33:07 +00:00
|
|
|
var Router = mux.New()
|
|
|
|
|
|
|
|
func init() {
|
2019-08-07 02:52:10 +00:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
2019-08-05 22:33:07 +00:00
|
|
|
flag.StringVar(&bot_token, "t", "", "Discord Authentication Token")
|
|
|
|
flag.StringVar(&bot_channel, "bc", "", "Bot status channel")
|
|
|
|
flag.Parse()
|
|
|
|
if os.Getenv("DISCORD_TOKEN") != "" {
|
|
|
|
Session.Token = "Bot " + os.Getenv("DISCORD_TOKEN")
|
|
|
|
} else {
|
|
|
|
Session.Token = "Bot " + bot_token
|
|
|
|
}
|
|
|
|
if os.Getenv("DISCORD_BOT_CHANNEL") != "" {
|
|
|
|
bot_channel = os.Getenv("DISCORD_BOT_CHANNEL")
|
|
|
|
}
|
2020-04-26 06:57:21 +00:00
|
|
|
if os.Getenv("POCKETBOT_ADMIN_ROLE") != "" {
|
|
|
|
bot_admin_role = os.Getenv("POCKETBOT_ADMIN_ROLE")
|
|
|
|
}
|
2019-08-05 22:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
fmt.Println("pocketbot")
|
|
|
|
//flag.Parse()
|
|
|
|
if Session.Token == "" {
|
|
|
|
log.Println("You must provide a Discord auth token!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//Handlers
|
|
|
|
Session.AddHandler(ready)
|
|
|
|
Session.AddHandler(Router.OnMessageCreate)
|
|
|
|
|
2019-08-06 00:57:23 +00:00
|
|
|
//Set the command prefix
|
|
|
|
if os.Getenv("POCKETBOT_PREFIX") != "" {
|
|
|
|
Router.Prefix = os.Getenv("POCKETBOT_PREFIX")
|
|
|
|
} else {
|
|
|
|
Router.Prefix = "!"
|
|
|
|
}
|
|
|
|
|
2019-08-05 22:33:07 +00:00
|
|
|
// Register the build-in help command.
|
|
|
|
Router.Route("help", "Display this message.", Router.Help)
|
2019-08-06 00:49:23 +00:00
|
|
|
Router.Route("swear", "Make me swear!", getSwear)
|
2019-08-06 01:05:30 +00:00
|
|
|
Router.Route("maki", "It's Maki Monday my dudes!", makiMonday)
|
|
|
|
Router.Route("monday", "It's Maki Monday my dudes!", makiMonday)
|
2019-08-06 01:10:18 +00:00
|
|
|
Router.Route("mixes", "Post the link to my fire mixtapes!", postMixes)
|
2019-08-07 02:51:53 +00:00
|
|
|
Router.Route("rmix", "Post a random mix!", getRandomMix)
|
2019-08-06 23:59:18 +00:00
|
|
|
Router.Route("xkcd", "Post a specific, random, or the latest XKCD comic", getXKCD)
|
2019-08-07 01:45:09 +00:00
|
|
|
Router.Route("restart", "Restart the bot.", restartBot)
|
2019-08-07 01:49:49 +00:00
|
|
|
Router.Route("kill", "Restart the bot.", restartBot)
|
2020-04-26 07:19:29 +00:00
|
|
|
Router.Route("sleep", "Something about sleeping...", goToSleep)
|
2020-04-26 08:45:16 +00:00
|
|
|
Router.Route("setplaying", "Set the nowplaying message for the bot.", setNowPlaying)
|
2020-05-01 05:46:47 +00:00
|
|
|
Router.Route("roll", "Roll some dice!", rollDice)
|
2020-05-21 01:40:22 +00:00
|
|
|
Router.Route("conch", "Ask the Magic Conch™ shell to predict the future!", askConch)
|
2020-05-01 05:48:09 +00:00
|
|
|
Router.Route("uwu", "Say UwU", sayUwU)
|
2019-08-05 22:33:07 +00:00
|
|
|
|
|
|
|
//Open a connection to Discord
|
|
|
|
err = Session.Open()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error opening connection to Discord, %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
//Wait for a CTRL-C
|
|
|
|
log.Printf("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
|
|
|
|
Session.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
2020-10-10 19:34:17 +00:00
|
|
|
playingstatus := "with droids!"
|
|
|
|
_, err := os.Stat("userdata/nowplaying.txt")
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
content, err := ioutil.ReadFile("userdata/nowplaying.txt")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
playingstatus = string(content)
|
|
|
|
}
|
|
|
|
s.UpdateStatus(0, playingstatus)
|
2020-04-26 06:10:20 +00:00
|
|
|
if os.Getenv("POCKETBOT_STARTUP_MESSAGE") == "TRUE" {
|
|
|
|
s.ChannelMessageSend(bot_channel, "This isn't Tatooine...")
|
|
|
|
}
|
2019-08-05 22:33:07 +00:00
|
|
|
}
|