added stop and fixed override

This commit is contained in:
DutchEllie 2021-05-25 11:15:41 +02:00
parent 614c0cd42c
commit 810d3aa616
3 changed files with 28 additions and 2 deletions

View File

@ -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)

View File

@ -21,6 +21,9 @@ type application struct {
adminroles *mysql.AdminRolesModel
trigger string
allBadWords map[string][]string
active bool
stop bool
}
func main() {

View File

@ -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) {