コード例 #1
0
 //Typing
 public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client,
                                             RequestOptions options = null)
 {
     await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false);
 }
コード例 #2
0
 internal RestGuild(BaseDiscordClient client, ulong id)
     : base(client, id)
 {
 }
コード例 #3
0
ファイル: GuildHelper.cs プロジェクト: MarkKoz/Discord.Net
        public static async Task <IReadOnlyCollection <RoleModel> > ReorderRolesAsync(IGuild guild, BaseDiscordClient client,
                                                                                      IEnumerable <ReorderRoleProperties> args, RequestOptions options)
        {
            var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id, x.Position));

            return(await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false));
        }
コード例 #4
0
 public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false);
 }
コード例 #5
0
 internal RestVoiceRegion(BaseDiscordClient client, string id)
     : base(client, id)
 {
 }
コード例 #6
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
        public static async Task <RestGuildIntegration> CreateIntegrationAsync(IGuild guild, BaseDiscordClient client,
                                                                               ulong id, string type, RequestOptions options)
        {
            var args  = new CreateGuildIntegrationParams(id, type);
            var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestGuildIntegration.Create(client, guild, model));
        }
コード例 #7
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
 public static async Task <RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
                                                              RequestOptions options)
 {
     return(await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false));
 }
コード例 #8
0
 public static async Task RemoveReactionAsync(IMessage msg, IUser user, IEmote emote, BaseDiscordClient client, RequestOptions options)
 {
     await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, user.Id, emote is Emote e?$"{e.Name}:{e.Id}" : emote.Name, options).ConfigureAwait(false);
 }
コード例 #9
0
        public static IAsyncEnumerable <IReadOnlyCollection <IUser> > GetReactionUsersAsync(IMessage msg, IEmote emote,
                                                                                            int?limit, BaseDiscordClient client, RequestOptions options)
        {
            Preconditions.NotNull(emote, nameof(emote));
            var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name);

            return(new PagedAsyncEnumerable <IUser>(
                       DiscordConfig.MaxUserReactionsPerBatch,
                       async(info, ct) =>
            {
                var args = new GetReactionUsersParams
                {
                    Limit = info.PageSize
                };

                if (info.Position != null)
                {
                    args.AfterUserId = info.Position.Value;
                }

                var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false);
                return models.Select(x => RestUser.Create(client, x)).ToImmutableArray();
            },
                       nextPage: (info, lastPage) =>
            {
                if (lastPage.Count != DiscordConfig.MaxUserReactionsPerBatch)
                {
                    return false;
                }

                info.Position = lastPage.Max(x => x.Id);
                return true;
            },
                       count: limit
                       ));
        }
コード例 #10
0
 public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
 => DeleteAsync(msg.Channel.Id, msg.Id, client, options);
コード例 #11
0
 public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false);
 }
コード例 #12
0
 internal static PruneAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
 {
     return(new PruneAuditLogData(entry.Options.PruneDeleteMemberDays.Value, entry.Options.PruneMembersRemoved.Value));
 }
コード例 #13
0
        public static async Task <RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
                                                                        int?maxAge, int?maxUses, bool isTemporary, bool isUnique, RequestOptions options)
        {
            var args = new CreateChannelInviteParams {
                IsTemporary = isTemporary, IsUnique = isUnique
            };

            if (maxAge.HasValue)
            {
                args.MaxAge = maxAge.Value;
            }
            else
            {
                args.MaxAge = 0;
            }
            if (maxUses.HasValue)
            {
                args.MaxUses = maxUses.Value;
            }
            else
            {
                args.MaxUses = 0;
            }
            var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestInviteMetadata.Create(client, null, channel, model));
        }
コード例 #14
0
 public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client,
                                            RequestOptions options)
 => new TypingNotifier(client, channel, options);
コード例 #15
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
        //General
        public static async Task <Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
                                                     Action <GuildProperties> func, RequestOptions options)
        {
            if (func == null)
            {
                throw new NullReferenceException(nameof(func));
            }

            var args = new GuildProperties();

            func(args);

            var apiArgs = new API.Rest.ModifyGuildParams
            {
                AfkChannelId = args.AfkChannelId,
                AfkTimeout   = args.AfkTimeout,
                DefaultMessageNotifications = args.DefaultMessageNotifications,
                Icon              = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional.Create <ImageModel?>(),
                Name              = args.Name,
                Splash            = args.Splash.IsSpecified ? args.Splash.Value?.ToModel() : Optional.Create <ImageModel?>(),
                Username          = args.Username,
                VerificationLevel = args.VerificationLevel
            };

            if (args.AfkChannel.IsSpecified)
            {
                apiArgs.AfkChannelId = args.AfkChannel.Value.Id;
            }
            else if (args.AfkChannelId.IsSpecified)
            {
                apiArgs.AfkChannelId = args.AfkChannelId.Value;
            }

            if (args.Owner.IsSpecified)
            {
                apiArgs.OwnerId = args.Owner.Value.Id;
            }
            else if (args.OwnerId.IsSpecified)
            {
                apiArgs.OwnerId = args.OwnerId.Value;
            }

            if (args.Region.IsSpecified)
            {
                apiArgs.RegionId = args.Region.Value.Id;
            }
            else if (args.RegionId.IsSpecified)
            {
                apiArgs.RegionId = args.RegionId.Value;
            }

            if (!apiArgs.Splash.IsSpecified && guild.SplashId != null)
            {
                apiArgs.Splash = new ImageModel(guild.SplashId);
            }
            if (!apiArgs.Icon.IsSpecified && guild.IconId != null)
            {
                apiArgs.Icon = new ImageModel(guild.IconId);
            }

            return(await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false));
        }
