Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
minisbett committed Dec 31, 2023
2 parents 8fbbc9b + 0554e58 commit 8db195b
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN dotnet publish -c Release -o out

# Run
FROM mcr.microsoft.com/dotnet/runtime:7.0
RUN apt-get install -y libgdiplus # for scottplot
WORKDIR /app
COPY --from=build /app/out .
CMD dotnet huisbot.dll
9 changes: 9 additions & 0 deletions huisbot/Embeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public static Embed Success(string message) => BaseEmbed
.WithDescription(message)
.Build();

/// <summary>
/// Returns an embed notifying the user that they lack Onion permissions.
/// </summary>
public static Embed NotOnion => BaseEmbed
.WithColor(Color.Red)
.WithTitle("Insufficient permissions.")
.WithDescription("You need Onion permissions in order to use this command.\nYou can apply for the Onion role here:\n[PP Discord](https://discord.gg/aqPCnXu) • <#1020389783110955008>")
.Build();

/// <summary>
/// Returns an embed with the specified rework.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public async Task HandleAsync(
{
await DeferAsync();

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get the matching rework for the specified rework identifier.
HuisRework? rework = await GetReworkAsync(reworkId);
if (rework is null)
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public async Task HandleAsync(
{
await DeferAsync();

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get the matching rework for the specified rework identifier.
HuisRework? rework = await GetReworkAsync(reworkId);
if (rework is null)
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/Rankings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public async Task HandlePlayerAsync(
{
await DeferAsync();

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get the sorting options.
HuisPlayerSort? sort = await GetPlayerSortAsync(sortId);
if (sort is null)
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/Reworks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public async Task HandleAsync()
{
await DeferAsync();

// Make sure the user is an onion.
if(!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get all available reworks from the Huis API.
HuisRework[]? reworks = await GetReworksAsync();
if (reworks is null)
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/Simulate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public async Task HandleAsync(
{
await DeferAsync();

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Check if either a beatmap ID or a score ID was .
if (beatmapId is null && scoreId is null)
{
Expand Down
13 changes: 10 additions & 3 deletions huisbot/Modules/Huis/Statistic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public async Task HandleAsync(
[Summary("amount", "Amount of entries to include, up to 500. Default is 500.") ][MinValue(1)] [MaxValue(500)] int amount = 500)
{
await DeferAsync();
bool topscores = statisticId == "topscores"; // True = topscores, False = topplayers
string target = statisticId.Substring(3, 1) + statisticId.Substring(4).TrimEnd('s'); // topscores or topplayers => Score or Player

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get the matching rework for the specified rework identifier.
HuisRework? rework = await GetReworkAsync(reworkId);
Expand All @@ -41,11 +48,11 @@ public async Task HandleAsync(
// Configure the plot with a size of 1000x600, colors, a legend in the upper center, the axis labels and an extra axis on the right for the difference.
Plot liveLocal = new Plot(1000, 600);
liveLocal.Style(Color.FromArgb(63, 66, 66), Color.FromArgb(63, 66, 66), Color.FromArgb(57, 59, 59), null, null, Color.White);
liveLocal.Title($"{(topscores ? "Top Scores" : "Top Players")} - Live vs {rework.Name} @ {DateTime.UtcNow.ToShortDateString()} " +
liveLocal.Title($"Top {target}s - Live vs {rework.Name} @ {DateTime.UtcNow.ToShortDateString()} " +
$"{DateTime.UtcNow.ToLongTimeString()} (commit {rework.Commit})");
liveLocal.LeftAxis.Label("Performance Points");
liveLocal.LeftAxis.Color(Color.LightGray);
liveLocal.BottomAxis.Label($"No. # Top {(topscores ? "Score" : "Player")}");
liveLocal.BottomAxis.Label($"No. # Top {target}");
liveLocal.BottomAxis.Color(Color.LightGray);
liveLocal.AddAxis(Edge.Right, 2, "Difference", Color.LightGray);
Legend legend = liveLocal.Legend(true, Alignment.UpperCenter);
Expand Down
7 changes: 7 additions & 0 deletions huisbot/Modules/Huis/TopPlays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public async Task HandleScoreAsync(
{
await DeferAsync();

// Make sure the user is an onion.
if (!IsOnion)
{
await FollowupAsync(embed: Embeds.NotOnion);
return;
}

// Get the matching rework for the specified rework identifier.
HuisRework? rework = await GetReworkAsync(reworkId);
if (rework is null)
Expand Down
21 changes: 21 additions & 0 deletions huisbot/Modules/ModuleBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using huisbot.Enums;
using huisbot.Models.Huis;
using huisbot.Models.Osu;
Expand Down Expand Up @@ -33,6 +34,26 @@ public ModuleBase(HuisApiService huis = null!, OsuApiService osu = null!, Persis
_persistence = persistence;
}

/// <summary>
/// Bool whether the user has the Onion role on the PP Discord, making them eligible to use Huis commands.
/// </summary>
public bool IsOnion
{
get
{
#if DEBUG
return true;
#endif

// Get the PP Discord guild.
SocketGuild guild = Context.Client.GetGuild(546120878908506119);

// Check whether the user is in that guild and has the Onion role.
SocketGuildUser user = guild.GetUser(284725640777695232);
return user != null && user.Roles.Any(x => x.Id == 577267917662715904);
}
}

/// <summary>
/// Returns all available reworks on Huismetbenen. If it failed, the user will automatically
/// be notified, unless the seeError parameter is set. In this case, this method returns null.
Expand Down
2 changes: 1 addition & 1 deletion huisbot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Program
/// <summary>
/// The version of the application.
/// </summary>
public const string VERSION = "1.4.3";
public const string VERSION = "1.5.0";

/// <summary>
/// The startup time of the application.
Expand Down

0 comments on commit 8db195b

Please sign in to comment.