Пример #1
0
        public async Task AddEmotesFromGuild(SocketGuild guild)
        {
            foreach (var emote in guild.Emotes)
            {
                if (!emotes.TryAdd($"$emote{emote.Name}", new Emote(emote.Id, emote.Name, emote.Url)))
                {
                    if (emotes.ContainsKey(emote.Name))
                    {
                        var msg = $"Duplicate emote \"{emote.Name}\" from {guild.Name}, skipping.";

                        await RiftBot.SendMessageToAdmins(msg);

                        RiftBot.Log.Error($"[{nameof(EmoteService)}] {msg}.");
                    }
                    else
                    {
                        var msg = $"Failed to add emote \"{emote.Name}\" from {guild.Name}.";

                        await RiftBot.SendMessageToAdmins(msg);

                        RiftBot.Log.Error($"[{nameof(EmoteService)}] {msg}");
                    }
                }
            }
        }
Пример #2
0
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            if (await RiftBot.IsModeratorAsync(context.User) || RiftBot.IsAdmin(context.User))
            {
                return(PreconditionResult.FromSuccess());
            }

            return(PreconditionResult.FromError(RiftBot.CommandDenyMessage));
        }
        public override async Task <PreconditionResult> CheckPermissionsAsync(
            ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            if (await Task.Run(() => RiftBot.IsDeveloper(context.User)))
            {
                return(PreconditionResult.FromSuccess());
            }

            return(PreconditionResult.FromError(RiftBot.CommandDenyMessage));
        }
Пример #4
0
        public FormatData(ulong userId)
        {
            UserId = userId;

            var provider = RiftBot.GetServiceProvider();

            EmoteService   = provider.GetService <IEmoteService>();
            RiotService    = provider.GetService <IRiotService>();
            EconomyService = provider.GetService <IEconomyService>();
            RewardService  = provider.GetService <IRewardService>();
        }
Пример #5
0
        public async Task BanAsync(IUser target, string reason, IUser moderator)
        {
            (var passed, var sgTarget) = await ValidateAsync(target, reason, moderator);

            if (!passed)
            {
                return;
            }

            if (RiftBot.IsAdmin(sgTarget) || await RiftBot.IsModeratorAsync(sgTarget))
            {
                await messageService.SendMessageAsync("mod-friendly-fire", Settings.ChannelId.Commands, new FormatData(moderator.Id));

                return;
            }

            if (!IonicHelper.GetGuild(Settings.App.MainGuildId, out var guild))
            {
                return;
            }

            await DB.ModerationLogs.AddAsync(sgTarget.Id, moderator.Id, "Ban", reason, DateTime.UtcNow, TimeSpan.Zero);

            (var oldToxicity, var newToxicity) = await GetNewToxicityAsync(sgTarget.Id, ToxicitySource.Ban);

            await DB.Toxicity.UpdatePercentAsync(sgTarget.Id, newToxicity.Percent);

            var data = new FormatData(target.Id)
            {
                Moderation = new ModerationData
                {
                    ModeratorId = moderator.Id,
                    TargetId    = sgTarget.Id,
                    Reason      = reason,
                }
            };

            await messageService.SendMessageAsync("mod-ban-success", Settings.ChannelId.Chat, data);

            await guild.AddBanAsync(sgTarget, 1, $"Banned by {moderator}: {reason}");
        }
Пример #6
0
        protected override void BeforeExecute(CommandInfo command)
        {
            if (moduleState == RiftModuleState.Disabled)
            {
                Task.Run(async() =>
                {
                    await base.ReplyAsync("В настоящий момент эта команда отключена администратором.");
                });
                return;
            }

            if (moduleState == RiftModuleState.AdminOnly && !RiftBot.IsAdmin(Context.User))
            {
                Task.Run(async() =>
                {
                    await base.ReplyAsync(
                        "В настоящий момент эта команда доступна только для администраторов.");
                });
                return;
            }
        }
