示例#1
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);
        }
示例#2
0
        public async Task UpdateSummonerAsync(ulong userId)
        {
            RiftBot.Log.Information($"[User|{userId.ToString()}] Getting summoner for the league data update");

            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                RiftBot.Log.Error($"{userId.ToString()} Failed to find guild user.");
                return;
            }

            var leagueData = await DB.LeagueData.GetAsync(userId);

            (var result, var data) = await GetSummonerByEncryptedSummonerIdAsync(leagueData.SummonerRegion, leagueData.SummonerId);

            if (result == RequestResult.Error)
            {
                RiftBot.Log.Error($"{userId.ToString()} League data update failed.");
                return;
            }

            await DB.LeagueData.UpdateAsync(userId, leagueData.SummonerRegion, leagueData.PlayerUUID, leagueData.AccountId,
                                            leagueData.SummonerId, data.Name);

            await UpdateRankRoleAsync(sgUser, leagueData);

            RiftBot.Log.Information($"{userId.ToString()} League data update completed.");
        }
示例#3
0
        async Task StartBotGifts()
        {
            RiftBot.Log.Debug("Gifts are on the way..");

            var users = await DB.Cooldowns.GetBotRespectedUsersAsync();

            if (users.Count == 0)
            {
                RiftBot.Log.Debug("No users with bot respect, rescheduling.");
                InitTimer();
                return;
            }

            foreach (var userId in users)
            {
                if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
                {
                    continue;
                }

                var reward = AvailableRewards.Random();
                await rewardService.DeliverToAsync(userId, reward);
            }

            await messageService.SendMessageAsync("yasuo-botrespect-success", Settings.ChannelId.Chat, null);

            RiftBot.Log.Debug("Finished sending gifts");

            InitTimer();
        }
示例#4
0
        public override Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, data.Moderation.TargetId, out var sgUser))
            {
                TemplateError("No user data found.");
                return(null);
            }

            return(ReplaceDataAsync(message, sgUser.ToString()));
        }
示例#5
0
        public override Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, data.Giveaway.TicketGiveaway.WinnerId, out var sgUser))
            {
                TemplateError("No user data found.");
                return(null);
            }

            return(ReplaceDataAsync(message, sgUser.Username));
        }
示例#6
0
        public override Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, data.Moderation.ModeratorId, out var sgUser))
            {
                TemplateError("No user data found.");
                return(Task.FromResult(message));
            }

            return(ReplaceDataAsync(message, sgUser.Username));
        }
示例#7
0
        public override async Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, data.UserId, out var sgUser))
            {
                TemplateError("No user data found.");
                return(message);
            }

            return(await ReplaceDataAsync(message, sgUser.GetAvatarUrl()));
        }
示例#8
0
        public async Task WhoIs(ulong userId)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                await ReplyAsync($"Пользователя с таким ID нет на сервере.");

                return;
            }

            await ReplyAsync($"Пользователь найден: {sgUser.Mention} ({sgUser})");
        }
示例#9
0
        public override async Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, data.UserId, out var sgUser) ||
                sgUser?.JoinedAt is null)
            {
                TemplateError("No user data found.");
                return(message);
            }

            return(await ReplaceDataAsync(message, sgUser.JoinedAt.Value.UtcDateTime.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)));
        }
示例#10
0
        public static async Task SendMessageToDevelopers(string msg)
        {
            foreach (var userId in developersIds)
            {
                if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
                {
                    return;
                }

                await sgUser.SendMessageAsync(msg);
            }
        }
示例#11
0
        async Task PostValidateAsync(RiftPendingUser pendingUser)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, pendingUser.UserId, out var sgUser))
            {
                return;
            }

            await DB.PendingUsers.RemoveAsync(pendingUser.UserId);

            await AssignRoleFromRankAsync(sgUser, pendingUser);

            await DB.Inventory.AddAsync(sgUser.Id, new InventoryData { Chests = 2u });

            await messageService.SendMessageAsync("register-success", Settings.ChannelId.Commands, new FormatData(pendingUser.UserId));
        }
示例#12
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);
        }
示例#13
0
        public async Task <(bool, Embed)> RemoveTempRoleAsync(ulong userId, ulong roleId)
        {
            await DB.TempRoles.RemoveAsync(userId, roleId);

            IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser);

            var role = sgUser?.Roles.FirstOrDefault(x => x.Id == roleId);

            if (role != null)
            {
                await sgUser.RemoveRoleAsync(role);
            }

            RiftBot.Log.Information($"Removed role {roleId.ToString()} from {sgUser} {userId.ToString()}");

            return(true, null);
        }
