messageHandler, changing project name slightly
This commit is contained in:
@ -28,17 +28,17 @@ func (c *ConfigRegister) LoadConf() *ConfigRegister {
|
||||
var CommandRegister = make(
|
||||
map[string]func(
|
||||
s *discordgo.Session,
|
||||
m *discordgo.MessageCreate))
|
||||
m *discordgo.MessageCreate,
|
||||
message string))
|
||||
|
||||
func SetCommand(aliases []string, command func(
|
||||
s *discordgo.Session,
|
||||
m *discordgo.MessageCreate),
|
||||
discord *discordgo.Session) {
|
||||
m *discordgo.MessageCreate,
|
||||
message string)) {
|
||||
for _, alias := range aliases {
|
||||
CommandRegister[alias] = command
|
||||
log.Printf("added %s to Register", alias)
|
||||
}
|
||||
discord.AddHandler(command)
|
||||
}
|
||||
|
||||
var Config ConfigRegister
|
||||
|
||||
@ -24,21 +24,26 @@ func createAudio(msg string) (filename string, file *bytes.Reader) {
|
||||
return
|
||||
}
|
||||
|
||||
func MessageHelp(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
func MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
for alias, command := range CommandRegister {
|
||||
if strings.HasPrefix(m.Content, alias) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
if m.Content == "/ggd help" {
|
||||
// build list of possible commands
|
||||
return
|
||||
var message string = strings.TrimPrefix(m.Content, alias)
|
||||
fmt.Println(message)
|
||||
command(s, m, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
func MessageHelp(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||
// build list of possible commands
|
||||
fmt.Println(message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||
if m.Content == "ping" {
|
||||
s.ChannelMessageSend(m.ChannelID, "Pong!")
|
||||
}
|
||||
@ -48,15 +53,8 @@ func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
}
|
||||
}
|
||||
|
||||
func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
var prefix string = "/ggd tts"
|
||||
if strings.HasPrefix(m.Content, prefix) {
|
||||
var message string = strings.TrimPrefix(m.Content, prefix)
|
||||
func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||
var cleanMessage string = prepareTTSMessage(message)
|
||||
filename, file := createAudio(cleanMessage)
|
||||
s.ChannelFileSend(m.ChannelID, filename, file)
|
||||
}
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module ariona.fr/git/gator/gogodisco
|
||||
module ariona.fr/git/gator/gogodiscordo
|
||||
|
||||
go 1.15
|
||||
|
||||
|
||||
10
main.go
10
main.go
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"ariona.fr/git/gator/gogodisco/core"
|
||||
"ariona.fr/git/gator/gogodiscordo/core"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
@ -19,9 +19,11 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
core.SetCommand([]string{"/ggd audio", "/gogodisco audio"}, core.MessageAudio, discord)
|
||||
core.SetCommand([]string{"/ggd ping", "/gogodisco ping"}, core.MessagePing, discord)
|
||||
core.SetCommand([]string{"/ggd help", "/gogodisco help"}, core.MessageHelp, discord)
|
||||
core.SetCommand([]string{"/ggd audio", "/gogodisco audio"}, core.MessageAudio)
|
||||
core.SetCommand([]string{"ping", "pong"}, core.MessagePing)
|
||||
core.SetCommand([]string{"/ggd help", "/gogodisco help"}, core.MessageHelp)
|
||||
|
||||
discord.AddHandler(core.MessageHandler)
|
||||
|
||||
err = discord.Open()
|
||||
if err != nil {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Gogodisco
|
||||
# Gogodiscordo
|
||||
|
||||
## About
|
||||
This is a simple bot in Go for the Discord messaging service, created for learning purpose and to quickly experiment with features discussed in different Discord channels I frequent.
|
||||
This is a simple bot in Go for the Discord messaging service, created for learning purpose and to quickly experiment with features discussed in different Discord channels I frequent. The dumb name is an opportunistic reference to Inspector Gadget.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user