feat: Implement macros

master
Luther Wen Xu 2020-05-30 20:51:04 +07:00
parent f531877521
commit 11fed61073
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
4 changed files with 36 additions and 1 deletions

@ -51,4 +51,5 @@ func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
v.Processor(dg, m, split[2:])
return
}
handleMacro(dg, m, split[1:])
}

@ -0,0 +1,30 @@
package commands
import (
"strings"
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
var (
CommonReplacement map[string]string
Macro map[string]string
)
func handleMacro(dg *discordgo.Session, m *discordgo.MessageCreate, split []string) {
for k, _ := range split {
split[k] = strings.ToLower(split[k])
if val, ok := CommonReplacement[split[k]]; ok {
split[k] = val
}
}
full := strings.Join(split, " ")
for k, v := range Macro {
if k == full {
util.SendMessage(dg, m.ChannelID, v)
return
}
}
}

@ -8,7 +8,9 @@ import (
type config struct {
Token string
ReportTarget string
ReportTarget string `toml:"report_target"`
MacroReplace map[string]string `toml:"macro_replace"`
Macro map[string]string
}
func LoadConfig() config {

@ -17,6 +17,8 @@ import (
func main() {
cfg := LoadConfig()
commands.CommonReplacement = cfg.MacroReplace
commands.Macro = cfg.Macro
util.ReportTarget = cfg.ReportTarget
dg, err := discordgo.New("Bot " + cfg.Token)