commit
3dd71c9445
|
@ -17,6 +17,10 @@ steps:
|
||||||
- ./discord-buttsbot-go -test
|
- ./discord-buttsbot-go -test
|
||||||
- name: discord
|
- name: discord
|
||||||
image: appleboy/drone-discord
|
image: appleboy/drone-discord
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
- failure
|
||||||
settings:
|
settings:
|
||||||
webhook_id:
|
webhook_id:
|
||||||
from_secret: discord_webhook_id
|
from_secret: discord_webhook_id
|
||||||
|
|
45
buttsbot.go
45
buttsbot.go
|
@ -5,8 +5,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,6 +42,7 @@ func main() {
|
||||||
|
|
||||||
//Handlers
|
//Handlers
|
||||||
Session.AddHandler(ready)
|
Session.AddHandler(ready)
|
||||||
|
Session.AddHandler(messageCreate)
|
||||||
|
|
||||||
//Open a connection to Discord
|
//Open a connection to Discord
|
||||||
err = Session.Open()
|
err = Session.Open()
|
||||||
|
@ -66,3 +69,45 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
s.UpdateStatus(0, "with butts!")
|
s.UpdateStatus(0, "with butts!")
|
||||||
s.ChannelMessageSend(bot_channel, "This isn't a butt...")
|
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