Beispiel #1
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            try
            {
                string[] command = message.Message.Split(' ');

                if (command.Length < 2)
                {
                    return;
                }

                bool isNumeric = int.TryParse(command[1], out int amount);

                if (isNumeric)
                {
                    foreach (Viewer vwr in ViewerModel.All)
                    {
                        vwr.GiveCoins(amount);
                    }

                    Toolkit.client.SendMessage($"@{message.User} " + Helper.ReplacePlaceholder("TwitchToolkitGiveAllCoins".Translate(), amount: amount.ToString()), CommandsHandler.SendToChatroom(message));
                }
            }
            catch (InvalidCastException e)
            {
                Helper.Log("Give All Coins Syntax Error " + e.Message);
            }
        }
Beispiel #2
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            // TODO fix award viewer coins
            //Viewers.AwardViewersCoins();

            Toolkit.client.SendMessage($"@{message.User} rewarding all active viewers coins.");
        }
        public override void RunCommand(TwitchIRCMessage message)
        {
            if ((DateTime.Now - Cooldowns.modsCommandCooldown).TotalSeconds <= 15)
            {
                return;
            }

            Cooldowns.modsCommandCooldown = DateTime.Now;
            string modmsg = "Version: " + Toolkit.Mod.Version + ", Mods: ";

            string[] mods = LoadedModManager.RunningMods.Select((m) => m.Name).ToArray();

            for (int i = 0; i < mods.Length; i++)
            {
                modmsg += mods[i] + ", ";

                if (i == (mods.Length - 1) || modmsg.Length > 256)
                {
                    modmsg = modmsg.Substring(0, modmsg.Length - 2);
                    Toolkit.client.SendMessage(modmsg, CommandsHandler.SendToChatroom(message));
                    modmsg = "";
                }
            }
            return;
        }
Beispiel #4
0
        public override void ParseCommand(TwitchIRCMessage msg)
        {
            if (msg.Message.StartsWith("!lookup") && CommandsHandler.AllowCommand(msg))
            {
                string[] command = msg.Message.Split(' ');
                if (command.Length < 2)
                {
                    return;
                }

                string searchObject = command[1].ToLower();

                if (searchObject == null || searchObject == "")
                {
                    return;
                }

                string searchQuery = null;

                if (command.Length > 2)
                {
                    searchQuery = command[2].ToLower();
                }

                if (searchQuery == null)
                {
                    searchQuery = "";
                }

                FindLookup(msg, searchObject, searchQuery);
            }

            Store_Logger.LogString("Finished lookup parse");
        }
Beispiel #5
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            // TODO fix refresh viewers
            //TwitchToolkitDev.WebRequest_BeginGetResponse.Main("https://tmi.twitch.tv/group/user/" + ToolkitSettings.Channel.ToLower() + "/chatters", new Func<TwitchToolkitDev.RequestState, bool>(Viewers.SaveUsernamesFromJsonResponse));

            Toolkit.client.SendMessage($"@{message.User} viewers have been refreshed.");
        }
Beispiel #6
0
        public static bool SendToChatroom(TwitchIRCMessage msg)
        {
            if (msg.Whisper && ToolkitSettings.WhispersGoToChatRoom)
            {
                return(true);
            }
            else if (msg.Whisper)
            {
                return(false);
            }

            if (msg.Channel == "#" + ToolkitSettings.Channel.ToLower())
            {
                return(false);
            }
            if (ToolkitSettings.UseSeparateChatRoom && !ToolkitSettings.AllowBothChatRooms)
            {
                return(true);
            }
            if (msg.Channel == "#chatrooms:" + ToolkitSettings.ChannelID + ":" + ToolkitSettings.ChatroomUUID && ToolkitSettings.UseSeparateChatRoom)
            {
                return(true);
            }
            return(false);
        }
