Esempio n. 1
0
        public async Task ReportAsync(
            CommandContext ctx,
            [Description("Your outcome (denial/ruin/o****m)")]
            string outcome = null,
            [Description("How many edges it took")]
            int edges = 0,
            [Description("How long it took (5m = 5 minutes | 5m12s = 5 minutes, 12 seconds)")]
            string time = null)
        {
            // TODO: Check for Channel

            if (outcome == null || time == null)
            {
                await ctx.RespondAsync("Please supply information about your report (``//report denial 5 12m5s`` to report denial after 5 edges and 12 minutes and 5 seconds)");

                return;
            }

            outcome = outcome.ToUpperInvariant();

            IQueryable <Slavereports> slaveReports =
                from report in _context.Slavereports.Where(report => report.TimeOfReport > DateTime.Now.AddHours(-16))
                where report.UserId == Convert.ToInt64(ctx.User.Id)
                select report;

            var lastReport = slaveReports.FirstOrDefault();

            if (lastReport != null)
            {
                await ctx.RespondAsync(
                    $"You can only report once every 20 hours. You can report again in {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(20) - DateTime.Now)}");

                var dm = await(await ctx.Guild.GetMemberAsync(Config.Users.Aki)).CreateDmChannelAsync();
                await dm.SendMessageAsync(
                    $"{ctx.Message.Author} has reported {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(20) - DateTime.Now)} too early.");

                return;
            }

            if (Enum.TryParse(outcome, true, out UserSetting.Outcome result))
            {
                TimeSpan span;
                try
                {
                    var user = await UserExtension.GetUser(ctx.Message.Author.Id);

                    span = TimeResolver.GetTimeSpan(time);

                    await Task.Run(
                        async() =>
                    {
                        var report = new Slavereports()
                        {
                            TimeOfReport   = DateTime.Now,
                            UserId         = user.UserId,
                            Edges          = edges,
                            TimeSpan       = span.Ticks,
                            SessionOutcome = outcome
                        };

                        _context.Slavereports.Add(report);

                        await _context.SaveChangesAsync();
                    });
                }
                catch
                {
                    var builder = new DiscordEmbedBuilder
                    {
                        Title       = "Error",
                        Description =
                            "That's not how this works, you can enter your time in one of the following formats:",
                        Footer = new DiscordEmbedBuilder.EmbedFooter {
                            Text = "You get the Idea..."
                        }
                    };

                    builder.AddField("1h5m12s", "1 hour, 5 minutes, 12 seconds");
                    builder.AddField("5m", "5 minutes");
                    builder.AddField("2h", "2 hours");
                    builder.AddField("1200s", "1200 seconds");

                    await ctx.RespondAsync(embed : builder.Build());

                    return;
                }
            }
            else
            {
                var builder = new DiscordEmbedBuilder
                {
                    Title       = "Error",
                    Description = "That's not how this works, you gotta use one of the following:"
                };

                foreach (string possibleOutcome in Enum.GetNames(typeof(UserSetting.Outcome)))
                {
                    builder.AddField(possibleOutcome, $"``//report {possibleOutcome} {edges} {time}``");
                }

                await ctx.RespondAsync(embed : builder.Build());

                return;
            }

            var    formatText    = "{0}{1}{2}";
            var    prefix        = "Hey, ";
            var    postfix       = ". Thanks for reporting your task.";
            string name          = ctx.User.Mention;
            var    parsedOutcome = Enum.Parse <UserSetting.Outcome>(outcome, true);

            var responseColor = DiscordColor.Green;

            if (parsedOutcome == UserSetting.Outcome.Denial)
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                        string>("Hehe, looks like that's it for you for today, ", " ^^"),
                    new Tuple <string,                                                        string>(
                        "That's what i like to see, ",
                        ". Now, can you do me a favor and report that again next time?~"),
                    new Tuple <string,                                                        string>(
                        "Ohh, is little ",
                        " denied? Well, too bad, you'll have to wait for your next chance~"),
                    new Tuple <string,                                                        string>(
                        "1, 2, 3, 4, ",
                        " is denied! ...Were you expecting a rhyme? Sucks being you, then.")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Red;
            }

            if (parsedOutcome == UserSetting.Outcome.Ruin)
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                                                             string>(
                        "Hmm, better than nothing, right, ",
                        "? Did it feel good?~ haha, of course not."),
                    new Tuple <string,                                                                                             string>(
                        "Oh ",
                        ", I don't know what i like more, denial or ruin... Do you think you get to deny yourself next time? :3"),
                    new Tuple <string,                                                                                             string>(
                        "It's not even a full o****m, but our ",
                        " still followed Orders. I bet you'll be even more obedient with your next chance..."),
                    new Tuple <string,                                                                                             string>("Another ruined one for ", " . Check.")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Yellow;
            }

            if (parsedOutcome == UserSetting.Outcome.O****m)
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                              string>(
                        "Meh, ",
                        " got a full O****m. How boring. It hope you get a ruined one next time."),
                    new Tuple <string,                                                              string>(
                        "And Mistress allowed that? You got lucky, ",
                        ". But i think i should ask Mistress to ruin your next one."),
                    new Tuple <string,                                                              string>("... ",                                 " ..."),
                    new Tuple <string,                                                              string>("Are you sure, you did it correctly, ", " ?")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Green;
            }

            var responseBuilder = new DiscordEmbedBuilder
            {
                Author = new DiscordEmbedBuilder.EmbedAuthor
                {
                    Name    = ctx.User.Username,
                    IconUrl = ctx.User.AvatarUrl
                },
                Color       = responseColor,
                Description = string.Format(formatText, prefix, name, postfix),
                Footer      = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "You can report back in 16 hours"
                }
            };

            await ctx.RespondAsync(embed : responseBuilder.Build());
        }
