···1+using NetCord;
2+using NetCord.Services;
3+using NetCord.Services.ApplicationCommands;
4+using StreakBot.Services;
5+6+namespace StreakBot.Commands;
7+8+public 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+}
+43
Commands/EndStreakCommand.cs
···0000000000000000000000000000000000000000000
···1+using NetCord;
2+using NetCord.Services.ApplicationCommands;
3+using StreakBot.Services;
4+5+namespace StreakBot.Commands;
6+7+public 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+}
···1# StreakBot
2+This is a Discord bot made using NetCord, for the purposes of creating a server to make streaks (a la TikTok or Duolingo). Creates voice channels that display the streak count and a timer of when the daily timer starts again.
3+4+You'll need to do the necessary steps of setting up a Discord bot (Set up a bot at https://discord.com/developers/applications), grab the token that it spits out after creating the bot, and put it into the appsettings.json.
5+6+Start a streak with /start <@username>
7+End a streak with /endstreak <@username>
8+Check your streaks with /streak