Beispiel #1
0
 /// <inheritdoc />
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task <RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null)
 => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options);
Beispiel #2
0
        /// <summary>
        /// Responds to an Interaction.
        /// <para>
        ///     If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
        ///     <see cref="FollowupAsync(string, bool, Embed, InteractionResponseType, AllowedMentions, RequestOptions)"/> instead.
        /// </para>
        /// </summary>
        /// <param name="text">The text of the message to be sent.</param>
        /// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param>
        /// <param name="embed">A <see cref="Embed"/> to send with this response.</param>
        /// <param name="type">The type of response to this Interaction.</param>
        /// <param name="allowedMentions">The allowed mentions for this response.</param>
        /// <param name="options">The request options for this response.</param>
        /// <returns>
        ///     The <see cref="IMessage"/> sent as the response. If this is the first acknowledgement, it will return null.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
        /// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>

        public async Task <IMessage> RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource, AllowedMentions allowedMentions = null, RequestOptions options = null)
        {
            if (type == InteractionResponseType.Pong)
            {
                throw new InvalidOperationException($"Cannot use {Type} on a send message function");
            }

            if (!IsValidToken)
            {
                throw new InvalidOperationException("Interaction token is no longer valid");
            }

            if (Discord.AlwaysAcknowledgeInteractions)
            {
                return(await FollowupAsync());
            }

            Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
            Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");

            // check that user flag and user Id list are exclusive, same with role flag and role Id list
            if (allowedMentions?.AllowedTypes != null)
            {
                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
                    allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
                {
                    throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
                }

                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
                    allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
                {
                    throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
                }
            }

            var response = new API.InteractionResponse()
            {
                Type = type,
                Data = new API.InteractionApplicationCommandCallbackData(text)
                {
                    AllowedMentions = allowedMentions?.ToModel(),
                    Embeds          = embed != null
                        ? new API.Embed[] { embed.ToModel() }
                        : Optional <API.Embed[]> .Unspecified,
                    TTS = isTTS
                }
            };

            await Discord.Rest.ApiClient.CreateInteractionResponse(response, this.Id, Token, options);

            return(null);
        }
Beispiel #3
0
 public Task <IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 {
     throw new NotImplementedException();
 }
Beispiel #4
0
 /// <inheritdoc />
 /// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task ModifyAsync(Action <MessageProperties> func, RequestOptions options = null, AllowedMentions allowedMentions = null)
 => MessageHelper.ModifyAsync(this, Discord, func, options, allowedMentions);
 /// <inheritdoc />
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task <RestUserMessage> SendFilesAsync(IEnumerable <FileAttachment> attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null)
 => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds);
        public static async Task <ulong> SendMessageAsync(DiscordWebhookClient client,
                                                          string text, bool isTTS, IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, MessageComponent components)
        {
            var args = new CreateWebhookMessageParams
            {
                Content = text,
                IsTTS   = isTTS
            };

            if (embeds != null)
            {
                args.Embeds = embeds.Select(x => x.ToModel()).ToArray();
            }
            if (username != null)
            {
                args.Username = username;
            }
            if (avatarUrl != null)
            {
                args.AvatarUrl = avatarUrl;
            }
            if (allowedMentions != null)
            {
                args.AllowedMentions = allowedMentions.ToModel();
            }
            if (components != null)
            {
                args.Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray();
            }

            var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options : options).ConfigureAwait(false);

            return(model.Id);
        }
Beispiel #7
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference)
 => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference).ConfigureAwait(false);