Beispiel #7
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            try
            {
                string[] command = message.Message.Split(' ');

                if (command.Length < 3)
                {
                    return;
                }

                string target = command[1].Replace("@", "");
                int    amount;
                bool   isNumeric = int.TryParse(command[2], out amount);
                if (isNumeric)
                {
                    Viewer targeted = ViewerModel.GetViewerByTypeAndUsername(target, message.Viewer.ViewerType);
                    targeted.Karma = amount;
                    Toolkit.client.SendMessage($"@{message.User}" + Helper.ReplacePlaceholder("TwitchToolkitSetKarma".Translate(), viewer: targeted.Username, karma: amount.ToString()), CommandsHandler.SendToChatroom(message));
                }
            }
            catch (InvalidCastException e)
            {
                Helper.Log("Invalid Check User Command " + e.Message);
            }
        }
 public override void RunCommand(TwitchIRCMessage message)
 {
     if (message.Message.Split(' ').Count() < 2)
     {
         return;
     }
     Purchase_Handler.ResolvePurchase(message.Viewer, message, CommandsHandler.SendToChatroom(message));
 }
Beispiel #9
0
        public static void AddNewMessage(TwitchIRCMessage message)
        {
            ircMessages.Add(message);

            if (ircMessages.Count > ToolkitSettings.ChatBoxMessageCount)
            {
                ircMessages.Remove(ircMessages.ElementAt(0));
            }
        }
Beispiel #10
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            Helper.Log("running balance command");

            Toolkit.client.SendMessage(
                $"@{message.Viewer.UsernameCap} " + Helper.ReplacePlaceholder("TwitchToolkitBalanceMessage".Translate(),
                                                                              amount: message.Viewer.Coins.ToString(), karma: message.Viewer.Karma.ToString()),
                CommandsHandler.SendToChatroom(message)
                );
        }
Beispiel #11
0
        public virtual void RunCommand(TwitchIRCMessage message)
        {
            Helper.Log("filtering command");

            string output = FilterTags(message, command.outputMessage);

            Helper.Log("command filtered");

            Toolkit.client.SendMessage(output);
        }
Beispiel #12
0
        public void RunCommand(TwitchIRCMessage message)
        {
            if (command == null)
            {
                throw new Exception("Command is null");
            }

            CommandDriver driver = (CommandDriver)Activator.CreateInstance(commandDriver);

            driver.command = this;
            driver.RunCommand(message);
        }
Beispiel #13
0
 public override void RunCommand(TwitchIRCMessage message)
 {
     if (ToolkitSettings.EarningCoins)
     {
         ToolkitSettings.EarningCoins = false;
         Toolkit.client.SendMessage($"@{message.User} " + "TwitchToolkitEarningCoinsMessage".Translate() + " " + "TwitchToolkitOff".Translate(), CommandsHandler.SendToChatroom(message));
     }
     else
     {
         ToolkitSettings.EarningCoins = true;
         Toolkit.client.SendMessage($"@{message.User} " + "TwitchToolkitEarningCoinsMessage".Translate() + " " + "TwitchToolkitOn".Translate(), CommandsHandler.SendToChatroom(message));
     }
 }
Beispiel #14
0
        public string FilterTags(TwitchIRCMessage message, string input)
        {
            Helper.Log("starting filter");

            StringBuilder output = new StringBuilder(input);

            output.Replace("{username}", message.Viewer.UsernameCap);
            output.Replace("{balance}", message.Viewer.Coins.ToString());
            output.Replace("{karma}", message.Viewer.Karma.ToString());
            output.Replace("{purchaselist}", ToolkitSettings.CustomPricingSheetLink);
            output.Replace("{coin-reward}", ToolkitSettings.CoinAmount.ToString());

            output.Replace("\n", "");

            Helper.Log("starting regex");

            Regex regex = new Regex(@"\[(.*?)\]");

            MatchCollection matches = regex.Matches(output.ToString());

            foreach (Match match in matches)
            {
                Helper.Log("found match " + match.Value);
                string code = match.Value;
                code = code.Replace("[", "");
                code = code.Replace("]", "");

                //Regex doubleReg = new Regex("double\\<(.*?)\\>");

                //foreach (Match innerMatch in doubleReg.Matches(match.Value.ToString()))
                //{
                //    Helper.Log("found match " + innerMatch.Value);

                //    string innerCode = innerMatch.Value;
                //    innerCode = innerCode.Replace("double<", "");
                //    innerCode = innerCode.Replace(">", "");

                //    Helper.Log("executing double " + innerCode);

                //    output.Replace(innerMatch.Value, MoonSharpDouble(code).ToString());
                //}

                // Helper.Log("finished inner code");

                output.Replace(match.Value, MoonSharpString(code));
            }

            return(output.ToString());
        }
