public async Task PurgeRole(string roleName)
        {
            IUser user = Context.User;
            IRole role = (user as IGuildUser).Guild.Roles.FirstOrDefault(x => x.Name == roleName);

            await role.DeleteAsync();

            await ReplyAsync($"Deleted role {role.Name}");
        }
Exemple #2
0
        public async Task DeleteRoleAsync(
            [Remainder]
            [Summary("The pingable role to delete.")]
            IRole role)
        {
            await _designatedRoleService.RemoveDesignatedRoleAsync(Context.Guild.Id, role.Id, DesignatedRoleType.Pingable);

            await role.DeleteAsync();

            await ReplyAsync($"Deleted role {Format.Bold(role.Name)}.");
        }
Exemple #3
0
        private async Task DeleteGameRoleAndVoiceChannel(SocketGuild guild, IRole gameRole, SocketGuildUser user)
        {
            await user.RemoveRoleAsync(gameRole);

            if (!guild.Users.Where(x => x != user).Any(x => x.Roles.Contains(gameRole))) // raderar
            {
                SocketVoiceChannel channel = guild.VoiceChannels.Where(x => x.ToString().Equals(gameRole.Name) && x.Bitrate == 96000).FirstOrDefault();
                await gameRole.DeleteAsync();

                await channel.DeleteAsync();
            }
        }
            public async Task DeleteRole([Remainder] IRole role)
            {
                var guser = (IGuildUser)Context.User;

                if (Context.User.Id != guser.Guild.OwnerId &&
                    guser.GetRoles().Max(x => x.Position) <= role.Position)
                {
                    return;
                }

                await role.DeleteAsync().ConfigureAwait(false);

                await ReplyConfirmLocalizedAsync("dr", Format.Bold(role.Name)).ConfigureAwait(false);
            }
Exemple #5
0
        public async Task RemoveColorAsync()
        {
            IRole _role = Context.Guild.Roles.FirstOrDefault(x => x.Name == $"USER-{Context.User.Id}");

            if (_role != null)
            {
                await ReplyAsync($"Removed your color role. Use `g.colorrole` `{_role.Color.R.ToString("X2") + _role.Color.G.ToString("X2") + _role.Color.B.ToString("X2")}` to get your color back.");

                await _role.DeleteAsync();
            }
            else
            {
                await ReplyAsync($"You don't have a color role. Use `g.colorrole` `ffffff` to get one.");
            }
        }
Exemple #6
0
        public async Task DeleteRole([Remainder] IRole targetRole)
        {
            if (!Context.Guild.Roles.Contains(targetRole))
            {
                await ReplyAsync("Cannot delete that role - It does not exist. Quite frankly Discord.NET should have barfed before this so if you're seeing this something broke.");

                return;
            }

            if (!_roleIds.Any(x => Context.Guild.Roles.Any(y => y.Id == x)))
            {
                await ReplyAsync("Cannot delete that role - it is not a marker role.");

                return;
            }

            _roleIds.Remove(targetRole.Id);
            await targetRole.DeleteAsync();

            await ReplyAsync($"Deleted and unregistered role `{targetRole.Name}`.");
        }
Exemple #7
0
        public async Task DeleteMentionGroup([Remainder] IRole role)
        {
            if (!await IsJoinableGroup(role.Id))
            {
                await ReplyAsync($"Cannot delete group \"{role.Name}\" as it is not a custom mention group.");
            }
            else if (Context.Guild.Users.Any(u => !u.IsBot && u.Roles.Select(r => r.Id).Contains(role.Id)))
            {
                await ReplyAsync($"There are currently members part of the group \"{role.Name}\". Only mention groups without members can be deleted.");
            }
            else
            {
                var db        = new AwsDbContext();
                var dbRoleObj = new MentionRole();
                dbRoleObj.RoleId = role.Id;
                await db.Delete(dbRoleObj);

                await role.DeleteAsync();
                await ReplyAsync($"Mention group deleted successfully.");
            }
        }
