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 RestoreCommand : ApplicationCommandModule<ApplicationCommandContext>
8{
9 private readonly StreakService _streakService;
10
11 public RestoreCommand(StreakService streakService)
12 {
13 _streakService = streakService;
14 }
15
16 [SlashCommand("restore", "Restores your streak with another user after it has been reset. Limited to 5 restores per month.")]
17 public async Task<string> Restore(
18 [SlashCommandParameter(Name = "user", Description = "The user to restore 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 restore a streak with yourself!";
27 }
28
29 if (user.IsBot)
30 {
31 return "You can't restore a streak with a bot!";
32 }
33
34 return await _streakService.RestoreStreakAsync(initiatorId, targetId);
35 }
36}