Beispiel #15
0
 public static bool AllowCommand(TwitchIRCMessage msg)
 {
     if (!ToolkitSettings.UseSeparateChatRoom && (msg.Whisper || ToolkitSettings.AllowBothChatRooms || msg.Channel == "#" + ToolkitSettings.Channel.ToLower()))
     {
         return(true);
     }
     if (msg.Channel == "#chatrooms:" + ToolkitSettings.ChannelID + ":" + ToolkitSettings.ChatroomUUID)
     {
         return(true);
     }
     if (ToolkitSettings.AllowBothChatRooms && ToolkitSettings.UseSeparateChatRoom || (msg.Whisper))
     {
         return(true);
     }
     return(false);
 }
Beispiel #16
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            Command buyCommand = DefDatabase <Command> .GetNamed("Buy");

            string minutess     = ToolkitSettings.CoinInterval > 1 ? "s" : "";
            string storeon      = buyCommand.enabled ? "TwitchToolkitOn".Translate() : "TwitchToolkitOff".Translate();
            string earningcoins = ToolkitSettings.EarningCoins ? "TwitchToolkitOn".Translate() : "TwitchToolkitOff".Translate();

            string stats_message = Helper.ReplacePlaceholder("TwitchToolkitModSettings".Translate(),
                                                             amount: ToolkitSettings.CoinAmount.ToString(),
                                                             first: ToolkitSettings.CoinInterval.ToString(),
                                                             second: storeon,
                                                             third: earningcoins,
                                                             karma: ToolkitSettings.KarmaCap.ToString()
                                                             );

            Toolkit.client.SendMessage(stats_message, CommandsHandler.SendToChatroom(message));
        }
Beispiel #17
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            List <Command> commands = DefDatabase <Command> .AllDefs.Where(s => !s.requiresAdmin && !s.requiresMod && s.enabled).ToList();

            string output = "@" + message.User + " viewer commands: ";


            for (int i = 0; i < commands.Count; i++)
            {
                output += "!" + commands[i].command;

                if (i < commands.Count - 1)
                {
                    output += ", ";
                }
            }

            Toolkit.client.SendMessage(output, CommandsHandler.SendToChatroom(message));
        }
Beispiel #18
0
        public void SendTenResults(TwitchIRCMessage msg, string searchObject, string searchQuery, string[] results)
        {
            if (results.Count() < 1)
            {
                return;
            }

            string output = "Lookup for " + searchObject + " \"" + searchQuery + "\": ";

            for (int i = 0; i < results.Count(); i++)
            {
                output += results[i].CapitalizeFirst();
                if (i != results.Count() - 1)
                {
                    output += ", ";
                }
            }

            Toolkit.client.SendMessage(output, CommandsHandler.SendToChatroom(msg));
        }
Beispiel #19
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            try
            {
                string[] command = message.Message.Split(' ');

                if (command.Length < 2)
                {
                    return;
                }

                string target = command[1].Replace("@", "");

                Viewer targeted = ViewerModel.GetViewerByTypeAndUsername(target, message.Viewer.ViewerType);
                Toolkit.client.SendMessage($"@{message.User} " + Helper.ReplacePlaceholder("TwitchToolkitCheckUser".Translate(), viewer: targeted.Username, amount: targeted.Coins.ToString(), karma: targeted.Karma.ToString()), CommandsHandler.SendToChatroom(message));
            }
            catch (InvalidCastException e)
            {
                Helper.Log("Invalid Check User Command " + e.Message);
            }
        }
