private void BetCounter(TwitchChat.User user, string arg2) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator) || user.Name == "aginsun") { SendMessage("Amount of people that have placed a bet: " + Bets[BetIndex].Count()); } }
private void CheckBet(TwitchChat.User user, string argument) { if (!CanBet) { return; } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage("Timer is not running, bets are closed"); return; case TimerPhase.Ended: SendMessage("The run has ended, nothing to check!"); return; } if (Bets[State.CurrentSplitIndex].ContainsKey(user.Name)) { var timeFormatter = new ShortTimeFormatter(); var time = Bets[State.CurrentSplitIndex][user.Name].Item1; var formattedTime = timeFormatter.Format(time); SendMessage(user.Name + ", Your bet for " + State.CurrentSplit.Name + " is " + formattedTime); } else { SendMessage(user.Name + ", You didn't bet for this split yet!"); } }
private void CheckBet(TwitchChat.User user, string argument) { if (SplitIndex < 0) { SendMessage(Settings.msgTimerNotRunning); return; } if (SplitIndex >= State.Run.Count) { SendMessage(Settings.msgCheckTimerEnd); return; } if (Bets[SplitIndex].ContainsKey(user.Name)) { var timeFormatter = new ShortTimeFormatter(); var time = Bets[SplitIndex][user.Name].Item1; var formattedTime = timeFormatter.Format(time); SendMessage(user.Name + ": Your bet for " + State.Run[SplitIndex].Name + " is " + formattedTime); } else { SendMessage(user.Name + ": You didn't bet for this split yet!"); } }
private void DisableBets(TwitchChat.User user, string argument) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || Settings.AllowMods && user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator)) { /*Removing bet related commands*/ Commands.Remove("bet"); Commands.Remove("checkbet"); Commands.Remove("unbet"); Commands.Remove("score"); Commands.Remove("highscore"); Commands.Remove("specialbet"); Commands.Remove("winners"); Commands.Remove("stop"); Commands.Add("start", EnableBets); /*Removing events*/ State.OnStart -= StartBets; State.OnSplit -= State_OnSplit; State.OnUndoSplit -= RollbackScore; State.OnSkipSplit -= CopyScore; State.OnReset -= ResetSplitsBet; SendMessage(Settings.msgDisable); } else { SendMessage("You're not allowed to stop the bets!"); } }
private void EnableBets(TwitchChat.User user, string argument) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || Settings.AllowMods && user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator)) { if (!CanBet) { CanBet = true; SendMessage("SplitsBet enabled !"); if (State.CurrentPhase != TimerPhase.NotRunning) { for (int i = 0; i < State.CurrentSplitIndex - 1; i++) { if (null == Scores[i]) { Scores[i] = new Dictionary <string, int>(Scores[i - 1]); Bets[i] = new Dictionary <string, Tuple <TimeSpan, double> >(); } } } } else { SendMessage("SplitsBet already enabled"); } } else { SendMessage("You're not allowed to start the bets !"); } }
private void BetCommands(TwitchChat.User user, string argument) { var ret = Commands .Select(x => "!" + x.Key) .Aggregate((a, b) => a + " " + b); SendMessage(ret); }
private void ExecuteCommand(CSharpScript script, TwitchChat.User user = null, String arguments = "") { try { script.Run(State, user, arguments); } catch (Exception ex) { } }
private void CheckWinners(TwitchChat.User user, string argument) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || (Settings.AllowMods && user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator))) { List <KeyValuePair <string, Tuple <int, string> > > list; list = Winners.OrderByDescending(kvp => kvp.Value.Item1).ToList(); SendMessage("Top 5 Winners!"); for (int i = 0; i < 5; i++) { SendMessage(list[i].Key + ": " + list[i].Value.Item1 + " - " + list[i].Value.Item2); } } }
private void Score(TwitchChat.User user, string argument) { if (SplitIndex < 0) { SendMessage(Settings.msgNoScore); return; } if (SplitIndex == 0 || !Scores[BetIndex - 1].ContainsKey(user.Name)) { SendMessage(user.Name + "'s score is 0"); return; } SendMessage(user.Name + "'s score is " + Scores[BetIndex - 1][user.Name]); }
private void UnBet(TwitchChat.User user, string argument) { if (!CanBet) { return; } if (!Settings.CanUnBet) { SendMessage("You can't unbet :("); return; } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage("Timer is not running, bets are closed"); return; case TimerPhase.Ended: SendMessage("The run has ended, nothing to unbet!"); return; } if (State.CurrentSplitIndex - 1 < 0) { SendMessage(user.Name + ", You have got no points to spend on undoing your bet yet!"); return; } if (!Bets[State.CurrentSplitIndex].ContainsKey(user.Name)) { SendMessage(user.Name + ", You didn't bet for this split yet!"); return; } if (Scores[State.CurrentSplitIndex - 1].ContainsKey(user.Name) && Scores[State.CurrentSplitIndex - 1][user.Name] < Settings.UnBetPenalty) { SendMessage(user.Name + ", You need " + Settings.UnBetPenalty + " points to undo your bet and just got " + Scores[State.CurrentSplitIndex - 1][user.Name] + "."); return; } if (State.CurrentSplitIndex >= 0 && Scores[State.CurrentSplitIndex] != null) { Scores[State.CurrentSplitIndex][user.Name] -= Settings.UnBetPenalty; } Bets[State.CurrentSplitIndex].Remove(user.Name); }
private void Highscore(TwitchChat.User user, string argument) { if (BetIndex < 0) { SendMessage(Settings.msgNoScore); return; } if (BetIndex > 0 && Scores[BetIndex - 1].Count > 0) { var orderedScores = Scores[BetIndex - 1].OrderByDescending(x => x.Value); SendMessage(orderedScores.ToList()[0].Key + "'s score is " + orderedScores.ToList()[0].Value); } else { SendMessage(Settings.msgNoHighscore); } }
private void EnableBets(TwitchChat.User user, string argument) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || Settings.AllowMods && user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator)) { /*Adding bet related commands*/ Commands.Add("checkbet", CheckBet); Commands.Add("unbet", UnBet); Commands.Add("score", Score); Commands.Add("highscore", Highscore); Commands.Add("specialbet", SpecialBet); Commands.Add("winners", CheckWinners); Commands.Add("betcount", BetCounter); Commands.Remove("start"); Commands.Add("stop", DisableBets); /*Setting Livesplit events*/ State.OnStart += StartBets; State.OnSplit += State_OnSplit; State.OnUndoSplit += RollbackScore; State.OnSkipSplit += CopyScore; State.OnReset += ResetSplitsBet; SplitIndex = State.CurrentSplitIndex; SendMessage(Settings.msgEnable); if (State.CurrentPhase != TimerPhase.NotRunning) { for (int i = 0; i < SplitIndex; i++) { if (null == Scores[i]) { Scores[i] = (i == 0 ? new Dictionary <string, int>() : new Dictionary <string, int>(Scores[i - 1])); } } for (int i = 0; i <= SplitIndex; i++) { Bets[i] = new Dictionary <string, Tuple <TimeSpan, double> >(); } } } else { SendMessage("You're not allowed to start the bets!"); } }
private void Score(TwitchChat.User user, string argument) { if (!CanBet) { return; } if (State.CurrentPhase == TimerPhase.NotRunning) { SendMessage("Timer is not running, no score available"); return; } if (State.CurrentSplitIndex == 0 || !Scores[State.CurrentSplitIndex - 1].ContainsKey(user.Name)) { SendMessage(user.Name + "'s score is 0"); return; } SendMessage(user.Name + "'s score is " + Scores[State.CurrentSplitIndex - 1][user.Name]); }
private void UnBet(TwitchChat.User user, string argument) { if (!Settings.CanUnBet) { SendMessage(Settings.msgNoUnbet); return; } if (SplitIndex < 0) { SendMessage(Settings.msgTimerNotRunning); return; } if (SplitIndex >= State.Run.Count) { SendMessage(Settings.msgUnbetTimerEnd); return; } if (SplitIndex - 1 < 0) { SendMessage(user.Name + ": You have no points to spend on undoing your bet yet!"); return; } if (!Bets[BetIndex].ContainsKey(user.Name)) { SendMessage(user.Name + ": You didn't bet for this split yet!"); return; } if (!Scores[BetIndex - 1].ContainsKey(user.Name) || Scores[BetIndex - 1][user.Name] < Settings.UnBetPenalty) { SendMessage(user.Name + ": You need " + Settings.UnBetPenalty + " points to undo your bet but only have " + (Scores[BetIndex - 1].ContainsKey(user.Name)?Scores[SplitIndex - 1][user.Name]:0) + "."); return; } if (BetIndex >= 0 && Scores[BetIndex - 1] != null) { Scores[BetIndex - 1][user.Name] -= Settings.UnBetPenalty; } Bets[BetIndex].Remove(user.Name); }
private void DisableBets(TwitchChat.User user, string argument) { if (user.Badges.HasFlag(TwitchChat.ChatBadges.Broadcaster) || Settings.AllowMods && user.Badges.HasFlag(TwitchChat.ChatBadges.Moderator)) { if (CanBet) { CanBet = false; SendMessage("SplitsBet disabled !"); } else { SendMessage("SplitsBet already disabled"); } } else { SendMessage("You're not allowed to stop the bets !"); } }
private void Highscore(TwitchChat.User user, string argument) { if (!CanBet) { return; } if (State.CurrentPhase == TimerPhase.NotRunning) { SendMessage("Timer is not running, no score available"); return; } if (State.CurrentSplitIndex > 0) { var orderedScores = Scores[State.CurrentSplitIndex - 1].OrderByDescending(x => x.Value); SendMessage(orderedScores.ToList()[0].Key + "'s score is " + orderedScores.ToList()[0].Value); } else { SendMessage("No highscore yet!"); } }
private void SpecialBet(TwitchChat.User user, string argument) { if (argument.ToLower().StartsWith("start")) { ActiveSpecialBets = true; return; } if (argument.ToLower().StartsWith("end") || argument.ToLower().StartsWith("stop")) { var args = argument.Split(new string[] { " " }, StringSplitOptions.None); if (args.Count() > 1) { try { //TODO Accuracy better than seconds, special events are meant to be short (OoT Dampe < 1 min iirc, SM64 Secret Slide between 12.5s and 13s generally...) var time = TimeSpanParser.Parse(args[1]); Scores[SplitIndex] = Scores[SplitIndex] ?? (SplitIndex > 0 ? new Dictionary <string, int>(Scores[SplitIndex - 1]) : new Dictionary <string, int>()); foreach (KeyValuePair <string, TimeSpan> entry in SpecialBets) { if (Scores[SplitIndex].ContainsKey(entry.Key)) { Scores[SplitIndex][entry.Key] += (int)(time.TotalSeconds * Math.Exp(-(Math.Pow((int)time.TotalSeconds - (int)entry.Value.TotalSeconds, 2) / (int)time.TotalSeconds))); } else { Scores[SplitIndex].Add(entry.Key, (int)(time.TotalSeconds * Math.Exp(-(Math.Pow((int)time.TotalSeconds - (int)entry.Value.TotalSeconds, 2) / (int)time.TotalSeconds)))); } } SendMessage("Scores will be shown at the next split!"); //TODO Special ShowScore() for special bets ? SpecialBets.Clear(); } catch (Exception e) { LogException(e); } } ActiveSpecialBets = false; return; } if (!ActiveSpecialBets) { SendMessage("No special bet active."); } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage(Settings.msgTimerNotRunning); return; case TimerPhase.Paused: SendMessage(Settings.msgTimerPaused); return; case TimerPhase.Ended: SendMessage(Settings.msgTimerEnded); return; } if (SpecialBets.ContainsKey(user.Name)) { SendMessage(user.Name + ": You already bet, silly!"); return; } try { var time = TimeSpanParser.Parse(argument); if (time.CompareTo(Settings.MinimumTime) <= 0) { SendMessage(user.Name + ": Invalid time, please retry."); return; } SpecialBets.Add(user.Name, time); } catch (Exception e) { LogException(e); } }
//TODO Errors management with Twitch messages, will be useful for alpha release in case of bugs private void Bet(TwitchChat.User user, string argument) { if (!CanBet) { return; } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage("Timer is not running, bets are closed"); return; case TimerPhase.Paused: SendMessage("Timer is paused, bets are paused too"); return; case TimerPhase.Ended: SendMessage("Run is ended, there is nothing to bet!"); return; } if (Bets[State.CurrentSplitIndex].ContainsKey(user.Name)) { SendMessage(user.Name + ", You already bet, silly!"); return; } var percentage = GetTime((State.CurrentTime - SegmentBeginning)).Value.TotalSeconds / GetTime(State.CurrentSplit.BestSegmentTime).Value.TotalSeconds; if (percentage > 0.75) { SendMessage("Too late to bet for this split, wait for the next one!"); return; } try { if (argument.ToLower().StartsWith("kappa")) { argument = "4:20.69"; SendMessage(user.Name + " bet 4:20.69 Kappa"); } var time = TimeSpanParser.Parse(argument); if (Settings.UseGlobalTime) { time -= GetTime(SegmentBeginning).Value; } if (time.CompareTo(Settings.MinimumTime) <= 0) { SendMessage(user.Name + ", Nice try, but it's invalid"); return; } var t = new Tuple <TimeSpan, double>(time, Math.Exp(-2 * Math.Pow(percentage, 2))); Bets[State.CurrentSplitIndex].Add(user.Name, t); } catch { SendMessage(user.Name + ", Invalid time, please retry"); } }
//Commands usually have self explaining names /** * Register a bet for the player "user" */ private void Bet(TwitchChat.User user, string argument) { //Check the state of the timer. It must be running to set a bet if (SplitIndex < 0) { SendMessage(Settings.msgTimerNotRunning); return; } if (State.CurrentPhase == TimerPhase.Paused) { SendMessage(Settings.msgTimerPaused); return; } if (SplitIndex >= State.Run.Count) { SendMessage(Settings.msgTimerEnded); return; } //You can't bet again if you have already bet once, unless you type !unbet, which erases your bet (and some of your points) if (Bets[BetIndex].ContainsKey(user.Name)) { SendMessage(user.Name + ": You already bet!"); return; } double percentage; var timeFormatted = new ShortTimeFormatter().Format(GetTime(State.Run[SplitIndex].BestSegmentTime)); //If no glod is set, percentage is kept to 0. There's no way to set a limit so better not fix an arbitrary one. if (TimeSpanParser.Parse(timeFormatted) > TimeSpan.Zero) { percentage = (GetTime(State.CurrentTime - SegmentBeginning[BetIndex])).Value.TotalSeconds / GetTime(State.Run[BetIndex].BestSegmentTime).Value.TotalSeconds; } else { percentage = 0; } //Forbids the bets if the time of the segment reaches over 75% of the best segment if (percentage > 0.75) { SendMessage(Settings.msgTooLateToBet); return; } try { //nice meme if (argument.ToLower().StartsWith("kappa")) { argument = "4:20.69"; SendMessage(user.Name + " bet 4:20.69 Kappa"); } //Parsing the time and checking if it's valid var time = TimeSpanParser.Parse(argument); if (Settings.UseGlobalTime) { time -= GetTime(SegmentBeginning[SplitIndex]).Value; } if (time.CompareTo(Settings.MinimumTime) <= 0) { SendMessage(user.Name + ": Invalid time, please retry."); return; } //Add the bet to its Dictionary var t = new Tuple <TimeSpan, double>(time, Math.Exp(-2 * Math.Pow(percentage, 4))); Bets[BetIndex].Add(user.Name, t); } catch { SendMessage(user.Name + ": Invalid time, please retry."); } }
public void Run(LiveSplitState state, TwitchChat.User user, string arguments) { CompiledCode.Execute(state, user, arguments); }
private void Version(TwitchChat.User user, string argument) { SendMessage("LiveSplit version " + SplitsBetFactory.VersionString + (SplitsBetFactory.VersionPostfix ?? "")); }