Exemple #1
0
        internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            var entity = new RestThreadChannel(discord, guild, model.Id, model.ThreadMetadata.GetValueOrDefault()?.CreatedAt.GetValueOrDefault());

            entity.Update(model);
            return(entity);
        }
        /// <summary>
        ///     Creates a thread within this <see cref="ITextChannel"/>.
        /// </summary>
        /// <remarks>
        ///     When <paramref name="message"/> is <see langword="null"/> the thread type will be based off of the
        ///     channel its created in. When called on a <see cref="ITextChannel"/>, it creates a <see cref="ThreadType.PublicThread"/>.
        ///     When called on a <see cref="INewsChannel"/>, it creates a <see cref="ThreadType.NewsThread"/>. The id of the created
        ///     thread will be the same as the id of the message, and as such a message can only have a
        ///     single thread created from it.
        /// </remarks>
        /// <param name="name">The name of the thread.</param>
        /// <param name="type">
        ///     The type of the thread.
        ///     <para>
        ///         <b>Note: </b>This parameter is not used if the <paramref name="message"/> parameter is not specified.
        ///     </para>
        /// </param>
        /// <param name="autoArchiveDuration">
        ///     The duration on which this thread archives after.
        ///     <para>
        ///         <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/>
        ///         are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the
        ///         guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>.
        ///     </para>
        /// </param>
        /// <param name="message">The message which to start the thread from.</param>
        /// <param name="options">The options to be used when sending the request.</param>
        /// <returns>
        ///     A task that represents the asynchronous create operation. The task result contains a <see cref="IThreadChannel"/>
        /// </returns>
        public virtual async Task <RestThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread,
                                                                        ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool?invitable = null, int?slowmode = null, RequestOptions options = null)
        {
            var model = await ThreadHelper.CreateThreadAsync(Discord, this, name, type, autoArchiveDuration, message, invitable, slowmode, options);

            return(RestThreadChannel.Create(Discord, Guild, model));
        }
Exemple #3
0
        internal static ThreadUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
        {
            var changes = entry.Changes;

            var id = entry.TargetId.Value;

            var nameModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name");
            var typeModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "type");

            var archivedModel            = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "archived");
            var autoArchiveDurationModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "auto_archive_duration");
            var lockedModel           = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "locked");
            var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user");

            var type = typeModel.OldValue.ToObject <ThreadType>(discord.ApiClient.Serializer);

            var oldName                = nameModel.OldValue.ToObject <string>(discord.ApiClient.Serializer);
            var oldArchived            = archivedModel.OldValue.ToObject <bool>(discord.ApiClient.Serializer);
            var oldAutoArchiveDuration = autoArchiveDurationModel.OldValue.ToObject <ThreadArchiveDuration>(discord.ApiClient.Serializer);
            var oldLocked              = lockedModel.OldValue.ToObject <bool>(discord.ApiClient.Serializer);
            var oldRateLimit           = rateLimitPerUserModel?.OldValue?.ToObject <int>(discord.ApiClient.Serializer);
            var before = new ThreadInfo(oldName, oldArchived, oldAutoArchiveDuration, oldLocked, oldRateLimit);

            var newName                = nameModel.NewValue.ToObject <string>(discord.ApiClient.Serializer);
            var newArchived            = archivedModel.NewValue.ToObject <bool>(discord.ApiClient.Serializer);
            var newAutoArchiveDuration = autoArchiveDurationModel.NewValue.ToObject <ThreadArchiveDuration>(discord.ApiClient.Serializer);
            var newLocked              = lockedModel.NewValue.ToObject <bool>(discord.ApiClient.Serializer);
            var newRateLimit           = rateLimitPerUserModel?.NewValue?.ToObject <int>(discord.ApiClient.Serializer);
            var after = new ThreadInfo(newName, newArchived, newAutoArchiveDuration, newLocked, newRateLimit);

            var threadInfo    = log.Threads.FirstOrDefault(x => x.Id == id);
            var threadChannel = threadInfo == null ? null : RestThreadChannel.Create(discord, (IGuild)null, threadInfo);

            return(new ThreadUpdateAuditLogData(threadChannel, type, before, after));
        }
Exemple #4
0
        public static async Task <IReadOnlyCollection <RestThreadChannel> > GetJoinedPrivateArchivedThreadsAsync(IGuildChannel channel, BaseDiscordClient client, int?limit = null,
                                                                                                                 DateTimeOffset?before = null, RequestOptions options = null)
        {
            var result = await client.ApiClient.GetJoinedPrivateArchivedThreadsAsync(channel.Id, before, limit, options);

            return(result.Threads.Select(x => RestThreadChannel.Create(client, channel.Guild, x)).ToImmutableArray());
        }
        internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            var entity = new RestThreadChannel(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),
     });
Exemple #7
0
        public static async Task <IReadOnlyCollection <RestThreadChannel> > GetActiveThreadsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
        {
            var result = await client.ApiClient.GetActiveThreadsAsync(guild.Id, options).ConfigureAwait(false);

            return(result.Threads.Select(x => RestThreadChannel.Create(client, guild, x)).ToImmutableArray());
        }