Added CommandContext, fixed commands compile errors
This commit is contained in:
@@ -129,9 +129,9 @@ namespace Discord.Rest
|
||||
|
||||
Task<IApplication> IDiscordClient.GetApplicationInfoAsync() { throw new NotSupportedException(); }
|
||||
|
||||
Task<IChannel> IDiscordClient.GetChannelAsync(ulong id)
|
||||
Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode)
|
||||
=> Task.FromResult<IChannel>(null);
|
||||
Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync()
|
||||
Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode)
|
||||
=> Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(ImmutableArray.Create<IPrivateChannel>());
|
||||
|
||||
Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync()
|
||||
@@ -140,13 +140,13 @@ namespace Discord.Rest
|
||||
Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId)
|
||||
=> Task.FromResult<IInvite>(null);
|
||||
|
||||
Task<IGuild> IDiscordClient.GetGuildAsync(ulong id)
|
||||
Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode)
|
||||
=> Task.FromResult<IGuild>(null);
|
||||
Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync()
|
||||
Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode)
|
||||
=> Task.FromResult<IReadOnlyCollection<IGuild>>(ImmutableArray.Create<IGuild>());
|
||||
Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) { throw new NotSupportedException(); }
|
||||
|
||||
Task<IUser> IDiscordClient.GetUserAsync(ulong id)
|
||||
Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode)
|
||||
=> Task.FromResult<IUser>(null);
|
||||
Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator)
|
||||
=> Task.FromResult<IUser>(null);
|
||||
|
||||
@@ -94,12 +94,12 @@ namespace Discord.Rest
|
||||
return RestUser.Create(client, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<RestUser> GetUserAsync(BaseDiscordClient client,
|
||||
string username, string discriminator)
|
||||
public static async Task<RestGuildUser> GetGuildUserAsync(BaseDiscordClient client,
|
||||
ulong guildId, ulong id)
|
||||
{
|
||||
var model = await client.ApiClient.GetUserAsync(username, discriminator).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(guildId, id).ConfigureAwait(false);
|
||||
if (model != null)
|
||||
return RestUser.Create(client, model);
|
||||
return RestGuildUser.Create(client, new RestGuild(client, guildId), model);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Discord.Net.Queue;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -60,8 +61,8 @@ namespace Discord.Rest
|
||||
public Task<RestUser> GetUserAsync(ulong id)
|
||||
=> ClientHelper.GetUserAsync(this, id);
|
||||
/// <inheritdoc />
|
||||
public Task<RestUser> GetUserAsync(string username, string discriminator)
|
||||
=> ClientHelper.GetUserAsync(this, username, discriminator);
|
||||
public Task<RestGuildUser> GetGuildUserAsync(ulong guildId, ulong id)
|
||||
=> ClientHelper.GetGuildUserAsync(this, guildId, id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync()
|
||||
@@ -74,10 +75,20 @@ namespace Discord.Rest
|
||||
async Task<IApplication> IDiscordClient.GetApplicationInfoAsync()
|
||||
=> await GetApplicationInfoAsync().ConfigureAwait(false);
|
||||
|
||||
async Task<IChannel> IDiscordClient.GetChannelAsync(ulong id)
|
||||
=> await GetChannelAsync(id);
|
||||
async Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync()
|
||||
=> await GetPrivateChannelsAsync();
|
||||
async Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetChannelAsync(id);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
async Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetPrivateChannelsAsync();
|
||||
else
|
||||
return ImmutableArray.Create<IPrivateChannel>();
|
||||
}
|
||||
|
||||
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync()
|
||||
=> await GetConnectionsAsync().ConfigureAwait(false);
|
||||
@@ -85,17 +96,30 @@ namespace Discord.Rest
|
||||
async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId)
|
||||
=> await GetInviteAsync(inviteId).ConfigureAwait(false);
|
||||
|
||||
async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id)
|
||||
=> await GetGuildAsync(id).ConfigureAwait(false);
|
||||
async Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync()
|
||||
=> await GetGuildsAsync().ConfigureAwait(false);
|
||||
async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetGuildAsync(id).ConfigureAwait(false);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
async Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetGuildsAsync().ConfigureAwait(false);
|
||||
else
|
||||
return ImmutableArray.Create<IGuild>();
|
||||
}
|
||||
async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon)
|
||||
=> await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false);
|
||||
|
||||
async Task<IUser> IDiscordClient.GetUserAsync(ulong id)
|
||||
=> await GetUserAsync(id).ConfigureAwait(false);
|
||||
async Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator)
|
||||
=> await GetUserAsync(username, discriminator).ConfigureAwait(false);
|
||||
async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetUserAsync(id).ConfigureAwait(false);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
async Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync()
|
||||
=> await GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -163,19 +163,19 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
//Users
|
||||
public static async Task<RestGuildUser> GetUserAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
public static async Task<RestGuildUser> GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
|
||||
ulong id)
|
||||
{
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id);
|
||||
if (model == null)
|
||||
return null;
|
||||
var user = RestGuildUser.Create(client, model);
|
||||
var user = RestGuildUser.Create(client, guild, model);
|
||||
if (!user.GetPermissions(channel).ReadMessages)
|
||||
return null;
|
||||
|
||||
return user;
|
||||
}
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
|
||||
ulong? froUserId = null, uint? limit = DiscordConfig.MaxUsersPerBatch)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestGuildUser>(
|
||||
@@ -188,8 +188,11 @@ namespace Discord.Rest
|
||||
};
|
||||
if (info.Position != null)
|
||||
args.AfterUserId = info.Position.Value;
|
||||
var models = await client.ApiClient.GetGuildMembersAsync(channel.GuildId, args);
|
||||
return models.Select(x => RestGuildUser.Create(client, x)).ToImmutableArray(); ;
|
||||
var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args);
|
||||
return models
|
||||
.Select(x => RestGuildUser.Create(client, guild, x))
|
||||
.Where(x => x.GetPermissions(channel).ReadMessages)
|
||||
.ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
{
|
||||
|
||||
@@ -16,24 +16,25 @@ namespace Discord.Rest
|
||||
|
||||
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
|
||||
|
||||
public ulong GuildId { get; }
|
||||
internal IGuild Guild { get; }
|
||||
public ulong GuildId => Guild.Id;
|
||||
|
||||
public string Name { get; private set; }
|
||||
public int Position { get; private set; }
|
||||
|
||||
internal RestGuildChannel(BaseDiscordClient discord, ulong id, ulong guildId)
|
||||
internal RestGuildChannel(BaseDiscordClient discord, IGuild guild, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
GuildId = guildId;
|
||||
Guild = guild;
|
||||
}
|
||||
internal new static RestGuildChannel Create(BaseDiscordClient discord, Model model)
|
||||
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
|
||||
{
|
||||
switch (model.Type)
|
||||
{
|
||||
case ChannelType.Text:
|
||||
return RestTextChannel.Create(discord, model);
|
||||
return RestTextChannel.Create(discord, guild, model);
|
||||
case ChannelType.Voice:
|
||||
return RestVoiceChannel.Create(discord, model);
|
||||
return RestVoiceChannel.Create(discord, guild, model);
|
||||
default:
|
||||
throw new InvalidOperationException("Unknown guild channel type");
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace Discord.Rest
|
||||
|
||||
public string Mention => MentionUtils.MentionChannel(Id);
|
||||
|
||||
internal RestTextChannel(BaseDiscordClient discord, ulong id, ulong guildId)
|
||||
: base(discord, id, guildId)
|
||||
internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id)
|
||||
: base(discord, guild, id)
|
||||
{
|
||||
}
|
||||
internal new static RestTextChannel Create(BaseDiscordClient discord, Model model)
|
||||
internal new static RestTextChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
|
||||
{
|
||||
var entity = new RestTextChannel(discord, model.Id, model.GuildId.Value);
|
||||
var entity = new RestTextChannel(discord, guild, model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
@@ -39,9 +39,9 @@ namespace Discord.Rest
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func);
|
||||
|
||||
public Task<RestGuildUser> GetUserAsync(ulong id)
|
||||
=> ChannelHelper.GetUserAsync(this, Discord, id);
|
||||
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
|
||||
=> ChannelHelper.GetUsersAsync(this, Discord);
|
||||
=> ChannelHelper.GetUsersAsync(this, Guild, Discord);
|
||||
|
||||
public Task<RestMessage> GetMessageAsync(ulong id)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id);
|
||||
|
||||
@@ -16,13 +16,13 @@ namespace Discord.Rest
|
||||
public int Bitrate { get; private set; }
|
||||
public int UserLimit { get; private set; }
|
||||
|
||||
internal RestVoiceChannel(BaseDiscordClient discord, ulong id, ulong guildId)
|
||||
: base(discord, id, guildId)
|
||||
internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id)
|
||||
: base(discord, guild, id)
|
||||
{
|
||||
}
|
||||
internal new static RestVoiceChannel Create(BaseDiscordClient discord, Model model)
|
||||
internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
|
||||
{
|
||||
var entity = new RestVoiceChannel(discord, model.Id, model.GuildId.Value);
|
||||
var entity = new RestVoiceChannel(discord, guild, model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ namespace Discord.Rest
|
||||
{
|
||||
var model = await client.ApiClient.GetChannelAsync(guild.Id, id).ConfigureAwait(false);
|
||||
if (model != null)
|
||||
return RestGuildChannel.Create(client, model);
|
||||
return RestGuildChannel.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id).ConfigureAwait(false);
|
||||
return models.Select(x => RestGuildChannel.Create(client, x)).ToImmutableArray();
|
||||
return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray();
|
||||
}
|
||||
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name)
|
||||
@@ -96,7 +96,7 @@ namespace Discord.Rest
|
||||
|
||||
var args = new CreateGuildChannelParams(name, ChannelType.Text);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return RestTextChannel.Create(client, model);
|
||||
return RestTextChannel.Create(client, guild, model);
|
||||
}
|
||||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name)
|
||||
@@ -105,7 +105,7 @@ namespace Discord.Rest
|
||||
|
||||
var args = new CreateGuildChannelParams(name, ChannelType.Voice);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return RestVoiceChannel.Create(client, model);
|
||||
return RestVoiceChannel.Create(client, guild, model);
|
||||
}
|
||||
|
||||
//Integrations
|
||||
@@ -155,7 +155,7 @@ namespace Discord.Rest
|
||||
{
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id).ConfigureAwait(false);
|
||||
if (model != null)
|
||||
return RestGuildUser.Create(client, model);
|
||||
return RestGuildUser.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client)
|
||||
@@ -166,7 +166,7 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new GetGuildMembersParams();
|
||||
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return models.Select(x => RestGuildUser.Create(client, x)).ToImmutableArray();
|
||||
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
|
||||
}
|
||||
public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client,
|
||||
int days = 30, bool simulate = false)
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Discord.Rest
|
||||
public string VoiceRegionId { get; private set; }
|
||||
public string IconId { get; private set; }
|
||||
public string SplashId { get; private set; }
|
||||
internal bool Available { get; private set; }
|
||||
|
||||
public ulong DefaultChannelId => Id;
|
||||
public string IconUrl => API.CDN.GetGuildIconUrl(Id, IconId);
|
||||
@@ -87,6 +88,8 @@ namespace Discord.Rest
|
||||
roles[model.Roles[i].Id] = RestRole.Create(Discord, model.Roles[i]);
|
||||
}
|
||||
_roles = roles.ToImmutable();
|
||||
|
||||
Available = true;
|
||||
}
|
||||
|
||||
//General
|
||||
@@ -169,7 +172,7 @@ namespace Discord.Rest
|
||||
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate);
|
||||
|
||||
//IGuild
|
||||
bool IGuild.Available => true;
|
||||
bool IGuild.Available => Available;
|
||||
IAudioClient IGuild.AudioClient => null;
|
||||
IRole IGuild.EveryoneRole => EveryoneRole;
|
||||
IReadOnlyCollection<IRole> IGuild.Roles => Roles;
|
||||
|
||||
@@ -15,19 +15,30 @@ namespace Discord.Rest
|
||||
private ImmutableArray<ulong> _roleIds;
|
||||
|
||||
public string Nickname { get; private set; }
|
||||
public ulong GuildId { get; private set; }
|
||||
internal IGuild Guild { get; private set; }
|
||||
|
||||
public ulong GuildId => Guild.Id;
|
||||
public GuildPermissions GuildPermissions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Guild.Available)
|
||||
throw new InvalidOperationException("Resolving permissions requires the parent guild to be downloaded.");
|
||||
return new GuildPermissions(Permissions.ResolveGuild(Guild, this));
|
||||
}
|
||||
}
|
||||
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
|
||||
|
||||
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
|
||||
|
||||
internal RestGuildUser(BaseDiscordClient discord, ulong id)
|
||||
internal RestGuildUser(BaseDiscordClient discord, IGuild guild, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
Guild = guild;
|
||||
}
|
||||
internal static RestGuildUser Create(BaseDiscordClient discord, Model model)
|
||||
internal static RestGuildUser Create(BaseDiscordClient discord, IGuild guild, Model model)
|
||||
{
|
||||
var entity = new RestGuildUser(discord, model.User.Id);
|
||||
var entity = new RestGuildUser(discord, guild, model.User.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
@@ -41,7 +52,7 @@ namespace Discord.Rest
|
||||
private void UpdateRoles(ulong[] roleIds)
|
||||
{
|
||||
var roles = ImmutableArray.CreateBuilder<ulong>(roleIds.Length + 1);
|
||||
roles.Add(GuildId);
|
||||
roles.Add(Guild.Id);
|
||||
for (int i = 0; i < roleIds.Length; i++)
|
||||
roles.Add(roleIds[i]);
|
||||
_roleIds = roles.ToImmutable();
|
||||
@@ -56,12 +67,10 @@ namespace Discord.Rest
|
||||
|
||||
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
||||
{
|
||||
throw new NotImplementedException(); //TODO: Impl
|
||||
var guildPerms = GuildPermissions;
|
||||
return new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, guildPerms.RawValue));
|
||||
}
|
||||
|
||||
//IGuildUser
|
||||
IReadOnlyCollection<ulong> IGuildUser.RoleIds => RoleIds;
|
||||
|
||||
//IVoiceState
|
||||
bool IVoiceState.IsDeafened => false;
|
||||
bool IVoiceState.IsMuted => false;
|
||||
|
||||
Reference in New Issue
Block a user