Beispiel #20
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            string[] command = message.Message.Split(' ');

            if (command.Count() < 3)
            {
                return;
            }

            string target = command[1].Replace("@", "");

            bool isNumeric = int.TryParse(command[2], out int amount);

            if (isNumeric && amount > 0)
            {
                Viewer giftee = Viewers.NewViewers.GetViewerByTypeAndUsername(target, message.Viewer.ViewerType);

                if (giftee == null)
                {
                    Toolkit.client.SendMessage($"@{message.Viewer.UsernameCap} viewer not found.");
                    return;
                }

                if (ToolkitSettings.KarmaReqsForGifting)
                {
                    if (giftee.Karma < ToolkitSettings.MinimumKarmaToRecieveGifts || message.Viewer.Karma < ToolkitSettings.MinimumKarmaToSendGifts)
                    {
                        return;
                    }
                }

                if (message.Viewer.Coins >= amount)
                {
                    message.Viewer.GiveCoins(amount);
                    giftee.GiveCoins(amount);
                    Toolkit.client.SendMessage($"@{giftee.UsernameCap} " + Helper.ReplacePlaceholder("TwitchToolkitGiftCoins".Translate(), amount: amount.ToString(), from: message.Viewer.UsernameCap), CommandsHandler.SendToChatroom(message));
                }
            }
        }
Beispiel #21
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            GameComponentPawns pawnComponent = Current.Game.GetComponent <GameComponentPawns>();

            if (pawnComponent.HasUserBeenNamed(message.User) || pawnComponent.UserInViewerQueue(message.User))
            {
                return;
            }

            if (ToolkitSettings.ChargeViewersForQueue)
            {
                if (message.Viewer.Coins < ToolkitSettings.CostToJoinQueue)
                {
                    Toolkit.client.SendMessage($"@{message.User} you do not have enough coins to purchase a ticket, it costs {ToolkitSettings.CostToJoinQueue} and you have {message.Viewer.Username}.", CommandsHandler.SendToChatroom(message));
                    return;
                }

                message.Viewer.TakeCoins(ToolkitSettings.CostToJoinQueue);
            }

            pawnComponent.AddViewerToViewerQueue(message.User);
            Toolkit.client.SendMessage($"@{message.User} you have purchased a ticket and are in the queue!", CommandsHandler.SendToChatroom(message));
        }
Beispiel #22
0
        public override void RunCommand(TwitchIRCMessage message)
        {
            try
            {
                string[] command = message.Message.Split(' ');

                if (command.Length < 3)
                {
                    return;
                }

                string receiver = command[1].Replace("@", "");

                if (message.User.ToLower() != ToolkitSettings.Channel.ToLower() && receiver.ToLower() == message.User.ToLower())
                {
                    Toolkit.client.SendMessage($"@{message.User} " + "TwitchToolkitModCannotGiveCoins".Translate());
                    return;
                }

                int  amount;
                bool isNumeric = int.TryParse(command[2], out amount);
                if (isNumeric)
                {
                    Viewer giftee = ViewerModel.GetViewerByTypeAndUsername(receiver, message.Viewer.ViewerType);

                    Helper.Log($"Giving viewer {giftee.Username} {amount} coins");
                    giftee.GiveCoins(amount);
                    Toolkit.client.SendMessage($"@{message.User} " + Helper.ReplacePlaceholder("TwitchToolkitGivingCoins".Translate(), viewer: giftee.Username, amount: amount.ToString(), newbalance: giftee.Coins.ToString()), CommandsHandler.SendToChatroom(message));
                    Store_Logger.LogGiveCoins(message.User, giftee.Username, amount);
                }
            }
            catch (InvalidCastException e)
            {
                Helper.Log("Invalid Give Viewer Coins Command " + e.Message);
            }
        }
        public static void ResolvePurchaseVariables(Viewer viewer, TwitchIRCMessage message, StoreIncidentVariables incident, bool separateChannel = false)
        {
            int cost = incident.cost;

            if (cost < 1 && incident.defName != "Item")
            {
                return;
            }

            if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel))
            {
                return;
            }

            if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel))
            {
                return;
            }

            if (incident != DefDatabase <StoreIncidentVariables> .GetNamed("Item"))
            {
                if (CheckIfKarmaTypeIsMaxed(incident, viewer.username, separateChannel))
                {
                    return;
                }
            }
            else
            {
                if (CheckIfCarePackageIsOnCooldown(viewer.username, separateChannel))
                {
                    return;
                }
            }

            if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel))
            {
                return;
            }

            viewerNamesDoingVariableCommands.Add(viewer.username);

            IncidentHelperVariables helper = StoreIncidentMaker.MakeIncidentVariables(incident);

            if (helper == null)
            {
                Helper.Log("Missing helper for incident " + incident.defName);
                return;
            }

            if (!helper.IsPossible(message.Message, viewer, separateChannel))
            {
                if (viewerNamesDoingVariableCommands.Contains(viewer.username))
                {
                    viewerNamesDoingVariableCommands.Remove(viewer.username);
                }
                return;
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            helper.Viewer  = viewer;
            helper.message = message.Message;

            Ticker.IncidentHelperVariables.Enqueue(helper);
            Store_Logger.LogPurchase(viewer.username, message.Message);
            component.LogIncident(incident);
        }
