starboard: Implement 'pgqstar' command

master 0.6
Luther Wen Xu 2019-11-20 16:34:14 +07:00
parent 0cce403a83
commit b843195845
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 37 additions and 0 deletions

@ -4,6 +4,7 @@ import (
"crypto/rand"
"fmt"
"math"
"strings"
"time"
"github.com/bwmarrin/discordgo"
@ -30,6 +31,9 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Content == "pgqprestige" {
handlePrestigeRequest(s, m)
}
if strings.HasPrefix(m.Content, "pgqstar ") {
handleStarRequest(s, m)
}
}
func handleXPRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
@ -126,3 +130,36 @@ func checkPrestigeReact(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
),
)
}
func handleStarRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
commandSplit := strings.SplitN(m.Content, " ", 2)
if len(commandSplit) == 1 {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
linkSplit := strings.SplitN(m.Content, "/", 7)
if len(linkSplit) < 7 {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
if linkSplit[0] != "https" && linkSplit[0] != "http" {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
if linkSplit[2] != "discordapp.com" && !strings.HasSuffix(linkSplit[2], ".discordapp.com") {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
if linkSplit[3] != "channels" {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
if linkSplit[4] != m.GuildID {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
return
}
err := s.MessageReactionAdd(linkSplit[5], linkSplit[6], starEmoji)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
}
}