示例#14
0
        public async Task <IonicMessage> GetUserActionLogsAsync(IUser user)
        {
            if (user is null)
            {
                return(MessageService.UserNotFound);
            }

            var list = await DB.ModerationLogs.GetAsync(user.Id);

            var toxicity = await DB.Toxicity.GetAsync(user.Id);

            var actions = string.Join('\n', list.Select(x =>
            {
                var action = FormatAction(x.Action);

                if (x.Duration != TimeSpan.Zero)
                {
                    action += $"({x.Duration.Humanize()})";
                }

                return(action);
            }));

            var datetime = string.Join('\n', list.Select(x =>
                                                         x.CreatedAt.Humanize()));

            var moderator = string.Join('\n', list.Select(x =>
            {
                IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.ModeratorId, out var sgUser);
                return(sgUser is null ? "-" : sgUser.Username);
            }));

            var embed = new RiftEmbed()
                        .WithDescription($"Досье товарища {user.Username}\nУровень токсичности: {FormatToxicityLevel(toxicity.Level)}")
                        .AddField("Действие", actions, true)
                        .AddField("Дата и время", datetime, true)
                        .AddField("Модератор", moderator, true);

            return(new IonicMessage(embed));
        }
示例#15
0
        public async Task <IonicMessage> GetLastActionsAsync()
        {
            var list = await DB.ModerationLogs.GetLastTenAsync();

            var mods = string.Join('\n', list.Select(x =>
            {
                IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.ModeratorId, out var sgUser);
                return(sgUser is null ? "-" : sgUser.Username);
            }));

            var targets = string.Join('\n', list.Select(x =>
            {
                IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.TargetId, out var sgUser);
                return(sgUser is null ? "-" : sgUser.Username);
            }));

            var actions = string.Join('\n', list.Select(x =>
            {
                var action = FormatAction(x.Action);

                if (x.Duration != TimeSpan.Zero)
                {
                    action += $"({x.Duration.Humanize()})";
                }

                return(action);
            }));

            var embed = new RiftEmbed()
                        .WithDescription("Последние действия банхаммером")
                        .AddField("Модератор", mods, true)
                        .AddField("Нарушитель", targets, true)
                        .AddField("Действие", actions, true);

            return(new IonicMessage(embed));
        }
示例#16
0
        async Task GiveRewardsForLevelAsync(ulong userId, uint fromLevel, uint toLevel)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                return;
            }

            var reward = new ItemReward();

            for (var level = fromLevel + 1; level <= toLevel; level++)
            {
                if (level == 100u)
                {
                    reward.AddCapsules(1u).AddCoins(2_000u);
                }
                else if (level == 50u)
                {
                    reward.AddSpheres(1u).AddCoins(2_000u);
                }
                else if (level % 25u == 0u)
                {
                    reward.AddSpheres(1u).AddCoins(2_000u);
                }
                else if (level % 10u == 0u)
                {
                    reward.AddTokens(2u).AddCoins(2_000u);
                }
                else if (level % 5u == 0u)
                {
                    reward.AddTickets(1u).AddCoins(2_000u);
                }
                else
                {
                    reward.AddChests(1u).AddCoins(2_000u);
                }

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

                if (IonicHelper.HasRolesAny(sgUser, nitroBooster.RoleId))
                {
                    reward.AddChests(2u);
                }

                var rankGold = await DB.Roles.GetAsync(3);

                if (IonicHelper.HasRolesAny(sgUser, rankGold.RoleId))
                {
                    reward.AddCoins(250u);
                }

                var rankPlatinum = await DB.Roles.GetAsync(11);

                if (IonicHelper.HasRolesAny(sgUser, rankPlatinum.RoleId))
                {
                    reward.AddCoins(500u);
                }

                var rankDiamond = await DB.Roles.GetAsync(8);

                if (IonicHelper.HasRolesAny(sgUser, rankDiamond.RoleId))
                {
                    reward.AddCoins(750u);
                }

                var rankMaster = await DB.Roles.GetAsync(79);

                if (IonicHelper.HasRolesAny(sgUser, rankMaster.RoleId))
                {
                    reward.AddCoins(1000u);
                }

                var rankGrandmaster = await DB.Roles.GetAsync(71);

                if (IonicHelper.HasRolesAny(sgUser, rankGrandmaster.RoleId))
                {
                    reward.AddCoins(1250u);
                }

                var rankChallenger = await DB.Roles.GetAsync(23);

                if (IonicHelper.HasRolesAny(sgUser, rankChallenger.RoleId))
                {
                    reward.AddCoins(1500u);
                }
            }

            await rewardService.DeliverToAsync(userId, reward);

            await messageService.SendMessageAsync("levelup", Settings.ChannelId.Chat, new FormatData(userId)
            {
                Reward = reward
            });
        }
