private void HandleCommand(Command command) { String buf; if (command.Matches("!flushgames")) { foreach (INHLGameInfo game in games) { game.StopMonitoring(); } games.Clear(); } else if (command.Matches("!xnick")) { if (command.HasArgument()) { irc.ChangeNick(command.GetArgumentOriginalCase()); } else { irc.ChangeNick(""); } } else if (command.Matches("!scores")) { //List<string> homeTeamNames = new List<string>(); bool nothingToReport = true; foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_PLAYING) { buf = String.Format("[{0}/{1}] Score: {2}", game.HomeTeamName, game.AwayTeamName, game.GetScoreString(true)); irc.SendMessage(buf, command); nothingToReport = false; //homeTeamNames.Add(game.HomeTeamName); } } if (nothingToReport) irc.SendMessage("No active games to report on", command); } else if (command.Matches("!debuggames")) { foreach (INHLGameInfo game in games) { buf = String.Format("[{0}/{1}]", game.HomeTeamName, game.AwayTeamName); irc.SendMessage(buf, command); } } else if (command.Matches("!allscores")) { //send this back via pm command.PrivateMessage = true; List<string> homeTeamNames = new List<string>(); foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) { buf = String.Format("[{0}/{1}] Score: {2}", game.HomeTeamName, game.AwayTeamName, game.GetScoreString(true)); irc.SendMessage(buf, command); homeTeamNames.Add(game.HomeTeamName); } } ScheduledGame[] otherGames = stats.GetScheduleToday(homeTeamNames); foreach (ScheduledGame game in otherGames) { buf = String.Format("[{0}/{1}] Starts at: {2}", game.HomeTeamName, game.AwayTeamName, game.StartTime); irc.SendMessage(buf, command); } } else if (command.Matches("!finalscores") || command.Matches("!finals")) { bool nothingToReport = true; foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_FINAL) { buf = String.Format("[{0}/{1}] Score: {2}", game.HomeTeamName, game.AwayTeamName, game.GetScoreString(true)); irc.SendMessage(buf, command); nothingToReport = false; } } if (nothingToReport) irc.SendMessage("No final scores to report", command); } else if (command.Matches("!schedule")) { string msg; DateTime? compareDate = null; NHLTeam team = null; NHLTeam teamA = null, teamB = null; bool backwardsResults = false; GetScheduleType type = GetScheduleType.GETSCHEDULE_DATE; if (command.HasArgument()) { int numOfSpaces = Regex.Matches(command.GetArgument(), " ").Count; if (numOfSpaces > 0) { type = GetScheduleType.GETSCHEDULE_TEAMS; string[] teams = command.GetArgument().Split(' '); for (int i = 0; i < teams.Length; ++i) { if (String.Compare(teams[i], "past", true) == 0) { backwardsResults = true; } else if (teamA == null) { teamA = stats.GetTeamFromCityOrTeam(teams[i]); } else if (teamB == null) { teamB = stats.GetTeamFromCityOrTeam(teams[i]); } } if (teamA == null || teamB == null) { type = GetScheduleType.GETSCHEDULE_DATE; compareDate = DateTimeEnglishParser.ParseRelative(DateTime.Now, command.GetArgument()); if (compareDate == null) { type = GetScheduleType.GETSCHEDULE_BADARGUMENT; } else { type = GetScheduleType.GETSCHEDULE_DATE; } } else if (teamA.Equals(teamB)) { type = GetScheduleType.GETSCHEDULE_TEAM; team = teamA; } } else { team = stats.GetTeamFromCityOrTeam(command.GetArgument()); if (team != null) { type = GetScheduleType.GETSCHEDULE_TEAM; } else { compareDate = DateTimeEnglishParser.ParseRelative(DateTime.Now, command.GetArgument()); if (compareDate == null) { type = GetScheduleType.GETSCHEDULE_BADARGUMENT; } else { type = GetScheduleType.GETSCHEDULE_DATE; } } } } else { type = GetScheduleType.GETSCHEDULE_DATE; compareDate = DateTime.Now; } ScheduledGame[] result = new ScheduledGame[0]; switch (type) { case GetScheduleType.GETSCHEDULE_BADARGUMENT: irc.SendMessage(string.Format("{0} is not recognized", command.GetArgument()), command); break; case GetScheduleType.GETSCHEDULE_DATE: result = stats.GetSchedule((DateTime)compareDate); break; case GetScheduleType.GETSCHEDULE_TEAM: result = stats.GetSchedule(team, 4); break; case GetScheduleType.GETSCHEDULE_TEAMS: // -82: how many times can a team play another one?? whatever result = stats.GetSchedule(teamA, teamB, backwardsResults ? -82 : 3); break; } switch (type) { case GetScheduleType.GETSCHEDULE_BADARGUMENT: break; case GetScheduleType.GETSCHEDULE_DATE: if (result.Length == 0) { irc.SendMessage( String.Format("Didn't find any scheduled games for {0}", ((DateTime)compareDate).ToShortDateString()), command); } else { irc.SendMessage(string.Format("Games for {0}:", ((DateTime)compareDate).ToShortDateString()), command); foreach (ScheduledGame game in result) { string matchup = string.Format("{0} @ {1}", game.AwayTeamName, game.HomeTeamName); string date = game.StartTime + " ET"; msg = string.Format("{0} {1} ({2})", matchup.PadRight(25), date.PadRight(15), game.ExtraInfo); irc.SendMessage(msg, command); } } break; case GetScheduleType.GETSCHEDULE_TEAMS: case GetScheduleType.GETSCHEDULE_TEAM: string name; if (type == GetScheduleType.GETSCHEDULE_TEAM) name = team.Name; else name = teamA.Name + " / " + teamB.Name; if (result.Length == 0) { irc.SendMessage( String.Format("Didn't find any scheduled games for {0}", name), command); } else { if (backwardsResults) { irc.SendMessage(string.Format("Results for all games between {0}:", name), command); } else { irc.SendMessage(string.Format("Next set of games for {0}:", name), command); } foreach (ScheduledGame game in result) { string matchup = string.Format("{0} @ {1}", game.AwayTeamName, game.HomeTeamName); string date = game.StartDateString + " " + game.StartTime + " ET"; msg = string.Format("{0} {1} ({2})", matchup.PadRight(25), date.PadRight(30), game.ExtraInfo); irc.SendMessage(msg, command); } } break; } } else if (command.Matches("!score")) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) { if (game.GetStatus() != NHLGameStatus.GAME_NODATA && game.HasTeam(name)) { buf = String.Format("[{0}/{1}] Score: {2}", game.HomeTeamName, game.AwayTeamName, game.GetScoreString(true)); irc.SendMessage(buf, command); break; } } else if ((game.GetStatus() == NHLGameStatus.GAME_NOTSTARTED || game.GetStatus() == NHLGameStatus.GAME_PREVIEWDATA) && game.HasTeam(name)) { buf = String.Format("[{0}/{1}] Starting shortly", game.HomeTeamName, game.AwayTeamName); irc.SendMessage(buf, command); } } } } else if (command.Matches("!debug")) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.GetStatus() != NHLGameStatus.GAME_NODATA && game.HasTeam(name)) { game.AddDebugEvent(); break; } } } } else if (command.Matches("!sog")) { if (command.HasArgument()) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(name)) { buf = String.Format("[{0}/{1}] Shots on goal: {2} {3}, {4} {5}", game.HomeTeamName, game.AwayTeamName, game.HomeTeamName, game.HomeShots, game.AwayTeamName, game.AwayShots); irc.SendMessage(buf, command); break; } } } } } else if (command.Matches("!hits")) { if (command.HasArgument()) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(name)) { buf = String.Format("[{0}/{1}] Hits: {2} {3}, {4} {5}", game.HomeTeamName, game.AwayTeamName, game.HomeTeamName, game.NhlGameStats.GetGameTeamStat("hit", true, false), game.AwayTeamName, game.NhlGameStats.GetGameTeamStat("hit", false, false)); irc.SendMessage(buf, command); break; } } } } } else if (command.Matches("!pim")) { if (command.HasArgument()) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(name)) { buf = String.Format("[{0}/{1}] Penalty Minutes: {2} {3}, {4} {5}", game.HomeTeamName, game.AwayTeamName, game.HomeTeamName, game.NhlGameStats.GetGameTeamStat("penalty", true, false), game.AwayTeamName, game.NhlGameStats.GetGameTeamStat("penalty", false, false)); irc.SendMessage(buf, command); break; } } } } } else if (command.Matches("!scratches")) { if (command.HasArgument()) { String name = command.GetArgument(); name = stats.GetTeamNameAlias(name); NHLTeam team = stats.GetTeamFromCityOrTeam(name); if (team != null) { name = team.Name; foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(name)) { string scratches = "Scratches: " + game.NhlGameStats.GetScratches(); irc.SendMessage(scratches, command); break; } } } } } else if (command.Matches("!ptop")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); String filter = GetFilterString(argument); argument = StripPrefixes(argument); String[] results = stats.GetPlayers(argument, true, season, filter); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!gtop")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); String filter = GetFilterString(argument); argument = StripPrefixes(argument); String[] results = stats.GetGoalies(argument, true, season, filter); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!ttop")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); argument = StripPrefixes(argument); String[] results = stats.GetTeams(argument, true, season); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!pbot")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); String filter = GetFilterString(argument); argument = StripPrefixes(argument); String[] results = stats.GetPlayers(argument, false, season, filter); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!gbot")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); String filter = GetFilterString(argument); argument = StripPrefixes(argument); String[] results = stats.GetGoalies(argument, false, season, filter); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!tbot")) { if (command.HasArgument()) { String argument = command.GetArgument(); String season = GetSeasonString(argument); argument = StripPrefixes(argument); String[] results = stats.GetTeams(argument, false, season); foreach (string s in results) { irc.SendMessage(s, command); } } } else if (command.Matches("!list")) { irc.SendMessage("http://www.sportsargumentwiki.com/index.php?title=Nhlfeed", command); } else if (command.Matches("!pstat") || command.Matches("!pstats")) { if (command.HasArgument()) { String argument = command.GetArgument(); String entry = String.Empty; String name, season; int s = argument.IndexOf('['); int e = argument.IndexOf(']'); if (s >= 0 && e > 0) { entry = argument.Substring(s + 1, e - s - 1); } season = GetSeasonString(argument); argument = StripPrefixes(argument); name = argument; irc.SendMessage(stats.GetIndividualPlayer(entry, name, season), command); } } else if (command.Matches("!gstat") || command.Matches("!gstats")) { if (command.HasArgument()) { String argument = command.GetArgument(); String entry = String.Empty; String name, season; int s = argument.IndexOf('['); int e = argument.IndexOf(']'); if (s >= 0 && e > 0) { entry = argument.Substring(s + 1, e - s - 1); } season = GetSeasonString(argument); argument = StripPrefixes(argument); name = argument; irc.SendMessage(stats.GetIndividualGoalie(entry, name, season), command); } } else if (command.Matches("!tstat") || command.Matches("!tstats")) { if (command.HasArgument()) { String argument = command.GetArgument(); String entry = String.Empty; String name, season; int s = argument.IndexOf('['); int e = argument.IndexOf(']'); if (s >= 0 && e > 0) { entry = argument.Substring(s + 1, e - s - 1); } season = GetSeasonString(argument); argument = StripPrefixes(argument); name = argument; irc.SendMessage(stats.GetIndividualTeam(entry, name, season), command); } } else if (command.Matches("!updatealiases")) { if (stats.FetchAliasesBroken) { irc.SendMessage("Some idiot broke the formatting on the alias page, fix it first", command); stats.FetchAliasesBroken = false; } else { if (!stats.FetchAliases) { stats.FetchAliases = true; } else { irc.SendMessage("Already in the process of loading aliases", command); } } } else if (command.Matches("!gamestats") || command.Matches("!gamestat")) { bool found = false; String entry; if (command.HasArgument()) { entry = command.GetArgument(); entry = stats.GetPlayerNameAlias(entry); entry = stats.GetGoalieNameAlias(entry); entry = stats.GetTeamNameAlias(entry); NHLTeam team = stats.GetTeamFromCityOrTeam(entry); if (team != null) { foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(team.Name)) { if (game.NhlGameStats != null) irc.SendMessage(game.NhlGameStats.GetGameStats(), command); else irc.SendMessage("No game stats available yet for that game", command); found = true; break; } } } if (!found) { string msg; foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) { if (game.NhlGameStats != null) { msg = game.NhlGameStats.GetIndividualStats(entry); if (msg != null) { irc.SendMessage(msg, command); found = true; break; } } } } } if (!found) irc.SendMessage("Couldn't find team/player/goalie for game stats", command); } } else if (command.Matches("!summary")) { bool found = false; String entry; if (command.HasArgument()) { entry = command.GetArgument(); entry = stats.GetPlayerNameAlias(entry); entry = stats.GetGoalieNameAlias(entry); entry = stats.GetTeamNameAlias(entry); NHLTeam team = stats.GetTeamFromCityOrTeam(entry); if (team != null) { foreach (INHLGameInfo game in games) { if ((game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) && game.HasTeam(team.Name)) { List<string> summary = game.NhlGameStats.GetGameEvents(); foreach (string e in summary) { irc.SendMessage(e, command); } found = true; break; } } } if (!found) { foreach (INHLGameInfo game in games) { if (game.GetStatus() == NHLGameStatus.GAME_PLAYING || game.GetStatus() == NHLGameStatus.GAME_FINAL) { if (game.NhlGameStats != null) { List<string> summary = game.NhlGameStats.GetPlayerEvents(entry); if (summary.Count > 0) { foreach (string e in summary) { irc.SendMessage(e, command); } found = true; break; } } } } } if (!found) irc.SendMessage("Couldn't find team/player for summary", command); } } else if (command.Matches("!getschedule")) { stats.UpdateSchedule(); } else if (command.Matches("!record")) { if (command.HasArgument()) { NHLTeam team = null; string[] words = command.GetArgument().Split(' '); foreach (string word in words) { team = stats.GetTeamFromCityOrTeam(word); if (team != null) break; } if (team != null) { bool? home = null; if (command.GetArgument().ToLower().Contains("home")) home = true; else if (command.GetArgument().ToLower().Contains("away")) home = false; NHLStats.TeamRecordFilterType filterType; if (home == null) filterType = NHLStats.TeamRecordFilterType.EITHER; else if (home == true) filterType = NHLStats.TeamRecordFilterType.HOME; else filterType = NHLStats.TeamRecordFilterType.AWAY; bool recent = false; if (command.GetArgument().ToLower().Contains("recent")) recent = true; List<TeamRecord> conferenceStandings = stats.ConferenceStandings(team.Conference == "Western", games, string.Empty, recent ? 10 : 82, filterType); List<TeamRecord> leagueStandings = stats.LeagueStandings(games, string.Empty, recent ? 10 : 82, filterType); int conferenceRank = 1, leagueRank = 1; TeamRecord record = null; foreach (TeamRecord teamRecord in conferenceStandings) { if (teamRecord.Team.Equals(team)) { record = teamRecord; break; } conferenceRank++; } foreach (TeamRecord teamRecord in leagueStandings) { if (teamRecord.Team.Equals(team)) { break; } leagueRank++; } string description = string.Empty; if (home == true) description = "Home Only"; else if (home == false) description = "Away Only"; if (recent && home != null) description += ", Last 10"; else if (recent) description += "Last 10"; irc.SendMessage(string.Format("{0} {1} ranked #{2} place in conference, #{3} in league {4} -- {5}", team.City, team.Name, conferenceRank, leagueRank, description.Length > 0 ? "(" + description + ")" : string.Empty, stats.FormatRecord(record)), command); } else { irc.SendMessage("Couldn't find that team", command); } } } else if (command.Matches("!standings")) { command.PrivateMessage = true; if (command.HasArgument()) { StandingsType standingsType = StandingsType.LEAGUE; if (command.GetArgument().ToLower().Contains("west")) standingsType = StandingsType.WEST; else if (command.GetArgument().ToLower().Contains("east")) standingsType = StandingsType.EAST; bool? home = null; if (command.GetArgument().ToLower().Contains("home")) home = true; else if (command.GetArgument().ToLower().Contains("away")) home = false; bool recent = false; if (command.GetArgument().ToLower().Contains("recent")) recent = true; NHLStats.TeamRecordFilterType filterType; if (home == null) filterType = NHLStats.TeamRecordFilterType.EITHER; else if (home == true) filterType = NHLStats.TeamRecordFilterType.HOME; else filterType = NHLStats.TeamRecordFilterType.AWAY; string title = string.Empty; if (recent) title = "Standings for points from teams' last 10 games only"; else title = "Current standings"; if (filterType == NHLStats.TeamRecordFilterType.AWAY) title += ", for away games"; else if (filterType == NHLStats.TeamRecordFilterType.HOME) title += ", for home games"; if (standingsType == StandingsType.EAST) title += " (Eastern Conference)"; else if (standingsType == StandingsType.WEST) title += " (Western Conference)"; irc.SendMessage(title, command); List<TeamRecord> standings; if (standingsType == StandingsType.LEAGUE) standings = stats.LeagueStandings(games, string.Empty, recent ? 10 : 82, filterType); else standings = stats.ConferenceStandings(standingsType == StandingsType.WEST, games, string.Empty, recent ? 10 : 82, filterType); int i = 1; foreach (TeamRecord teamRecord in standings) { if (i == 9 && standingsType != StandingsType.LEAGUE) irc.SendMessage("==============================", command); string rank = Convert.ToString(i) + "."; irc.SendMessage(string.Format("{0} {1} {2}", rank.PadRight(3), teamRecord.Team.Name.PadRight(16), stats.FormatRecord(teamRecord)), command); i++; } } else { List<TeamRecord> standings = stats.LeagueStandings(games, string.Empty, 82, NHLStats.TeamRecordFilterType.EITHER); int i = 1; foreach (TeamRecord teamRecord in standings) { string rank = Convert.ToString(i) + "."; irc.SendMessage(string.Format("{0} {1} {2}", rank.PadRight(3), teamRecord.Team.Name.PadRight(16), stats.FormatRecord(teamRecord)), command); i++; } } } }
public void SendMessage(string text, Command originalCommand) { if (originalCommand == null) { ircClient.SendMessage(SendType.Message, CHANNEL, text); if (CHANNEL2.Length > 0) ircClient.SendMessage(SendType.Message, CHANNEL2, text); } else { if (originalCommand.PrivateMessage) ircClient.SendMessage(SendType.Message, originalCommand.UserName, text); else ircClient.SendMessage(SendType.Message, originalCommand.Channel, text); } }