diff --git a/services/grid-bot/lib/utility/Extensions/IUserMessageExtensions.cs b/services/grid-bot/lib/utility/Extensions/IUserMessageExtensions.cs new file mode 100755 index 00000000..45b6d674 --- /dev/null +++ b/services/grid-bot/lib/utility/Extensions/IUserMessageExtensions.cs @@ -0,0 +1,66 @@ +namespace Grid.Bot.Extensions; + +using System.IO; +using System.Threading.Tasks; + +using Discord; + +/// +/// Extension methods for +/// +public static class IUserMessageExtensions +{ + /// + /// Sends an inline reply that references a message. + /// + /// The message that is being replied on. + /// The stream of the file to send. + /// The name of the file to send. + /// The message to be sent. + /// Determines whether the message should be read aloud by Discord or not. + /// The to be sent. + /// A array of s to send with this response. Max 10. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If , all mentioned roles and users will be notified. + /// + /// The options to be used when sending the request. + /// Determines whether the file should be sent as a spoiler or not. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// Message flags combined as a bitfield. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public static Task ReplyWithFileAsync( + this IUserMessage msg, + Stream fileStream, + string fileName, + string text = null, + bool isTTS = false, + Embed embed = null, + AllowedMentions allowedMentions = null, + RequestOptions options = null, + bool isSpoiler = false, + MessageComponent components = null, + ISticker[] stickers = null, + Embed[] embeds = null, + MessageFlags flags = MessageFlags.None + ) + => msg.Channel.SendFileAsync( + fileStream, + fileName, + text, + isTTS, + embed, + options, + isSpoiler, + allowedMentions, + new MessageReference(messageId: msg.Id), + components, + stickers, + embeds, + flags + ); +} \ No newline at end of file diff --git a/services/grid-bot/lib/utility/Extensions/ModuleBaseExtensions.cs b/services/grid-bot/lib/utility/Extensions/ModuleBaseExtensions.cs new file mode 100755 index 00000000..bd536626 --- /dev/null +++ b/services/grid-bot/lib/utility/Extensions/ModuleBaseExtensions.cs @@ -0,0 +1,163 @@ +namespace Grid.Bot.Extensions; + +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; + +using Discord; +using Discord.Commands; + +/// +/// Extension methods for +/// +public static class ModuleBaseExtensions +{ + /// + /// Sends an inline reply that references a message. + /// + /// The module in use. + /// The message to be sent. + /// Determines whether the message should be read aloud by Discord or not. + /// The to be sent. + /// A array of s to send with this response. Max 10. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If , all mentioned roles and users will be notified. + /// + /// The options to be used when sending the request. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// Message flags combined as a bitfield. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public static Task ReplyWithReferenceAsync( + this ModuleBase module, + string text = null, + bool isTTS = false, + Embed embed = null, + AllowedMentions allowedMentions = null, + RequestOptions options = null, + MessageComponent components = null, + ISticker[] stickers = null, + Embed[] embeds = null, + MessageFlags flags = MessageFlags.None + ) + => module.Context.Channel.SendMessageAsync( + text, + isTTS, + embed, + options, + allowedMentions, + new MessageReference(messageId: module.Context.Message.Id), + components, + stickers, + embeds, + flags + ); + + /// + /// Sends an inline reply that references a message. + /// + /// The module in use. + /// The stream of the file to send. + /// The name of the file to send. + /// The message to be sent. + /// Determines whether the message should be read aloud by Discord or not. + /// The to be sent. + /// A array of s to send with this response. Max 10. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If , all mentioned roles and users will be notified. + /// + /// The options to be used when sending the request. + /// Determines whether the file should be sent as a spoiler or not. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// Message flags combined as a bitfield. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public static Task ReplyWithFileAsync( + this ModuleBase module, + Stream fileStream, + string fileName, + string text = null, + bool isTTS = false, + Embed embed = null, + AllowedMentions allowedMentions = null, + RequestOptions options = null, + bool isSpoiler = false, + MessageComponent components = null, + ISticker[] stickers = null, + Embed[] embeds = null, + MessageFlags flags = MessageFlags.None + ) + => module.Context.Channel.SendFileAsync( + fileStream, + fileName, + text, + isTTS, + embed, + options, + isSpoiler, + allowedMentions, + new MessageReference(messageId: module.Context.Message.Id), + components, + stickers, + embeds, + flags + ); + + /// + /// Sends an inline reply that references a message. + /// + /// The module in use. + /// The file attachments send. + /// The name of the file to send. + /// The message to be sent. + /// Determines whether the message should be read aloud by Discord or not. + /// The to be sent. + /// A array of s to send with this response. Max 10. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If , all mentioned roles and users will be notified. + /// + /// The options to be used when sending the request. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// Message flags combined as a bitfield. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public static Task ReplyWithFilesAsync( + this ModuleBase module, + IEnumerable attachments, + string fileName, + string text = null, + bool isTTS = false, + Embed embed = null, + AllowedMentions allowedMentions = null, + RequestOptions options = null, + MessageComponent components = null, + ISticker[] stickers = null, + Embed[] embeds = null, + MessageFlags flags = MessageFlags.None + ) + => module.Context.Channel.SendFilesAsync( + attachments, + text, + isTTS, + embed, + options, + allowedMentions, + new MessageReference(messageId: module.Context.Message.Id), + components, + stickers, + embeds, + flags + ); +} \ No newline at end of file