C# Discord bot made using NetCord for keeping a TikTok-style streak
1using NetCord;
2using NetCord.Services.ApplicationCommands;
3using StreakBot.Services;
4
5namespace StreakBot.Commands;
6
7public class EndStreakCommand : ApplicationCommandModule<ApplicationCommandContext>
8{
9 private readonly StreakService _streakService;
10
11 public EndStreakCommand(StreakService streakService)
12 {
13 _streakService = streakService;
14 }
15
16 [SlashCommand("endstreak", "!!!WARNING PERMANENT DESTRUCTIVE ACTION!!! Ends the daily streak you have with another user.")]
17 public async Task<string> EndStreak(
18 [SlashCommandParameter(Name = "user", Description = "The user to end your streak with")]
19 User user)
20 {
21 var initiatorId = Context.User.Id;
22 var targetId = user.Id;
23
24 if (initiatorId == targetId)
25 {
26 return "You can't end a streak with yourself!";
27 }
28
29 if (user.IsBot)
30 {
31 return "You can't end a streak with a bot!";
32 }
33
34 var success = await _streakService.DeleteStreakAsync(initiatorId, targetId);
35
36 if (success == null)
37 {
38 return $"No streak found between <@{initiatorId}> and <@{targetId}>.";
39 }
40
41 return (bool)success ? $"Streak ended between <@{initiatorId}> and <@{targetId}>" : "Failed to end streak. Contact @minito for further information.";
42 }
43}