Beispiel #24
0
 public override void RunCommand(TwitchIRCMessage message)
 {
     Toolkit.client.SendMessage($"@{message.Viewer.UsernameCap} " + "TwitchToolkitWhatIsKarma".Translate() + $" { message.Viewer.Karma}%", CommandsHandler.SendToChatroom(message));
 }
Beispiel #25
0
 public override void RunCommand(TwitchIRCMessage message)
 {
     Toolkit.client.SendMessage($"@{message.User} " + "TwitchToolkitPurchaseList".Translate() + $" {ToolkitSettings.CustomPricingSheetLink}", CommandsHandler.SendToChatroom(message));
 }
        public static void ResolvePurchase(Viewer viewer, TwitchIRCMessage message, bool separateChannel = false)
        {
            List <string> command = message.Message.Split(' ').ToList();

            if (command.Count < 2)
            {
                return;
            }

            if (command[0] == "!levelskill")
            {
                command[0] = "levelskill";
                command.Insert(0, "!buy");
            }

            string productKey = command[1].ToLower();

            Helper.Log(productKey);
            message.Message = string.Join(" ", command.ToArray());

            StoreIncidentSimple incident = allStoreIncidentsSimple.Find(s => productKey.ToLower() == s.abbreviation);

            if (incident != null)
            {
                ResolvePurchaseSimple(viewer, message, incident, separateChannel);
                return;
            }

            StoreIncidentVariables incidentVariables = allStoreIncidentsVariables.Find(s => productKey.ToLower() == s.abbreviation);

            if (incidentVariables != null)
            {
                ResolvePurchaseVariables(viewer, message, incidentVariables, separateChannel);
                return;
            }

            Item item = StoreInventory.items.Find(s => s.abr == productKey);

            Helper.Log($"abr: {productKey} ");

            if (item != null)
            {
                List <String> commandSplit = message.Message.Split(' ').ToList();
                commandSplit.Insert(1, "item");

                if (commandSplit.Count < 4)
                {
                    commandSplit.Add("1");
                }

                if (!int.TryParse(commandSplit[3], out int quantity))
                {
                    commandSplit.Insert(3, "1");
                }

                message.Message = string.Join(" ", commandSplit.ToArray());

                ResolvePurchaseVariables(viewer, message, StoreIncidentDefOf.Item, separateChannel);
            }

            return;
        }
