messageHandler, changing project name slightly
This commit is contained in:
@ -28,17 +28,17 @@ func (c *ConfigRegister) LoadConf() *ConfigRegister {
|
|||||||
var CommandRegister = make(
|
var CommandRegister = make(
|
||||||
map[string]func(
|
map[string]func(
|
||||||
s *discordgo.Session,
|
s *discordgo.Session,
|
||||||
m *discordgo.MessageCreate))
|
m *discordgo.MessageCreate,
|
||||||
|
message string))
|
||||||
|
|
||||||
func SetCommand(aliases []string, command func(
|
func SetCommand(aliases []string, command func(
|
||||||
s *discordgo.Session,
|
s *discordgo.Session,
|
||||||
m *discordgo.MessageCreate),
|
m *discordgo.MessageCreate,
|
||||||
discord *discordgo.Session) {
|
message string)) {
|
||||||
for _, alias := range aliases {
|
for _, alias := range aliases {
|
||||||
CommandRegister[alias] = command
|
CommandRegister[alias] = command
|
||||||
log.Printf("added %s to Register", alias)
|
log.Printf("added %s to Register", alias)
|
||||||
}
|
}
|
||||||
discord.AddHandler(command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config ConfigRegister
|
var Config ConfigRegister
|
||||||
|
|||||||
@ -24,21 +24,26 @@ func createAudio(msg string) (filename string, file *bytes.Reader) {
|
|||||||
return
|
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 {
|
if m.Author.ID == s.State.User.ID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Content == "/ggd help" {
|
var message string = strings.TrimPrefix(m.Content, alias)
|
||||||
// build list of possible commands
|
fmt.Println(message)
|
||||||
return
|
command(s, m, message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func MessageHelp(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||||
if m.Author.ID == s.State.User.ID {
|
// build list of possible commands
|
||||||
|
fmt.Println(message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||||
if m.Content == "ping" {
|
if m.Content == "ping" {
|
||||||
s.ChannelMessageSend(m.ChannelID, "Pong!")
|
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) {
|
func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
|
||||||
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)
|
|
||||||
var cleanMessage string = prepareTTSMessage(message)
|
var cleanMessage string = prepareTTSMessage(message)
|
||||||
filename, file := createAudio(cleanMessage)
|
filename, file := createAudio(cleanMessage)
|
||||||
s.ChannelFileSend(m.ChannelID, filename, file)
|
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
|
go 1.15
|
||||||
|
|
||||||
|
|||||||
10
main.go
10
main.go
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ariona.fr/git/gator/gogodisco/core"
|
"ariona.fr/git/gator/gogodiscordo/core"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -19,9 +19,11 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
core.SetCommand([]string{"/ggd audio", "/gogodisco audio"}, core.MessageAudio, discord)
|
core.SetCommand([]string{"/ggd audio", "/gogodisco audio"}, core.MessageAudio)
|
||||||
core.SetCommand([]string{"/ggd ping", "/gogodisco ping"}, core.MessagePing, discord)
|
core.SetCommand([]string{"ping", "pong"}, core.MessagePing)
|
||||||
core.SetCommand([]string{"/ggd help", "/gogodisco help"}, core.MessageHelp, discord)
|
core.SetCommand([]string{"/ggd help", "/gogodisco help"}, core.MessageHelp)
|
||||||
|
|
||||||
|
discord.AddHandler(core.MessageHandler)
|
||||||
|
|
||||||
err = discord.Open()
|
err = discord.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# Gogodisco
|
# Gogodiscordo
|
||||||
|
|
||||||
## About
|
## 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