示例#1
0
        public static async Task <IReadOnlyCollection <RestGuildChannel> > GetChannelsAsync(IGuild guild, BaseDiscordClient client,
                                                                                            RequestOptions options)
        {
            var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false);

            return(models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray());
        }
示例#2
0
        //Channels
        public static async Task <RestGuildChannel> GetChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                    ulong id, RequestOptions options)
        {
            var model = await client.ApiClient.GetChannelAsync(guild.Id, id, options).ConfigureAwait(false);

            if (model != null)
            {
                return(RestGuildChannel.Create(client, guild, model));
            }
            return(null);
        }
示例#3
0
        internal static RestChannel Create(BaseDiscordClient discord, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
            case ChannelType.Voice:
                return(RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model));

            case ChannelType.DM:
            case ChannelType.Group:
                return(CreatePrivate(discord, model) as RestChannel);

            default:
                return(new RestChannel(discord, model.Id));
            }
        }
示例#4
0
 /// <exception cref="InvalidOperationException">Unexpected channel type.</exception>
 internal static RestChannel Create(BaseDiscordClient discord, Model model)
 {
     return(model.Type switch
     {
         ChannelType.News or
         ChannelType.Text or
         ChannelType.Voice or
         ChannelType.Stage or
         ChannelType.NewsThread or
         ChannelType.PrivateThread or
         ChannelType.PublicThread
         => RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model),
         ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel,
         ChannelType.Category => RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model),
         _ => new RestChannel(discord, model.Id),
     });
示例#5
0
        internal static RestChannel Create(BaseDiscordClient discord, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
            case ChannelType.Voice:
                return(RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model));

            case ChannelType.DM:
            case ChannelType.Group:
                return(CreatePrivate(discord, model) as RestChannel);

            default:
                throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
            }
        }