diff --git a/discord/discord.go b/discord/discord.go index dae77d8..dfc8d71 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -40,6 +40,8 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message /* --- Bot commands for words --- */ case "pepes": app.sendManyPepes(s, m, splitCommand) + case "stop": + app.stopRequest(s, m) /* --- Bot commands, but only admins --- */ case "addword": app.addWord(s, m, splitCommand) diff --git a/discord/main.go b/discord/main.go index 012aff3..d3328df 100644 --- a/discord/main.go +++ b/discord/main.go @@ -21,6 +21,9 @@ type application struct { adminroles *mysql.AdminRolesModel trigger string allBadWords map[string][]string + + active bool + stop bool } func main() { diff --git a/discord/simple.go b/discord/simple.go index ac6fdf5..8b30add 100644 --- a/discord/simple.go +++ b/discord/simple.go @@ -147,14 +147,35 @@ func (app *application) sendManyPepes(s *discordgo.Session, m *discordgo.Message if (val <= 0 || val > 3) && !override { s.ChannelMessageSend(m.ChannelID, "The amount has to be > 0 and < 4") + return } else if val <= 0 && override { s.ChannelMessageSend(m.ChannelID, "I know you're admin and all, but you still have to provide a positive integer amount of pepes to send...") + return } + app.active = true + for i := 0; i < val; i++ { - go app.sendPepe(s, m) - //time.Sleep(time.Millisecond * 500) + if app.stop { + app.stop = false + break + } + app.sendPepe(s, m) + time.Sleep(time.Millisecond * 500) } + + app.active = false +} + +func (app *application) stopRequest(s *discordgo.Session, m *discordgo.MessageCreate) { + if app.active { + app.stop = true + s.ChannelMessageSend(m.ChannelID, "Emergency stop called, hopefully I stop now") + } else { + app.stop = false + s.ChannelMessageSend(m.ChannelID, "But I wasn't doing anything!") + } + } func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCreate) {