示例#17
0
        async Task DeliverAsync(SendMessageBase message)
        {
            switch (message.DestinationType)
            {
            case DestinationType.DM:

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

                var userChannel = await sgUser.GetOrCreateDMChannelAsync();

                switch (message.MessageType)
                {
                case MessageType.PlainText:

                    await userChannel.SendMessageAsync(message.Text).ConfigureAwait(false);

                    break;

                case MessageType.Embed:

                    await userChannel.SendEmbedAsync(message.Embed).ConfigureAwait(false);

                    break;

                case MessageType.Mixed:

                    await userChannel.SendMessageAsync(message.Text, embed : message.Embed)
                    .ConfigureAwait(false);

                    break;
                }

                break;

            case DestinationType.GuildChannel:

                if (!IonicHelper.GetTextChannel(Settings.App.MainGuildId, message.DestinationId, out var channel))
                {
                    return;
                }

                switch (message.MessageType)
                {
                case MessageType.PlainText:

                    await channel.SendMessageAsync(message.Text).ConfigureAwait(false);

                    break;

                case MessageType.Embed:

                    await channel.SendEmbedAsync(message.Embed).ConfigureAwait(false);

                    break;

                case MessageType.Mixed:

                    await channel.SendMessageAsync(message.Text, embed : message.Embed).ConfigureAwait(false);

                    break;
                }

                break;
            }
        }
示例#18
0
        public async Task StartTicketGiveawayAsync(int rewardId, ulong startedBy)
        {
            var dbReward = await DB.Rewards.GetAsync(rewardId);

            if (dbReward is null)
            {
                RiftBot.Log.Warning("Wrong reward ID, skipping execution.");
                return;
            }

            var reward = dbReward.ToRewardBase();

            var usersWithTickets = await DB.Inventory.GetAsync(x => x.Tickets >= 1);

            if (usersWithTickets is null || usersWithTickets.Count == 0)
            {
                RiftBot.Log.Warning("No users with tickets, skipping execution.");
                return;
            }

            RiftBot.Log.Information($"Ticket giveaway started for {usersWithTickets.Count.ToString()}, reward ID {rewardId.ToString()}.");

            var removeInv = new InventoryData {
                Tickets = 1u
            };

            var userList = usersWithTickets.ToList();
            var winnerId = 0ul;

            do
            {
                if (userList.Count == 0)
                {
                    RiftBot.Log.Warning("No users on server participated, skipping execution.");
                    return;
                }

                var winner = userList.Random();
                winnerId = winner.UserId;
                userList.Remove(winner);
            } while (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, winnerId, out var sgUser));

            foreach (var userInventory in usersWithTickets)
            {
                await DB.Inventory.RemoveAsync(userInventory.UserId, removeInv); // very slow on tunneled db connection
            }

            await rewardService.DeliverToAsync(winnerId, reward);

            await messageService.SendMessageAsync("giveaway-ticket-success", Settings.ChannelId.Chat, new FormatData(startedBy)
            {
                Giveaway = new GiveawayData
                {
                    TicketGiveaway = new TicketGiveaway
                    {
                        ParticipantsCount = usersWithTickets.Count,
                        WinnerId          = winnerId
                    }
                },
                Reward = reward
            });

            var log = new RiftGiveawayLog
            {
                Name         = "Ticket Giveaway",
                Winners      = new[] { winnerId },
                Participants = usersWithTickets.Select(x => x.UserId).ToArray(),
                Reward       = "No reward provided",
                StartedBy    = startedBy,
                StartedAt    = DateTime.Now,
                Duration     = TimeSpan.Zero,
                FinishedAt   = DateTime.UtcNow,
            };

            await DB.GiveawayLogs.AddAsync(log);
        }
示例#19
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);
            }
        }