Пример #1
0
        public async Task OracleRollCommand([Remainder] string TableNameAndOptionalGame)
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            GameName game        = Utilities.GetGameContainedInString(TableNameAndOptionalGame);
            string   oracleTable = Utilities.RemoveGameNamesFromString(TableNameAndOptionalGame);

            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            OracleRoller roller = new OracleRoller(Services, game);

            try
            {
                var msg = await ReplyAsync("", false, roller.BuildRollResults(oracleTable).GetEmbed());

                if (roller.RollResultList.Count == 1 && roller.RollResultList[0].ParentTable.Pair?.Length > 0)
                {
                    await msg.AddReactionAsync(new Emoji("\uD83E\uDDE6"));
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine($"{Context.User} triggered an ArgumentException: {ex.Message}");
                await ReplyAsync(ex.Message);
            }
        }
Пример #2
0
        public async Task AssetList([Remainder] string AssetListOptions = "")
        {
            var game = Utilities.GetGameContainedInString(AssetListOptions);

            AssetListOptions = Utilities.RemoveGameNamesFromString(AssetListOptions).Trim();
            if (game == GameName.None)
            {
                var settings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

                game = settings?.DefaultGame ?? GameName.None;
            }

            var sourceList = Services.GetRequiredService <List <Asset> >().Where(a => a.Game == game || game == GameName.None).ToList();
            var assetList  = new List <Asset>();

            if (AssetListOptions.Length > 0)
            {
                assetList.AddRange(sourceList.Where(a => a.AssetType.Contains(AssetListOptions, StringComparison.OrdinalIgnoreCase)));
                assetList.AddRange(sourceList.Where(a => a.Name.Contains(AssetListOptions, StringComparison.OrdinalIgnoreCase)));
            }
            else
            {
                assetList = new List <Asset>(sourceList);
            }

            if (assetList.Count > 0)
            {
                string replyMessage = string.Join(", ", assetList.Select(a => a.Name));
                await ReplyAsync(replyMessage).ConfigureAwait(false);
            }
            else
            {
                await ReplyAsync(AssetResources.UnknownAssetError);
            }
        }
Пример #3
0
        public async Task OracleList()
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            string reply = $"__Here's a list of available Oracle Tables:__\n";

            foreach (var oracle in _oracleService.OracleList.Where(orc => channelSettings == null || channelSettings.DefaultGame == GameName.None || orc.Game == channelSettings.DefaultGame))
            {
                string aliases = string.Empty;
                if (oracle.Aliases != null)
                {
                    aliases = $"{string.Join(", ", oracle.Aliases)}, ";
                }
                reply += $"**{oracle.Name}**, {aliases}";
            }
            reply = reply.Remove(reply.LastIndexOf(", "));

            while (true)
            {
                if (reply.Length < DiscordConfig.MaxMessageSize)
                {
                    await ReplyAsync(reply);

                    break;
                }

                int cutoff = reply.Substring(0, DiscordConfig.MaxMessageSize).LastIndexOf(',');
                await ReplyAsync(reply.Substring(0, cutoff));

                reply = reply.Substring(cutoff + 1).Trim();
            }
        }
Пример #4
0
        public async Task NPCPost([Remainder] string NPCNameAndOptionalGame = "")
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            var game = Utilities.GetGameContainedInString(NPCNameAndOptionalGame);

            if (game != GameName.None)
            {
                NPCNameAndOptionalGame = Utilities.RemoveGameNamesFromString(NPCNameAndOptionalGame);
            }
            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            var NPCGen = new NpcFactory(serviceProvider).GetNPCGenerator(game);

            var msg = await ReplyAsync(embed : NPCGen.Build(NPCNameAndOptionalGame).GetEmbed());

            if (NPCGen.ReactionsToAdd != null)
            {
                await Task.Run(async() =>
                {
                    foreach (var emote in NPCGen.ReactionsToAdd)
                    {
                        await msg.AddReactionAsync(emote);
                    }
                }).ConfigureAwait(false);
            }
        }
        public async Task BuildTrackerCommand([Remainder] string Description = "")
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            InitiativeTracker tracker = new InitiativeTracker(channelSettings);

            tracker.Description = Description;
            var msg = await ReplyAsync(embed : tracker.GetEmbedBuilder().Build());

            await msg.AddReactionAsync(AdvantageEmoji);

            await msg.AddReactionAsync(DisadvantageEmoji);

            return;
        }
