Passed
Push — master ( 7c6f03...32a915 )
by Viktor
01:49
created

cmd.SlapCommand   B

Complexity

Conditions 6

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nop 1
dl 0
loc 19
rs 8.6666
c 0
b 0
f 0
1
package cmd
2
3
import (
4
	"fmt"
5
	"github.com/FlameInTheDark/dtbot/api/fun"
6
	"github.com/FlameInTheDark/dtbot/bot"
7
)
8
9
// SlapCommand returns slap image
10
func SlapCommand(ctx bot.Context) {
11
	if len(ctx.Args) > 0 {
12
		ctx.MetricsCommand("fun", "slap")
13
		url, err := fun.GetImageURL("slap")
14
		if err == nil {
15
			if len(ctx.Args) > 0 {
16
				var userID string
17
				if len(ctx.Args[0]) > 3 {
18
					userID = ctx.Args[0][2 : len(ctx.Args[0])-1]
19
				}
20
				user := ctx.GetGuildUser(userID)
21
				var mention= ctx.Args[0]
22
				if user != nil {
23
					mention = user.Username
24
				}
25
				ctx.ReplyEmbedAttachmentImageURL("", fmt.Sprintf(ctx.Loc("slapping"), ctx.User.Username, mention), url)
0 ignored issues
show
introduced by
can't check non-constant format in call to Sprintf
Loading history...
26
			}
27
		} else {
28
			fmt.Printf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Printf
Loading history...
29
		}
30
	}
31
}
32
33
// FUCommand returns FU image
34
func FUCommand(ctx bot.Context) {
35
	if len(ctx.Args) > 0 {
36
		ctx.MetricsCommand("fun", "fu")
37
		url, err := fun.GetImageURL("fu")
38
		if err == nil {
39
			if len(ctx.Args) > 0 {
40
				var userID string
41
				if len(ctx.Args[0]) > 3 {
42
					userID = ctx.Args[0][2 : len(ctx.Args[0])-1]
43
				}
44
				user := ctx.GetGuildUser(userID)
45
				var mention = ctx.Args[0]
46
				if user != nil {
47
					mention = user.Username
48
				}
49
				ctx.ReplyEmbedAttachmentImageURL("", fmt.Sprintf(ctx.Loc("send_fu"), ctx.User.Username, mention), url)
0 ignored issues
show
introduced by
can't check non-constant format in call to Sprintf
Loading history...
50
			}
51
		} else {
52
			fmt.Printf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Printf
Loading history...
53
		}
54
	}
55
}