Пример #7
0
        public async Task MuteAsync(IUser target, string reason, string time, IUser moderator)
        {
            (var passed, var sgTarget) = await ValidateAsync(target, reason, moderator);

            if (!passed)
            {
                return;
            }

            if (RiftBot.IsAdmin(sgTarget) || await RiftBot.IsModeratorAsync(sgTarget))
            {
                await messageService.SendMessageAsync("mod-friendly-fire", Settings.ChannelId.Commands, new FormatData(moderator.Id));

                return;
            }

            if (!int.TryParse(time.Remove(time.Length - 1), out var timeInt))
            {
                await messageService.SendMessageAsync("mod-wrong-time-format", Settings.ChannelId.Commands, new FormatData(moderator.Id));

                return;
            }

            TimeSpan ts;

            var timeMod = time.Last();

            switch (timeMod)
            {
            case 's':
                ts = TimeSpan.FromSeconds(timeInt);
                break;

            case 'm':
                ts = TimeSpan.FromMinutes(timeInt);
                break;

            case 'h':
                ts = TimeSpan.FromHours(timeInt);
                break;

            case 'd':
                ts = TimeSpan.FromDays(timeInt);
                break;

            default:
                await messageService.SendMessageAsync("mod-wrong-time-format", Settings.ChannelId.Commands, new FormatData(moderator.Id));

                return;
            }

            var muted = await DB.Roles.GetAsync(40);

            await roleService.AddTempRoleAsync(sgTarget.Id, muted.RoleId, ts,
                                               $"Muted by {moderator}|{moderator.Id.ToString()} with reason: {reason}");

            await DB.ModerationLogs.AddAsync(sgTarget.Id, moderator.Id, "Mute", reason, DateTime.UtcNow, ts);

            (var oldToxicity, var newToxicity) = await GetNewToxicityAsync(sgTarget.Id, ToxicitySource.Mute);

            await DB.Toxicity.UpdatePercentAsync(sgTarget.Id, newToxicity.Percent);

            if (newToxicity.Level > oldToxicity.Level)
            {
                await messageService.SendMessageAsync("mod-toxicity-increased", Settings.ChannelId.Chat, new FormatData(sgTarget.Id));
            }

            var data = new FormatData(sgTarget.Id)
            {
                Moderation = new ModerationData
                {
                    TargetId    = sgTarget.Id,
                    ModeratorId = moderator.Id,
                    Reason      = reason,
                    Duration    = ts
                }
            };

            await messageService.SendMessageAsync("mod-mute-success", Settings.ChannelId.Chat, data);
        }
Пример #8
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);
            }
        }
