| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package cmd |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "fmt" |
||
| 5 | "github.com/FlameInTheDark/dtbot/bot" |
||
| 6 | ) |
||
| 7 | |||
| 8 | // TwitchCommand manipulates twitch announcer |
||
| 9 | func TwitchCommand(ctx bot.Context) { |
||
| 10 | ctx.MetricsCommand("twitch") |
||
| 11 | if ctx.GetRoles().ExistsName("bot.admin") || ctx.IsAdmin() { |
||
| 12 | if len(ctx.Args) == 0 { |
||
| 13 | return |
||
| 14 | } |
||
| 15 | switch ctx.Args[0] { |
||
| 16 | case "add": |
||
| 17 | if len(ctx.Args) > 1 { |
||
| 18 | username, err := ctx.Twitch.AddStreamer(ctx.Guild.ID, ctx.Message.ChannelID, ctx.Args[1]) |
||
| 19 | if err != nil { |
||
| 20 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_add_error")) |
||
| 21 | } else { |
||
| 22 | ctx.ReplyEmbed("Twitch", fmt.Sprintf(ctx.Loc("twitch_added"), username)) |
||
|
|
|||
| 23 | } |
||
| 24 | } |
||
| 25 | case "remove": |
||
| 26 | if len(ctx.Args) > 1 { |
||
| 27 | err := ctx.Twitch.RemoveStreamer(ctx.Args[1], ctx.Guild.ID) |
||
| 28 | if err != nil { |
||
| 29 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_remove_error")) |
||
| 30 | } else { |
||
| 31 | ctx.ReplyEmbed("Twitch", ctx.Loc("twitch_removed")) |
||
| 32 | } |
||
| 33 | } |
||
| 34 | case "count": |
||
| 35 | if ctx.IsAdmin() { |
||
| 36 | count := 0 |
||
| 37 | for _,g := range ctx.Twitch.Guilds { |
||
| 38 | count += len(g.Streams) |
||
| 39 | } |
||
| 40 | ctx.ReplyEmbed("Twitch", fmt.Sprintf("Streamers: %v", count)) |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } else { |
||
| 44 | ctx.ReplyEmbed("Twitch", ctx.Loc("admin_require")) |
||
| 45 | } |
||
| 46 | } |