Beispiel #1
0
        public async Task FreeAsync([RequireInvokerHierarchy("free")] SocketGuildUser user)
        {
            SocketRole role = await modRolesDatabase.PrisonerRole.GetPrisonerRoleAsync(Context.Guild);

            List <SocketRole> roles = await modRolesDatabase.UserRoles.GetUserRolesAsync(user);

            if ((role == null || !user.Roles.Contains(role)) && roles.Count == 0)
            {
                await Context.Channel.SendMessageAsync($"Our security team has informed us that {user.Nickname ?? user.Username} is not held captive.");

                return;
            }

            EmbedBuilder embed = new EmbedBuilder()
                                 .WithColor(new Color(12, 156, 24))
                                 .WithDescription($"{user.Mention} has been freed from Guantanamo Bay after a good amount of ~~torture~~ re-education.");

            List <Task> cmds = new()
            {
                modRolesDatabase.Prisoners.RemovePrisonerAsync(user),
                Context.Channel.SendMessageAsync(embed: embed.Build()),
                FreeModLog.SendToModLogAsync(Context.User as SocketGuildUser, user)
            };

            if (roles.Count > 0)
            {
                cmds.AddRange(new List <Task>()
                {
                    user.AddRolesAsync(roles),
                    modRolesDatabase.UserRoles.RemoveUserRolesAsync(user)
                });
            }
            if (role != null)
            {
                cmds.Add(user.RemoveRoleAsync(role));
            }
            await Task.WhenAll(cmds);

            if (!await modRolesDatabase.Prisoners.HasPrisoners(Context.Guild))
            {
                SocketTextChannel channel = await modRolesDatabase.PrisonerChannel.GetPrisonerChannelAsync(Context.Guild);

                cmds = new()
                {
                    modRolesDatabase.PrisonerChannel.RemovePrisonerChannelAsync(Context.Guild),
                    modRolesDatabase.PrisonerRole.RemovePrisonerRoleAsync(Context.Guild)
                };
                if (channel != null)
                {
                    cmds.Add(channel.DeleteAsync());
                }
                if (role != null)
                {
                    cmds.Add(role.DeleteAsync());
                }
                await Task.WhenAll(cmds);
            }
        }
Beispiel #2
0
        public async Task TempArrestAsync([RequireBotHierarchy("arrest")][RequireInvokerHierarchy("arrest")] SocketGuildUser user, string timeout = null, [Remainder] string reason = null)
        {
            IRole role = await modRolesDatabase.PrisonerRole.GetPrisonerRoleAsync(Context.Guild) ?? await CreatePrisonerRoleAsync();

            if (user.Roles.Contains(role))
            {
                await Context.Channel.SendMessageAsync($"Our security team has informed us that {user.Nickname ?? user.Username} is already held captive.");

                return;
            }

            ITextChannel channel = await modRolesDatabase.PrisonerChannel.GetPrisonerChannelAsync(Context.Guild) ?? await CreateGuantanamoAsync(role);

            List <SocketRole> roles = user.Roles.ToList();

            roles.Remove(Context.Guild.EveryoneRole);
            roles.RemoveAll(x => x.IsManaged);

            await Task.WhenAll
            (
                modRolesDatabase.UserRoles.SaveUserRolesAsync(roles, user),
                user.RemoveRolesAsync(roles),
                user.AddRoleAsync(role),
                modRolesDatabase.Prisoners.RecordPrisonerAsync(user)
            );

            bool         isTimeout = double.TryParse(timeout, out double minutes);
            EmbedBuilder embed     = new EmbedBuilder()
                                     .WithColor(new Color(255, 61, 24))
                                     .WithDescription($"{user.Mention} has been sent to Guantanamo Bay{(timeout != null && isTimeout ? $" for {timeout} {(minutes == 1 ? "minute" : "minutes")}" : "")}.");

            EmbedFieldBuilder reasonField = new EmbedFieldBuilder()
                                            .WithIsInline(false)
                                            .WithName("Reason")
                                            .WithValue($"{reason ?? "*No reason necessary*"}");

            embed.AddField(reasonField);

            await Task.WhenAll
            (
                Context.Channel.SendMessageAsync(embed: embed.Build()),
                ArrestModLog.SendToModLogAsync(Context.User as SocketGuildUser, user, timeout, reason)
            );

            if (isTimeout)
            {
                await Task.Delay((int)(minutes * 60 * 1000));

                role = Context.Guild.GetRole(role.Id);

                if (!user.Roles.Contains(role))
                {
                    return;
                }

                await Task.WhenAll
                (
                    user.AddRolesAsync(roles),
                    user.RemoveRoleAsync(role),
                    modRolesDatabase.UserRoles.RemoveUserRolesAsync(user),
                    modRolesDatabase.Prisoners.RemovePrisonerAsync(user)
                );

                List <Task> cmds = !await modRolesDatabase.Prisoners.HasPrisoners(Context.Guild)
                    ? new List <Task>()
                {
                    channel?.DeleteAsync(),
                            role?.DeleteAsync(),
                            modRolesDatabase.PrisonerChannel.RemovePrisonerChannelAsync(Context.Guild),
                    modRolesDatabase.PrisonerRole.RemovePrisonerRoleAsync(Context.Guild)
                }

                    : new List <Task>();
                cmds.Add(FreeModLog.SendToModLogAsync(Context.Guild.CurrentUser, user));

                await Task.WhenAll(cmds);
            }
        }