1
0

commented code

This commit is contained in:
2022-05-07 11:03:14 +02:00
parent 6bbae4da79
commit e8d5293911
5 changed files with 24 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package core
import (
"bytes"
"fmt"
"log"
"math/rand"
"sort"
"strings"
@ -47,6 +48,7 @@ func getHelpMessage() string {
return welcome + strings.Join(help, "")
}
// return random hats
func getHatMessage() string {
hat := []string{"🧢", "👒", "⛑", "🎩", "🎓"}
rand.Seed(time.Now().UnixNano())
@ -59,6 +61,8 @@ func getHatMessage() string {
return strings.Join(bag, " ")
}
// returns a random message if the processed message matchs with a pattern.
// patterns are substrings belonging to a "domain" of lexical items
func getTalkbackMessage(message string) string {
for _, t := range ConfigRegister.Talkback {
for _, p := range t.Domain.Patterns {
@ -72,6 +76,7 @@ func getTalkbackMessage(message string) string {
return ""
}
// check if a message is a valid command. if yes, execute the command
func MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
for alias, _ := range CommandRegister {
if strings.HasPrefix(m.Content, alias) {
@ -113,12 +118,15 @@ func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate, message strin
}
}
// generate TTS version of the message and upload it to the channel
func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate, message string) {
log.Println("Messageaudio :", message)
var cleanMessage string = prepareTTSMessage(message)
filename, out := getAudioMessage(cleanMessage)
file := bytes.NewReader(out)
s.ChannelFileSend(m.ChannelID, filename, file)
// delete the receveid command after processing it. less clutter
log.Println("Messageaudio :", cleanMessage)
s.ChannelMessageDelete(m.ChannelID, m.ID)
}