//Typing
 public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client,
                                             RequestOptions options = null)
 {
     await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false);
 }
Esempio n. 2
0
 internal RestGuild(BaseDiscordClient client, ulong id)
     : base(client, id)
 {
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false);
 }
Esempio n. 5
0
 internal RestVoiceRegion(BaseDiscordClient client, string id)
     : base(client, id)
 {
 }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
 public static async Task <RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
                                                              RequestOptions options)
 {
     return(await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false));
 }
Esempio n. 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);
 }
Esempio n. 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
                       ));
        }
Esempio n. 10
0
 public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
 => DeleteAsync(msg.Channel.Id, msg.Id, client, options);
Esempio n. 11
0
 public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false);
 }
Esempio n. 12
0
 internal static PruneAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
 {
     return(new PruneAuditLogData(entry.Options.PruneDeleteMemberDays.Value, entry.Options.PruneMembersRemoved.Value));
 }
Esempio n. 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));
        }
Esempio n. 14
0
 public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client,
                                            RequestOptions options)
 => new TypingNotifier(client, channel, options);
Esempio n. 15
0
        //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));
        }
Esempio n. 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);
 }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
 internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
     : base(discord, id, channel, author, source)
 {
 }
Esempio n. 19
0
        //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());
        }
Esempio n. 20
0
 internal RestWebhookUser(BaseDiscordClient discord, IGuild guild, ulong id, ulong webhookId)
     : base(discord, id)
 {
     Guild     = guild;
     WebhookId = webhookId;
 }
Esempio n. 21
0
 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
                ));
 }
Esempio n. 22
0
 internal static RestUser Create(BaseDiscordClient discord, Model model)
 => Create(discord, null, model, null);
Esempio n. 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)));
        }
Esempio n. 24
0
 internal static RestBan Create(BaseDiscordClient client, Model model)
 {
     return(new RestBan(RestUser.Create(client, model.User), model.Reason));
 }
Esempio n. 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);
 }
Esempio n. 26
0
 internal RestUserGuild(BaseDiscordClient discord, ulong id)
     : base(discord, id)
 {
 }
Esempio n. 27
0
 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);
 }
Esempio n. 28
0
 public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
                                         ulong userId, RequestOptions options)
 {
     await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
 }
Esempio n. 29
0
 public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
                                      RequestOptions options)
 {
     await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
 }
Esempio n. 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);
        }