commit
3dd71c9445
|
@ -17,6 +17,10 @@ steps:
|
|||
- ./discord-buttsbot-go -test
|
||||
- name: discord
|
||||
image: appleboy/drone-discord
|
||||
when:
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
settings:
|
||||
webhook_id:
|
||||
from_secret: discord_webhook_id
|
||||
|
|
45
buttsbot.go
45
buttsbot.go
|
@ -5,8 +5,10 @@ import (
|
|||
"fmt"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
@ -40,6 +42,7 @@ func main() {
|
|||
|
||||
//Handlers
|
||||
Session.AddHandler(ready)
|
||||
Session.AddHandler(messageCreate)
|
||||
|
||||
//Open a connection to Discord
|
||||
err = Session.Open()
|
||||
|
@ -66,3 +69,45 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
|||
s.UpdateStatus(0, "with butts!")
|
||||
s.ChannelMessageSend(bot_channel, "This isn't a butt...")
|
||||
}
|
||||
|
||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
//Ignore messages by itself
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
|
||||
//Check if the bot was mentioned
|
||||
if isUserMentioned(m, s.State.User) == true {
|
||||
s.ChannelMessageSend(m.ChannelID, textToButt(m, s))
|
||||
return
|
||||
}
|
||||
|
||||
//Replace words in random messages
|
||||
if rand.Intn(100) > 85 {
|
||||
s.ChannelMessageSend(m.ChannelID, textToButt(m, s))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//Easy way to check if a user was mentioned in a message
|
||||
func isUserMentioned(m *discordgo.MessageCreate, u *discordgo.User) bool {
|
||||
//mentioned := false
|
||||
for _, user := range m.Mentions {
|
||||
if user.ID == u.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
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, " ")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue