bot/greeting.go   A
last analyzed

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bot.Greetings 0 9 4
A bot.*Context.AddGreetings 0 3 1
A bot.*Context.RemoveGreetings 0 3 1
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