Beispiel #8
0
        /// <exception cref="ArgumentException">
        /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more
        /// invalid characters as defined by <see cref="System.IO.Path.GetInvalidPathChars"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="filePath" /> is <c>null</c>.
        /// </exception>
        /// <exception cref="PathTooLongException">
        /// The specified path, file name, or both exceed the system-defined maximum length. For example, on
        /// Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260
        /// characters.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        /// The specified path is invalid, (for example, it is on an unmapped drive).
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        /// <paramref name="filePath" /> specified a directory.-or- The caller does not have the required permission.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        /// The file specified in <paramref name="filePath" /> was not found.
        /// </exception>
        /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception>
        /// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
        public static async Task <RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client,
                                                                 string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler)
        {
            string filename = Path.GetFileName(filePath);

            using (var file = File.OpenRead(filePath))
                return(await SendFileAsync(channel, client, file, filename, text, isTTS, embed, allowedMentions, options, isSpoiler).ConfigureAwait(false));
        }
Beispiel #9
0
        /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
        public static async Task <RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client,
                                                                 Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler)
        {
            Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
            Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");

            // check that user flag and user Id list are exclusive, same with role flag and role Id list
            if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
            {
                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
                    allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
                {
                    throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
                }

                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
                    allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
                {
                    throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
                }
            }

            var args = new UploadFileParams(stream)
            {
                Filename = filename, Content = text, IsTTS = isTTS, Embed = embed?.ToModel() ?? Optional <API.Embed> .Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional <API.AllowedMentions> .Unspecified, IsSpoiler = isSpoiler
            };
            var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestUserMessage.Create(client, channel, client.CurrentUser, model));
        }
Beispiel #10
0
 public static async Task <RestThreadChannel> CreatePostAsync(IForumChannel channel, BaseDiscordClient client, string title, ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay, int?slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None)
 {
     embeds ??= Array.Empty <Embed>();
     if (embed != null)
     {
         embeds = new[] { embed }
     }
Beispiel #11
0
        /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
        public static async Task <RestUserMessage> SendMessageAsync(IMessageChannel channel, BaseDiscordClient client,
                                                                    string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, RequestOptions options)
        {
            Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
            Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");

            // check that user flag and user Id list are exclusive, same with role flag and role Id list
            if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
            {
                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
                    allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
                {
                    throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
                }

                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
                    allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
                {
                    throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
                }
            }

            var args = new CreateMessageParams(text)
            {
                IsTTS = isTTS, Embed = embed?.ToModel(), AllowedMentions = allowedMentions?.ToModel(), MessageReference = messageReference?.ToModel()
            };
            var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestUserMessage.Create(client, channel, client.CurrentUser, model));
        }
Beispiel #12
0
        public static async Task <Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action <MessageProperties> func,
                                                     RequestOptions options)
        {
            var args = new MessageProperties();

            func(args);

            var embed  = args.Embed;
            var embeds = args.Embeds;

            bool hasText        = args.Content.IsSpecified && string.IsNullOrEmpty(args.Content.Value);
            bool hasEmbeds      = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0;
            bool hasComponents  = args.Components.IsSpecified && args.Components.Value != null;
            bool hasAttachments = args.Attachments.IsSpecified;

            if (!hasComponents && !hasText && !hasEmbeds && !hasAttachments)
            {
                Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content));
            }

            if (args.AllowedMentions.IsSpecified)
            {
                AllowedMentions allowedMentions = args.AllowedMentions.Value;
                Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
                Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");

                // check that user flag and user Id list are exclusive, same with role flag and role Id list
                if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
                {
                    if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
                        allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
                    {
                        throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
                    }

                    if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
                        allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
                    {
                        throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
                    }
                }
            }

            var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List <API.Embed>() : null;

            if (embed.IsSpecified && embed.Value != null)
            {
                apiEmbeds.Add(embed.Value.ToModel());
            }

            if (embeds.IsSpecified && embeds.Value != null)
            {
                apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel()));
            }

            Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed.");

            if (!args.Attachments.IsSpecified)
            {
                var apiArgs = new API.Rest.ModifyMessageParams
                {
                    Content         = args.Content,
                    Embeds          = apiEmbeds?.ToArray() ?? Optional <API.Embed[]> .Unspecified,
                    Flags           = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create <MessageFlags?>(),
                    AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create <API.AllowedMentions>(),
                    Components      = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty <API.ActionRowComponent>() : Optional <API.ActionRowComponent[]> .Unspecified,
                };
                return(await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false));
            }
            else
            {
                var apiArgs = new UploadFileParams(args.Attachments.Value.ToArray())
                {
                    Content          = args.Content,
                    Embeds           = apiEmbeds?.ToArray() ?? Optional <API.Embed[]> .Unspecified,
                    Flags            = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create <MessageFlags?>(),
                    AllowedMentions  = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create <API.AllowedMentions>(),
                    MessageComponent = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty <API.ActionRowComponent>() : Optional <API.ActionRowComponent[]> .Unspecified
                };

                return(await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false));
            }
        }