Пример #6
0
        public async Task SetDebilities(int numberOfDebilities)
        {
            if (!(Context.Message.ReferencedMessage is IUserMessage message) || !IsPlayerCardPost(message))
            {
                await ReplyAsync(PlayerResources.InlineReplyMissingError).ConfigureAwait(false);

                return;
            }

            var cs = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            var player = new Player().WithChannelSettings(cs).PopulateFromEmbed(message.Embeds.First());

            player.Debilities = numberOfDebilities;

            await message.ModifyAsync(msg => msg.Embed = player.GetEmbedBuilder().Build()).ConfigureAwait(false);
        }
Пример #7
0
        public async Task NPCPost([Remainder] string NPCArguments = "")
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            var game = Utilities.GetGameContainedInString(NPCArguments);

            if (game != GameName.None)
            {
                NPCArguments = Utilities.RemoveGameNamesFromString(NPCArguments);
            }
            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            var NPCGen = new NpcFactory(serviceProvider).GetNPCGenerator(game);

            await ReplyAsync(embed : NPCGen.Build(NPCArguments).GetEmbed());
        }
Пример #8
0
        private async Task BurnMomentumReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!IsPlayerCardPost(message))
            {
                return;
            }

            var cs = await ChannelSettings.GetChannelSettingsAsync(channel.Id);

            var player           = new Player().WithChannelSettings(cs).PopulateFromEmbed(message.Embeds.First());
            int startingMomentum = player.Momentum;

            player.Momentum = 2 - player.Debilities;

            await message.ModifyAsync(msg => msg.Embed = player.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            await message.ReplyAsync(String.Format(PlayerResources.BurnMomentumMessage, player.Name, startingMomentum));
        }
Пример #9
0
        private async Task InitiativeReactionsHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(channel.Id);

            if (!InitiativeTracker.IsInitiativeTrackerMessage(message))
            {
                return;
            }

            InitiativeTracker tracker = InitiativeTracker.FromMessage(message).WithChannelSettings(channelSettings);

            if (reaction.Emote.Name == DisadvantageEmoji)
            {
                if (!tracker.Disadvantage.Contains(user.ToString()))
                {
                    await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

                    tracker.Disadvantage.Add(user.ToString());
                    tracker.Advantage.RemoveAll(s => s == user.ToString());
                    await message.ModifyAsync(msg => msg.Embed = tracker.GetEmbedBuilder().Build());

                    return;
                }
            }
            if (reaction.Emote.Name == AdvantageEmoji)
            {
                if (!tracker.Advantage.Contains(user.ToString()))
                {
                    await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

                    tracker.Advantage.Add(user.ToString());
                    tracker.Disadvantage.RemoveAll(s => s == user.ToString());
                    await message.ModifyAsync(msg => msg.Embed = tracker.GetEmbedBuilder().Build());

                    return;
                }
            }

            return;
        }
Пример #10
0
        public List <OracleTable> ParseOracleTables(string tableName)
        {
            var result = new List <OracleTable>();

            // Match [table1/table2] style entries
            var match = Regex.Match(tableName, @"\[.*\]");

            if (match.Success)
            {
                var splits = tableName.Replace("[", "").Replace("]", "").Split('/');
                foreach (var item in splits)
                {
                    result.AddRange(OracleService.OracleList.Where(o => o.MatchTableAlias(item) && (Game == GameName.None || Game == o.Game)).ToList());
                }
            }
            else
            {
                result = OracleService.OracleList.Where(o => o.MatchTableAlias(tableName) && (Game == GameName.None || Game == o.Game)).ToList();
            }

            if (result.GroupBy(t => t.Game).Count() > 1)
            {
                var             Context         = ServiceProvider.GetService <CommandContext>();
                ChannelSettings channelSettings = ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id).Result;
            }

            if (result.GroupBy(t => t.Game).Count() > 1)
            {
                string games     = string.Empty;
                var    gamesList = result.GroupBy(tbl => tbl.Game).Select(g => g.First());
                foreach (var g in gamesList)
                {
                    games += (g == gamesList.Last()) ? $"`{g.Game}`" : $"`{g.Game}`, ";
                }
                throw new ArgumentException(string.Format(OracleResources.TooManyGamesError, games));
            }

            return(result);
        }
