Skip to content

Commit 1c41699

Browse files
committed
.NET 10, extension members
1 parent 74c7416 commit 1c41699

8 files changed

Lines changed: 40 additions & 42 deletions

File tree

global.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
3-
"version": "5.0",
4-
"rollForward": "latestMajor",
5-
"allowPrerelease": false
3+
"version": "10.0.100",
4+
"rollForward": "latestFeature",
5+
"allowPrerelease": true
66
}
77
}

src/Bot/Helpers/DiscordHelper.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using JetBrains.Annotations;
12
using RyuBot.Interactions;
23

34
namespace RyuBot.Helpers;
@@ -45,15 +46,9 @@ public static SocketRole GetHighestRole(this SocketUser user, bool requireColor
4546
if (user is not SocketGuildUser sgu) return null;
4647

4748
return sgu.Roles
48-
.Where(x => !requireColor || x.HasColor())
49+
.Where(x => !requireColor || x.HasColor)
4950
.MaxBy(static x => x.Position);
5051
}
51-
52-
public static bool TryGetSpotifyStatus(this IUser user, out SpotifyGame spotify)
53-
{
54-
spotify = user.Activities.FirstOrDefault(x => x is SpotifyGame).Cast<SpotifyGame>();
55-
return spotify != null;
56-
}
5752

