/// <summary> /// Gets the tags from the SEDE query. If the email and password has not already /// been set then those credentials will be saved and used. Will also tell /// the chat room if the tags are being refreshed (because it takes some time). /// </summary> /// <param name="chatRoom"></param> /// <param name="email"></param> /// <param name="password"></param> /// <returns></returns> public static Dictionary<string, int> GetTags(Room chatRoom, string email, string password) { // Set the email/password if not set. if (loginEmail == null) { loginEmail = email; loginPassword = password; } // If tags have not been gotten yet or its been more than 30 minutes since the last get // then refresh the tag listing. if (tags == null || (DateTime.UtcNow - lastRevIdCheckTime).TotalMinutes > 30) { chatRoom.PostMessageOrThrow("Refreshing the tag listing. Please wait..."); var currentID = ""; if ((currentID = Client.GetSedeQueryRunUrl(236526)) != lastRevision || tags == null) { lastRevision = currentID; tags = Client.GetTags(lastRevision); } lastRevIdCheckTime = DateTime.UtcNow; } return tags; }
public override void RunAction(Message incommingChatMessage, Room chatRoom, InstallationSettings roomSettings) { var message = "This is a chat bot for the SO Close Vote Reviewers chat room, developed by [gunr2171](http://stackoverflow.com/users/1043380/gunr2171) and the other members of the SO Close Vote Reviewers chat room. " + "For more information see the [github page](https://github.com/SO-Close-Vote-Reviewers/SOCVR-Chatbot). " + "Reply with `{0}` to see a list of commands." .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<Commands>()); chatRoom.PostMessageOrThrow(message); }
public override void RunAction(Message incomingChatMessage, ChatExchangeDotNet.Room chatRoom) { var runningCommands = RunningChatbotActionsManager.GetRunningChatbotActions(); var now = DateTimeOffset.Now; var tableMessage = runningCommands .Select(x => new { Command = x.ChatbotActionName, ForUser = $"{x.RunningForUserName} ({x.RunningForUserId})", Started = (now - x.StartTs).ToUserFriendlyString() + " ago", }) .ToStringTable(new[] { "Command", "For User", "Started" }, x => x.Command, x => x.ForUser, x => x.Started); chatRoom.PostReplyOrThrow(incomingChatMessage, "The following is a list of commands that I'm currently running:"); chatRoom.PostMessageOrThrow(tableMessage); }
/// <summary> /// Call this method if you get an error while running a ChatbotAction. /// This will attempt to send a message to chat about error in a standard format. /// </summary> /// <param name="ex"></param> /// <param name="chatRoom"></param> /// <param name="actionToRun"></param> private void TellChatAboutErrorWhileRunningAction(Exception ex, Room chatRoom, ChatbotAction actionToRun) { var headerLine = "I hit an error while trying to run '{0}':" .FormatSafely(actionToRun.GetActionName()); var errorMessage = " " + ex.FullErrorMessage(Environment.NewLine + " "); var stackTraceMessage = ex.GetAllStackTraces(); var detailsLine = errorMessage + Environment.NewLine + " ----" + Environment.NewLine + stackTraceMessage; chatRoom.PostMessageOrThrow(headerLine); chatRoom.PostMessageOrThrow(detailsLine); }