예제 #1
0
        public override void Run(BotMain bot, BotCommandController commandController, string[] rawTerms, string[] terms, string characterName, string channel, UserGeneratedCommand command)
        {
            string tableName = commandController.GetTableNameFromCommandTerms(terms);

            SavedRollTable deleteTable = Utils.GetTableFromId(bot.SavedTables, tableName);

            string sendMessage = "No tables found for [user]" + characterName + "[/user]";

            if (deleteTable != null)
            {
                if (characterName == deleteTable.OriginCharacter)
                {
                    bot.SavedTables.Remove(deleteTable);

                    sendMessage = "[b]" + deleteTable.TableId + "[/b] deleted by [user]" + characterName + "[/user]";

                    Utils.WriteToFileAsData(bot.SavedTables, Utils.GetTotalFileName(BotMain.FileFolder, BotMain.SavedTablesFileName));
                }
                else
                {
                    sendMessage = "Only " + deleteTable.OriginCharacter + " can delete their own saved table.";
                }
            }

            bot.SendMessageInChannel(sendMessage, channel);
        }
예제 #2
0
        public override void Run(BotMain bot, BotCommandController commandController, string[] rawTerms, string[] terms, string characterName, string channel, UserGeneratedCommand command)
        {
            ChannelSettings thisChannel = bot.GetChannelSettings(channel);

            if (thisChannel.AllowTableInfo)
            {
                string tableName = commandController.GetTableNameFromCommandTerms(terms);

                SavedRollTable infoTable = Utils.GetTableFromId(bot.SavedTables, tableName);

                string sendMessage = "Table \'" + tableName + "\' not found.";
                if (infoTable != null)
                {
                    sendMessage = "Table id [b]" + infoTable.TableId + "[/b] created by [user]" + infoTable.OriginCharacter + "[/user]";

                    if (infoTable.Table != null)
                    {
                        string tabledesc = infoTable.Table.Description + "\n";
                        sendMessage += "\n\n Name: [b]" + infoTable.Table.Name + "[/b]\n " + tabledesc + " Roll Die: d" + infoTable.Table.DieSides + " Roll Bonus: " + infoTable.Table.RollBonus;
                        sendMessage += "\n" + infoTable.Table.GetTableEntryList();
                    }
                    else
                    {
                        sendMessage += "\n (Rolltable contents not found)";
                    }
                }

                bot.SendMessageInChannel(sendMessage, channel);
            }
            else
            {
                bot.SendMessageInChannel(Name + " is currently not allowed in this channel under " + Utils.GetCharacterUserTags("Dice Bot") + "'s settings for this channel.", channel);
            }
        }
예제 #3
0
        public override void Run(BotMain bot, BotCommandController commandController, string[] rawTerms, string[] terms, string characterName, string channel, UserGeneratedCommand command)
        {
            ChannelSettings thisChannel = bot.GetChannelSettings(channel);

            if (thisChannel.AllowTableRolls)
            {
                bool includeLabel   = true;
                bool secondaryRolls = true;

                if (terms != null && terms.Length >= 1 && terms.Contains("nolabel"))
                {
                    includeLabel = false;
                }
                if (terms != null && terms.Length >= 1 && terms.Contains("nosecondary"))
                {
                    secondaryRolls = false;
                }

                int    rollModifier = commandController.GetRollModifierFromCommandTerms(terms);
                string tableName    = commandController.GetTableNameFromCommandTerms(terms);

                SavedRollTable savedTable = Utils.GetTableFromId(bot.SavedTables, tableName);

                if (savedTable.DefaultTable || thisChannel.AllowCustomTableRolls)
                {
                    string sendMessage = bot.DiceBot.GetRollTableResult(bot.SavedTables, tableName, characterName, channel, rollModifier, includeLabel, secondaryRolls, 3);

                    bot.SendMessageInChannel(sendMessage, channel);
                }
                else
                {
                    bot.SendMessageInChannel("Only default talbes are allowed in this channel under " + Utils.GetCharacterUserTags("Dice Bot") + "'s settings for this channel.", channel);
                }
            }
            else
            {
                bot.SendMessageInChannel(Name + " is currently not allowed in this channel under " + Utils.GetCharacterUserTags("Dice Bot") + "'s settings for this channel.", channel);
            }
        }