Beispiel #27
0
        public override void ParseCommand(TwitchIRCMessage msg)
        {
            GameComponentPawns component = Current.Game.GetComponent <GameComponentPawns>();

            if (msg.Message.StartsWith("!mypawnskills") && CommandsHandler.AllowCommand(msg))
            {
                if (!component.HasUserBeenNamed(msg.Viewer.Username))
                {
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} you are not in the colony.", CommandsHandler.SendToChatroom(msg));
                    return;
                }

                Pawn   pawn   = component.PawnAssignedToUser(msg.Viewer.Username);
                string output = $"@{msg.Viewer.Username} {pawn.Name.ToStringShort.CapitalizeFirst()}'s skill levels are ";

                List <SkillRecord> skills = pawn.skills.skills;

                for (int i = 0; i < skills.Count; i++)
                {
                    if (skills[i].TotallyDisabled)
                    {
                        output += $"{skills[i].def.LabelCap}: -";
                    }
                    else
                    {
                        output += $"{skills[i].def.LabelCap}: {skills[i].levelInt}";
                    }

                    if (skills[i].passion == Passion.Minor)
                    {
                        output += "+";
                    }
                    if (skills[i].passion == Passion.Major)
                    {
                        output += "++";
                    }

                    if (i != skills.Count - 1)
                    {
                        output += ", ";
                    }
                }

                Toolkit.client.SendMessage(output, CommandsHandler.SendToChatroom(msg));
            }

            if (msg.Message.StartsWith("!mypawnstory") && CommandsHandler.AllowCommand(msg))
            {
                if (!component.HasUserBeenNamed(msg.Viewer.Username))
                {
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} you are not in the colony.", CommandsHandler.SendToChatroom(msg));
                    return;
                }

                Pawn pawn = component.PawnAssignedToUser(msg.Viewer.Username);

                string output = $"@{msg.Viewer.Username} About {pawn.Name.ToStringShort.CapitalizeFirst()}: ";

                List <Backstory> backstories = pawn.story.AllBackstories.ToList();

                for (int i = 0; i < backstories.Count; i++)
                {
                    output += backstories[i].title;
                    if (i != backstories.Count - 1)
                    {
                        output += ", ";
                    }
                }

                output += " | " + pawn.gender;

                StringBuilder stringBuilder            = new StringBuilder();
                WorkTags      combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags;
                if (combinedDisabledWorkTags == WorkTags.None)
                {
                    stringBuilder.Append("(" + "NoneLower".Translate() + "), ");
                }
                else
                {
                    List <WorkTags> list  = WorkTagsFrom(combinedDisabledWorkTags).ToList <WorkTags>();
                    bool            flag2 = true;
                    foreach (WorkTags tags in list)
                    {
                        if (flag2)
                        {
                            stringBuilder.Append(tags.LabelTranslated().CapitalizeFirst());
                        }
                        else
                        {
                            stringBuilder.Append(tags.LabelTranslated());
                        }
                        stringBuilder.Append(", ");
                        flag2 = false;
                    }
                }
                string text = stringBuilder.ToString();
                text = text.Substring(0, text.Length - 2);

                output += " | Incapable of: " + text;

                output += " | Traits: ";

                List <Trait> traits = pawn.story.traits.allTraits;
                for (int i = 0; i < traits.Count; i++)
                {
                    output += traits[i].LabelCap;

                    if (i != traits.Count - 1)
                    {
                        output += ", ";
                    }
                }

                Toolkit.client.SendMessage(output, CommandsHandler.SendToChatroom(msg));
            }

            if (msg.Message.StartsWith("!changepawnname") && CommandsHandler.AllowCommand(msg))
            {
                string[] command = msg.Message.Split(' ');

                if (command.Length < 2)
                {
                    return;
                }

                string newName = command[1];

                if (newName == null || newName == "" || newName.Length > 16)
                {
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} your name can be up to 16 characters.", CommandsHandler.SendToChatroom(msg));
                    return;
                }

                if (!component.HasUserBeenNamed(msg.Viewer.Username))
                {
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} you are not in the colony.", CommandsHandler.SendToChatroom(msg));
                    return;
                }

                if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(msg.Viewer, 500, true))
                {
                    return;
                }

                msg.Viewer.TakeCoins(500);
                nameRequests.Add(msg.Viewer.Username, newName);
                Toolkit.client.SendMessage($"@{ToolkitSettings.Channel} {msg.Viewer.Username} has requested to be named {newName}, use !approvename @{msg.Viewer.Username} or !declinename @{msg.Viewer.Username}", false);
            }

            if (msg.Viewer.Mod || msg.Viewer.Username == ToolkitSettings.Channel)
            {
                if (msg.Message.StartsWith("!unstickpeople"))
                {
                    Purchase_Handler.viewerNamesDoingVariableCommands = new List <string>();
                }

                if (msg.Message.StartsWith("!approvename"))
                {
                    string[] command = msg.Message.Split(' ');

                    if (command.Length < 2)
                    {
                        return;
                    }

                    string username = command[1].Replace("@", "");

                    if (username == null || username == "" || !nameRequests.ContainsKey(username))
                    {
                        Toolkit.client.SendMessage($"@{msg.Viewer.Username} invalid username", CommandsHandler.SendToChatroom(msg));
                        return;
                    }

                    if (!component.HasUserBeenNamed(username))
                    {
                        return;
                    }

                    Pawn       pawn = component.PawnAssignedToUser(username);
                    NameTriple old  = pawn.Name as NameTriple;
                    pawn.Name = new NameTriple(old.First, nameRequests[username], old.Last);
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} approved request for name change from {old} to {pawn.Name}");
                }

                if (msg.Message.StartsWith("!declinename"))
                {
                    string[] command = msg.Message.Split(' ');

                    if (command.Length < 2)
                    {
                        return;
                    }

                    string username = command[1].Replace("@", "");

                    if (username == null || username == "" || !nameRequests.ContainsKey(username))
                    {
                        Toolkit.client.SendMessage($"@{msg.Viewer.Username} invalid username", CommandsHandler.SendToChatroom(msg));
                        return;
                    }

                    if (!component.HasUserBeenNamed(username))
                    {
                        return;
                    }

                    nameRequests.Remove(username);
                    Toolkit.client.SendMessage($"@{msg.Viewer.Username} declined name change request from {username}");
                }
            }

            Store_Logger.LogString("Parsed pawn command");
        }