Пример #11
0
        public async Task ReferencePost([Remainder] string query)
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            GameName game = Utilities.GetGameContainedInString(query);

            query = Utilities.RemoveGameNamesFromString(query);

            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            query = query.Trim();

            if (ruleService.Rules.Any(r => MatchNameOrAlias(r, query)))
            {
                var rules = ruleService.Rules.Where(r => MatchNameOrAlias(r, query));

                if (rules.GroupBy(r => r.Game).Count() > 1)
                {
                    rules = rules.Where(r => r.Game == game);
                }

                foreach (var rule in rules)
                {
                    if (rule.Moves.Count() == 0)
                    {
                        await ReplyAsync(string.Format(RulesResources.NoMovesError, query));

                        return;
                    }

                    string CategoryReply = string.Empty;
                    foreach (var move in rule.Moves)
                    {
                        CategoryReply += $"{move.Name}\n";
                    }

                    await ReplyAsync($"__**{rule.Category}**__:\n{CategoryReply}\n\n{rule.Source}");
                }

                return;
            }

            string specificMovesReply = string.Empty;
            var    specRules          = ruleService.Rules.Where(r => r.Moves.Any(m => MatchNameOrAlias(m, query)));

            if (specRules.GroupBy(r => r.Game).Count() > 1)
            {
                specRules = specRules.Where(r => r.Game == game || game == GameName.None);
            }

            foreach (var rules in specRules)
            {
                var actualGame = rules.Game;
                foreach (var move in rules.Moves.Where(m => MatchNameOrAlias(m, query)))
                {
                    string sourceText = (move.Source != null) ? $"{move.Source}\n\n" : string.Empty;
                    string temp       = $"__{actualGame} - **{move.Name}**__\n{move.Text}\n\n{sourceText}".Replace("\n\n\n", "\n\n");
                    if (specificMovesReply.Length + temp.Length > DiscordConfig.MaxMessageSize)
                    {
                        if (specificMovesReply.Length > 0)
                        {
                            await ReplyAsync(specificMovesReply);

                            specificMovesReply = string.Empty;
                        }

                        temp.Replace("\n\n\n", "\n\n");
                        if (temp.Length > DiscordConfig.MaxMessageSize)
                        {
                            int messageCutoff = temp.Substring(0, DiscordConfig.MaxMessageSize).LastIndexOf("\n");

                            var matches = Regex.Matches(temp, "```");
                            if (matches.Count > 0)
                            {
                                var match = matches.LastOrDefault(m => m.Index <DiscordConfig.MaxMessageSize && m.Index> temp.Length - DiscordConfig.MaxMessageSize);
                                if (match != default)
                                {
                                    messageCutoff = match.Index;
                                }
                            }
                            await ReplyAsync(temp.Substring(0, messageCutoff));

                            temp = temp.Substring(messageCutoff);
                        }
                    }
                    specificMovesReply += temp;
                }
            }

            if (specificMovesReply.Length == 0)
            {
                await ReplyAsync(string.Format(RulesResources.UnknownMoveError, query));

                return;
            }

            await ReplyAsync(specificMovesReply);
        }
Пример #12
0
        public async Task StandardAsset([Remainder] string AssetCommand)
        {
            var assets = Services.GetRequiredService <List <Asset> >();

            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            var game = Utilities.GetGameContainedInString(AssetCommand);

            if (game != GameName.None)
            {
                AssetCommand = Utilities.RemoveGameNamesFromString(AssetCommand);
            }
            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            var asset = assets.FirstOrDefault(a => new Regex(@"(\W|\b)" + a.Name + @"(\W|\b)", RegexOptions.IgnoreCase).IsMatch(AssetCommand) && (game == GameName.None || game == a.Game)); //Strong match

            if (asset == default)
            {
                asset = assets.FirstOrDefault(a => new Regex(@"(\W|\b)" + a.Name, RegexOptions.IgnoreCase).IsMatch(AssetCommand) && (game == GameName.None || game == a.Game));
            }
            if (asset == default)
            {
                asset = assets.FirstOrDefault(a => AssetCommand.Contains(a.Name, StringComparison.OrdinalIgnoreCase) && (game == GameName.None || game == a.Game));                   //Weakest match - This is mostly for languages that don't have spaces between words
            }
            if (asset == default)
            {
                throw new ArgumentException(AssetResources.UnknownAssetError);
            }

            string additionalInputsRaw = AssetCommand.ReplaceFirst(asset.Name, "", StringComparison.OrdinalIgnoreCase).Replace("  ", " ").Trim();

            string[] seperators = new string[] { ",", "\n" };
            if (additionalInputsRaw.Contains(",") || additionalInputsRaw.Contains("\n"))
            {
                additionalInputsRaw.Replace("\"", string.Empty);
            }

            string[] arguments = additionalInputsRaw.Split(seperators, StringSplitOptions.RemoveEmptyEntries);

            var message = await ReplyAsync(embed : asset.GetEmbed(arguments));

            await Task.Run(async() =>
            {
                if (asset.NumericAssetTrack != null)
                {
                    await message.AddReactionAsync(new Emoji("⬆️"));
                    await message.AddReactionAsync(new Emoji("⬇️"));
                }

                if (asset.MultiFieldAssetTrack != null)
                {
                    await message.AddReactionAsync(new Emoji("⬅️"));
                    await message.AddReactionAsync(new Emoji("➡️"));
                }

                if (asset.CountingAssetTrack != null)
                {
                    await message.AddReactionAsync(new Emoji("➖"));
                    await message.AddReactionAsync(new Emoji("➕"));
                }

                for (int i = 0; i < asset.AssetFields.Count; i++)
                {
                    if (asset.AssetFields[i].Enabled)
                    {
                        continue;
                    }
                    if (i == 0)
                    {
                        await message.AddReactionAsync(GenericReactions.oneEmoji);
                    }
                    if (i == 1)
                    {
                        await message.AddReactionAsync(GenericReactions.twoEmoji);
                    }
                    if (i == 2)
                    {
                        await message.AddReactionAsync(GenericReactions.threeEmoji);
                    }
                    if (i == 3)
                    {
                        await message.AddReactionAsync(GenericReactions.fourEmoji);
                    }
                }
            }).ConfigureAwait(false);
        }