예제 #4
0
파일: Utils.cs 프로젝트: LeetheM/FCDiceBot
        public static SavedRollTable GetTableFromId(List <SavedRollTable> tables, string id)
        {
            SavedRollTable infoTable = tables.FirstOrDefault(a => a.TableId == id);

            return(infoTable);
        }
예제 #5
0
        public override void Run(BotMain bot, BotCommandController commandController, string[] rawTerms, string[] terms, string characterName, string channel, UserGeneratedCommand command)
        {
            string saveJson    = Utils.GetFullStringOfInputs(rawTerms);
            string sendMessage = "";

            try
            {
                FChatDicebot.DiceFunctions.RollTable newTable = JsonConvert.DeserializeObject <FChatDicebot.DiceFunctions.RollTable>(saveJson);
                newTable.Name = Utils.LimitStringToNCharacters(newTable.Name, BotMain.MaximumCharactersTableName);
                string newTableId = newTable.Name.Replace(" ", "").ToLower();

                newTable.Description = Utils.LimitStringToNCharacters(newTable.Description, BotMain.MaximumCharactersTableDescription);

                var thisCharacterTables = bot.SavedTables.Where(a => a.OriginCharacter == characterName);

                SavedRollTable existingTable = Utils.GetTableFromId(bot.SavedTables, newTableId);

                if (thisCharacterTables.Count() >= BotMain.MaximumSavedTablesPerCharacter && existingTable == null)
                {
                    sendMessage = "Failed: A character can only save up to 3 tables at one time. Delete or overwrite old tables.";
                }
                else if (existingTable != null && existingTable.OriginCharacter != characterName)
                {
                    sendMessage = "Failed: This table name is taken by a different character.";
                }
                else if (newTableId.Length < 2)
                {
                    sendMessage = "Failed: Table name too short.";
                }
                else if (newTable.TableEntries == null)
                {
                    sendMessage = "Failed: No table entries found for this table.";
                }
                else if (newTable.TableEntries.Count > BotMain.MaximumSavedEntriesPerTable)
                {
                    sendMessage = "Failed: Table contains more than " + BotMain.MaximumSavedEntriesPerTable + " entries.";
                }
                else
                {
                    foreach (FChatDicebot.DiceFunctions.TableEntry t in newTable.TableEntries)
                    {
                        t.Name        = Utils.LimitStringToNCharacters(t.Name, BotMain.MaximumCharactersTableName);
                        t.Description = Utils.LimitStringToNCharacters(t.Description, BotMain.MaximumCharactersTableEntryDescription);

                        if (t.Triggers != null && t.Triggers.Count > BotMain.MaximumRollTriggersPerEntry)
                        {
                            t.Triggers = t.Triggers.Take(BotMain.MaximumRollTriggersPerEntry).ToList();
                        }
                    }

                    SavedRollTable newSavedRollTable = new SavedRollTable()
                    {
                        Table           = newTable,
                        OriginCharacter = characterName,
                        DefaultTable    = false,
                        TableId         = newTableId
                    };

                    if (existingTable != null)
                    {
                        existingTable.Copy(newSavedRollTable);
                    }
                    else
                    {
                        bot.SavedTables.Add(newSavedRollTable);
                    }

                    Utils.WriteToFileAsData(bot.SavedTables, Utils.GetTotalFileName(BotMain.FileFolder, BotMain.SavedTablesFileName));

                    sendMessage = "[b]Success[/b]. Table saved by [user]" + characterName + "[/user]. Roll on this table using !rolltable " + newTableId;
                }
            }
            catch (Exception)
            {
                sendMessage = "Failed to parse table entry data. Make sure the Json is correctly formatted.";
            }

            bot.SendMessageInChannel(sendMessage, channel);
        }