forked from Minecraft/canopeas
parent
520cc5968c
commit
e37945c5d5
|
@ -2,6 +2,7 @@ package discord
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -100,6 +101,7 @@ func Bot(cfg *config.Config, db *database.Database) (*discordgo.Session, error)
|
|||
}
|
||||
|
||||
bot.AddHandler(readyHandler())
|
||||
bot.AddHandler(joinHandler(cfg))
|
||||
bot.AddHandler(leaveHandler(cfg))
|
||||
bot.AddHandler(commandHandler(cfg, db, sapi, twitterClient))
|
||||
bot.AddHandler(messageHandler(cfg, db))
|
||||
|
@ -294,3 +296,32 @@ func updateStatus(s *discordgo.Session) {
|
|||
<-ticker.C
|
||||
}
|
||||
}
|
||||
|
||||
func joinHandler(cfg *config.Config) func(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
||||
return func(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
||||
sendMessage(s, cfg.Welcome.Channel, os.Expand(cfg.Welcome.Message, func(s string) string {
|
||||
switch strings.ToLower(s) {
|
||||
case "user":
|
||||
return m.Mention()
|
||||
default:
|
||||
return s
|
||||
}
|
||||
}), false)
|
||||
|
||||
if cfg.Welcome.DM != "" {
|
||||
dm, err := s.UserChannelCreate(m.User.ID)
|
||||
if err != nil {
|
||||
log.Err(err).Msgf("could not create DM with %s", m.User.Username)
|
||||
return
|
||||
}
|
||||
sendMessage(s, dm.ID, os.Expand(cfg.Welcome.DM, func(s string) string {
|
||||
switch strings.ToLower(s) {
|
||||
case "user":
|
||||
return m.Mention()
|
||||
default:
|
||||
return s
|
||||
}
|
||||
}), false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue