bot.*Context.AddGreetings   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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