コード例 #16
0
 public static async Task PinAsync(IMessage msg, BaseDiscordClient client,
                                   RequestOptions options)
 {
     await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
 }
コード例 #17
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var args  = new CreateGuildChannelParams(name, ChannelType.Voice);
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
コード例 #18
0
 internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
     : base(discord, id, channel, author, source)
 {
 }
コード例 #19
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
        //Invites
        public static async Task <IReadOnlyCollection <RestInviteMetadata> > GetInvitesAsync(IGuild guild, BaseDiscordClient client,
                                                                                             RequestOptions options)
        {
            var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);

            return(models.Select(x => RestInviteMetadata.Create(client, guild, null, x)).ToImmutableArray());
        }
コード例 #20
0
ファイル: RestWebhookUser.cs プロジェクト: COsborn2/GhandiBot
 internal RestWebhookUser(BaseDiscordClient discord, IGuild guild, ulong id, ulong webhookId)
     : base(discord, id)
 {
     Guild     = guild;
     WebhookId = webhookId;
 }
コード例 #21
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
 public static IAsyncEnumerable <IReadOnlyCollection <RestGuildUser> > GetUsersAsync(IGuild guild, BaseDiscordClient client,
                                                                                     ulong?fromUserId, int?limit, RequestOptions options)
 {
     return(new PagedAsyncEnumerable <RestGuildUser>(
                DiscordConfig.MaxMessagesPerBatch,
                async(info, ct) =>
     {
         var args = new GetGuildMembersParams
         {
             Limit = info.PageSize
         };
         if (info.Position != null)
         {
             args.AfterUserId = info.Position.Value;
         }
         var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
         return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
     },
                nextPage: (info, lastPage) =>
     {
         if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch)
         {
             return false;
         }
         info.Position = lastPage.Max(x => x.Id);
         return true;
     },
                start: fromUserId,
                count: limit
                ));
 }
コード例 #22
0
 internal static RestUser Create(BaseDiscordClient discord, Model model)
 => Create(discord, null, model, null);
コード例 #23
0
        internal static MessageUnpinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
        {
            var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);

            return(new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, RestUser.Create(discord, userInfo)));
        }
コード例 #24
0
ファイル: RestBan.cs プロジェクト: Lelouch99/bot_cc
 internal static RestBan Create(BaseDiscordClient client, Model model)
 {
     return(new RestBan(RestUser.Create(client, model.User), model.Reason));
 }
コード例 #25
0
 internal RestDMChannel(BaseDiscordClient discord, ulong id, ulong recipientId)
     : base(discord, id)
 {
     Recipient   = new RestUser(Discord, recipientId);
     CurrentUser = new RestUser(Discord, discord.CurrentUser.Id);
 }
コード例 #26
0
 internal RestUserGuild(BaseDiscordClient discord, ulong id)
     : base(discord, id)
 {
 }
コード例 #27
0
ファイル: GuildHelper.cs プロジェクト: MarkKoz/Discord.Net
 public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client,
                                               IEnumerable <ReorderChannelProperties> args, RequestOptions options)
 {
     var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position));
     await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
 }
コード例 #28
0
ファイル: GuildHelper.cs プロジェクト: speakezz/Discord.Net
 public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
                                         ulong userId, RequestOptions options)
 {
     await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
 }
コード例 #29
0
ファイル: GuildHelper.cs プロジェクト: MarkKoz/Discord.Net
 public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
 }
コード例 #30
0
        //Users
        public static async Task <RestGuildUser> GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
                                                              ulong id, RequestOptions options)
        {
            var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options).ConfigureAwait(false);

            if (model == null)
            {
                return(null);
            }
            var user = RestGuildUser.Create(client, guild, model);

            if (!user.GetPermissions(channel).ReadMessages)
            {
                return(null);
            }

            return(user);
        }