public void ExecuteCommandDiscord(Message message) { Viewer viewer; try { viewer = MainWindow.colDatabase.FirstOrDefault(x => x.DiscordID == message.User.Id.ToString()); MainWindow.popMsgBox(viewer.UserName); } catch (Exception) { viewer = new Viewer(message.User.Name); } if (viewer == null) { return; } if (CanExecute(viewer)) { Match targetMatch = Regex.Match(message.Text, @"@(?<name>[a-zA-Z0-9_]{4,25})"); string target = targetMatch.Groups["name"].Value; // Parse response line here // @user@ -> Display name of the user of the command // @followdate@ -> Command user's follow date // @followdatetime@ -> Command user's follow date and time // @game@ -> Channels current game // @title@ -> Channels current title string parsedResponse = Regex.Replace(response, @"@(?<item>\w+)@", m => { string[] split = Regex.Split(message.Text, @"\s+"); switch (m.Groups["item"].Value.ToLower()) { case "user": return(viewer.UserName); case "followdate": return(viewer.GetFollowDateTime("yyyy-MM-dd")); case "followdatetime": return(viewer.GetFollowDateTime("yyyy-MM-dd HH:mm")); case "game": return(Utils.GetClient().GetMyChannel().Game); case "title": return(Utils.GetClient().GetMyChannel().Status); case "var1": if (split.Count() == 2) { var1 = split[1]; return(var1); } return(""); default: return(""); } }); MainWindow.discord.GetServer(message.Server.Id).GetChannel(message.Channel.Id).SendMessage(parsedResponse.Trim()); } }
public void ExecuteCommand(IrcMessage message) { // Get command user's Viewer object Viewer viewer = MainWindow.colDatabase.FirstOrDefault(x => x.UserName == message.Author); if (viewer == null) { return; } if (CanExecute(viewer)) { Match targetMatch = Regex.Match(message.Message, @"@(?<name>[a-zA-Z0-9_]{4,25})"); string target = targetMatch.Groups["name"].Value; // Parse response line here // @user@ -> Display name of the user of the command // @followdate@ -> Command user's follow date // @followdatetime@ -> Command user's follow date and time // @game@ -> Channels current game // @title@ -> Channels current title string parsedResponse = Regex.Replace(response, @"@(?<item>\w+)@", m => { string[] split = Regex.Split(message.Message, @"\s+"); switch (m.Groups["item"].Value.ToLower()) { case "user": return(viewer.UserName); case "followdate": return(viewer.GetFollowDateTime("yyyy-MM-dd")); case "followdatetime": return(viewer.GetFollowDateTime("yyyy-MM-dd HH:mm")); case "game": return(Utils.GetClient().GetMyChannel().Game); case "title": return(Utils.GetClient().GetMyChannel().Status); case "var1": if (split.Count() == 2) { var1 = split[1]; return(var1); } return(""); default: return(""); } }); // Set timestamps lastUsed = DateTime.UtcNow; dictLastUsed[message.Author] = DateTime.UtcNow; // Notify the UI of the new last used date NotifyPropertyChanged("LastUsed"); // Send the response if (sendAsStreamer) { // Send message to IRC, no need to add to collection as this will be received by bot account MainWindow.instance.streamerChatConnection.SendChatMessage(parsedResponse.Trim()); } else { // Send message to IRC MainWindow.instance.botChatConnection.SendChatMessage(parsedResponse.Trim()); // Add message to collection App.Current.Dispatcher.BeginInvoke(new Action(delegate { MainWindow.colChatMessages.Add(new IrcMessage( MainWindow.instance.accountBot.UserName, parsedResponse.Trim())); })); } } }