Beispiel #1
0
 private ThreadUpdateAuditLogData(IThreadChannel thread, ThreadType type, ThreadInfo before, ThreadInfo after)
 {
     Thread     = thread;
     ThreadType = type;
     Before     = before;
     After      = After;
 }
        public static Task LeaveAsync(this IThreadChannel thread,
                                      IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = thread.GetRestClient();

            return(client.LeaveThreadAsync(thread.Id, options, cancellationToken));
        }
 public ThreadUpdatedEventArgs(
     CachedThreadChannel oldThread,
     IThreadChannel newThread)
 {
     OldThread = oldThread;
     NewThread = newThread;
 }
        public static Task <IReadOnlyList <IThreadMember> > FetchMembersAsync(this IThreadChannel thread,
                                                                              IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = thread.GetRestClient();

            return(client.FetchThreadMembersAsync(thread.Id, options, cancellationToken));
        }
Beispiel #5
0
        public async Task ReportAsync([Remainder] string output = "")
        {
            if (Context.Guild != null)
            {
                _ = WarnOfPublicReport();
            }
            var responseMessage = await Context.Channel.SendMessageAsync(Properties.Resources.ModmailThankYou);

            var guild = Context.Client.GetGuild(SpecialGuilds.CrystalExploratoryMissions);

            var member = guild.GetUser(Context.User.Id);

            var guildConfig = Db.Guilds.Single(g => g.Id == guild.Id);

            var postChannel = guild.GetTextChannel(guildConfig.ReportChannel);
            var threadStart = await postChannel.SendMessageAsync($"{Context.User.Mention} just sent a modmail!");

            var            threadName = member?.Nickname ?? Context.User.Username;
            IThreadChannel thread     =
                postChannel.Threads.FirstOrDefault(t => t.Name == threadName)
                ?? await postChannel.CreateThreadAsync(threadName, message : threadStart);

            await thread.SendMessageAsync($"<@&{guildConfig.Roles["Moderator"]}>");

            while (output.Length > 2000)
            {
                await thread.SendMessageAsync(output[..2000]);
        public ThreadCreatedEventArgs(
            IThreadChannel thread)
        {
            Guard.IsNotNull(thread);

            Thread = thread;
        }
        public static Task <IThreadChannel> ModifyAsync(this IThreadChannel thread,
                                                        Action <ModifyThreadChannelActionProperties> action,
                                                        IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = thread.GetRestClient();

            return(client.ModifyThreadChannelAsync(thread.Id, action, options, cancellationToken));
        }
        public static Task FetchMemberAsync(this IThreadChannel thread,
                                            Snowflake memberId,
                                            IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = thread.GetRestClient();

            return(client.FetchThreadMemberAsync(thread.Id, memberId, options, cancellationToken));
        }
Beispiel #9
0
        public ThreadCreatedEventArgs(IThreadChannel thread)
        {
            if (thread == null)
            {
                throw new ArgumentNullException(nameof(thread));
            }

            Thread = thread;
        }
Beispiel #10
0
 private ThreadCreateAuditLogData(IThreadChannel thread, ulong id, string name, ThreadType type, bool archived,
                                  ThreadArchiveDuration autoArchiveDuration, bool locked, int?rateLimit)
 {
     Thread              = thread;
     ThreadId            = id;
     ThreadName          = name;
     ThreadType          = type;
     IsArchived          = archived;
     AutoArchiveDuration = autoArchiveDuration;
     IsLocked            = locked;
     SlowModeInterval    = rateLimit;
 }
Beispiel #11
0
        public static async Task Handler(IDbService db, SocketMessageComponent component)
        {
            if (component.Data.CustomId != "cem-modmail")
            {
                return;
            }
            if (component.Message.Channel is not ITextChannel channel)
            {
                return;
            }

            var guildConfig = db.Guilds.FirstOrDefault(g => g.Id == channel.GuildId);

            if (guildConfig == null)
            {
                Log.Warning("Modmail: no guild configuration exists for guild {GuildName}", channel.Guild.Name);
                return;
            }

            // Create the user thread
            var member = await channel.Guild.GetUserAsync(component.User.Id);

            var threadName = string.IsNullOrEmpty(member.Nickname) ? member.ToString() : member.Nickname;
            var userThread = await channel.CreateThreadAsync(threadName, ThreadType.PrivateThread);

            var requestMessage = await userThread.SendMessageAsync("Please enter the contents of your modmail here.");

            await userThread.AddUserAsync(member);

            Log.Information("Created thread \"{ThreadName}\" for user \"{User}\".", threadName, member.ToString());

            // Create the mod thread
            if (await channel.Guild.GetTextChannelAsync(guildConfig.ReportChannel) is not SocketTextChannel reportsChannel)
            {
                Log.Warning("Modmail: reports channel is not of type SocketTextChannel");
                return;
            }

            var threadStart = await reportsChannel.SendMessageAsync($"{member.Mention} just sent a modmail!");

            IThreadChannel modThread =
                reportsChannel.Threads.FirstOrDefault(t => t.Name == threadName)
                ?? await reportsChannel.CreateThreadAsync(threadName, message : threadStart);

            await modThread.SendMessageAsync($"<@&{guildConfig.Roles["Moderator"]}>: {requestMessage.GetJumpUrl()}");
        }
        public static async Task <Model> ModifyAsync(IThreadChannel channel, BaseDiscordClient client,
                                                     Action <TextChannelProperties> func,
                                                     RequestOptions options)
        {
            var args = new TextChannelProperties();

            func(args);
            var apiArgs = new ModifyThreadParams
            {
                Name                = args.Name,
                Archived            = args.Archived,
                AutoArchiveDuration = args.AutoArchiveDuration,
                Locked              = args.Locked,
                Slowmode            = args.SlowModeInterval
            };

            return(await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false));
        }
        public static async Task <RestThreadUser> GetUserAsync(ulong userId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null)
        {
            var model = await client.ApiClient.GetThreadMemberAsync(channel.Id, userId, options).ConfigureAwait(false);

            return(RestThreadUser.Create(client, channel.Guild, model, channel));
        }
        internal static RestThreadUser Create(BaseDiscordClient client, IGuild guild, Model model, IThreadChannel channel)
        {
            var entity = new RestThreadUser(client, guild, channel, model.UserId.Value);

            entity.Update(model);
            return(entity);
        }
 internal RestThreadUser(BaseDiscordClient discord, IGuild guild, IThreadChannel channel, ulong id)
     : base(discord, id)
 {
     Guild  = guild;
     Thread = channel;
 }
        public static Task <IReadOnlyList <IThreadChannel> > FetchPublicArchivedThreadsAsync(this IThreadChannel channel, int limit = 100, DateTimeOffset?startFromDate = null, IRestRequestOptions options = null)
        {
            var client = channel.GetRestClient();

            return(client.FetchPublicArchivedThreadsAsync(channel.Id, limit, startFromDate, options));
        }
        public static Task <IReadOnlyList <IThreadMember> > FetchMembersAsync(this IThreadChannel thread, IRestRequestOptions options = null)
        {
            var client = thread.GetRestClient();

            return(client.FetchThreadMembersAsync(thread.Id, options));
        }
        public static Task RemoveMemberAsync(this IThreadChannel thread, Snowflake memberId, IRestRequestOptions options = null)
        {
            var client = thread.GetRestClient();

            return(client.RemoveThreadMemberAsync(thread.Id, memberId, options));
        }
        public static Task LeaveAsync(this IThreadChannel thread, IRestRequestOptions options = null)
        {
            var client = thread.GetRestClient();

            return(client.LeaveThreadAsync(thread.Id, options));
        }
        public static CachedTextChannel GetChannel(this IThreadChannel thread)
        {
            var client = thread.GetGatewayClient();

            return(client.GetChannel(thread.GuildId, thread.ChannelId) as CachedTextChannel);
        }
        public static async Task <RestThreadUser[]> GetUsersAsync(IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null)
        {
            var users = await client.ApiClient.ListThreadMembersAsync(channel.Id, options);

            return(users.Select(x => RestThreadUser.Create(client, channel.Guild, x, channel)).ToArray());
        }