Beispiel #13
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions)
 => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions).ConfigureAwait(false);
Beispiel #14
0
 /// <inheritdoc />
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task <RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null)
 => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, options, isSpoiler);
 public static Task <ulong> SendFileAsync(DiscordWebhookClient client, FileAttachment attachment, string text, bool isTTS, IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, MessageComponent components, RequestOptions options)
 => SendFilesAsync(client, new FileAttachment[] { attachment }, text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options);
Beispiel #16
0
 /// <inheritdoc />
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
 public virtual Task <RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false,
                                                     Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null,
                                                     MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null,
                                                     Embed[] embeds = null, MessageFlags flags = MessageFlags.None)
 => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference,
                                components, stickers, options, embeds, flags);
        public static async Task <ulong> SendFilesAsync(DiscordWebhookClient client,
                                                        IEnumerable <FileAttachment> attachments, string text, bool isTTS, IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, MessageComponent components, RequestOptions options)
        {
            embeds ??= Array.Empty <Embed>();

            Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
            Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
            Preconditions.AtMost(embeds.Count(), 10, nameof(embeds), "A max of 10 embeds are allowed.");

            foreach (var attachment in attachments)
            {
                Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null");
            }

            // check that user flag and user Id list are exclusive, same with role flag and role Id list
            if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
            {
                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
                    allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
                {
                    throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
                }

                if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
                    allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
                {
                    throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
                }
            }

            var args = new UploadWebhookFileParams(attachments.ToArray())
            {
                AvatarUrl = avatarUrl, Username = username, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional <API.Embed[]> .Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional <API.AllowedMentions> .Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional <API.ActionRowComponent[]> .Unspecified
            };
            var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options).ConfigureAwait(false);

            return(msg.Id);
        }
Beispiel #18
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS,
                                                         Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference,
                                                         MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags)
 => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference,
                        components, stickers, embeds, flags).ConfigureAwait(false);
Beispiel #19
0
 /// <inheritdoc />
 /// <exception cref="ArgumentException">
 /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more
 /// invalid characters as defined by <see cref="System.IO.Path.GetInvalidPathChars"/>.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="filePath" /> is <c>null</c>.
 /// </exception>
 /// <exception cref="PathTooLongException">
 /// The specified path, file name, or both exceed the system-defined maximum length. For example, on
 /// Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260
 /// characters.
 /// </exception>
 /// <exception cref="DirectoryNotFoundException">
 /// The specified path is invalid, (for example, it is on an unmapped drive).
 /// </exception>
 /// <exception cref="UnauthorizedAccessException">
 /// <paramref name="filePath" /> specified a directory.-or- The caller does not have the required permission.
 /// </exception>
 /// <exception cref="FileNotFoundException">
 /// The file specified in <paramref name="filePath" /> was not found.
 /// </exception>
 /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception>
 /// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task <RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, options, isSpoiler);
Beispiel #20
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendFilesAsync(IEnumerable <FileAttachment> attachments, string text,
                                                          bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference,
                                                          MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags)
 => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags).ConfigureAwait(false);
