-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Null channels within private thread channels. (#335)
#!components: grid-bot #!deployable-components: grid-bot * Update ScriptLogger.cs ~ Take into account that forum channels exist. ~ Allow logging of already existing script hashes (just log the hash instead of the whole content) * Implement channel patches discord-net/Discord.Net#2997 and #335 In the case of interactions, fallback to ChannelId. In the case of messages, fallback to Thread ID. * Update build.yml Add ability to append suffixes to versions * Add fixture * Correct ref mistake * #335: SocketInteractionContext extensions Implement extension methods for the socket interaction context class for the following purposes: ~ Getting the channel as a string, taking into consideration that the channel can be null when interactions are executed within private thread channels. ~ Getting the guild as an object from the interaction context when the interaction is coming from a private thread channel, as the conventional method of checking the type of the interaction's channel against SocketGuildChannel will not work. * LuaUtility.cs ~ Move Regex for format parts to a GeneratedRegex function to improve performance. ~ Only read the LuaVM template once, as it is read from the resources on every subsequent use. ~ Account for the absence of the LuaVM in results. * #335: Private threads hotfix. ExecuteScript.cs: ~ Take reference to current DiscordShardedClient. ~ Move correspondence calls when errors are called to use LuaError instead of regular follow ups. ~ Add detection of scripts containing code blocks within zero content (causes exception) ~ Rewrite error for scripts that contain unicode to reduce ambiguity. ~ Rename GridJob to ClientJob. ~ Clean up call to PollDeletion ~ Integrate use of GetChannelAsString and GetGuild. OnSlashCommand, OnSlashCommandExecuted, LoggerFactory, ScriptLogger: ~ Clean up usings. ~ Rewrite GetGuildId to use extension methods. ~ Change around references to channel to use extension methods.
- Loading branch information
Showing
9 changed files
with
176 additions
and
66 deletions.
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
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
40 changes: 40 additions & 0 deletions
40
services/grid-bot/lib/utility/Extensions/SocketInteractionExtensions.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,40 @@ | ||
namespace Grid.Bot.Extensions; | ||
|
||
using Discord; | ||
using Discord.WebSocket; | ||
|
||
using Threading.Extensions; | ||
|
||
/// <summary> | ||
/// Extension methods for <see cref="SocketInteraction" /> | ||
/// </summary> | ||
public static class SocketInteractionExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the channel from the <see cref="SocketInteraction" />, taking private threads into consideration. | ||
/// </summary> | ||
/// <param name="interaction">The current <see cref="SocketInteraction"/></param> | ||
/// <returns>A string version of either <see cref="ISocketMessageChannel"/> or <see cref="IMessageChannel"/></returns> | ||
public static string GetChannelAsString(this SocketInteraction interaction) | ||
{ | ||
if (interaction.Channel is not null) return interaction.Channel.ToString(); | ||
|
||
return interaction.InteractionChannel.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets an <see cref="IGuild"/> for a specific <see cref="SocketInteraction"/>, taking private threads into consideration. | ||
/// </summary> | ||
/// <param name="interaction"></param> | ||
/// <param name="client"></param> | ||
/// <returns></returns> | ||
public static IGuild GetGuild(this SocketInteraction interaction, IDiscordClient client) | ||
{ | ||
if (interaction.GuildId == null) return null; | ||
|
||
if (interaction.Channel is SocketGuildChannel guildChannel) | ||
return guildChannel.Guild; | ||
|
||
return client.GetGuildAsync(interaction.GuildId.Value).SyncOrDefault(); | ||
} | ||
} |
Oops, something went wrong.