Пример #9
0
        async Task <IonicMessage> GiftAsync(SocketGuildUser fromSgUser, SocketGuildUser toSgUser)
        {
            var senderId   = fromSgUser.Id;
            var receiverId = toSgUser.Id;

            if (toSgUser.IsBot)
            {
                RiftBot.Log.Debug("[Gift] Target is bot.");
                return(await messageService.GetMessageAsync("gift-target-bot", new FormatData(senderId)));
            }

            if (fromSgUser.Id == toSgUser.Id)
            {
                RiftBot.Log.Debug("[Gift] Ouch, self-gift.");
                return(await messageService.GetMessageAsync("gift-target-self", new FormatData(senderId)));
            }

            (var canGift, var remainingTime) = await CanGift(senderId);

            if (!canGift)
            {
                return(await messageService.GetMessageAsync("gift-cooldown", new FormatData(senderId)
                {
                    Gift = new GiftData
                    {
                        Cooldown = remainingTime
                    }
                }));
            }

            var dbInventory = await DB.Inventory.GetAsync(senderId);

            if (dbInventory.Coins < Settings.Economy.GiftPrice)
            {
                return(await messageService.GetMessageAsync("gift-nocoins", new FormatData(senderId)
                {
                    Gift = new GiftData
                    {
                        NecessaryCoins = Settings.Economy.GiftPrice - dbInventory.Coins
                    }
                }));
            }

            await DB.Inventory.RemoveAsync(senderId, new InventoryData { Coins = Settings.Economy.GiftPrice });

            var giftItem = new GiftReward();
            await rewardService.DeliverToAsync(receiverId, giftItem);

            GiftSent?.Invoke(null, new GiftSentEventArgs(senderId, receiverId));
            GiftReceived?.Invoke(null, new GiftReceivedEventArgs(senderId, fromSgUser.Id));

            if (toSgUser.Id == 178443743026872321ul)
            {
                GiftedFounder?.Invoke(null, new GiftedFounderEventArgs(receiverId, senderId));
            }

            var developers = await DB.Roles.GetAsync(44);

            if (IonicHelper.HasRolesAny(toSgUser, developers.RoleId))
            {
                GiftedDeveloper?.Invoke(null, new GiftedDeveloperEventArgs(senderId, receiverId));
            }

            if (await RiftBot.IsModeratorAsync(toSgUser))
            {
                GiftedModerator?.Invoke(null, new GiftedModeratorEventArgs(senderId, receiverId));
            }

            if (!(await DB.Streamers.GetAsync(receiverId) is null))
            {
                GiftedStreamer?.Invoke(null, new GiftedStreamerEventArgs(senderId, receiverId));
            }

            RiftBot.Log.Debug("[Gift] Success.");

            await DB.Cooldowns.SetLastGiftTimeAsync(senderId, DateTime.UtcNow);

            await DB.Statistics.AddAsync(senderId, new StatisticData { GiftsSent = 1u });

            await DB.Statistics.AddAsync(receiverId, new StatisticData { GiftsReceived = 1u });

            return(await messageService.GetMessageAsync("gift-success", new FormatData(senderId)
            {
                Gift = new GiftData
                {
                    TargetId = receiverId
                },
                Reward = giftItem
            }));
        }
Пример #10
0
        static async Task UpdateDataAsync()
        {
            (var newDataAvailable, var version) = await CheckNewVersionAsync().ConfigureAwait(false);

            if (!newDataAvailable)
            {
                LoadData();
                return;
            }

            RiftBot.Log.Information($"Initiating data update: {Settings.App.LolVersion} -> {version}");

            await DownloadDataAsync(version).ContinueWith(async x =>
            {
                if (x.IsFaulted)
                {
                    RiftBot.Log.Error(x.Exception, "Data download failed!");
                    RiftBot.Log.Warning("Falling back to existing data.");
                    LoadData();

                    return;
                }

                var path = Path.Combine(TempFolder, $"{version}.tgz");

                await UnpackData(path, version).ContinueWith(async y =>
                {
                    if (!y.IsCompletedSuccessfully)
                    {
                        RiftBot.Log.Error(y.Exception, "Data download failed!");
                        LoadData();

                        return;
                    }

                    var tempPath = Path.Combine(TempFolder, version, "champion.json");
                    var realPath = Path.Combine(DataDragonDataFolder, "champion.json");

                    try
                    {
                        if (File.Exists(realPath))
                        {
                            File.Delete(realPath);
                        }

                        File.Move(tempPath, realPath);
                    }
                    catch (Exception ex)
                    {
                        RiftBot.Log.Error(ex, "An error occured while moving lol data files");
                        return;
                    }

                    LoadData();

                    Settings.App.LolVersion = version;
                    await Settings.SaveAppAsync();

                    RiftBot.Log.Information($"Data update completed. New version is {Settings.App.LolVersion}");

                    await RiftBot.SendMessageToDevelopers(
                        $"Data update completed. New version is {Settings.App.LolVersion}.");
                });
            });
        }
Пример #11
0
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var role = await DB.Roles.GetAsync(173);

            if (IonicHelper.HasRolesAny(Settings.App.MainGuildId, context.User.Id, role.RoleId) || RiftBot.IsAdmin(context.User))
            {
                return(PreconditionResult.FromSuccess());
            }

            return(PreconditionResult.FromError(RiftBot.CommandDenyMessage));
        }