|
| 1 | +using JetBrains.Annotations; |
1 | 2 | using RyuBot.Interactions; |
2 | 3 |
|
3 | 4 | namespace RyuBot.Helpers; |
@@ -45,15 +46,9 @@ public static SocketRole GetHighestRole(this SocketUser user, bool requireColor |
45 | 46 | if (user is not SocketGuildUser sgu) return null; |
46 | 47 |
|
47 | 48 | return sgu.Roles |
48 | | - .Where(x => !requireColor || x.HasColor()) |
| 49 | + .Where(x => !requireColor || x.HasColor) |
49 | 50 | .MaxBy(static x => x.Position); |
50 | 51 | } |
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 | | - } |
57 | 52 |
|
58 | 53 | public static string ToMarkdownTimestamp(long unixSeconds, char timestampType) |
59 | 54 | => $"<t:{unixSeconds}:{timestampType}>"; |
@@ -83,9 +78,6 @@ public static string GetInviteUrl(this IDiscordClient client, bool withAdmin = t |
83 | 78 |
|
84 | 79 | public static string GetInviteUrl(this IDiscordClient client, long permissions) |
85 | 80 | => $"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); |
89 | 81 |
|
90 | 82 | public static void RegisterVolteEventHandlers(this DiscordSocketClient client, ServiceProvider provider) |
91 | 83 | { |
@@ -172,18 +164,24 @@ public static async Task<bool> TryDeleteAsync(this IDeletable deletable, Request |
172 | 164 | public static Task<bool> TryDeleteAsync(this IDeletable deletable, string reason) |
173 | 165 | => deletable.TryDeleteAsync(RequestOptions(opts => opts.AuditLogReason = reason)); |
174 | 166 |
|
175 | | - public static string GetEffectiveUsername(this IGuildUser user) => |
176 | | - user.Nickname ?? user.DisplayName ?? user.Username; |
177 | | - |
178 | 167 | public static string GetEffectiveAvatarUrl(this IUser user, ImageFormat format = ImageFormat.Auto, |
179 | 168 | ushort size = 128) |
180 | 169 | => user.GetAvatarUrl(format, size) ?? user.GetDefaultAvatarUrl(); |
181 | 170 |
|
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 | + } |
184 | 180 |
|
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 | + } |
187 | 185 |
|
188 | 186 | public static EmbedBuilder WithDescription(this EmbedBuilder e, StringBuilder sb) |
189 | 187 | => e.WithDescription(sb.ToString()); |
|
0 commit comments