Exemplo n.º 1
0
        public async Task AddAssignableRoleAsync(CachedMember member)
        {
            var currentMember = member.Guild.CurrentMember;

            if (!currentMember.Permissions.ManageRoles)
            {
                return;
            }

            if (member.Roles.Count > 1)
            {
                return;
            }

            using var scope = RiasBot.CreateScope();
            var db      = scope.ServiceProvider.GetRequiredService <RiasDbContext>();
            var guildDb = await db.Guilds.FirstOrDefaultAsync(x => x.GuildId == member.Guild.Id);

            if (guildDb is null)
            {
                return;
            }

            var aar = member.Guild.GetRole(guildDb.AutoAssignableRoleId);

            if (aar is null)
            {
                return;
            }

            if (currentMember.CheckRoleHierarchy(aar) > 0 && !aar.IsManaged && member.GetRole(aar.Id) is null)
            {
                await member.GrantRoleAsync(aar.Id);
            }
        }
        public override async Task RewardAsync(CachedMember member)
        {
            foreach (var id in AddedRoleIds)
            {
                await member.GrantRoleAsync(id);
            }

            foreach (var id in RemovedRoleIds)
            {
                await member.RevokeRoleAsync(id);
            }
        }
Exemplo n.º 3
0
            public async ValueTask <AdminCommandResult> GrantRoleAsync(CachedMember target,
                                                                       [RequireHierarchy] CachedRole role)
            {
                if (target.Roles.Keys.Any(x => x == role.Id))
                {
                    return(CommandErrorLocalized("role_give_role_exists", args: Markdown.Bold(target.Tag.Sanitize())));
                }

                await target.GrantRoleAsync(role.Id);

                return(CommandSuccessLocalized("role_give_success",
                                               args: new object[] { Markdown.Bold(target.Tag.Sanitize()), role.Format() }));
            }
Exemplo n.º 4
0
        public async Task UpdateKingQueenAsync()
        {
            try
            {
                LogService.LogInformation("Update has been requested", LogSource.RoleService);
                var data     = Services.GetRequiredService <DataService>();
                var guild    = Client.GetGuild(759143648339558412);
                var KingR    = guild.GetRole(KingId);
                var QueenR   = guild.GetRole(QueenId);
                var tmpking  = data.ImposterKings.OrderByDescending(x => x.count).FirstOrDefault();
                var tmpqueen = data.ImposterQueens.OrderByDescending(x => x.count).FirstOrDefault();

                if (CurrentKing?.Id != tmpking.id)
                {
                    LogService.LogInformation($"{CurrentKing} has been outranked.=> decrowning", LogSource.RoleService, guild.Id);
                    if (CurrentKing != null)
                    {
                        await CurrentKing.RevokeRoleAsync(KingId);
                    }
                    CurrentKing = guild.GetMember(tmpking.id);
                    await CurrentKing.GrantRoleAsync(KingId);

                    LogService.LogInformation($"{CurrentKing} has crowned king", LogSource.RoleService, guild.Id);
                }

                if (CurrentQueen?.Id != tmpqueen.id)
                {
                    LogService.LogInformation($"{CurrentQueen} has been outranked.=> decrowning", LogSource.RoleService, guild.Id);
                    if (CurrentQueen != null)
                    {
                        await CurrentQueen.RevokeRoleAsync(QueenId);
                    }
                    CurrentQueen = guild.GetMember(tmpqueen.id);
                    await CurrentQueen.GrantRoleAsync(QueenId);

                    LogService.LogInformation($"{CurrentQueen} has crowned queen", LogSource.RoleService, guild.Id);
                }
            }
            catch (Exception e)
            {
                LogService.LogError($"uh oh shit broke", LogSource.RoleService, 0, e);
            }
        }