Esempio n. 2
0
        public async Task ReportAsync(
            CommandContext ctx,
            [Description("Your outcome (denial/ruin/o****m)")]
            string outcome,
            [Description("How many edges it took")]
            int edges,
            [Description("How long it took (5m = 5 minutes | 5m12s = 5 minutes, 12 seconds)")]
            string time)
        {
            if (ctx.Channel.Name != Config.Channels.Instruction)
            {
                await ctx.RespondAsync($"Please report only in the {Config.Channels.Instruction} channel");

                return;
            }

            IQueryable <Slavereports> slaveReports =
                from report in _context.Slavereports.Where(report => report.TimeOfReport > DateTime.Now.AddHours(-20))
                where report.UserId == Convert.ToInt64(ctx.User.Id)
                select report;

            if (slaveReports.Any() && Convert.ToInt64(ctx.Message.Author.Id) != 347004618183540740)
            {
                var lastReport = slaveReports.First();

                if (lastReport != null)
                {
                    await ctx.RespondAsync(
                        $"You can only report once every 20 hours. You can report again in {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(20) - DateTime.Now)}");

                    var dm = await(await ctx.Guild.GetMemberAsync(Config.Users.Aki)).CreateDmChannelAsync();
                    await dm.SendMessageAsync(
                        $"{ctx.Message.Author} has reported {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(20) - DateTime.Now)} too early.");

                    return;
                }
            }
            else if (Convert.ToInt64(ctx.Message.Author.Id) == 347004618183540740)
            {
                IQueryable <Slavereports> slaveReportsPj =
                    from report in _context.Slavereports.Where(report => report.TimeOfReport > DateTime.Now.AddHours(-8))
                    where report.UserId == Convert.ToInt64(ctx.User.Id)
                    select report;

                if (slaveReportsPj.Any())
                {
                    var lastReport = slaveReportsPj.First();

                    if (lastReport != null)
                    {
                        await ctx.RespondAsync(
                            $"You can only report once every 8 hours. You can report again in {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(8) - DateTime.Now)}");

                        var dm = await(await ctx.Guild.GetMemberAsync(Config.Users.Aki)).CreateDmChannelAsync();
                        await dm.SendMessageAsync(
                            $"{ctx.Message.Author} has reported {TimeResolver.TimeToString(lastReport.TimeOfReport.AddHours(8) - DateTime.Now)} too early.");

                        return;
                    }
                }
            }

            if (Enum.TryParse(outcome, out SlaveReportsExtension.Outcome result))
            {
                TimeSpan span;
                try
                {
                    span = TimeResolver.GetTimeSpan(time);

                    await Task.Run(
                        async() =>
                    {
                        var report = new Slavereports()
                        {
                            TimeOfReport   = ctx.Message.Timestamp.LocalDateTime,
                            UserId         = Convert.ToInt64(Convert.ToInt64(ctx.Message.Author.Id)),
                            Edges          = edges,
                            TimeSpan       = span.Ticks,
                            SessionOutcome = outcome
                        };

                        await _context.SaveChangesAsync();
                    });
                }
                catch
                {
                    var builder = new DiscordEmbedBuilder
                    {
                        Title       = "Error",
                        Description =
                            "That's not how this works, you can enter your time in one of the following formats:",
                        Footer = new DiscordEmbedBuilder.EmbedFooter {
                            Text = "You get the Idea..."
                        }
                    };

                    builder.AddField("1h5m12s", "1 hour, 5 minutes, 12 seconds");
                    builder.AddField("5m", "5 minutes");
                    builder.AddField("2h", "2 hours");
                    builder.AddField("1200s", "1200 seconds");

                    await ctx.RespondAsync(embed : builder.Build());

                    return;
                }
            }
            else
            {
                var builder = new DiscordEmbedBuilder
                {
                    Title       = "Error",
                    Description = "That's not how this works, you gotta use one of the following:"
                };

                foreach (string possibleOutcome in Enum.GetNames(typeof(SlaveReportsExtension.Outcome)))
                {
                    builder.AddField(possibleOutcome, $"``//report {possibleOutcome} {edges} {time}``");
                }

                await ctx.RespondAsync(embed : builder.Build());

                return;
            }

            var    formatText = "{0}{1}{2}";
            var    prefix     = "Hey, ";
            var    postfix    = ". Thanks for reporting your task.";
            string name       = ctx.User.Mention;

            var responseColor = DiscordColor.Green;

            if (outcome == SlaveReportsExtension.Outcome.Denial.ToString())
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                        string>("hihi, looks like that's it for you, for today, ", " ^^"),
                    new Tuple <string,                                                        string>(
                        "That's what i like to see, ",
                        ". Now, can you do me a favor and report that again next time?~"),
                    new Tuple <string,                                                        string>(
                        "Ohh, is little ",
                        " denied? Well, too bad, you'll have to wait for your next chance~"),
                    new Tuple <string,                                                        string>(
                        "1, 2, 3, 4, ",
                        " is denied! ...Were you expecting a rhyme? Sucks being you, then.")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Red;
            }

            if (outcome == SlaveReportsExtension.Outcome.Ruin.ToString())
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                                                             string>(
                        "Hmm, better than nothing, right, ",
                        "? Did it feel good?~ haha, of course not."),
                    new Tuple <string,                                                                                             string>(
                        "Oh ",
                        ", I don't know what i like more, denial or ruin... Do you think you get to deny yourself next time? :3"),
                    new Tuple <string,                                                                                             string>(
                        "It's not even a full o****m, but our ",
                        " still followed Orders. I bet you'll be even more obedient with your next chance..."),
                    new Tuple <string,                                                                                             string>("Another ruined one for ", " . Check.")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Yellow;
            }

            if (outcome == SlaveReportsExtension.Outcome.O****m.ToString())
            {
                Tuple <string, string>[] templates =
                {
                    new Tuple <string,                                                              string>(
                        "Meh, ",
                        " got a full O****m. How boring. It hope you get a ruined one next time."),
                    new Tuple <string,                                                              string>(
                        "And Mistress allowed that? You got lucky, ",
                        ". But i think i should ask Mistress to ruin your next one."),
                    new Tuple <string,                                                              string>("... ",                                 " ..."),
                    new Tuple <string,                                                              string>("Are you sure, you did it correctly, ", " ?")
                };

                Tuple <string, string> template = templates[Helpers.RandomGenerator.RandomInt(0, templates.Length)];
                prefix  = template.Item1;
                postfix = template.Item2;

                responseColor = DiscordColor.Green;
            }

            if (Convert.ToInt64(ctx.Message.Author.Id) == 347004618183540740 && DateTime.Now < new DateTime(2018, 9, 13))
            {
                if (outcome == SlaveReportsExtension.Outcome.Denial.ToString())
                {
                    prefix  = "Enjoy your 21 days, ";
                    postfix = " . I'm sure you're having fun :)";
                }
                else
                {
                    prefix =
                        $"Ohoho, {(await ctx.Guild.GetMemberAsync(Config.Users.Aki)).Mention} isn't gonna enjoy that, ";
                    postfix = " .";
                }
            }

            var responseBuilder = new DiscordEmbedBuilder
            {
                Author = new DiscordEmbedBuilder.EmbedAuthor
                {
                    Name    = ctx.User.Username,
                    IconUrl = ctx.User.AvatarUrl
                },
                Color       = responseColor,
                Description = string.Format(formatText, prefix, name, postfix),
                Footer      = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "You can report back in 20 hours"
                }
            };

            if (Convert.ToInt64(ctx.Message.Author.Id) == 347004618183540740)
            {
                responseBuilder.Footer = new DiscordEmbedBuilder.EmbedFooter()
                {
                    Text = "You can report back in 8 hours"
                };
            }

            await ctx.RespondAsync(embed : responseBuilder.Build());
        }