2019-08-06 00:49:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-26 06:56:15 +00:00
|
|
|
"context"
|
2019-08-07 02:51:53 +00:00
|
|
|
"encoding/json"
|
2019-08-06 00:49:23 +00:00
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"github.com/bwmarrin/disgord/x/mux"
|
2019-08-06 23:59:18 +00:00
|
|
|
"github.com/nishanths/go-xkcd"
|
2019-08-06 00:49:23 +00:00
|
|
|
"io/ioutil"
|
2019-08-07 01:45:09 +00:00
|
|
|
"log"
|
2019-08-07 02:51:53 +00:00
|
|
|
"math/rand"
|
2019-08-06 00:49:23 +00:00
|
|
|
"net/http"
|
2019-08-07 01:45:09 +00:00
|
|
|
"os"
|
2019-08-06 23:59:18 +00:00
|
|
|
"regexp"
|
|
|
|
"strconv"
|
2019-08-06 00:49:23 +00:00
|
|
|
)
|
|
|
|
|
2019-08-07 01:44:49 +00:00
|
|
|
//Check member roles
|
|
|
|
func checkRole(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context, roleid string) bool {
|
|
|
|
if ctx.IsPrivate {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
channel, _ := s.Channel(m.ChannelID)
|
|
|
|
guild := channel.GuildID
|
|
|
|
member, _ := s.GuildMember(guild, m.Author.ID)
|
|
|
|
for _, role := range member.Roles {
|
|
|
|
if role == roleid {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-08-06 00:49:23 +00:00
|
|
|
//Generate a heckin swear word
|
|
|
|
func getSwear(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
|
|
|
resp := ""
|
|
|
|
swear, err := http.Get("https://swear.jawa.moe/")
|
|
|
|
if err != nil {
|
|
|
|
resp = "Error fetching swear: " + err.Error()
|
|
|
|
}
|
|
|
|
defer swear.Body.Close()
|
|
|
|
|
|
|
|
if swear.StatusCode == http.StatusOK {
|
|
|
|
body, err := ioutil.ReadAll(swear.Body)
|
|
|
|
if err != nil {
|
|
|
|
resp = "Error fetching swear: " + err.Error()
|
|
|
|
}
|
|
|
|
resp = string(body)
|
|
|
|
}
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
}
|
2019-08-06 01:05:30 +00:00
|
|
|
|
|
|
|
//Post the Maki Monday pic!
|
|
|
|
func makiMonday(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
|
|
|
resp := "https://maki.jawa.moe/monday.png"
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
}
|
2019-08-06 01:10:18 +00:00
|
|
|
|
|
|
|
//Post link to mixes B)
|
|
|
|
func postMixes(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
|
|
|
resp := "https://maki.jawa.moe/mixes/"
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
}
|
2019-08-06 23:59:18 +00:00
|
|
|
|
2019-08-07 02:51:53 +00:00
|
|
|
//Post a link to a random mix
|
|
|
|
func getRandomMix(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
|
|
|
|
|
|
|
//Define mix details
|
|
|
|
type Mix struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Mtime string `json:"mtime"`
|
|
|
|
Size int `json:"size"`
|
|
|
|
}
|
|
|
|
|
|
|
|
mixresp, err := http.Get("https://maki.jawa.moe/mixesjson/")
|
|
|
|
if err != nil {
|
|
|
|
resp := "Error fetching mixes: " + err.Error()
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer mixresp.Body.Close()
|
|
|
|
|
|
|
|
if mixresp.StatusCode == http.StatusOK {
|
|
|
|
var mixes []*Mix
|
|
|
|
err = json.NewDecoder(mixresp.Body).Decode(&mixes)
|
|
|
|
rmix := mixes[rand.Intn(len(mixes))]
|
|
|
|
resp := "https://maki.jawa.moe/mixes/" + rmix.Name
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 23:59:18 +00:00
|
|
|
//Post XKCD comic!
|
|
|
|
func getXKCD(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
|
|
|
resp := ""
|
|
|
|
xkclient := xkcd.NewClient()
|
|
|
|
var err error
|
|
|
|
var comic xkcd.Comic
|
|
|
|
var arg string
|
|
|
|
if len(ctx.Fields) > 1 {
|
|
|
|
arg = ctx.Fields[1]
|
|
|
|
} else {
|
|
|
|
arg = "random"
|
|
|
|
}
|
|
|
|
matchedNum, _ := regexp.MatchString(`[0-9]+`, arg)
|
|
|
|
if arg == "latest" {
|
2020-04-26 06:56:15 +00:00
|
|
|
comic, err = xkclient.Latest(context.Background())
|
2019-08-06 23:59:18 +00:00
|
|
|
} else if matchedNum {
|
|
|
|
comicNum, _ := strconv.Atoi(arg)
|
2020-04-26 06:56:15 +00:00
|
|
|
comic, err = xkclient.Get(context.Background(), comicNum)
|
2019-08-06 23:59:18 +00:00
|
|
|
} else {
|
2020-04-26 06:56:15 +00:00
|
|
|
latestcomic, _ := xkclient.Latest(context.Background())
|
|
|
|
randcomic := rand.Intn(latestcomic.Number)
|
|
|
|
comic, err = xkclient.Get(context.Background(), randcomic)
|
2019-08-06 23:59:18 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
resp = err.Error()
|
|
|
|
}
|
|
|
|
resp = comic.ImageURL
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
}
|
2019-08-07 01:45:09 +00:00
|
|
|
|
|
|
|
//Restart the bot
|
|
|
|
func restartBot(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) {
|
2020-04-26 06:57:21 +00:00
|
|
|
if !checkRole(s, m, ctx, bot_admin_role) {
|
2019-08-07 01:45:09 +00:00
|
|
|
resp := "OwO you aren't my daddy..."
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp := "Goodnight ;-;"
|
|
|
|
s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
|
Session.Close()
|
|
|
|
log.Println("brb dying at the request of ", m.Author.String())
|
|
|
|
os.Exit(0)
|
|
|
|
}
|