public IProcessingResult Undo(IBot bot, IProcessingResult pr, string arg) { pr.Solved = true; pr.Respond = true; pr.ResponseOrigin = Helper.GetExecutingMethodName(this); var editablePosts = bot.GetStillEditableMessages(); var wc = Helper.WordCount(arg); var a1 = Helper.FirstWord(arg).Trim().TrimStart(':'); if (wc == 0) { if (editablePosts.Count > 0) { var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return pr; } else { pr.ResponseText = "No messages less than 2 minutes old."; return pr; } } if (wc == 1) { if (a1 == "last") { if (editablePosts.Count > 0) { var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return pr; } else { pr.ResponseText = "No messages less than 2 minutes old."; return pr; } } else { int i = 0; var b = int.TryParse(a1, out i); if (!b) { pr.ResponseText = "Could not parse the number of messages to delete or messageid, whatever it was."; return pr; } else { if (i < 100) { if (editablePosts.Count > 0) { if (editablePosts.Count >= i) { // get i first posts to delete var todel = new List<IChatMessage>(); for (int n = 0; n < i; n++) todel.Add(editablePosts[n]); foreach (var tod in todel) bot.DeleteMessage(tod.RoomID, tod.MessageID); pr.Respond = false; return pr; } else { foreach (var tod in editablePosts) bot.DeleteMessage(tod.RoomID, tod.MessageID); pr.Respond = false; return pr; } } else { pr.ResponseText = "No messages less than 2 minutes old."; return pr; } } else // delete by messageid { // try to get the messageid foreach (var v in editablePosts) if (v.MessageID == i) { bot.DeleteMessage(v.RoomID, v.MessageID); pr.Respond = false; return pr; } } } } } var wrest = Helper.TextAfter(arg, a1); if (a1.ToLowerInvariant() == "last") { var v = editablePosts[0].MessageID; var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return pr; } else { int mid = 0; if (int.TryParse(a1, out mid)) { pr.OwnResponseMessageIDToEdit = mid; pr.ResponseText = wrest; } else { pr.ResponseText = "Could not parse messageid."; return pr; } } return pr; }
public IProcessingResult Undo(IBot bot, IProcessingResult pr, string arg) { pr.Solved = true; pr.Respond = true; pr.ResponseOrigin = Helper.GetExecutingMethodName(this); var editablePosts = bot.GetStillEditableMessages(); var wc = Helper.WordCount(arg); var a1 = Helper.FirstWord(arg).Trim().TrimStart(':'); if (wc == 0) { if (editablePosts.Count > 0) { var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return(pr); } else { pr.ResponseText = "No messages less than 2 minutes old."; return(pr); } } if (wc == 1) { if (a1 == "last") { if (editablePosts.Count > 0) { var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return(pr); } else { pr.ResponseText = "No messages less than 2 minutes old."; return(pr); } } else { int i = 0; var b = int.TryParse(a1, out i); if (!b) { pr.ResponseText = "Could not parse the number of messages to delete or messageid, whatever it was."; return(pr); } else { if (i < 100) { if (editablePosts.Count > 0) { if (editablePosts.Count >= i) { // get i first posts to delete var todel = new List <IChatMessage>(); for (int n = 0; n < i; n++) { todel.Add(editablePosts[n]); } foreach (var tod in todel) { bot.DeleteMessage(tod.RoomID, tod.MessageID); } pr.Respond = false; return(pr); } else { foreach (var tod in editablePosts) { bot.DeleteMessage(tod.RoomID, tod.MessageID); } pr.Respond = false; return(pr); } } else { pr.ResponseText = "No messages less than 2 minutes old."; return(pr); } } else // delete by messageid { // try to get the messageid foreach (var v in editablePosts) { if (v.MessageID == i) { bot.DeleteMessage(v.RoomID, v.MessageID); pr.Respond = false; return(pr); } } } } } } var wrest = Helper.TextAfter(arg, a1); if (a1.ToLowerInvariant() == "last") { var v = editablePosts[0].MessageID; var last = editablePosts[0]; bot.DeleteMessage(last.RoomID, last.MessageID); pr.Respond = false; return(pr); } else { int mid = 0; if (int.TryParse(a1, out mid)) { pr.OwnResponseMessageIDToEdit = mid; pr.ResponseText = wrest; } else { pr.ResponseText = "Could not parse messageid."; return(pr); } } return(pr); }