-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StandUpStreak - implement internal counter #345
Open
LucyAnne98
wants to merge
21
commits into
fit-ctu-discord:develop
Choose a base branch
from
LucyAnne98:standUpStreak
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fe15420
StandUpStreak
LGAP98 3d1620e
Changes implemented.
LGAP98 4e42d72
Streaks migration
LGAP98 ce01cb3
StandUpStats - counting stats
LGAP98 7cc1931
Updated logic & debugged after testing
LGAP98 483da86
Update src/HonzaBotner.Database/HonzaBotnerDbContext.cs
LucyAnne98 b45252f
Update src/HonzaBotner.Services.Contract/Dto/StandUpStat.cs
LucyAnne98 e7e643f
Merge branch 'develop' into standUpStreak
LucyAnne98 1b51f90
♻️ Enhance code
tenhobi 341b70a
Merge branch 'standUpStreak' of github.com:LucyAnne98/honza-botner in…
tenhobi be8e771
♻️ Extract stand-up config to separate options
tenhobi c0345c9
🔥 Remove sending DM, will be implemented using SC
tenhobi 3aa5a8d
♻️ Fix lints
tenhobi 7a71a67
Merge branch 'develop' into standUpStreak
stepech 8ca03cf
Standup: Improve message collection logic
stepech 97a8b6a
Revert code enhancement
stepech 165e4c6
StandUp: Final touches to service provider, prepare for button
stepech 618d006
StandUp: Like if I'm doing this for the first time....
stepech 00e976c
StandUp: Streaks counting finish, and button
stepech c836963
And this.. Commit this too
stepech 168b1c6
StandUp: Commit suggestions (code formatting)
stepech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace HonzaBotner.Database; | ||
|
||
public class StandUpStat | ||
{ | ||
[Key] public ulong UserId { get; set; } | ||
public int Streak { get; set; } | ||
public int LongestStreak { get; set; } | ||
public int Freezes { get; set; } | ||
public DateTime LastDayOfStreak { get; set; } | ||
public int LastDayCompleted { get; set; } | ||
public int LastDayTasks { get; set; } | ||
public int TotalCompleted { get; set; } | ||
public int TotalTasks { get; set; } | ||
} |
71 changes: 71 additions & 0 deletions
71
src/HonzaBotner.Discord.Services/EventHandlers/StandUpHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DSharpPlus; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.EventArgs; | ||
using HonzaBotner.Discord.EventHandler; | ||
using HonzaBotner.Discord.Services.Options; | ||
using HonzaBotner.Services.Contract; | ||
using HonzaBotner.Services.Contract.Dto; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace HonzaBotner.Discord.Services.EventHandlers; | ||
|
||
public class StandUpHandler : IEventHandler<ComponentInteractionCreateEventArgs> | ||
{ | ||
|
||
private readonly ButtonOptions _buttonOptions; | ||
private readonly IStandUpStatsService _standUpStats; | ||
private readonly ILogger<StandUpHandler> _logger; | ||
|
||
public StandUpHandler( | ||
IOptions<ButtonOptions> buttonOptions, | ||
IStandUpStatsService standUpStats, | ||
ILogger<StandUpHandler> logger) | ||
{ | ||
_buttonOptions = buttonOptions.Value; | ||
_standUpStats = standUpStats; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<EventHandlerResult> Handle(ComponentInteractionCreateEventArgs args) | ||
{ | ||
if (args.Id != _buttonOptions.StandUpStatsId) | ||
{ | ||
return EventHandlerResult.Continue; | ||
} | ||
|
||
_logger.LogDebug("{User} requested stats info", args.User.Username); | ||
|
||
StandUpStat? stats = await _standUpStats.GetStreak(args.User.Id); | ||
|
||
DiscordInteractionResponseBuilder response = new(); | ||
response.AsEphemeral(true); | ||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder().WithAuthor("Stats", iconUrl: args.User.AvatarUrl); | ||
|
||
if (stats is null) | ||
{ | ||
embed.Description = "Unfortunately you are not in the database yet.\nDatabase updates daily at 8 am"; | ||
embed.Color = new Optional<DiscordColor>(DiscordColor.Gold); | ||
response.AddEmbed(embed.Build()); | ||
|
||
await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response); | ||
return EventHandlerResult.Stop; | ||
} | ||
|
||
embed.Description = $"Cool stats for {args.User.Mention}"; | ||
embed.AddField("Current streak", stats.Streak.ToString(), true); | ||
embed.AddField("Available freezes", stats.Freezes.ToString(), true); | ||
embed.AddField("Total tasks", stats.TotalTasks.ToString(), true); | ||
embed.AddField("Total completed tasks", stats.TotalCompleted.ToString(), true); | ||
embed.AddField("Last streak update", | ||
"<t:" + ((DateTimeOffset)stats.LastDayOfStreak.AddDays(1)).ToUnixTimeSeconds() + ":D>"); | ||
embed.Color = new Optional<DiscordColor>(DiscordColor.Wheat); | ||
|
||
response.AddEmbed(embed.Build()); | ||
await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response); | ||
return EventHandlerResult.Stop; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/HonzaBotner.Discord.Services/Options/StandUpOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace HonzaBotner.Discord.Services.Options; | ||
|
||
public class StandUpOptions | ||
{ | ||
public static string ConfigName => "StandUpOptions"; | ||
|
||
public ulong StandUpRoleId { get; set; } | ||
public ulong StandUpChannelId { get; set; } | ||
|
||
public int DaysToAcquireFreeze { get; set; } | ||
public int TasksCompletedThreshold { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace HonzaBotner.Services.Contract.Dto; | ||
|
||
public record StandUpStat( | ||
ulong UserId, int Streak, | ||
int LongestStreak, int Freezes, | ||
DateTime LastDayOfStreak, int TotalCompleted, | ||
int TotalTasks, int LastDayCompleted, | ||
int LastDayTasks | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading.Tasks; | ||
using HonzaBotner.Services.Contract.Dto; | ||
namespace HonzaBotner.Services.Contract; | ||
|
||
public interface IStandUpStatsService | ||
{ | ||
/// <summary> | ||
/// Get StandUp stats for a user with a given userId | ||
/// </summary> | ||
/// <param name="userId">Id of the user</param> | ||
/// <returns>Null if user not in database, else his stats</returns> | ||
Task<StandUpStat?> GetStreak(ulong userId); | ||
|
||
/// <summary> | ||
/// Update database record of given user regarding StandUp stats. Should be called just once per day per user. | ||
/// </summary> | ||
/// <param name="userId">Id of the user</param> | ||
/// <param name="completed">Amount of completed tasks yesterday</param> | ||
/// <param name="total">Total amount of tasks yesterday</param> | ||
Task UpdateStats(ulong userId, int completed, int total); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to keep it consistent with previous loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually turned everything red, so I kept it the way it is now.. For some reason once we substitute Mtch for var, it no longer knows that var contains some groups...