Exemple #8
0
        public async Task RoleDelete(SocketGuild server, IRole role, SocketChannel channel = null, bool outputMessages = false)
        {
            // Define variables
            string output;

            // Initialise variables
            output = "";

            try
            {
                output += $"Role {role.Name} deleted.";
                await role.DeleteAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            if (channel != null && outputMessages)
            {
                await ReplyAsync(output);
            }
        }
Exemple #9
0
        public async Task clear()
        {
            Console.WriteLine(Context.Message.Author.Username);
            if (Context.Message.Author.Username == "hex")
            {
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Clearing all objects...");

                //iterate through groups and delete everything
                ArrayList groups = (ArrayList)SaveGroup.get();
                int       count  = groups.Count;
                if (count != 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        Group group = (Group)groups[i];

                        //delete group role
                        IRole role = group.getRole();
                        Console.WriteLine("Role: " + role);
                        //group role can not exist
                        try
                        {
                            await role.DeleteAsync();
                        }
                        catch (Exception e)
                        {
                        }

                        //delete creator role
                        IRole creatorRole = group.getCreatorRole();
                        Console.WriteLine("Creator Role: " + creatorRole);
                        await creatorRole.DeleteAsync();

                        //delete group channel
                        RestVoiceChannel channel = group.getChannel();
                        Console.WriteLine("Channel: " + channel);
                        //channel can not exist
                        try
                        {
                            await channel.DeleteAsync();
                        }
                        catch (Exception e)
                        {
                        }

                        //Store empty group object
                        SaveGroup.store(new ArrayList());
                    }
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Cleared succesfully!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Nothing to clear.");
                }
            }
            else
            {
                //INVALID USER
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: You are not my creator...");
            }
        }
Exemple #10
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);
            }
        }
Exemple #11
0
        public async Task StartRemindersAsync()
        {
            var dbGuild = _database.Guild;

            var channel = _client.GetChannel(dbGuild.WarChannelId) as SocketTextChannel;
            var guild   = channel.Guild;

            IRole warRole = null;

            while (true)
            {
                try
                {
                    var currentWar = await _clash.GetCurrentWarAsync(dbGuild.ClanTag);

                    if (currentWar is null || currentWar.State == WarState.Default || currentWar.State == WarState.Ended)
                    {
                        await Task.Delay(TimeSpan.FromMinutes(10), _maintenanceCts.Token);

                        continue;
                    }

                    async Task RunRemindersAsync(bool hasMatched)
                    {
                        TimeSpan threshold;

                        if (hasMatched)
                        {
                            currentWar = await _clash.GetCurrentWarAsync(dbGuild.ClanTag);

                            threshold = DateTimeOffset.UtcNow - currentWar.StartTime;
                        }

                        else
                        {
                            threshold = DateTimeOffset.UtcNow - currentWar.PreparationTime;
                        }

                        if (threshold < TimeSpan.FromMinutes(60))
                        {
                            if (!hasMatched)
                            {
                                warRole = await WarMatchAsync(channel, dbGuild, guild, currentWar);

                                var startTime = currentWar.StartTime - DateTimeOffset.UtcNow;

                                await Task.Delay(startTime, _maintenanceCts.Token);
                            }

                            await channel.SendMessageAsync($"{warRole?.Mention} war has started!");

                            _warTcs.SetResult(true);

                            var beforeEnd = currentWar.EndTime - DateTimeOffset.UtcNow.AddHours(1);

                            await Task.Delay(beforeEnd, _maintenanceCts.Token);

                            currentWar = await _clash.GetCurrentWarAsync(dbGuild.ClanTag);

                            await NeedToAttackAsync(channel, dbGuild.GuildMembers, currentWar);

                            await Task.Delay(TimeSpan.FromHours(1).Add(TimeSpan.FromMinutes(10)));

                            currentWar = await _clash.GetCurrentWarAsync(dbGuild.ClanTag);

                            await WarEndedAsync(channel, dbGuild.GuildMembers, currentWar);

                            await warRole.DeleteAsync();
                        }
                    }

                    switch (currentWar.State)
                    {
                    case WarState.Preparation:
                        await RunRemindersAsync(false);

                        break;

                    case WarState.InWar:
                        await RunRemindersAsync(true);

                        break;
                    }

                    await Task.Delay(TimeSpan.FromMinutes(10), _maintenanceCts.Token);
                }
                catch (TaskCanceledException)
                {
                    await channel.SendMessageAsync("Maintenance break");

                    try
                    {
                        await Task.Delay(-1, _noMaintenanceCts.Token);
                    }
                    catch (TaskCanceledException) { }

                    await channel.SendMessageAsync("Maintenance ended");
                }
                catch (Exception ex)
                {
                    await _logger.LogAsync(Source.Reminder, Severity.Error, string.Empty, ex);
                }
                finally
                {
                    _warTcs = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
                }
            }
        }