public TwitchResponse processCommand(string username, string command) { if (isRunning == false) { return(null); } TwitchResponse response = null; if (command.StartsWith("!gyms")) { response = processGymCommand(); } else if (command.ToLower().StartsWith("!opengym")) { var leader = from l in gymLeaders where l.Name.ToLower() == username.ToLower() select l; response = processOpenGymCommand(username, leader.First().gymUpMessage); } else if (command.ToLower().StartsWith("!closegym")) { var leader = from l in gymLeaders where l.Name.ToLower() == username.ToLower() select l; response = processCloseGymCommand(username, leader.First().gymDownMessage); } else if (command.ToLower().StartsWith("!givebadge")) { string[] buffer = command.Split(' '); if (buffer.Count() == 2) { response = givebadge(username, buffer[1]); } } else if (command.ToLower().StartsWith("!checkbadges")) { string checkuser = username; string[] buffer = command.Split(' '); if (buffer.Count() == 2) { checkuser = buffer[1]; } response = checkBadges(username, checkuser); } //else if (command.ToLower().StartsWith("!")) //{ // var leader = from l in gymLeaders // where l.Name.ToLower() == username.ToLower() // select l; // if (leader.Count() > 0) // { // if (command.ToLower().StartsWith(leader.First().gymUpCommand)) // response = processOpenGymCommand(username, leader.First().gymUpMessage); // else if (command.ToLower().StartsWith(leader.First().gymDownCommand)) // response = processCloseGymCommand(username, leader.First().gymDownMessage); // } //} return(response); }
private TwitchResponse processCloseGymCommand(string username, string messageformat) { TwitchResponse response = null; var leader = from l in gymLeaders where l.Name.ToLower() == username.ToLower() select l; if (leader.Count() > 0) { response = new TwitchResponse(); response.response = String.Format(messageformat, username); response.publicNotification = true; leader.First().Online = "Online"; } return(response); }
public void ProcessCommands() { while (isConnected) { try { string message = client.readMessage(); log.DebugFormat("<< {0}", message); TwitchCommand tc = new TwitchCommand(message); if (tc.validMessage) { if (tc.message.StartsWith("!hello")) { //System.Windows.MessageBox.Show(message); //client.SendChatMessage(String.Format("Well hello there @{0}!", tc.username)); } else { TwitchResponse response = gymBotCommand.processCommand(tc.username, tc.message); if (response != null) { if (tc.isWhisper && !response.publicNotification) { client.SendWhisperMessage(tc.username, response.response); } else { client.SendChatMessage(response.response); } } } } } catch (OperationCanceledException) { } catch (Exception ex) { log.WarnFormat("Something when wrong processing commands.... {0}", ex.ToString()); } } }
private TwitchResponse processOpenGymCommand(string username, string messageformat) { TwitchResponse response = null; var leader = from l in gymLeaders where l.Name.ToLower() == username.ToLower() select l; if (leader.Count() > 0) { response = new TwitchResponse(); response.response = String.Format(messageformat, username); response.publicNotification = true; leader.First().Online = "Open"; leader.First().offlineCountdown = numberOfMissedChecksAllowed; leader.First().LastOpen = DateTime.Now; UpdateGymFile(); } return(response); }
private TwitchResponse processGymCommand() { TwitchResponse response = null; StringBuilder sb = new StringBuilder(); lock (this) { //sb.Append("Elite 4 members currently online:"); //var elite4online = from leader in gymLeaders // where leader.Online == "Open" && // leader.gymType == GymType.Elite4 // select leader; var gymsOnline = from leader in gymLeaders where leader.Online == "Open" && leader.gymType == GymType.Gym select leader; //if (elite4online.Count() > 0) //{ // foreach (GymLeader s in elite4online) // sb.Append(String.Format(" {0} ", s.Name)); //} //else //{ // sb.Append(" None "); //} if (gymsOnline.Count() > 0) { sb.Append("The following gym leaders currently have their gyms open:"); foreach (GymLeader s in gymsOnline) { sb.Append(String.Format(" @{0} ", s.Name)); } } else { sb.Append("Sorry, there are currently no gyms accepting challengers."); } response = new TwitchResponse(); response.publicNotification = false; response.response = sb.ToString(); } return(response); }
private TwitchResponse givebadge(string leaderName, string challenger) { TwitchResponse response = null; var leader = from l in gymLeaders where l.Name.ToLower() == leaderName.ToLower() select l; if (leader.Count() > 0) { badgeInfo badge = new badgeInfo { GymLeader = leaderName, Trainer = challenger, Earned = DateTime.Now }; var checklist = from l in badgeList where l.GymLeader.ToLower().Equals(leaderName.ToLower()) && l.Trainer.ToLower().Equals(challenger.ToLower()) select l; if (checklist.FirstOrDefault() == null) { badgeList.Add(badge); UpdateBadgeFile(); response = new TwitchResponse { publicNotification = true, response = String.Format("@{0} has earned the badge from @{1}.", challenger, leaderName) }; } else { response = new TwitchResponse { publicNotification = true, response = String.Format("@{0} already earned the badge from @{1} on {2}.", challenger, leaderName, checklist.First().Earned) }; } } return(response); }
private TwitchResponse checkBadges(string username, string checkuser) { TwitchResponse response = null; bool found = false; StringBuilder sb = new StringBuilder(); var leader = from l in gymLeaders where l.Name.ToLower() == username.ToLower() && l.gymType == GymType.Elite4 select l; if (leader.Count() > 0) { var badges = from l in badgeList where l.Trainer.ToLower().Equals(checkuser.ToLower()) select l; if (badges.Count() == 0) { found = true; sb.AppendFormat("@{0} has not yet obtained any badges", checkuser); } else if (badges.Count() == 1) { found = true; sb.AppendFormat("@{0} has obtained 1 badge from @{1}", checkuser, badges.First().GymLeader); } else { found = true; sb.AppendFormat("@{0} has obtained {1} badges from the following gyms: ", checkuser, badges.Count()); foreach (badgeInfo badge in badges) { sb.AppendFormat("@{0} ", badge.GymLeader); } } } else if (username.ToLower().Equals(checkuser.ToLower())) { var badges = from l in badgeList where l.Trainer.ToLower().Equals(checkuser.ToLower()) select l; if (badges.Count() == 0) { found = true; sb.AppendFormat("@{0} has not yet obtained any badges", checkuser); } else if (badges.Count() == 1) { found = true; sb.AppendFormat("@{0} has obtained 1 badge from @{1}", checkuser, badges.First().GymLeader); } else { found = true; sb.AppendFormat("@{0} has obtained {1} badges from the following gyms: ", checkuser, badges.Count()); foreach (badgeInfo badge in badges) { sb.AppendFormat(" @{0} ", badge.GymLeader); } } } if (found) { response = new TwitchResponse { publicNotification = true, response = sb.ToString() }; } return(response); }