Beispiel #28
0
        public static void CheckCommand(TwitchIRCMessage msg)
        {
            if (msg == null)
            {
                return;
            }

            if (msg.Message == null)
            {
                return;
            }

            Viewer viewer = msg.Viewer;

            viewer.WasSeen();


            if (viewer.IsBanned)
            {
                return;
            }

            if (!msg.Message.StartsWith("!"))
            {
                IRCMessageLog.AddNewMessage(msg);
            }

            Command commandDef = DefDatabase <Command> .AllDefs.ToList().Find(s => msg.Message.StartsWith("!" + s.command));

            if (commandDef != null)
            {
                bool runCommand = true;

                if (commandDef.requiresMod && (!viewer.Mod && viewer.UsernameLower != ToolkitSettings.Channel.ToLower()))
                {
                    runCommand = false;
                }

                if (commandDef.requiresAdmin && msg.User.ToLower() != ToolkitSettings.Channel.ToLower())
                {
                    runCommand = false;
                }

                if (!commandDef.enabled)
                {
                    runCommand = false;
                }

                if (commandDef.shouldBeInSeparateRoom && !AllowCommand(msg))
                {
                    runCommand = false;
                }

                if (runCommand)
                {
                    commandDef.RunCommand(msg);
                }
            }

            List <TwitchInterfaceBase> modExtensions = Current.Game.components.OfType <TwitchInterfaceBase>().ToList();

            if (modExtensions == null)
            {
                return;
            }

            foreach (TwitchInterfaceBase parser in modExtensions)
            {
                parser.ParseCommand(msg);
            }
        }
        public static void ResolvePurchaseSimple(Viewer viewer, TwitchIRCMessage message, StoreIncidentSimple incident, bool separateChannel = false)
        {
            int cost = incident.cost;

            if (cost < 1)
            {
                return;
            }

            if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel))
            {
                return;
            }

            if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel))
            {
                return;
            }

            if (CheckIfKarmaTypeIsMaxed(incident, viewer.username, separateChannel))
            {
                return;
            }

            if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel))
            {
                return;
            }

            IncidentHelper helper = StoreIncidentMaker.MakeIncident(incident);

            if (helper == null)
            {
                Helper.Log("Missing helper for incident " + incident.defName);
                return;
            }

            if (!helper.IsPossible())
            {
                Toolkit.client.SendMessage($"@{viewer.username} " + "TwitchToolkitEventNotPossible".Translate(), separateChannel);
                return;
            }

            if (!ToolkitSettings.UnlimitedCoins)
            {
                viewer.TakeViewerCoins(cost);
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            helper.Viewer  = viewer;
            helper.message = message.Message;

            Ticker.IncidentHelpers.Enqueue(helper);
            Store_Logger.LogPurchase(viewer.username, message.Message);
            component.LogIncident(incident);
            viewer.CalculateNewKarma(incident.karmaType, cost);

            if (ToolkitSettings.PurchaseConfirmations)
            {
                Toolkit.client.SendMessage(
                    Helper.ReplacePlaceholder(
                        "TwitchToolkitEventPurchaseConfirm".Translate(),
                        first: incident.label.CapitalizeFirst(),
                        viewer: viewer.username
                        ),
                    separateChannel
                    );
            }
        }
