Пример #1
0
        public async Task FavouritePastaList(EventContext e, bool lovedPastas = true)
        {
            Locale       locale       = Locale.GetEntity(e.Channel.Id.ToDbLong());
            IDiscordUser targetUser   = e.Author;
            float        totalPerPage = 25f;
            int          page         = 0;

            if (e.message.MentionedUserIds.Count() >= 1)
            {
                targetUser = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First());

                string[] args = e.arguments.Split(' ');
                int.TryParse((args.Count() > 1 ? args[1] : "0"), out page);
                page -= page <= 0 ? 0 : 1;
            }
            else
            {
                int.TryParse(e.arguments, out page);
                page -= 1;
            }

            using (MikiContext context = new MikiContext())
            {
                long authorId = targetUser.Id.ToDbLong();
                IEnumerable <PastaVote> pastaVotes = context.Votes.Where(x => x.UserId == authorId && x.PositiveVote == lovedPastas);

                int maxPage = (int)Math.Floor(pastaVotes.Count() / totalPerPage);
                page = page > maxPage ? maxPage : page;
                page = page < 0 ? 0 : page;


                if (pastaVotes.Count() <= 0)
                {
                    string loveString  = (lovedPastas ? locale.GetString("miki_module_pasta_loved") : locale.GetString("miki_module_pasta_hated"));
                    string errorString = locale.GetString("miki_module_pasta_favlist_self_none", loveString);
                    if (e.message.MentionedUserIds.Count() >= 1)
                    {
                        errorString = locale.GetString("miki_module_pasta_favlist_mention_none", loveString);
                    }
                    await Utils.ErrorEmbed(e, errorString).QueueToChannel(e.Channel.Id);

                    return;
                }

                IDiscordEmbed    embed        = Utils.Embed;
                List <PastaVote> neededPastas = pastaVotes.Skip((int)totalPerPage * page).Take((int)totalPerPage).ToList();

                string resultString = "";
                neededPastas.ForEach(x => { resultString += "`" + x.Id + "` "; });

                string useName = string.IsNullOrEmpty(targetUser.Nickname) ? targetUser.Username : targetUser.Nickname;
                embed.SetTitle($"{( lovedPastas ? locale.GetString( "miki_module_pasta_loved_header" ) : locale.GetString( "miki_module_pasta_hated_header" ) )} - {useName}");
                embed.SetDescription(resultString);
                embed.SetFooter(locale.GetString("page_index", page + 1, Math.Ceiling(pastaVotes.Count() / totalPerPage)), "");

                await embed.QueueToChannel(e.Channel);
            }
        }
Пример #2
0
        public async Task SteamGameAsync(EventContext context)
        {
            DateTime requestStart = DateTime.Now;

            string[] args = context.arguments.Split(' ');

            IDiscordEmbed embed = Utils.Embed;

            embed.SetAuthor("Steam Game", steamAuthorIcon, "");

            SteamGameInfo gameInfo = await steam.GetGameInfo(args[0]);

            embed.SetDescription(gameInfo.Name);
            embed.SetThumbnailUrl(gameInfo.HeaderImage);

            embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", "");
            embed.QueueToChannel(context.Channel);
        }
Пример #3
0
        public async Task SteamUserAsync(EventContext context)
        {
            DateTime requestStart = DateTime.Now;

            string[] args = context.arguments.Split(' ');

            IDiscordEmbed embed = Utils.Embed;

            embed.SetAuthor("Steam Profile", steamAuthorIcon, "");

            SteamUserInfo user = await steam.GetSteamUser(args[0]);

            if (user == null)
            {
                embed = Utils.ErrorEmbed(context, "No user was found!");
                embed.QueueToChannel(context.Channel);
                return;
            }

            string userLevel = await steam.GetSteamLevel(user.SteamID);

            embed.SetThumbnailUrl(user.GetAvatarURL());

            /* Current Game & Embed Colour */
            if (user.IsPlayingGame())
            {
                if (user.CurrentGameName != "???")
                {
                    embed.SetDescription("Currently playing " + user.CurrentGameName);
                }
                else
                {
                    embed.SetDescription("Currently in-game");
                }
                embed.Color = new Color(0.5f, 1, 0.5f);
            }
            else if (user.PersonaState != 0)
            {
                embed.Color = new Color(0.5f, 0.5f, 1);
            }

            /* Name & ID */
            embed.AddInlineField("Name", user.GetUsername());
            embed.AddInlineField("ID", user.SteamID);

            /* Real Name & Country */
            embed.AddInlineField("Real Name", user.RealName);
            embed.AddInlineField("Country", (user.CountryCode != "???" ? ":flag_" + user.CountryCode.ToLower() + ": " : "") + user.CountryCode);

            /* Profile Link */
            embed.AddField("Link", user.ProfileURL);

            /* Created & Status */
            embed.AddInlineField("Created", String.Format("{0:MMMM d, yyyy}", user.TimeCreated));
            if (user.GetStatus() == "Offline")
            {
                embed.AddInlineField("Offline Since", ToTimeString(user.OfflineSince()));
            }
            else
            {
                embed.AddInlineField("Status", user.GetStatus());
            }

            /* Level */
            embed.AddInlineField("Level", userLevel);

            embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", "");
            embed.QueueToChannel(context.Channel);
        }
