Skip to content

Commit 160a895

Browse files
committed
Merge branch 'release/0.0.21'
2 parents 67da1ad + 3ec52fc commit 160a895

File tree

85 files changed

+833
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+833
-52
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<!-- Solution settings -->
4-
<Version>0.0.20</Version>
4+
<Version>0.0.21</Version>
55
<LangVersion>latest</LangVersion>
66
<TargetFramework>net9.0</TargetFramework>
77
<ImplicitUsings>enable</ImplicitUsings>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</ItemGroup>
99
<ItemGroup>
1010
<PackageVersion Include="AngleSharp" Version="1.3.0" />
11-
<PackageVersion Include="AspNet.Security.OAuth.Discord" Version="9.2.0" />
11+
<PackageVersion Include="AspNet.Security.OAuth.Discord" Version="9.3.0" />
1212
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
1313
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
1414
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />

src/Borealis.Core/Options/BorealisAuthenticationOptions.cs

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Borealis.Core.Options;
2+
3+
public class BorealisOptions {
4+
public required string ApplicationUrl { get; set; }
5+
}

src/Borealis.Core/Services/DiscordBotService.cs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
using System.Globalization;
22
using Borealis.Core.Contracts;
33
using Borealis.Core.Models;
4+
using Borealis.Core.Options;
45
using Discord;
56
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.Extensions.Options;
68

79
namespace Borealis.Core.Services;
810

