Exemplo n.º 1
0
        public async Task RestoreTempRolesAsync(SocketGuildUser sgUser)
        {
            RiftBot.Log.Information($"User {sgUser.ToLogString()} joined, checking temp roles");

            var tempRoles = await DB.TempRoles.GetAsync(sgUser.Id);

            if (tempRoles is null || tempRoles.Count == 0)
            {
                RiftBot.Log.Debug($"No temp roles for user {sgUser}");
                return;
            }

            var remainingRoles = tempRoles.Select(x => x.RoleId).Except(sgUser.Roles.Select(x => x.Id));

            foreach (var id in remainingRoles)
            {
                if (!IonicHelper.GetRole(Settings.App.MainGuildId, id, out var role))
                {
                    RiftBot.Log.Error($"Applying role {id.ToString()}: FAILED");
                    continue;
                }

                await sgUser.AddRoleAsync(role);

                RiftBot.Log.Debug($"Successfully added temp role \"{role.Name}\" for user {sgUser}");
            }
        }
Exemplo n.º 2
0
        public async Task AddTempRoleAsync(ulong userId, ulong roleId, TimeSpan duration, string reason)
        {
            var role = new RiftTempRole
            {
                UserId         = userId,
                RoleId         = roleId,
                ObtainedFrom   = reason,
                ObtainedTime   = DateTime.UtcNow,
                ExpirationTime = DateTime.UtcNow + duration,
            };

            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                return;
            }

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, roleId, out var serverRole))
            {
                return;
            }

            await sgUser.AddRoleAsync(serverRole);

            await DB.TempRoles.AddAsync(role);
        }
Exemplo n.º 3
0
        public async Task <List <ulong> > GetNitroBoostersAsync()
        {
            var nitro = await DB.Roles.GetAsync(91);

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, nitro.RoleId, out var role) ||
                !(role is SocketRole sgRole))
            {
                return(null);
            }

            return(sgRole.Members.Select(x => x.Id).ToList());
        }
Exemplo n.º 4
0
        public async Task <(bool, IonicMessage)> RemovePermanentRoleAsync(ulong userId, ulong roleId)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                return(false, MessageService.UserNotFound);
            }

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, roleId, out var role))
            {
                return(false, MessageService.RoleNotFound);
            }

            await sgUser.RemoveRoleAsync(role);

            return(true, null);
        }
Exemplo n.º 5
0
        async Task UpdateRankRoleAsync(IGuildUser sgUser, RiftLeagueData leagueData)
        {
            (var rankResult, var rankData) =
                await GetLeaguePositionsByEncryptedSummonerIdAsync(leagueData.SummonerRegion, leagueData.SummonerId);

            if (rankResult != RequestResult.Success)
            {
                return;
            }

            var newRank = GetRankFromEntry(rankData.FirstOrDefault(x => x.QueueType == "RANKED_SOLO_5x5"));

            var currentRank = await GetCurrentRank(sgUser);

            if (currentRank == newRank)
            {
                RiftBot.Log.Information($"{sgUser.ToLogString()} Same rank, nothing to update.");
                return;
            }

            await RemoveRankedRole(sgUser, currentRank);

            var roleId = await GetRoleByLeagueRank(newRank);

            if (roleId is null || roleId.RoleId == 0ul)
            {
                return;
            }

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, roleId.RoleId, out var role))
            {
                return;
            }

            await messageService.SendMessageAsync("rank-updated", Settings.ChannelId.Chat, new FormatData(sgUser.Id)
            {
                RankData = new RankData
                {
                    PreviousRank = GetStatStringFromRank(currentRank),
                    CurrentRank  = GetStatStringFromRank(newRank)
                }
            });

            await sgUser.AddRoleAsync(role);
        }
Exemplo n.º 6
0
        public async Task <string> FormatAsync(RoleReward reward)
        {
            var text = "роль";

            var dbRole = await DB.Roles.GetAsync(reward.RoleId);

            if (dbRole is null || !IonicHelper.GetRole(Settings.App.MainGuildId, dbRole.RoleId, out var role))
            {
                text += " не найдена";
                return(text);
            }

            text += $" {role.Name}";

            if (reward.Duration != null)
            {
                text += $" на {reward.Duration.Value.Humanize(culture: RiftBot.Culture)}";
            }

            return(text);
        }
