diff --git a/buttsbot.go b/buttsbot.go index 01aaff0..34f9975 100644 --- a/buttsbot.go +++ b/buttsbot.go @@ -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, " ") +}