911
public class DiscordBotService : IDiscordBotService {
1012
private readonly BorealisContext _borealisContext;
1113
private readonly IDiscordClient _discordClient;
14+
private readonly IOptions<BorealisOptions> _borealisOptions;
1215
private readonly ILogger<DiscordBotService> _logger;
1316

14-
public DiscordBotService(BorealisContext borealisContext, IDiscordClient discordClient, ILogger<DiscordBotService> logger) {
17+
public DiscordBotService(
18+
BorealisContext borealisContext,
19+
IDiscordClient discordClient,
20+
IOptions<BorealisOptions> borealisOptions,
21+
ILogger<DiscordBotService> logger) {
1522
_borealisContext = borealisContext;
1623
_discordClient = discordClient;
24+
_borealisOptions = borealisOptions;
1725
_logger = logger;
1826
}
1927

@@ -30,7 +38,23 @@ public DiscordBotService(BorealisContext borealisContext, IDiscordClient discord
3038
return settings;
3139
}
3240

33-
public async Task SendMessageAsync(string? channelId, string message, CancellationToken cancellationToken) {
41+
private async Task SendPlayerMessageAsync(string? channelId, string message, Player player) {
42+
var options = _borealisOptions.Value;
43+
44+
var builder = new ComponentBuilder();
45+
46+
// TODO Add containers and stuff when supported
47+
48+
if(!string.IsNullOrWhiteSpace(options.ApplicationUrl)) {
49+
builder.AddRow(new ActionRowBuilder()
50+
.WithButton("View player", style: ButtonStyle.Link, url: $"{options.ApplicationUrl}players/{player.Id}")
51+
);
52+
}
53+
54+
await SendMessageAsync(channelId, message, builder.Build());
55+
}
56+
57+
public async Task SendMessageAsync(string? channelId, string message, MessageComponent? messageComponent = null) {
3458
if(!ulong.TryParse(channelId, out var parseChannelId)) {
3559
_logger.LogWarning("Invalid channel ID: {ChannelId}", channelId);
3660
return;
@@ -41,7 +65,7 @@ public async Task SendMessageAsync(string? channelId, string message, Cancellati
4165
throw new InvalidOperationException($"Channel {parseChannelId} is not a valid message channel.");
4266
}
4367

44-
await channel.SendMessageAsync(message);
68+
await channel.SendMessageAsync(message, components: messageComponent);
4569
}
4670

4771
public async Task SendGiftCodeAddedMessageAsync(GiftCode giftCode, CancellationToken cancellationToken) {
@@ -50,8 +74,18 @@ public async Task SendGiftCodeAddedMessageAsync(GiftCode giftCode, CancellationT
5074
return;
5175
}
5276

77+
var options = _borealisOptions.Value;
78+
79+
var builder = new ComponentBuilder();
80+
81+
if(!string.IsNullOrWhiteSpace(options.ApplicationUrl)) {
82+
builder.AddRow(new ActionRowBuilder()
83+
.WithButton("View gift code", style: ButtonStyle.Link, url: $"{options.ApplicationUrl}gift-codes/{giftCode.Id}")
84+
);
85+
}
86+
5387
var message = $"New gift code found: {giftCode.Code}";
54-
await SendMessageAsync(settings.GiftCodeChannelId, message, cancellationToken);
88+
await SendMessageAsync(settings.GiftCodeChannelId, message, builder.Build());
5589
}
5690

5791
public async Task SendPlayerChangedNameMessageAsync(Player player, string newName, string oldName, CancellationToken cancellationToken) {
@@ -64,8 +98,18 @@ public async Task SendPlayerChangedNameMessageAsync(Player player, string newNam
6498
return;
6599
}
66100

67-
var message = $"Player {oldName} changed their name to {newName}.";
68-
await SendMessageAsync(settings.PlayerRenameChannelId, message, cancellationToken);
101+
var previousNames = player.PreviousNames
102+
.Select(x => x.Name)
103+
.Except([newName, oldName])
104+
.Distinct()
105+
.ToList();
106+
107+
var message = $"Player {oldName} (#{player.State}) changed their name to {newName}.";
108+
if(previousNames.Count > 0) {
109+
message += $" Previous names: {string.Join(", ", previousNames)}.";
110+
}
111+
112+
await SendPlayerMessageAsync(settings.PlayerRenameChannelId, message, player);
69113
}
70114

71115
public async Task SendPlayerChangedFurnaceLevelMessageAsync(Player player, string furnaceLevel, CancellationToken cancellationToken) {
@@ -78,8 +122,8 @@ public async Task SendPlayerChangedFurnaceLevelMessageAsync(Player player, strin
78122
return;
79123
}
80124

81-
var message = $"Player {player.Name} increased their furnace level to {furnaceLevel}.";
82-
await SendMessageAsync(settings.PlayerFurnaceLevelChannelId, message, cancellationToken);
125+
var message = $"Player {player.Name} (#{player.State}) increased their furnace level to {furnaceLevel}.";
126+
await SendPlayerMessageAsync(settings.PlayerFurnaceLevelChannelId, message, player);
83127
}
84128

85129
public async Task SendPlayerChangedStateMessageAsync(Player player, int newState, int oldState, CancellationToken cancellationToken) {
@@ -93,7 +137,7 @@ public async Task SendPlayerChangedStateMessageAsync(Player player, int newState
93137
}
94138

95139
var message = $"Player {player.Name} moved state from {oldState} to {newState}.";
96-
await SendMessageAsync(settings.PlayerMovedStateChannelId, message, cancellationToken);
140+
await SendPlayerMessageAsync(settings.PlayerMovedStateChannelId, message, player);
97141
}
98142

99143
public async Task<IReadOnlyCollection<DiscordGuild>> GetGuildsAsync(CancellationToken cancellationToken) {
@@ -104,6 +148,7 @@ public async Task<IReadOnlyCollection<DiscordGuild>> GetGuildsAsync(Cancellation
104148
GuildId = guild.Id.ToString(CultureInfo.InvariantCulture),
105149
Name = guild.Name
106150
})
151+
.OrderBy(guild => guild.Name, StringComparer.OrdinalIgnoreCase)
107152
];
108153
}
109154

@@ -118,6 +163,7 @@ public async Task<IReadOnlyCollection<DiscordChannel>> GetChannelsAsync(string g
118163
ChannelId = channel.Id.ToString(CultureInfo.InvariantCulture),
119164
Name = channel.Name
120165
})
166+
.OrderBy(guild => guild.Name, StringComparer.OrdinalIgnoreCase)
121167
];
122168
}
123169
}

src/Borealis.Frontend/.yarn/cache/@eslint-js-npm-9.25.1-6002ce1a0f-ad58128895.zip renamed to src/Borealis.Frontend/.yarn/cache/@eslint-js-npm-9.26.0-526664c6ef-863d35df8f.zip

6.31 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)