| Conditions | 10 |
| Total Lines | 28 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like cmd.TwitchCommand 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 |
||
| 8 | func TwitchCommand(ctx bot.Context) { |
||
| 9 | ctx.MetricsCommand("bot") |
||
| 10 | if ctx.GetRoles().ExistsName("bot.admin") || ctx.IsAdmin() { |
||
| 11 | if len(ctx.Args) == 0 { |
||
| 12 | return |
||
| 13 | } |
||
| 14 | switch ctx.Args[0] { |
||
| 15 | case "add": |
||
| 16 | if len(ctx.Args) > 1 { |
||
| 17 | err := ctx.Twitch.AddStreamer(ctx.Guild.ID, ctx.Message.ChannelID, ctx.Args[1]) |
||
| 18 | if err != nil { |
||
| 19 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_add_error")) |
||
| 20 | } else { |
||
| 21 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_added")) |
||
| 22 | } |
||
| 23 | } |
||
| 24 | case "remove": |
||
| 25 | if len(ctx.Args) > 1 { |
||
| 26 | err := ctx.Twitch.RemoveStreamer(ctx.Guild.ID, ctx.Args[1]) |
||
| 27 | if err != nil { |
||
| 28 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_remove_error")) |
||
| 29 | } else { |
||
| 30 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_removed")) |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } else { |
||
| 35 | ctx.ReplyEmbed("Twitch", ctx.Loc("admin_require")) |
||
| 36 | } |
||
| 37 | } |