diff --git a/commands/owner.go b/commands/owner.go index f041182..dae896f 100644 --- a/commands/owner.go +++ b/commands/owner.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "math/rand" "strings" "github.com/bwmarrin/discordgo" @@ -26,7 +27,13 @@ func playingMsgCommand(s *discordgo.Session, m *discordgo.Message) { // Displays current playing message if it's only that if len(commandStrings) == 1 { - _, err := s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Current playing message is: `%v` \n\n To change the message please use `%vplayingmsg [new message]`", config.PlayingMsg, guildPrefix)) + var playingMsgs string + misc.MapMutex.Lock() + for _, msg := range config.PlayingMsg { + playingMsgs += fmt.Sprintf("\n`%v`,", msg) + } + misc.MapMutex.Unlock() + _, err := s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Current playing messages are: %v \n\nTo add more messages please use `%vplayingmsg [new message]`", playingMsgs, guildPrefix)) if err != nil { _, err = s.ChannelMessageSend(guildBotLog, err.Error()+"\n"+misc.ErrorLocation(err)) if err != nil { @@ -39,7 +46,7 @@ func playingMsgCommand(s *discordgo.Session, m *discordgo.Message) { // Changes and writes new playing message to storage misc.MapMutex.Lock() - config.PlayingMsg = commandStrings[1] + config.PlayingMsg = append(config.PlayingMsg, commandStrings[1]) err := config.WriteConfig() if err != nil { misc.MapMutex.Unlock() @@ -49,13 +56,13 @@ func playingMsgCommand(s *discordgo.Session, m *discordgo.Message) { misc.MapMutex.Unlock() // Refreshes playing message - err = s.UpdateStatus(0, config.PlayingMsg) + err = s.UpdateStatus(0, commandStrings[1]) if err != nil { misc.CommandErrorHandler(s, m, err, guildBotLog) return } - _, err = s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Success! New playing message is: `%v`", config.PlayingMsg)) + _, err = s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Success! New playing message added is: `%v`", commandStrings[1])) if err != nil { _, err = s.ChannelMessageSend(guildBotLog, err.Error()+"\n"+misc.ErrorLocation(err)) if err != nil { @@ -65,6 +72,65 @@ func playingMsgCommand(s *discordgo.Session, m *discordgo.Message) { } } +// Handles removing a playing message +func removePlayingMsgCommand(s *discordgo.Session, m *discordgo.Message) { + + if m.Author.ID != config.OwnerID { + return + } + + misc.MapMutex.Lock() + guildPrefix := misc.GuildMap[m.GuildID].GuildConfig.Prefix + guildBotLog := misc.GuildMap[m.GuildID].GuildConfig.BotLog.ID + misc.MapMutex.Unlock() + + commandStrings := strings.SplitN(m.Content, " ", 2) + + if len(commandStrings) == 1 { + _, err := s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Usage: `%vremoveplayingmsg [msg]`", guildPrefix)) + if err != nil { + _, err = s.ChannelMessageSend(guildBotLog, err.Error()+"\n"+misc.ErrorLocation(err)) + if err != nil { + return + } + return + } + return + } + + // Changes and removes playing msg from storage + misc.MapMutex.Lock() + var index int + for i, msg := range config.PlayingMsg { + if msg == commandStrings[1] { + index = i + break + } + } + config.PlayingMsg = append(config.PlayingMsg[:index], config.PlayingMsg[index+1:]...) + err := config.WriteConfig() + if err != nil { + misc.MapMutex.Unlock() + misc.CommandErrorHandler(s, m, err, guildBotLog) + return + } + + // Refreshes playing message + randMsg := rand.Intn(len(config.PlayingMsg)-1) + err = s.UpdateStatus(0, config.PlayingMsg[randMsg]) + if err != nil { + misc.MapMutex.Unlock() + misc.CommandErrorHandler(s, m, err, guildBotLog) + return + } + misc.MapMutex.Unlock() + + _, err = s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Success! Removed playing message: `%v`", commandStrings[1])) + if err != nil { + _, _ = s.ChannelMessageSend(guildBotLog, err.Error()+"\n"+misc.ErrorLocation(err)) + } +} + // Prints in how many servers the BOT is func serversCommand(s *discordgo.Session, m *discordgo.Message) { @@ -107,7 +173,15 @@ func init() { add(&command{ execute: playingMsgCommand, trigger: "playingmsg", - desc: "Prints or changes the current BOT playing message.", + desc: "Prints or adds a BOT playing message.", + elevated: true, + admin: true, + }) + add(&command{ + execute: removePlayingMsgCommand, + trigger: "removeplayingmsg", + aliases: []string{"killplayingmsg"}, + desc: "Removes a BOT playing message.", elevated: true, admin: true, }) diff --git a/commands/schedule.go b/commands/schedule.go index e60438e..f62b549 100644 --- a/commands/schedule.go +++ b/commands/schedule.go @@ -297,6 +297,7 @@ func init() { add(&command{ execute: scheduleCommand, trigger: "schedule", + aliases: []string{"schedul", "schedu", "schedle", "schdule", "animeschedule", "anischedule"}, desc: "Print anime air times SUBBED. Add a day to specify a day", category: "normal", DMAble: true, diff --git a/commands/stats.go b/commands/stats.go index 589a771..3590c0d 100644 --- a/commands/stats.go +++ b/commands/stats.go @@ -518,7 +518,7 @@ func init() { add(&command{ execute: showStats, trigger: "stats", - aliases: []string{"channelstats", "channels"}, + aliases: []string{"channelstats", "channels", "stat", "chanstat", "chanstats", "statss"}, desc: "Prints all channel stats.", elevated: true, category: "stats", diff --git a/config/config.go b/config/config.go index a1dcba4..62f9e92 100644 --- a/config/config.go +++ b/config/config.go @@ -16,7 +16,7 @@ var ( BotLogID string OwnerID string Website string - PlayingMsg string + PlayingMsg []string RedditAppName string RedditAppSecret string DiscordAppSecret string @@ -38,7 +38,7 @@ type configStruct struct { VoteChannelCategoryID string `json:"VoteChannelCategoryID"` Kaguya string `json:"Kaguya"` MsgAttachRemoval string `json:"MsgAttachRemoval"` - PlayingMsg string `json:"PlayingMsg"` + PlayingMsg []string `json:"PlayingMsg"` } type configSecrets struct { diff --git a/misc/events.go b/misc/events.go index 4ed8eb3..d9e37fa 100644 --- a/misc/events.go +++ b/misc/events.go @@ -43,7 +43,11 @@ func StatusReady(s *discordgo.Session, e *discordgo.Ready) { } // Update playing status - _ = s.UpdateStatus(0, config.PlayingMsg) + MapMutex.Lock() + rand.Seed(time.Now().UnixNano()) + randInt := rand.Intn(len(config.PlayingMsg)) + _ = s.UpdateStatus(0, config.PlayingMsg[randInt]) + MapMutex.Unlock() // Sends server count to bot list sites if it's the public ZeroTsu sendServers(s) @@ -166,6 +170,13 @@ func UnbanEmbed(s *discordgo.Session, user *UserInfo, mod string, botLog string) func TwentyMinTimer(s *discordgo.Session, e *discordgo.Ready) { for range time.NewTicker(20 * time.Minute).C { + // Update playing status + MapMutex.Lock() + rand.Seed(time.Now().UnixNano()) + randInt := rand.Intn(len(config.PlayingMsg)) + _ = s.UpdateStatus(0, config.PlayingMsg[randInt]) + MapMutex.Unlock() + MapMutex.Lock() for _, guild := range e.Guilds {