public static void GiveAllViewersCoins(int amount, List <Viewer> viewers = null) { if (viewers != null) { foreach (Viewer viewer in viewers) { viewer.GiveViewerCoins(amount); } return; } List <string> usernames = ParseViewersFromJsonAndFindActiveViewers(); if (usernames != null) { foreach (string username in usernames) { Viewer viewer = Viewers.GetViewer(username); if (viewer != null && viewer.GetViewerKarma() > 1) { viewer.GiveViewerCoins(amount); } } } }
public static void GiveAllViewersKarma(int amount, List <Viewer> viewers = null) { if (viewers != null) { foreach (Viewer viewer in viewers) { viewer.SetViewerKarma(Math.Min(ToolkitSettings.KarmaCap, viewer.GetViewerKarma() + amount)); } return; } List <string> usernames = ParseViewersFromJsonAndFindActiveViewers(); if (usernames != null) { foreach (string username in usernames) { Viewer viewer = Viewers.GetViewer(username); if (viewer != null && viewer.GetViewerKarma() > 1) { viewer.SetViewerKarma(Math.Min(ToolkitSettings.KarmaCap, viewer.GetViewerKarma() + amount)); } } } }
public static void CheckCommand(ITwitchMessage twitchMessage) { Log.Message($"Checking command - {twitchMessage.Message}"); if (twitchMessage == null) { return; } if (twitchMessage.Message == null) { return; } string message = twitchMessage.Message; string user = twitchMessage.Username; Viewer viewer = Viewers.GetViewer(user); viewer.last_seen = DateTime.Now; if (viewer.IsBanned) { return; } Command commandDef = DefDatabase <Command> .AllDefs.ToList().Find(s => twitchMessage.Message.StartsWith("!" + s.command)); if (commandDef != null) { bool runCommand = true; if (commandDef.requiresMod && (!viewer.mod && viewer.username.ToLower() != ToolkitSettings.Channel.ToLower())) { runCommand = false; } if (commandDef.requiresAdmin && twitchMessage.Username.ToLower() != ToolkitSettings.Channel.ToLower()) { runCommand = false; } if (!commandDef.enabled) { runCommand = false; } if (runCommand) { commandDef.RunCommand(twitchMessage); } } }
public static bool IsModerator(string user) { if (Viewers.GetViewer(user).mod) { return(true); } if (ToolkitSettings.ViewerModerators == null) { return(false); } return(ToolkitSettings.ViewerModerators.ContainsKey(user)); }
public string FilterTags(ITwitchMessage twitchMessage, string input) { Helper.Log("starting filter"); Viewer viewer = Viewers.GetViewer(twitchMessage.Username); StringBuilder output = new StringBuilder(input); output.Replace("{username}", viewer.username); output.Replace("{balance}", viewer.GetViewerCoins().ToString()); output.Replace("{karma}", viewer.GetViewerKarma().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()); }
public static void GiveAllViewersKarma(int amount) { List <string> usernames = ParseViewersFromJson(); if (usernames != null) { foreach (string username in usernames) { Viewer viewer = Viewers.GetViewer(username); if (viewer != null && viewer.GetViewerKarma() > 1) { viewer.SetViewerKarma(Math.Min(ToolkitSettings.KarmaCap, viewer.GetViewerKarma() + amount)); } } } }
public static void GiveAllViewersCoins(int amount) { List <string> usernames = ParseViewersFromJson(); if (usernames != null) { foreach (string username in usernames) { Viewer viewer = Viewers.GetViewer(username); if (viewer != null && viewer.GetViewerKarma() > 1) { viewer.GiveViewerCoins(amount); } } } }
public override void Tick() { try { if (_game == null || _mod == null) { return; } _mod.Tick(); var minutes = (int)(_game.Info.RealPlayTimeInteracting / 60f); double getTime = (double)Time.time / 60f; int time = Convert.ToInt32(Math.Truncate(getTime)); if (IncidentHelpers.Count > 0) { for (int i = 0; i < IncidentHelpers.Count; i++) { var incidentHelper = IncidentHelpers.Dequeue(); if (!(incidentHelper is VotingHelper)) { Purchase_Handler.QueuePlayerMessage(incidentHelper.Viewer, incidentHelper.message); } incidentHelper.TryExecute(); } Helper.playerMessages = new List <string>(); } if (IncidentHelperVariables.Count > 0) { for (int i = 0; i < IncidentHelperVariables.Count; i++) { var incidentHelper = IncidentHelperVariables.Dequeue(); Purchase_Handler.QueuePlayerMessage(incidentHelper.Viewer, incidentHelper.message, incidentHelper.storeIncident.variables); incidentHelper.TryExecute(); if (Purchase_Handler.viewerNamesDoingVariableCommands.Contains(incidentHelper.Viewer.username)) { Purchase_Handler.viewerNamesDoingVariableCommands.Remove(incidentHelper.Viewer.username); } } Helper.playerMessages = new List <string>(); } if (Incidents.Count > 0) { var incident = Incidents.Dequeue(); IncidentParms incidentParms = new IncidentParms(); incidentParms.target = Helper.AnyPlayerMap; incident.TryExecute(incidentParms); } if (FiringIncidents.Count > 0) { Helper.Log("Firing " + FiringIncidents.First().def.defName); var incident = FiringIncidents.Dequeue(); incident.def.Worker.TryExecute(incident.parms); } VoteHandler.CheckForQueuedVotes(); if (_lastCoinReward < 0) { _lastCoinReward = time; } else if (ToolkitSettings.EarningCoins && ((time - _lastCoinReward) >= ToolkitSettings.CoinInterval) && Viewers.jsonallviewers != null) { _lastCoinReward = time; Viewers.AwardViewersCoins(); } if (_lastMinute < 0) { _lastMinute = time; } else if (_lastMinute < time) { _lastMinute = time; Toolkit.JobManager.CheckAllJobs(); Viewers.RefreshViewers(); } } catch (Exception ex) { Helper.Log("Exception: " + ex.Message + ex.StackTrace); } }
public Viewer GetViewer(string username) { return(Viewers.GetViewer(username)); }
public static void CheckCommand(IRCMessage msg) { if (msg == null) { return; } if (msg.Message == null) { return; } string message = msg.Message; string user = msg.User; if (message.Split(' ')[0] == "/w") { List <string> messagewhisper = message.Split(' ').ToList(); messagewhisper.RemoveAt(0); message = string.Join(" ", messagewhisper.ToArray()); Helper.Log(message); } Viewer viewer = Viewers.GetViewer(user); viewer.last_seen = DateTime.Now; if (viewer.IsBanned) { return; } 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.username.ToLower() != 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); } }