Beispiel #21
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference)
 => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference).ConfigureAwait(false);
 protected override Task <IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 {
     return(base.ReplyAsync(message, isTTS, embed, options, allowedMentions ?? new AllowedMentions(AllowedMentionTypes.None)));
 }
 /// <inheritdoc />
 /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
 public Task <RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null)
 => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds);
        private async ValueTask HandlePingReaction(MessageReactionAddEvent evt, FullMessage msg)
        {
            if (!_bot.PermissionsIn(evt.ChannelId).HasFlag(PermissionSet.ManageMessages))
            {
                return;
            }

            // Check if the "pinger" has permission to send messages in this channel
            // (if not, PK shouldn't send messages on their behalf)
            var member = await _rest.GetGuildMember(evt.GuildId !.Value, evt.UserId);

            var requiredPerms = PermissionSet.ViewChannel | PermissionSet.SendMessages;

            if (member == null || !_cache.PermissionsFor(evt.ChannelId, member).HasFlag(requiredPerms))
            {
                return;
            }

            if (msg.System.PingsEnabled)
            {
                // If the system has pings enabled, go ahead
                await _rest.CreateMessage(evt.ChannelId, new()
                {
                    Content    = $"Psst, **{msg.Member.DisplayName()}** (<@{msg.Message.Sender}>), you have been pinged by <@{evt.UserId}>.",
                    Components = new []
                    {
                        new MessageComponent
                        {
                            Type       = ComponentType.ActionRow,
                            Components = new[]
                            {
                                new MessageComponent
                                {
                                    Style = ButtonStyle.Link,
                                    Type  = ComponentType.Button,
                                    Label = "Jump",
                                    Url   = evt.JumpLink()
                                }
                            }
                        }
                    },
                    AllowedMentions = new AllowedMentions {
                        Users = new[] { msg.Message.Sender }
                    }
                });
            }
            else
            {
                // If not, tell them in DMs (if we can)
                try
                {
                    var dm = await _cache.GetOrCreateDmChannel(_rest, evt.UserId);

                    await _rest.CreateMessage(dm.Id, new MessageRequest
                    {
                        Content = $"{Emojis.Error} {msg.Member.DisplayName()}'s system has disabled reaction pings. If you want to mention them anyway, you can copy/paste the following message:"
                    });

                    await _rest.CreateMessage(dm.Id, new MessageRequest { Content = $"<@{msg.Message.Sender}>".AsCode() });
                }
                catch (ForbiddenException) { }
            }

            await TryRemoveOriginalReaction(evt);
        }
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds)
 => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false);
        public static async Task <ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS,
                                                       IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, MessageComponent components)
        {
            string filename = Path.GetFileName(filePath);

            using (var file = File.OpenRead(filePath))
                return(await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components).ConfigureAwait(false));
        }
Beispiel #27
0
 public static async Task <IUserMessage> SendMessageSafe(this ISocketMessageChannel self, string message, Embed embed = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null) => await SendMessageSafe(async m => await self.SendMessageAsync(m, false, embed, allowedMentions: allowedMentions ?? AllowedMentions.Regular, messageReference: messageReference), message);
 public static Task <ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS,
                                          IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler,
                                          MessageComponent components)
 => SendFileAsync(client, new FileAttachment(stream, filename, isSpoiler: isSpoiler), text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options);
Beispiel #29
0
        public Task <IUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
        {
            TaskCompletionSource <IUserMessage> taskCompleter = new TaskCompletionSource <IUserMessage>();
            var message = Locator.Instance.Fetch <IUserMessage>() as TestUserMessage;

            message.Message = text;
            taskCompleter.SetResult(message);

            return(taskCompleter.Task);
        }
Beispiel #30
0
 /// <summary> Sends a message to the channel for this webhook with an attachment. </summary>
 /// <returns> Returns the ID of the created message. </returns>
 public Task <ulong> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false,
                                   IEnumerable <Embed> embeds = null, string username             = null, string avatarUrl = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, InteractionRow[] components = null)
 => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler, allowedMentions, components);