//Typing public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, RequestOptions options = null) { await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false); }
internal RestGuild(BaseDiscordClient client, ulong id) : base(client, id) { }
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)); }
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false); }
internal RestVoiceRegion(BaseDiscordClient client, string id) : base(client, id) { }
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)); }
public static async Task <RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { return(await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false)); }
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); }
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 )); }
public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) => DeleteAsync(msg.Channel.Id, msg.Id, client, options);
public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); }
internal static PruneAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { return(new PruneAuditLogData(entry.Options.PruneDeleteMemberDays.Value, entry.Options.PruneMembersRemoved.Value)); }
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)); }
public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) => new TypingNotifier(client, channel, options);
//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)); }
public static async Task PinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); }
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)); }
internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source) : base(discord, id, channel, author, source) { }
//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()); }
internal RestWebhookUser(BaseDiscordClient discord, IGuild guild, ulong id, ulong webhookId) : base(discord, id) { Guild = guild; WebhookId = webhookId; }
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 )); }
internal static RestUser Create(BaseDiscordClient discord, Model model) => Create(discord, null, model, null);
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))); }
internal static RestBan Create(BaseDiscordClient client, Model model) { return(new RestBan(RestUser.Create(client, model.User), model.Reason)); }
internal RestDMChannel(BaseDiscordClient discord, ulong id, ulong recipientId) : base(discord, id) { Recipient = new RestUser(Discord, recipientId); CurrentUser = new RestUser(Discord, discord.CurrentUser.Id); }
internal RestUserGuild(BaseDiscordClient discord, ulong id) : base(discord, id) { }
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); }
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) { await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); }
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); }
//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); }