Beispiel #30
0
        public void FindLookup(TwitchIRCMessage msg, string searchObject, string searchQuery)
        {
            List <string> results = new List <string>();

            switch (searchObject)
            {
            case "disease":
                FindLookup(msg, "diseases", searchQuery);
                break;

            case "skill":
                FindLookup(msg, "skills", searchQuery);
                break;

            case "event":
                FindLookup(msg, "events", searchQuery);
                break;

            case "item":
                FindLookup(msg, "items", searchQuery);
                break;

            case "animal":
                FindLookup(msg, "animals", searchQuery);
                break;

            case "trait":
                FindLookup(msg, "traits", searchQuery);
                break;

            case "diseases":
                IncidentDef[] allDiseases = DefDatabase <IncidentDef> .AllDefs.Where(s =>
                                                                                     s.category == IncidentCategoryDefOf.DiseaseHuman &&
                                                                                     (string.Join("", s.LabelCap.Split(' ')).ToLower().Contains(searchQuery) ||
                                                                                      string.Join("", s.LabelCap.Split(' ')).ToLower() == searchQuery)
                                                                                     ).Take(10).ToArray();

                foreach (IncidentDef disease in allDiseases)
                {
                    results.Add(string.Join("", disease.LabelCap.Split(' ')).ToLower());
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;

            case "skills":
                SkillDef[] allSkills = DefDatabase <SkillDef> .AllDefs.Where(s =>
                                                                             (string.Join("", s.LabelCap.Split(' ')).ToLower().Contains(searchQuery) ||
                                                                              string.Join("", s.LabelCap.Split(' ')).ToLower() == searchQuery)
                                                                             ).Take(10).ToArray();

                foreach (SkillDef skill in allSkills)
                {
                    results.Add(skill.defName.ToLower());
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;

            case "events":
                StoreIncident[] allEvents = DefDatabase <StoreIncident> .AllDefs.Where(s =>
                                                                                       s.cost > 0 &&
                                                                                       (string.Join("", s.abbreviation.Split(' ')).ToLower().Contains(searchQuery) ||
                                                                                        string.Join("", s.abbreviation.Split(' ')).ToLower() == searchQuery ||
                                                                                        s.defName.ToLower().Contains(searchQuery) ||
                                                                                        s.defName.ToLower() == searchQuery)
                                                                                       ).Take(10).ToArray();

                foreach (StoreIncident evt in allEvents)
                {
                    results.Add(string.Join("", evt.abbreviation.Split(' ')).ToLower());
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;

            case "items":
                Item[] allItems = StoreInventory.items.Where(s =>
                                                             s.price > 0 &&
                                                             (string.Join("", s.abr.Split(' ')).ToLower().Contains(searchQuery) ||
                                                              string.Join("", s.abr.Split(' ')).ToLower() == searchQuery ||
                                                              s.defname.ToLower().Contains(searchQuery) ||
                                                              s.defname.ToLower() == searchQuery)
                                                             ).Take(10).ToArray();

                foreach (Item item in allItems)
                {
                    results.Add(string.Join("", item.abr.Split(' ')).ToLower());
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;

            case "animals":
                PawnKindDef[] allAnimals = DefDatabase <PawnKindDef> .AllDefs.Where(s =>
                                                                                    s.RaceProps.Animal &&
                                                                                    (string.Join("", s.LabelCap.Split(' ')).ToLower().Contains(searchQuery) ||
                                                                                     string.Join("", s.LabelCap.Split(' ')).ToLower() == searchQuery ||
                                                                                     s.defName.ToLower().Contains(searchQuery) ||
                                                                                     s.defName.ToLower() == searchQuery)
                                                                                    ).Take(10).ToArray();

                foreach (PawnKindDef animal in allAnimals)
                {
                    results.Add(animal.defName.ToLower());
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;

            case "traits":
                BuyableTrait[] allTrait = AllTraits.buyableTraits.Where(s =>
                                                                        s.label.Contains(searchQuery) ||
                                                                        s.label == searchQuery ||
                                                                        s.def.defName.ToLower().Contains(searchQuery) ||
                                                                        s.def.defName == searchQuery
                                                                        ).Take(10).ToArray();

                foreach (BuyableTrait trait in allTrait)
                {
                    results.Add(trait.label);
                }
                SendTenResults(msg, searchObject.CapitalizeFirst(), searchQuery, results.ToArray());
                break;
            }
        }