/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action <TextChannelProperties> func = null) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var props = new TextChannelProperties(); func?.Invoke(props); var args = new CreateGuildChannelParams(name, ChannelType.Text) { CategoryId = props.CategoryId, Topic = props.Topic, IsNsfw = props.IsNsfw, Position = props.Position, SlowModeInterval = props.SlowModeInterval, Overwrites = props.PermissionOverwrites.IsSpecified ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite { TargetId = overwrite.TargetId, TargetType = overwrite.TargetType, Allow = overwrite.Permissions.AllowValue.ToString(), Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() : Optional.Create <API.Overwrite[]>(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestTextChannel.Create(client, guild, model)); }
internal new static RestTextChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { var entity = new RestTextChannel(discord, guild, model.Id); entity.Update(model); return(entity); }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { return(model.Type switch { ChannelType.News => RestNewsChannel.Create(discord, guild, model), ChannelType.Text => RestTextChannel.Create(discord, guild, model), ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model), ChannelType.Stage => RestStageChannel.Create(discord, guild, model), ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model), _ => new RestGuildChannel(discord, guild, model.Id), });
public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var args = new CreateGuildChannelParams(name, ChannelType.Text); var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestTextChannel.Create(client, guild, model)); }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { switch (model.Type) { case ChannelType.Text: return(RestTextChannel.Create(discord, guild, model)); case ChannelType.Voice: return(RestVoiceChannel.Create(discord, guild, model)); default: throw new InvalidOperationException("Unknown guild channel type"); } }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { switch (model.Type) { case ChannelType.Text: return(RestTextChannel.Create(discord, guild, model)); case ChannelType.Voice: return(RestVoiceChannel.Create(discord, guild, model)); default: // TODO: Channel categories return(new RestGuildChannel(discord, guild, model.Id)); } }
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action <TextChannelProperties> func = null) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var props = new TextChannelProperties(); func?.Invoke(props); var args = new CreateGuildChannelParams(name, ChannelType.Text) { CategoryId = props.CategoryId, Topic = props.Topic, IsNsfw = props.IsNsfw, }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestTextChannel.Create(client, guild, model)); }
/// <summary> /// Constructs a new <see cref="RestTextChannelAbstraction"/> around an existing <see cref="Rest.RestTextChannel"/>. /// </summary> /// <param name="restTextChannel">The value to use for <see cref="Rest.RestTextChannel"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restTextChannel"/>.</exception> public RestTextChannelAbstraction(RestTextChannel restTextChannel) : base(restTextChannel) { }
/// <summary> /// Converts an existing <see cref="RestTextChannel"/> to an abstracted <see cref="IRestTextChannel"/> value. /// </summary> /// <param name="restTextChannel">The existing <see cref="RestTextChannel"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restTextChannel"/>.</exception> /// <returns>An <see cref="IRestTextChannel"/> that abstracts <paramref name="restTextChannel"/>.</returns> public static IRestTextChannel Abstract(this RestTextChannel restTextChannel) => new RestTextChannelAbstraction(restTextChannel);
/// <inheritdoc /> public Task SyncPermissionsAsync(RequestOptions options = null) => RestTextChannel.SyncPermissionsAsync(options);
/// <inheritdoc /> public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) => (await RestTextChannel.SendMessageAsync(text, isTTS, embed, options)) .Abstract();
/// <inheritdoc /> public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) => (await RestTextChannel.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler)) .Abstract();
/// <inheritdoc /> public IDisposable EnterTypingState(RequestOptions options = null) => RestTextChannel.EnterTypingState(options);
/// <inheritdoc /> public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => RestTextChannel.DeleteMessageAsync(message, options);
/// <inheritdoc /> public async Task <IRestUserMessage> ModifyMessageAsync(ulong messageId, Action <MessageProperties> func, RequestOptions options = null) => (IRestUserMessage)(await RestTextChannel.ModifyMessageAsync(messageId, func, options)) ?.Abstract();
/// <inheritdoc /> public IAsyncEnumerable <IReadOnlyCollection <IRestGuildUser> > GetUsersAsync(RequestOptions options = null) => RestTextChannel.GetUsersAsync(options) .Select(x => x .Select(RestGuildUserAbstractionExtensions.Abstract) .ToArray());
/// <inheritdoc /> public async Task <IRestGuildUser> GetUserAsync(ulong id, RequestOptions options = null) => (await RestTextChannel.GetUserAsync(id, options)) ?.Abstract();
/// <inheritdoc /> public async Task <IReadOnlyCollection <IRestMessage> > GetPinnedMessagesAsync(RequestOptions options = null) => (await RestTextChannel.GetPinnedMessagesAsync(options)) .Select(RestMessageAbstractionExtensions.Abstract) .ToArray();
/// <inheritdoc /> public IAsyncEnumerable <IReadOnlyCollection <IRestMessage> > GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null) => RestTextChannel.GetMessagesAsync(fromMessage, dir, limit, options) .Select(x => x .Select(RestMessageAbstractionExtensions.Abstract) .ToArray());
/// <inheritdoc /> public async Task <IReadOnlyCollection <IInviteMetadata> > GetInvitesAsync(RequestOptions options = null) => (await RestTextChannel.GetInvitesAsync(options)) .Select(InviteMetadataAbstractionExtensions.Abstract) .ToArray();
/// <inheritdoc /> public async Task <ICategoryChannel> GetCategoryAsync(RequestOptions options = null) => (await RestTextChannel.GetCategoryAsync(options)) .Abstract();
/// <inheritdoc /> public async Task <IInviteMetadata> CreateInviteAsync(int?maxAge = 86400, int?maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => (await RestTextChannel.CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options)) .Abstract();
/// <inheritdoc /> public async Task <IRestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) => (await RestTextChannel.CreateWebhookAsync(name, avatar, options)) .Abstract();
/// <inheritdoc /> public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) => RestTextChannel.DeleteMessageAsync(messageId, options);
/// <inheritdoc /> public Task ModifyAsync(Action <TextChannelProperties> func, RequestOptions options = null) => RestTextChannel.ModifyAsync(func, options);
/// <inheritdoc /> public Task DeleteMessagesAsync(IEnumerable <ulong> messageIds, RequestOptions options = null) => RestTextChannel.DeleteMessagesAsync(messageIds, options);
/// <inheritdoc /> public async Task <IRestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) => (await RestTextChannel.GetWebhookAsync(id, options)) ?.Abstract();
/// <inheritdoc /> public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null) => (await RestTextChannel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference)) .Abstract();
/// <inheritdoc /> public async Task <IReadOnlyCollection <IRestWebhook> > GetWebhooksAsync(RequestOptions options = null) => (await RestTextChannel.GetWebhooksAsync(options)) .Select(RestWebhookAbstractionExtensions.Abstract) .ToArray();
/// <inheritdoc /> public async Task <IRestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null) => (await RestTextChannel.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions)) .Abstract();