Replace random words with butt when mentioned

pull/2/head
pocketjawa 2019-04-27 13:38:04 -04:00
parent 80b71a47fb
commit 2c726283dc
1 changed files with 15 additions and 1 deletions

View File

@ -5,8 +5,10 @@ import (
"fmt"
"github.com/bwmarrin/discordgo"
"log"
"math/rand"
"os"
"os/signal"
"strings"
"syscall"
)
@ -76,7 +78,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
//Check if the bot was mentioned
if isUserMentioned(m, s.State.User) == true {
s.ChannelMessageSend(m.ChannelID, "butt")
s.ChannelMessageSend(m.ChannelID, textToButt(m, s))
}
}
@ -90,3 +92,15 @@ func isUserMentioned(m *discordgo.MessageCreate, u *discordgo.User) bool {
}
return false
}
//Replace words with butt
func textToButt(m *discordgo.MessageCreate, s *discordgo.Session) string {
cleanmessage, _ := m.ContentWithMoreMentionsReplaced(s)
words := strings.Fields(cleanmessage)
for i, _ := range words {
if rand.Intn(10) > 7 {
words[i] = "butt"
}
}
return strings.Join(words, " ")
}