Пример #4
0
        public async Task StartRPS(EventContext e, int bet)
        {
            float rewardMultiplier = 1f;

            string[] args = e.arguments.Split(' ');

            if (args.Length < 2)
            {
                e.ErrorEmbed("You need to choose a weapon!").QueueToChannel(e.Channel);
            }
            else
            {
                User          user;
                RPSManager    rps           = RPSManager.Instance;
                IDiscordEmbed resultMessage = Utils.Embed
                                              .SetTitle("Rock, Paper, Scissors!");

                if (rps.TryParse(args[1], out RPSWeapon playerWeapon))
                {
                    RPSWeapon botWeapon = rps.GetRandomWeapon();

                    resultMessage.SetDescription($"{playerWeapon.Name.ToUpper()} {playerWeapon.Emoji} vs. {botWeapon.Emoji} {botWeapon.Name.ToUpper()}");

                    switch (rps.CalculateVictory(playerWeapon, botWeapon))
                    {
                    case RPSManager.VictoryStatus.WIN:
                    {
                        using (var context = new MikiContext())
                        {
                            user = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                            if (user != null)
                            {
                                await user.AddCurrencyAsync((int)(bet * rewardMultiplier), e.Channel);

                                await context.SaveChangesAsync();
                            }
                        }
                        resultMessage.Description += $"\n\nYou won `{(int)(bet * rewardMultiplier)}` mekos! Your new balance is `{user.Currency}`.";
                    } break;

                    case RPSManager.VictoryStatus.LOSE:
                    {
                        using (var context = new MikiContext())
                        {
                            user = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                            if (user != null)
                            {
                                await user.RemoveCurrencyAsync(context, null, bet);

                                await context.SaveChangesAsync();
                            }
                        }
                        resultMessage.Description += $"\n\nYou lost `{bet}` mekos ! Your new balance is `{user.Currency}`.";
                    }
                    break;

                    case RPSManager.VictoryStatus.DRAW:
                    {
                        resultMessage.Description += $"\n\nIt's a draw! no mekos were lost!.";
                    }
                    break;
                    }
                }
                else
                {
                    resultMessage.SetDescription("Invalid weapon!").QueueToChannel(e.Channel);
                    return;
                }
                resultMessage.QueueToChannel(e.Channel);
            }
        }
Пример #5
0
        public async Task ConfigRoleInteractiveAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                IDiscordEmbed sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                            .SetDescription("Type out the role name you want to config")
                                            .SetColor(138, 182, 239);
                IDiscordMessage sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                IDiscordMessage msg = null;

                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    if (msg.Content.Length < 20)
                    {
                        break;
                    }

                    sourceMessage.Modify("", e.ErrorEmbed("That role name is way too long! Try again."));
                }

                IDiscordRole role    = GetRoleByName(e.Guild, msg.Content.ToLower());
                LevelRole    newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong());

                if (newRole == null)
                {
                    newRole = (await context.LevelRoles.AddAsync(new LevelRole()
                    {
                        RoleId = role.Id.ToDbLong(),
                        GuildId = e.Guild.Id.ToDbLong()
                    })).Entity;
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription("Is there a role that is needed to get this role? Type out the role name, or `-` to skip")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);


                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    IDiscordRole parentRole = GetRoleByName(e.Guild, msg.Content.ToLower());

                    if (parentRole != null || msg.Content == "-")
                    {
                        newRole.RequiredRole = (long?)parentRole?.Id ?? 0;
                        break;
                    }

                    sourceMessage.Modify(null, e.ErrorEmbed("I couldn't find that role. Try again!"));
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Is there a level requirement? type a number, if there is no requirement type 0")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    if (int.TryParse(msg.Content, out int r))
                    {
                        if (r >= 0)
                        {
                            newRole.RequiredLevel = r;
                            break;
                        }
                        else
                        {
                            sourceMessage.Modify(null, sourceEmbed.SetDescription($"Please pick a number above 0. Try again"));
                        }
                    }
                    else
                    {
                        sourceMessage.Modify(null, sourceEmbed.SetDescription($"Are you sure `{msg.Content}` is a number? Try again"));
                    }
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Should I give them when the user level ups? type `yes`, otherwise it will be considered as no")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                if (msg == null)
                {
                    return;
                }

                newRole.Automatic = msg.Content.ToLower()[0] == 'y';

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Should users be able to opt in? type `yes`, otherwise it will be considered as no")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                newRole.Optable = msg.Content.ToLower()[0] == 'y';

                if (newRole.Optable)
                {
                    sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                  .SetDescription($"Do you want the user to pay mekos for the role? Enter any amount. Enter 0 to keep the role free.")
                                  .SetColor(138, 182, 239);

                    sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                    while (true)
                    {
                        msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                        if (msg == null)
                        {
                            return;
                        }

                        if (int.TryParse(msg.Content, out int r))
                        {
                            if (r >= 0)
                            {
                                newRole.Price = r;
                                break;
                            }
                            else
                            {
                                sourceMessage.Modify(null, e.ErrorEmbed($"Please pick a number above 0. Try again"));
                            }
                        }
                        else
                        {
                            sourceMessage.Modify(null, e.ErrorEmbed($"Not quite sure if this is a number 🤔"));
                        }
                    }
                }

                await context.SaveChangesAsync();

                Utils.Embed.SetTitle("⚙ Role Config")
                .SetColor(102, 117, 127)
                .SetDescription($"Updated {role.Name}!")
                .QueueToChannel(e.Channel);
            }
        }