Пример #13
0
        public async Task OracleList([Remainder] string OracleListOptions = "")
        {
            var ShowPostInChannel = OracleResources.ShowListInChannel.Split(',').Any(s => OracleListOptions.Contains(s, StringComparison.OrdinalIgnoreCase));

            var UserGame = Utilities.GetGameContainedInString(OracleListOptions);

            if (UserGame == GameName.None)
            {
                ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

                UserGame = channelSettings?.DefaultGame ?? GameName.None;
            }

            var baseList = _oracleService.OracleList.Where(orc => UserGame == GameName.None || orc.Game == UserGame);

            baseList.ToList().ForEach(o => { if (o.Category == null || o.Category.Length == 0)
                                             {
                                                 o.Category = o.Game?.ToString() ?? "Misc";
                                             }
                                      });

            foreach (var game in baseList.GroupBy(o => o.Game).Select(o => o.First().Game))
            {
                EmbedBuilder  builder         = new EmbedBuilder().WithTitle(String.Format(OracleResources.OracleListTitle, game));
                string        currentCategory = string.Empty;
                string        entries         = string.Empty;
                List <string> splitUpList     = new List <string>();

                foreach (var oracle in baseList.Where(o => o.Game == game).OrderBy(o => o.Category))
                {
                    if (oracle.Category != currentCategory)
                    {
                        currentCategory = oracle.Category;
                        string catValue = $"\n**{currentCategory}**\n";

                        if (entries.Length + catValue.Length > 950) //Keep it under 1024 so we are less likely up with duplicated top level entries
                        {
                            splitUpList.Add(entries.Replace("\n\n\n", "\n\n"));
                            entries = string.Empty;
                        }
                        entries += catValue;
                    }

                    string aliases = string.Empty;
                    if (oracle.Aliases != null)
                    {
                        aliases = $" • {string.Join("\n• ", oracle.Aliases)}";
                    }

                    string entry = $" __`{oracle.Name}`__\n{aliases}\n";

                    if (entries.Length + entry.Length > 1024)
                    {
                        splitUpList.Add(entries.Replace("\n\n\n", "\n\n"));
                        entries = $"**{currentCategory}**\n";
                    }

                    entries += entry;
                }

                splitUpList.Add(entries.Replace("\n\n\n", "\n\n"));

                foreach (var s in splitUpList)
                {
                    string title = "Title";
                    string temp  = Utilities.RemoveGameNamesFromString(s);
                    var    match = Regex.Matches(temp, @"\*\*([a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])");
                    if (match.Count > 0)
                    {
                        title = string.Format(OracleResources.OracleListFieldTitle, match[0].Groups[1], match.Last().Groups[1]);
                    }
                    builder.AddField(title, s, true);
                }

                if (ShowPostInChannel)
                {
                    await ReplyAsync(embed : builder.Build()).ConfigureAwait(false);
                }
                else
                {
                    await Context.User.SendMessageAsync(embed : builder.Build()).ConfigureAwait(false);
                }
            }

            if (!ShowPostInChannel)
            {
                await ReplyAsync(OracleResources.ListSentInDM).ConfigureAwait(false);
            }
        }
