C# Discord bot made using NetCord for keeping a TikTok-style streak
1using NetCord;
2using NetCord.Services;
3using NetCord.Services.ApplicationCommands;
4using StreakBot.Services;
5
6namespace StreakBot.Commands;
7
8public class CheckStreakCommand : ApplicationCommandModule<ApplicationCommandContext>
9{
10 private readonly StreakService _streakService;
11
12 public CheckStreakCommand(StreakService streakService)
13 {
14 _streakService = streakService;
15 }
16
17 [SlashCommand("streak", "Check your daily streak with another user")]
18 public async Task<string> CheckStreak()
19 {
20 if (Context.Interaction.GuildId is not null)
21 {
22 return "This command can only be used in a dm!";
23 }
24
25 var initiatorId = Context.User.Id;
26
27 var streaks = await _streakService.CheckStreaksAsync(initiatorId);
28
29 if (!streaks.Any())
30 {
31 return "You have no streaks.";
32 }
33
34 var output = "You have the following streaks:";
35
36 foreach (var streak in streaks)
37 {
38 var targetId = streak.User1Id == initiatorId ? streak.User2Id : streak.User1Id;
39 output += $"\n\nYour streak with <@{targetId}> started on {streak.CreatedDate:MMM-dd-yyyy}, and your current streak pet is {streak.StreakNumber} days old!";
40 }
41
42 return output;
43
44 }
45}