Esempio n. 1
0
        public async Task Spoiler()
        {
            if (_tournamentChannels.Contains(Context.Channel.Id))
            {
                // Silently ignore.
                return;
            }

            var userSeedEntity = await UserSeedRepository.GetById(Context.User.Id);

            if (userSeedEntity == null)
            {
                await ReplyAsync("You haven't generated any seeds recently.");

                return;
            }
            var(_, _, _, spoilerLogPath, _) = MMRService.GetSeedPaths(userSeedEntity.LastSeedRequest, userSeedEntity.Version ?? "1.13.0.13");
            if (File.Exists(spoilerLogPath))
            {
                var result = await Context.Channel.SendFileAsync(spoilerLogPath);

                File.Delete(spoilerLogPath);
            }
            else
            {
                await ReplyAsync("Spoiler log not found.");
            }
        }
Esempio n. 2
0
        public async Task Spoiler()
        {
            if (_tournamentChannels.Contains(Context.Channel.Id))
            {
                // Silently ignore.
                return;
            }

            var lastSeedRequest = (await UserSeedRepository.GetById(Context.User.Id))?.LastSeedRequest;

            if (!lastSeedRequest.HasValue)
            {
                await ReplyAsync("You haven't generated any seeds recently.");

                return;
            }
            var spoilerLogFilename = MMRService.GetSpoilerLogPath(lastSeedRequest.Value);

            if (File.Exists(spoilerLogFilename))
            {
                var result = await Context.Channel.SendFileAsync(spoilerLogFilename);

                File.Delete(spoilerLogFilename);
            }
            else
            {
                await ReplyAsync("Spoiler log not found.");
            }
        }
Esempio n. 3
0
        private async Task <bool> VerifySeedFrequency()
        {
            var lastSeedRequest = (await UserSeedRepository.GetById(Context.User.Id))?.LastSeedRequest;

            if (lastSeedRequest.HasValue && (DateTime.UtcNow - lastSeedRequest.Value).TotalHours < 6)
            {
                await ReplyNoTagAsync("You may only request a seed once every 6 hours.");

                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        public async Task Seed([Remainder] string settingName = null)
        {
            if (_tournamentChannels.Contains(Context.Channel.Id))
            {
                // Tournament seed
                var mentionedUsers = Context.Message.MentionedUsers.DistinctBy(u => u.Id);
                if (mentionedUsers.Any(u => u.Id == Context.User.Id))
                {
                    await ReplyAsync("Cannot generate a seed for yourself.");

                    return;
                }
                if (mentionedUsers.Count() < 2)
                {
                    await ReplyAsync("Must mention at least two users.");

                    return;
                }
                var tournamentSeedReply = await ReplyAsync("Generating seed...");

                new Thread(async() =>
                {
                    try
                    {
                        (var patchPath, var hashIconPath, var spoilerLogPath) = await MMRService.GenerateSeed(DateTime.UtcNow, null);
                        if (File.Exists(patchPath) && File.Exists(hashIconPath) && File.Exists(spoilerLogPath))
                        {
                            foreach (var user in mentionedUsers)
                            {
                                await user.SendFileAsync(patchPath, "Here is your tournament match seed! Please be sure your Hash matches and let an organizer know if you have any issues before you begin.");
                                await user.SendFileAsync(hashIconPath);
                            }
                            await Context.User.SendFileAsync(spoilerLogPath);
                            await Context.User.SendFileAsync(hashIconPath);
                            File.Delete(spoilerLogPath);
                            File.Delete(patchPath);
                            File.Delete(hashIconPath);
                            await tournamentSeedReply.ModifyAsync(mp => mp.Content = "Success.");
                        }
                        else
                        {
                            throw new Exception("MMR.CLI succeeded, but output files not found.");
                        }
                    }
                    catch (Exception e)
                    {
                        // TODO log exception.
                        await tournamentSeedReply.ModifyAsync(mp => mp.Content = "An error occured.");
                    }
                }).Start();
                return;
            }
            var lastSeedRequest = (await UserSeedRepository.GetById(Context.User.Id))?.LastSeedRequest;

            if (lastSeedRequest.HasValue && (DateTime.UtcNow - lastSeedRequest.Value).TotalHours < 6)
            {
                await ReplyAsync("You may only request a seed once every 6 hours.");

                return;
            }
            if (!string.IsNullOrWhiteSpace(settingName))
            {
                settingName = MMRService.GetSettingsPath(Context.Guild.Id, settingName);
                if (!File.Exists(settingName))
                {
                    await ReplyAsync("Setting not found.");

                    return;
                }
            }
            var now = DateTime.UtcNow;
            await UserSeedRepository.Save(new UserSeedEntity
            {
                UserId          = Context.User.Id,
                LastSeedRequest = now
            });

            var messageResult = await ReplyAsync("Generating seed...");

            new Thread(async() =>
            {
                try
                {
                    (var patchPath, var hashIconPath, var spoilerLogPath) = await MMRService.GenerateSeed(now, settingName);
                    await Context.Channel.SendFileAsync(patchPath);
                    await Context.Channel.SendFileAsync(hashIconPath);
                    File.Delete(patchPath);
                    File.Delete(hashIconPath);
                    await messageResult.DeleteAsync();
                }
                catch
                {
                    await UserSeedRepository.DeleteById(Context.User.Id);
                    await messageResult.ModifyAsync(mp => mp.Content = "An error occured.");
                }
            }).Start();
        }