Пример #14
0
        public async Task ReferencePost([Remainder] string query)
        {
            ChannelSettings channelSettings = await ChannelSettings.GetChannelSettingsAsync(Context.Channel.Id);

            GameName game = Utilities.GetGameContainedInString(query);

            query = Utilities.RemoveGameNamesFromString(query);

            if (game == GameName.None && channelSettings != null)
            {
                game = channelSettings.DefaultGame;
            }

            query = query.Trim();

            if (ruleService.Rules.Any(r => MatchNameOrAlias(r, query)))
            {
                var rules = ruleService.Rules.Where(r => MatchNameOrAlias(r, query));

                if (rules.GroupBy(r => r.Game).Count() > 1)
                {
                    rules = rules.Where(r => r.Game == game);
                }

                foreach (var rule in rules)
                {
                    if (rule.Moves.Count() == 0)
                    {
                        await ReplyAsync($"No moves in {query}");

                        return;
                    }

                    string CategoryReply = string.Empty;
                    foreach (var move in rule.Moves)
                    {
                        CategoryReply += $"{move.Name}\n";
                    }

                    await ReplyAsync($"__**{rule.Category}**__:\n{CategoryReply}");
                }

                return;
            }

            string specificMovesReply = string.Empty;
            var    specRules          = ruleService.Rules.Where(r => r.Moves.Any(m => MatchNameOrAlias(m, query)));

            if (specRules.GroupBy(r => r.Game).Count() > 1)
            {
                specRules = specRules.Where(r => r.Game == game);
            }

            foreach (var rules in specRules)
            {
                var actualGame = rules.Game;
                foreach (var move in rules.Moves.Where(m => MatchNameOrAlias(m, query)))
                {
                    string temp = $"__{actualGame} - **{move.Name}**__\n{move.Text}\n\n";
                    if (specificMovesReply.Length + temp.Length > DiscordConfig.MaxMessageSize)
                    {
                        await ReplyAsync(specificMovesReply);

                        specificMovesReply = string.Empty;
                    }
                    specificMovesReply += temp;
                }
            }

            if (specificMovesReply.Length == 0)
            {
                await ReplyAsync($"Unknown move: '{query}'");

                return;
            }

            await ReplyAsync(specificMovesReply);
        }
Пример #15
0
        private async Task ResourceChangeHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!IsPlayerCardPost(message))
            {
                return;
            }
            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            var healthActive   = message.GetReactionUsersAsync(healthEmoji, 5).AnyAsync(col => col.Any(u => u.Id == user.Id));
            var spiritActive   = message.GetReactionUsersAsync(spiritEmoji, 5).AnyAsync(col => col.Any(u => u.Id == user.Id));
            var supplyActive   = message.GetReactionUsersAsync(supplyEmoji, 5).AnyAsync(col => col.Any(u => u.Id == user.Id));
            var momentumActive = message.GetReactionUsersAsync(momentumEmoji, 5).AnyAsync(col => col.Any(u => u.Id == user.Id));

            Task[] tasks = new Task[] { healthActive.AsTask(), supplyActive.AsTask(), spiritActive.AsTask(), momentumActive.AsTask() };

            await Task.WhenAll(tasks);

            List <bool> activeResources = new List <bool> {
                healthActive.Result, supplyActive.Result, spiritActive.Result, momentumActive.Result
            };

            if (activeResources.Count(b => b) > 1)
            {
                var existingEmbed = message.Embeds.First().ToEmbedBuilder();
                existingEmbed.WithFooter(PlayerResources.TooManyStatsActive);

                await message.ModifyAsync(msg => msg.Embed = existingEmbed.Build()).ConfigureAwait(false);

                return;
            }

            int direction = 0;

            if (reaction.Emote.IsSameAs(upEmoji))
            {
                direction = 1;
            }
            if (reaction.Emote.IsSameAs(downEmoji))
            {
                direction = -1;
            }

            var cs = await ChannelSettings.GetChannelSettingsAsync(channel.Id);

            var player = new Player().WithChannelSettings(cs).PopulateFromEmbed(message.Embeds.First());

            if (healthActive.Result)
            {
                player.Health += direction;
            }
            if (supplyActive.Result)
            {
                player.Supply += direction;
            }
            if (spiritActive.Result)
            {
                player.Spirit += direction;
            }
            if (momentumActive.Result)
            {
                player.Momentum += direction;
            }

            await message.ModifyAsync(msg => msg.Embed = player.GetEmbedBuilder().Build());
        }