Exemplo n.º 7
0
        public async Task AddRole(ulong roleId)
        {
            var dbRole = await DB.Roles.GetByRoleIdAsync(roleId);

            if (dbRole is null ||
                !IonicHelper.GetRole(Settings.App.MainGuildId, roleId, out var sr) ||
                !(sr is SocketRole role))
            {
                await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands);

                return;
            }

            var count = 0;

            foreach (var user in role.Members)
            {
                await user.RemoveRoleAsync(sr);

                if (!await DB.Users.EnsureExistsAsync(user.Id))
                {
                    await messageService.SendMessageAsync(MessageService.Error, Settings.ChannelId.Commands);

                    return;
                }

                if (await DB.RoleInventory.HasAnyAsync(user.Id, dbRole.Id))
                {
                    continue;
                }

                await DB.RoleInventory.AddAsync(user.Id, dbRole.Id, "Launch seeding");

                count++;
            }

            await ReplyAsync($"Added role \"{role.Name}\" to {count.ToString()} user(s).");
        }
Exemplo n.º 8
0
        public async Task NitroRewards()
        {
            var reward = new ItemReward().AddTokens(10u);

            var role = await DB.Roles.GetAsync(91);

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, role.RoleId, out var gr))
            {
                return;
            }

            if (!(gr is SocketRole sr))
            {
                return;
            }

            foreach (var sgUser in sr.Members)
            {
                await rewardService.DeliverToAsync(sgUser.Id, reward);
            }

            await messageService.SendMessageAsync("nitro-booster-reward", Settings.ChannelId.Chat, null);
        }
Exemplo n.º 9
0
        public async Task AddBack(ulong roleId, int backId)
        {
            var dbBack = await DB.ProfileBackgrounds.GetAsync(backId);

            if (dbBack is null ||
                !IonicHelper.GetRole(Settings.App.MainGuildId, roleId, out var sr) ||
                !(sr is SocketRole role))
            {
                await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands);

                return;
            }

            var count = 0;

            foreach (var user in role.Members)
            {
                if (!await DB.Users.EnsureExistsAsync(user.Id))
                {
                    await messageService.SendMessageAsync(MessageService.Error, Settings.ChannelId.Commands);

                    return;
                }

                if (await DB.BackgroundInventory.HasAsync(user.Id, dbBack.Id))
                {
                    continue;
                }

                await DB.BackgroundInventory.AddAsync(user.Id, dbBack.Id);

                count++;
            }

            await ReplyAsync($"Added background \"{dbBack.Name}\" for role \"{role.Name}\" ({count.ToString()} user(s)).");
        }
Exemplo n.º 10
0
        public async Task UpdateInventoryRoleAsync(ulong userId, int id, bool add)
        {
            if (!await DB.RoleInventory.HasAnyAsync(userId, id))
            {
                await messageService.SendMessageAsync("roleinventory-wrongnumber", Settings.ChannelId.Commands, new FormatData(userId));

                return;
            }

            var dbUser = await DB.Users.GetAsync(userId);

            if (dbUser is null || !IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                await messageService.SendMessageAsync(MessageService.UserNotFound, Settings.ChannelId.Commands);

                return;
            }

            var role = await DB.Roles.GetAsync(id);

            if (role is null)
            {
                await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands);

                await RiftBot.SendMessageToAdmins($"User <@{userId.ToString()}> failed to set role ID {id.ToString()}.");

                return;
            }

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, role.RoleId, out var guildRole))
            {
                await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands);

                return;
            }

            var hasRole = IonicHelper.HasRolesAny(Settings.App.MainGuildId, userId, role.RoleId);

            if (add)
            {
                if (hasRole)
                {
                    await messageService.SendMessageAsync("roleinventory-hasrole", Settings.ChannelId.Commands, new FormatData(userId));

                    return;
                }

                await sgUser.AddRoleAsync(guildRole);
            }
            else
            {
                if (!hasRole)
                {
                    await messageService.SendMessageAsync("roleinventory-norole", Settings.ChannelId.Commands, new FormatData(userId));

                    return;
                }

                await sgUser.RemoveRoleAsync(guildRole);
            }
        }