Passed
Push — master ( 553a4f...c4b1b7 )
by Viktor
02:52 queued 01:06
created

cmd.HelpCommand   F

Complexity

Conditions 14

Size

Total Lines 32
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 30
nop 1
dl 0
loc 32
rs 3.6
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like cmd.HelpCommand often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package cmd
2
3
import (
4
	"github.com/FlameInTheDark/dtbot/bot"
5
)
6
7
// HelpCommand shows help
8
func HelpCommand(ctx bot.Context) {
9
	ctx.MetricsCommand("help_command")
10
	if len(ctx.Args) == 0 {
11
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_reply"))
12
		return
13
	}
14
	switch ctx.Args[0] {
15
	case "!v":
16
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!v"))
17
	case "!b":
18
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!b"))
19
		if (ctx.IsAdmin()) {
20
			ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!b_admin"))
21
		}
22
	case "!y":
23
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!y"))
24
	case "!r":
25
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!r"))
26
	case "!w":
27
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!w"))
28
	case "!n":
29
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!n"))
30
	case "!t":
31
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!t"))
32
	case "!c":
33
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!c"))
34
	case "!p":
35
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!p"))
36
	case "!geoip":
37
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!geoip"))
38
	case "!twitch":
39
		ctx.ReplyEmbed(ctx.Loc("help"), ctx.Loc("help_command_!twitch"))
40
	}
41
}
42