/
greeting.go
33 lines (28 loc) · 919 Bytes
/
greeting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package bot
import (
"github.com/bwmarrin/discordgo"
"github.com/globalsign/mgo/bson"
)
// Greetings sends greetings for user
func Greetings(discord *discordgo.Session, event *discordgo.GuildMemberAdd, guild *GuildData) {
if guild.Greeting != "" {
ch, cErr := discord.UserChannelCreate(event.User.ID)
if cErr != nil {
return
}
_, mErr := discord.ChannelMessageSend(ch.ID, guild.Greeting)
if mErr != nil {
return
}
}
}
// AddGreetings adds new greetings to guild
func (ctx *Context) AddGreetings(text string) {
ctx.Guilds.Guilds[ctx.Guild.ID].Greeting = text
_ = ctx.DB.Guilds().Update(bson.M{"id": ctx.Guild.ID}, bson.M{"$set": bson.M{"greeting": text}})
}
// RemoveGreetings removes greetings from guild
func (ctx *Context) RemoveGreetings() {
ctx.Guilds.Guilds[ctx.Guild.ID].Greeting = ""
_ = ctx.DB.Guilds().Update(bson.M{"id": ctx.Guild.ID}, bson.M{"$set": bson.M{"greeting": ""}})
}