コード例 #1
0
ファイル: ChannelHelper.cs プロジェクト: Nensec/FRTools
        /// <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,
                                                                 IEnumerable <KeyValuePair <string, Stream> > files, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, 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(files)
            {
                Content = text, IsTTS = isTTS, Embed = embed?.ToModel() ?? Optional <API.Embed> .Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional <API.AllowedMentions> .Unspecified, MessageReference = messageReference?.ToModel() ?? Optional <API.MessageReference> .Unspecified, IsSpoiler = isSpoiler
            };
            var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestUserMessage.Create(client, channel, client.CurrentUser, model));
        }
コード例 #2
0
ファイル: RestDMChannel.cs プロジェクト: NeKzor/Discord.Net
 /// <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, MessageReference messageReference = null)
 => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, options);
コード例 #3
0
ファイル: ChannelHelper.cs プロジェクト: Nensec/FRTools
        public static async Task <RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client,
                                                                 IEnumerable <string> filePaths, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, RequestOptions options, bool isSpoiler)
        {
            var files = filePaths.Select(x => new KeyValuePair <string, Stream>(Path.GetFileName(x), File.OpenRead(x)));
            var id    = await SendFileAsync(channel, client, files, text, isTTS, embed, allowedMentions, messageReference, options, isSpoiler).ConfigureAwait(false);

            foreach (var file in files)
            {
                file.Value.Dispose();
            }
            return(id);
        }
コード例 #4
0
ファイル: ChannelHelper.cs プロジェクト: Nensec/FRTools
 public static async Task <RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client,
                                                          Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, RequestOptions options, bool isSpoiler)
 => await SendFileAsync(channel, client, new[] { new KeyValuePair <string, Stream>(filename, stream) }, text, isTTS, embed, allowedMentions, messageReference, options, isSpoiler);
コード例 #5
0
 async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
 => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
コード例 #6
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false)
 => (await RestGroupChannel.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler))
 .Abstract();
コード例 #7
0
 public override string Respond(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException();
コード例 #8
0
ファイル: RestDMChannel.cs プロジェクト: NeKzor/Discord.Net
 /// <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);
コード例 #9
0
 async Task <IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options)
 => await SendFileAsync(filePath, text, isTTS, embed, options);
コード例 #10
0
 public Task <RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed = null, RequestOptions options = null)
 => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options);
コード例 #11
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
 => (await(RestGroupChannel as IMessageChannel).SendMessageAsync(text, isTTS, embed, options))
 .Abstract();
コード例 #12
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
 => (await RestGroupChannel.SendMessageAsync(text, isTTS, embed, options))
 .Abstract();
コード例 #13
0
 /// <inheritdoc />
 async Task <IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler)
 => (await(RestGroupChannel as IMessageChannel).SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler))
 .Abstract();
コード例 #14
0
ファイル: RestDMChannel.cs プロジェクト: NeKzor/Discord.Net
 /// <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)
 => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, options, isSpoiler);
コード例 #15
0
 public override Task <RestFollowupMessage> FollowupWithFileAsync(string filePath, string fileName       = null, string text    = null, Embed[] embeds = null, bool isTTS      = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException();
コード例 #16
0
ファイル: RestDMChannel.cs プロジェクト: NeKzor/Discord.Net
 /// <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);
コード例 #17
0
 public override Task <RestFollowupMessage> FollowupWithFilesAsync(IEnumerable <FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException();
コード例 #18
0
 async Task <IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options)
 => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
コード例 #19
0
ファイル: ChannelHelper.cs プロジェクト: Nensec/FRTools
        /// <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, MessageReference messageReference, 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, messageReference, options, isSpoiler).ConfigureAwait(false));
        }
コード例 #20
0
 public Task <RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
 => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
コード例 #21
0
ファイル: ChannelHelper.cs プロジェクト: vijaykakani/AimiBot
        public static async Task <RestUserMessage> SendMessageAsync(IMessageChannel channel, BaseDiscordClient client,
                                                                    string text, bool isTTS, Embed embed, RequestOptions options)
        {
            var args = new CreateMessageParams(text)
            {
                IsTTS = isTTS, Embed = embed?.ToModel()
            };
            var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestUserMessage.Create(client, channel, client.CurrentUser, model));
        }