5853
public static string ToMarkdownTimestamp(long unixSeconds, char timestampType)
5954
=> $"<t:{unixSeconds}:{timestampType}>";
@@ -83,9 +78,6 @@ public static string GetInviteUrl(this IDiscordClient client, bool withAdmin = t
8378

8479
public static string GetInviteUrl(this IDiscordClient client, long permissions)
8580
=> $"https://discord.com/oauth2/authorize?client_id={client.CurrentUser.Id}&permissions={permissions}&scope=bot%20applications.commands";
86-
87-
public static SocketUser GetOwner(this BaseSocketClient client)
88-
=> client.GetUser(Config.Owner);
8981

9082
public static void RegisterVolteEventHandlers(this DiscordSocketClient client, ServiceProvider provider)
9183
{
@@ -172,18 +164,24 @@ public static async Task<bool> TryDeleteAsync(this IDeletable deletable, Request
172164
public static Task<bool> TryDeleteAsync(this IDeletable deletable, string reason)
173165
=> deletable.TryDeleteAsync(RequestOptions(opts => opts.AuditLogReason = reason));
174166

175-
public static string GetEffectiveUsername(this IGuildUser user) =>
176-
user.Nickname ?? user.DisplayName ?? user.Username;
177-
178167
public static string GetEffectiveAvatarUrl(this IUser user, ImageFormat format = ImageFormat.Auto,
179168
ushort size = 128)
180169
=> user.GetAvatarUrl(format, size) ?? user.GetDefaultAvatarUrl();
181170

182-
public static bool HasAttachments(this IMessage message)
183-
=> message.Attachments.Count != 0;
171+
extension(BaseSocketClient client)
172+
{
173+
[CanBeNull] public SocketUser BotOwner => client.GetUser(Config.Owner);
174+
}
175+
176+
extension(IGuildUser user)
177+
{
178+
public string EffectiveDisplayName => user.Nickname ?? user.DisplayName ?? user.Username;
179+
}
184180

185-
public static bool HasColor(this IRole role)
186-
=> role.Color.RawValue != 0;
181+
extension(IRole role)
182+
{
183+
public bool HasColor => role.Color.RawValue != 0;
184+
}
187185

188186
public static EmbedBuilder WithDescription(this EmbedBuilder e, StringBuilder sb)
189187
=> e.WithDescription(sb.ToString());

src/Bot/Helpers/Extensions/SystemExtensions.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,8 @@ public static string ToHexadecimalString(this System.Drawing.Color color,
3434
}
3535

3636
public static string ToHexadecimalString(this Color color,
37-
string prefix = "#")
38-
{
39-
return $"{color.R:X2}{color.G:X2}{color.B:X2}";
40-
}
41-
42-
public static bool ExistsInAny<T>(this T @this, params IEnumerable<T>[] collections)
43-
=> collections.Any(x => x.Contains(@this));
44-
45-
public static string CalculateUptime(this Process process)
46-
=> (DateTime.Now - process.StartTime).Humanize(3);
37+
string prefix = "#") =>
38+
$"{prefix}{color.R:X2}{color.G:X2}{color.B:X2}";
4739

4840
public static Task<IUserMessage> SendFileToAsync(this Stream stream,
4941
ITextChannel channel, string filename, string text = null, bool isTts = false, Embed embed = null,

src/Bot/Helpers/Logger.Internal.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void Log(SentryLevel logLevel, [CanBeNull] string message, Exception exce
1919
=> LogEventHandler.Call(new VolteLogEventArgs
2020
{
2121
Source = LogSource.Sentry,
22-
Severity = logLevel.ToSeverity(),
22+
Severity = logLevel.Severity,
2323
Message = message?.Format(args),
2424
Error = exception
2525
});
@@ -169,8 +169,9 @@ private static (Color Color, string Level) VerifySeverity(LogSeverity severity)
169169

170170
public static string P(this string input, int padding = 10) => string.Intern(input.PadRight(padding));
171171

172-
public static LogSeverity ToSeverity(this SentryLevel sentryLevel) =>
173-
sentryLevel switch
172+
extension(SentryLevel sentryLevel)
173+
{
174+
public LogSeverity Severity => sentryLevel switch
174175
{
175176
SentryLevel.Debug => LogSeverity.Debug,
176177
SentryLevel.Info => LogSeverity.Info,
@@ -179,9 +180,11 @@ public static LogSeverity ToSeverity(this SentryLevel sentryLevel) =>
179180
SentryLevel.Fatal => LogSeverity.Critical,
180181
_ => throw new ArgumentOutOfRangeException(nameof(sentryLevel), sentryLevel, null)
181182
};
183+
}
182184

183-
public static SentryLevel ToSentryLevel(this LogSeverity severity) =>
184-
severity switch
185+
extension(LogSeverity severity)
186+
{
187+
public SentryLevel Sentry => severity switch
185188
{
186189
LogSeverity.Critical => SentryLevel.Fatal,
187190
LogSeverity.Error => SentryLevel.Error,
@@ -191,4 +194,5 @@ public static SentryLevel ToSentryLevel(this LogSeverity severity) =>
191194
LogSeverity.Debug => SentryLevel.Debug,
192195
_ => throw new ArgumentOutOfRangeException(nameof(severity), severity, null)
193196
};
197+
}
194198
}

src/Bot/Interactions/API/Extensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ public static EmbedBuilder CreateEmbedBuilder(this SocketUserMessage userMessage
5151
=> new EmbedBuilder().WithDescription(content ?? string.Empty)
5252
.WithColor(userMessage.Author.Cast<SocketGuildUser>()?.GetHighestRole()?.Color ?? Config.SuccessColor);
5353

54-
public static MessageComponentId GetId(this IComponentInteraction interaction)
55-
=> interaction.Data.CustomId;
54+
extension(IComponentInteraction interaction)
55+
{
56+
public MessageComponentId CustomId => interaction.Data.CustomId;
57+
}
5658

57-
public static MessageComponentId GetId(this SocketInteractionContext<SocketMessageComponent> ctx)
58-
=> ctx.Interaction.Data.CustomId;
59+
extension(SocketInteractionContext<SocketMessageComponent> ctx)
60+
{
61+
public MessageComponentId CustomId => ctx.Interaction.Data.CustomId;
62+
}
5963

6064
public static ReplyBuilder<TInteraction> CreateReplyBuilder<TInteraction>(
6165
this SocketInteractionContext<TInteraction> context,

src/Bot/RyuBot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
77
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>

src/UI/Converters/VolteBrushConverters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ public LogSourceToBrush()
5858

5959
protected IBrush GetBrush(Color color) => Brush.Parse(color.ToHexadecimalString());
6060

61-
protected IBrush GetBrush(Discord.Color color) => Brush.Parse(color.ToHexadecimalString());
61+
protected IBrush GetBrush(Discord.Color color) => Brush.Parse(color.ToHexadecimalString(""));
6262
}

src/UI/RyuBot.UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>

0 commit comments

Comments
 (0)