private void ProcessChatCommandLogIn(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser); if (twitterUser != null) { throw new InvalidOperationException(string.Format( "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName, twitterUser.TwitterUser.ScreenName)); } if (parameters.Count != 2) { throw new InvalidCommandParametersException(1); } // Create new Twitter user and log in. var twitterBotUser = new TwitterBotUser(sourceUser); twitterBotUser.LogIn(parameters[0], parameters[1]); this.twitterUsers.Add(twitterBotUser); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.", twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name); }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandSend( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; // var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 1) { throw new InvalidCommandParametersException(1); } //Send System Message. //TODO: Add GM Check and Sending System Message Code here //Twitter Code Delete this crap after new code is written. // var tweetStatus = twitterBotUser.SendTweet(parameters[0].TrimStart()); // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // client.LocalUser.SendMessage(replyTargets, "Tweet sent by {0} at {1}.", tweetStatus.User.ScreenName, // tweetStatus.CreatedDate.ToLongTimeString()); }
public bool handleURL(string url, IrcClient ctx, CtcpClient ctpcclient = null, IIrcMessageSource source = null ) { var title = GetPageTitle(url).Trim(); if (!string.IsNullOrWhiteSpace(title)) { if(title.ToLower().Contains("Domainpark - Bitte den Rasen nicht betreten".ToLower())) { int roll = random.Next(0, 101); if(roll < 5) { if(ctpcclient != null) { string textMessage = "slaps " + source.Name + " and screamed:"; BotDeathmicMessageTarget target = new BotDeathmicMessageTarget(); target.Name = Properties.Settings.Default.Channel.ToString(); ctpcclient.SendAction(target, textMessage); ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, "Runter vom Rasen!"); } } } else { if(title.ToLower() == "Imgur: The most awesome images on the Internet".ToLower()) { } else { ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, title); } } } return true; }
private void ReadChatCommand(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, string[] parameters) { var defaultReplyTarget = GetDefaultReplyTarget(client, source, targets); ChatCommandProcessor processor; if (this.chatCommandProcessors.TryGetValue(command, out processor)) { try { processor(client, source, targets, command, parameters); } catch (InvalidCommandParametersException exInvalidCommandParameters) { client.LocalUser.SendNotice(defaultReplyTarget, exInvalidCommandParameters.GetMessage(command)); } catch (Exception ex) { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice(defaultReplyTarget, "Error processing '{0}' command: {1}", command, ex.Message); } } } else { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice(defaultReplyTarget, "Command '{0}' not recognized.", command); } } }
private void ProcessChatCommandZoneInfo( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { if (!this.executingRequestPlayfieldList) { this.executingRequestPlayfieldList = true; int numberOfZoneEnginesConnected = Program.ISCom.ClientCount; List <string> addressList = Program.ISCom.GetZoneEngineIds(); Program.ISCom.BroadCast(new RequestPlayfieldList()); StringBuilder sb = new StringBuilder(); var sourceUser = (IrcUser)source; IList <IIrcMessageTarget> replyTargets = this.GetDefaultReplyTarget(client, sourceUser, targets); DateTime startWait = DateTime.UtcNow; bool timeOut = true; while ((DateTime.UtcNow - startWait < TimeSpan.FromSeconds(10) && timeOut)) { lock (this.replyQueuePlayfieldList) { if (this.replyQueuePlayfieldList.Count == Program.ISCom.ClientCount) { timeOut = false; } } } if (timeOut) { client.LocalUser.SendMessage(replyTargets, "{0}", "Not all ZoneEngines replied."); } client.LocalUser.SendMessage( replyTargets, "{0}", "Number of ZoneEngines connected: " + numberOfZoneEnginesConnected); while (this.replyQueuePlayfieldList.Count > 0) { RequestPlayfieldList r = this.replyQueuePlayfieldList.Dequeue(); client.LocalUser.SendMessage( replyTargets, "{0}: Playfields {1}", r.ZoneEngineAddress, string.Join( ", ", r.PlayfieldIds.Select( x => PlayfieldLoader.PFData[x.Instance].Name.Trim() + " (" + x.Instance + ")") .ToArray())); } this.executingRequestPlayfieldList = false; } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="source"></param> /// <param name="targets"></param> /// <param name="command"></param> /// <param name="parameters"></param> private void ProcessChatCommandRegister( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { //TODO: Add Command to register user for CellAO }
internal void HandleNoticeReceived(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text) { var previewEventArgs = new IrcPreviewMessageEventArgs(source, targets, text, this.Client.TextEncoding); OnPreviewNoticeReceived(previewEventArgs); if (!previewEventArgs.Handled) { OnNoticeReceived(new IrcMessageEventArgs(source, targets, text, this.Client.TextEncoding)); } }
internal void HandleMessageReceived(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text) { var previewEventArgs = new IrcPreviewMessageEventArgs(source, targets, text); OnPreviewMessageReceived(previewEventArgs); if (!previewEventArgs.Handled) { OnMessageReceived(new IrcMessageEventArgs(source, targets, text)); } }
private void ProcessChatCommandStats(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { // Send reply with bot statistics. var replyTargets = GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendNotice(replyTargets, "Bot launch time: {0:f} ({1:g} ago)", this.launchTime, DateTime.Now - this.launchTime); }
public IrcMessageCommand( IrcBot bot, IrcBotUser user, IrcClient client, string[] parameters, IIrcMessageTarget target, IIrcMessageSource source ) : base(bot, user, client, parameters, target, source) { }
private void ProcessChatCommandHelp(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { if (parameters.Count != 0) throw new InvalidCommandParametersException(0); // List all commands recognized by this bot. var replyTarget = GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendMessage(replyTarget, "Commands recognized by bot:"); client.LocalUser.SendMessage(replyTarget, string.Join(", ", this.ChatCommandProcessors.Select(kvPair => kvPair.Key))); }
protected IList <IIrcMessageTarget> GetDefaultReplyTarget(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets) { if (targets.Contains(client.LocalUser) && source is IIrcMessageTarget) { return new[] { (IIrcMessageTarget)source } } ; else { return(targets); } }
private void CheckModeratorStatus(IIrcMessageSource msgSource) { IrcUser ircuser = msgSource as IrcUser; if (ircuser != null) { IrcChannelUser chanUser = m_channel.GetChannelUser(ircuser); if (chanUser != null) { CheckModeratorStatus(chanUser); } } }
public bool handleURL(string url, IrcDotNet.IrcClient ctx, CtcpClient ctpcclient = null, IIrcMessageSource source = null) { var match = _imgurreg.Match(url); if (match.Success) { var id = match.Groups[2].Value; url = "http://imgur.com/gallery/" + id; website.handleURL(url, ctx, ctpcclient, source); return true; } return false; }
/// <summary> /// Need to change Some Information in this code. Probably a Seperate MOTD for IRC or something to have the bot read and send for /// connection Info. /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandServerInfo( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { IList <IIrcMessageTarget> replyTarget = this.GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendMessage(replyTarget, "A How to Setup Connection to CellAO can be found here: {0}", Config.Instance.CurrentConfig.WebHostName); client.LocalUser.SendMessage( replyTarget, "This is the address for the server: " + Config.Instance.CurrentConfig.ListenIP + " On Port: " + Config.Instance.CurrentConfig.LoginPort); }
private void ProcessChatCommandStats(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { // Send reply with bot statistics. var replyTargets = GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendNotice(replyTargets, "Bot launch time: {0:f} ({1:g} ago)", this.launchTime, DateTime.Now - this.launchTime); client.LocalUser.SendNotice(replyTargets, "Number of training messages received: {0:#,#0} ({1:#,#0} words)", this.numTrainingMessagesReceived, this.numTrainingWordsReceived); client.LocalUser.SendNotice(replyTargets, "Number of unique words in vocabulary: {0:#,#0}", this.markovChain.Nodes.Count); }
private void ProcessChatCommandHelp(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { if (parameters.Count != 0) { throw new InvalidCommandParametersException(1); } // List all commands recognized by this bot. var replyTarget = GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendMessage(replyTarget, "Commands recognized by bot:"); client.LocalUser.SendMessage(replyTarget, string.Join(", ", this.ChatCommandProcessors.Select(kvPair => kvPair.Key))); }
public void Run(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { Client = client; SourceUser = (IrcUser)source; Command = command; Parameters = parameters; if (targets.Contains(Client.LocalUser) && source != null) ReplyTargets = new[] { (IIrcMessageTarget)source }; else { ReplyTargets = targets; } Run(); }
/// <summary> /// Initializes a new instance of the <see cref="IrcMessageEventArgs"/> class. /// </summary> /// <param name="source">The source of the message.</param> /// <param name="targets">A list of the targets of the message.</param> /// <param name="text">The text of the mesage.</param> /// <exception cref="ArgumentNullException"><paramref name="targets"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="text"/> is <see langword="null"/>.</exception> public IrcMessageEventArgs(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text) : base() { if (targets == null) { throw new ArgumentNullException("target"); } if (text == null) { throw new ArgumentNullException("text"); } this.Source = source; this.Targets = new ReadOnlyCollection <IIrcMessageTarget>(targets); this.Text = text; }
public bool AddUser(string username, Channels ChannelWatch, IIrcMessageTarget target, IIrcMessageSource source, IrcClient ircConnection) { ModifyingConfig = true; bool returnvalue = false; IrcChannel findChannel = null; foreach (IrcChannel ircChannel in ircConnection.Channels) { if(ircChannel.Name == target.Name) { findChannel = ircChannel; } } if (Utilities.CheckOp(source.Name, findChannel)) { try { Channels Watch = new Channels(); foreach (Channels c in TwitchChannels) { if (findChannel.Name == c.ChannelName) { Watch = c; }//if (findChannel.Name == c.ChannelName) }//foreach (Channels c in TwitchChannels) // config writing XElement newStreamer = new XElement("streamer"); newStreamer.SetAttributeValue("value", username); XElement xElem = ConfigDocument.Descendants("servers").FirstOrDefault().Descendants("server").FirstOrDefault().Elements("channel").First(x => x.Attribute("id").Value == Watch.ChannelName); xElem.Descendants("streamers").FirstOrDefault().Add(newStreamer); TwitchStuff twitchInfo = new TwitchStuff(); twitchInfo.UpdateInfo(username,this); Watch.Streamers.Add(username); Watch.StreamInfo.Add(twitchInfo); returnvalue = true; ConfigDocument.Save(FileName); }//try catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: " + ex.Message); Console.ForegroundColor = ConsoleColor.Gray; returnvalue = false; } } ModifyingConfig = false; return returnvalue; }
public IrcCommand( IrcBot bot, IrcBotUser user, IrcClient client, string[] parameters, IIrcMessageTarget target, IIrcMessageSource source ) { this.Bot = bot; this.User = user; this.Client = client; this.Target = target; this.Source = source; ParseParameters(parameters); }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandLogIn( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; CellAoBotUser CellAOUser = this.cellAoBotUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser); if (CellAOUser != null) { throw new InvalidOperationException( string.Format( "User '{0}' is already logged in to CellAO as {1}.", sourceUser, CellAOUser.IrcUser.NickName)); } if (parameters.Count != 2) { throw new InvalidCommandParametersException(1); } // // Create new CellAO user and log in to service. var cellaoBotUser = new CellAoBotUser(sourceUser); // bool success = cellaoBotUser.LogIn(parameters[0], parameters[1]); cellaoBotUser.LogIn(parameters[0], parameters[1]); IList <IIrcMessageTarget> replyTargets = this.GetDefaultReplyTarget(client, sourceUser, targets); if (cellaoBotUser.IsAuthenticated) { this.cellAoBotUsers.Add(cellaoBotUser); client.LocalUser.SendMessage( replyTargets, "You are now logged in as {0} / '{1}'.", cellaoBotUser.IrcUser.NickName, cellaoBotUser.IrcUser.NickName); this.GMlevel = cellaoBotUser.GMLevel(this.username); } else { client.LocalUser.SendMessage(replyTargets, "Login failed"); } }
private void ProcessChatCommandSend(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 1) { throw new InvalidCommandParametersException(1); } // Send tweet from user. var tweetStatus = twitterBotUser.SendTweet(parameters[0].TrimStart()); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Tweet sent by {0} at {1}.", tweetStatus.User.ScreenName, tweetStatus.CreatedDate.ToLongTimeString()); }
private void ProcessChatCommandLogOut(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 0) { throw new InvalidCommandParametersException(1); } // Log out Twitter user. twitterBotUser.LogOut(); this.twitterUsers.Remove(twitterBotUser); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "You are now logged out."); }
private void ProcessChatCommandTalk(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { // Send reply containing random message text (generated from Markov chain). int numSentences = -1; if (parameters.Count >= 1) { numSentences = int.Parse(parameters[0]); } string higlightNickName = null; if (parameters.Count >= 2) { higlightNickName = parameters[1] + ": "; } SendRandomMessage(client, GetDefaultReplyTarget(client, source, targets), higlightNickName, numSentences); }
/// <summary> /// Responds to a !tell command by storing the message, or reporting an error if the input isn't valid. /// </summary> /// <param name="client"></param> /// <param name="source"></param> /// <param name="targets"></param> /// <param name="command"></param> /// <param name="parameters"></param> private void ProcessChatCommandTell(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { if (parameters.Count >= 2) { TellMessage message = new TellMessage { From = source.Name, To = parameters[0], Message = string.Join(" ", parameters.Skip(1)), SentOn = DateTime.Now }; Messages.Add(message); client.LocalUser.SendMessage(targets, $"Okay, {source.Name}"); SaveMessages(); return; } client.LocalUser.SendMessage(targets, "Error: Syntax must be: \"!tell Nickname message\""); }
private void ProcessChatCommandMentions(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 0) { throw new InvalidCommandParametersException(1); } // List tweets on Home timeline of user. var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Recent tweets mentioning '{0}':", twitterBotUser.TwitterUser.ScreenName); foreach (var tweet in twitterBotUser.ListTweetsMentioningMe()) { SendTweetInfo(client, replyTargets, tweet); } }
private void ProcessChatCommandListUsers(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; if (parameters.Count != 0) { throw new InvalidCommandParametersException(1); } // List all currently logged-in twitter users. var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Currently logged-in Twitter users ({0}):", this.twitterUsers.Count); foreach (var tu in this.twitterUsers) { client.LocalUser.SendMessage(replyTargets, "{0} / {1} ({2} @ {3})", tu.TwitterUser.ScreenName, tu.TwitterUser.Name, tu.IrcUser.NickName, tu.IrcUser.Client.ServerName); } }
/// <summary> /// Initializes a new instance of the <see cref="IrcMessageEventArgs" /> class. /// </summary> /// <param name="source">The source of the message.</param> /// <param name="targets">A list of the targets of the message.</param> /// <param name="text">The text of the message.</param> /// <param name="encoding">The encoding of the message text.</param> /// <exception cref="ArgumentNullException"><paramref name="targets" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="text" /> is <see langword="null" />.</exception> public IrcMessageEventArgs(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text, Encoding encoding) { if (targets == null) { throw new ArgumentNullException("target"); } if (text == null) { throw new ArgumentNullException("text"); } if (encoding == null) { throw new ArgumentNullException("textEncoding"); } Source = source; Targets = new ReadOnlyCollection <IIrcMessageTarget>(targets); Text = text; Encoding = encoding; }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandLogIn( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; // var sourceUser = (IrcUser)source; // var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser); // if (twitterUser != null) // throw new InvalidOperationException(string.Format( // "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName, // twitterUser.TwitterUser.ScreenName)); // if (parameters.Count != 2) // throw new InvalidCommandParametersException(1); // // Create new Twitter user and log in to service. // var twitterBotUser = new TwitterBotUser(sourceUser); // var success = twitterBotUser.LogIn(parameters[0], parameters[1]); // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // if (success) // { // // Log-in succeeded. // this.twitterUsers.Add(twitterBotUser); // client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.", // twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name); // } // else // { // // Log-in failed. // client.LocalUser.SendMessage(replyTargets, "Invalid log-in username/password."); // } }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandHome( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { // var sourceUser = (IrcUser)source; // var twitterBotUser = GetTwitterBotUser(sourceUser); // if (parameters.Count != 0) // throw new InvalidCommandParametersException(1); //// List tweets on Home timeline of user. // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // client.LocalUser.SendMessage(replyTargets, "Recent tweets on home timeline of '{0}':", // twitterBotUser.TwitterUser.ScreenName); // foreach (var tweet in twitterBotUser.ListTweetsOnHomeTimeline()) // { // SendTweetInfo(client, replyTargets, tweet); // } }
private void ProcessChatCommandSeen(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { if (source is IrcUser) { if (parameters[0].Equals(source.Name, StringComparison.OrdinalIgnoreCase)) { client.LocalUser.SendMessage(targets, "If you're trying to find yourself, might I suggest long hikes in nature and meditation."); } else if (parameters[0].Equals(ConfigSettings.NickName, StringComparison.OrdinalIgnoreCase)) { client.LocalUser.SendMessage(targets, $"I was last seen being asked a stupid question by {source.Name}."); } else if (UsersSeen.ContainsKey(parameters[0])) { UserSeenStatus status = UsersSeen[parameters[0]]; var mostRecentEvent = status.SeenEvents.OrderBy(kvp => kvp.Value.TimeSeen).Last();// .Values.Select(kvp => kvp).Max(kvp => kvp.TimeSeen); client.LocalUser.SendMessage(targets, $"{parameters[0]} was last seen in {mostRecentEvent.Value.Channel} {mostRecentEvent.Key.ToFriendlyString()}" + $" \"{mostRecentEvent.Value.ActivityText}\" on {status.GetActivityTimeString(mostRecentEvent.Key)}"); } else if (parameters[0].Equals("-l", StringComparison.OrdinalIgnoreCase) && UsersSeen.ContainsKey(parameters[1])) { UserSeenStatus status = UsersSeen[parameters[1]]; string action_time = status.GetActivityTimeString(UserSeenStatus.ActivityType.Action); string quit_time = status.GetActivityTimeString(UserSeenStatus.ActivityType.Part); string join_time = status.GetActivityTimeString(UserSeenStatus.ActivityType.Join); string nick_time = status.GetActivityTimeString(UserSeenStatus.ActivityType.NicknameChange); string text_time = status.GetActivityTimeString(UserSeenStatus.ActivityType.Chat); client.LocalUser.SendMessage(targets, $"action_time: {action_time} quit_time: {quit_time} join_time: {join_time} nick_time: {nick_time} text_time: {text_time}"); } else { client.LocalUser.SendMessage(targets, "I see nothing, nothing!"); } } }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandListUsers( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { var sourceUser = (IrcUser)source; if (parameters.Count != 0) { throw new InvalidCommandParametersException(1); } // List all currently logged-in twitter users. var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); foreach (var tu in CharacterDao.Instance.GetLoggedInCharacters()) { client.LocalUser.SendMessage(replyTargets, "Online Characters: {0}", tu.Name); } }
private void ProcessChatCommandZoneInfo( IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, IList <string> parameters) { int numberOfZoneEnginesConnected = Program.ISCom.ClientCount; List <string> addressList = Program.ISCom.GetZoneEngineIds(); StringBuilder sb = new StringBuilder(); var sourceUser = (IrcUser)source; IList <IIrcMessageTarget> replyTargets = this.GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage( replyTargets, "{0}", "Number of ZoneEngines connected: " + numberOfZoneEnginesConnected); sb.AppendLine("Number of ZoneEngines connected: " + numberOfZoneEnginesConnected); foreach (string s in addressList) { client.LocalUser.SendMessage(replyTargets, "{0}", s); } }
private void ReadChatCommand(IrcClient client, IIrcMessageSource source, IList <IIrcMessageTarget> targets, string command, string[] parameters) { var defaultReplyTarget = GetDefaultReplyTarget(client, source, targets); ChatCommandProcessor processor; if (this.chatCommandProcessors.TryGetValue(command, out processor)) { System.Threading.Tasks.Task.Factory.StartNew(() => { try { processor(client, source, targets, command, parameters); } catch (InvalidCommandParametersException exInvalidCommandParameters) { ConsoleUtilities.WriteError(exInvalidCommandParameters.GetMessage(command)); } catch (Exception ex) { if (source is IIrcMessageTarget) { ConsoleUtilities.WriteError("Error processing '{0}' command: {1}", command, ex.Message); } } }, System.Threading.Tasks.TaskCreationOptions.LongRunning); } else { if (source is IIrcMessageTarget) { ConsoleUtilities.WriteError("Command '{0}' not recognized.", command); } } }
/// <summary> /// Initializes a new instance of the <see cref="IrcMessageEventArgs"/> class. /// </summary> /// <param name="source">The source of the message.</param> /// <param name="targets">A list of the targets of the message.</param> /// <param name="text">The text of the message.</param> /// <param name="encoding">The encoding of the message text.</param> /// <exception cref="ArgumentNullException"><paramref name="targets"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="text"/> is <see langword="null"/>.</exception> public IrcMessageEventArgs(IIrcMessageSource source, IList<IIrcMessageTarget> targets, string text, Encoding encoding) : base() { if (targets == null) throw new ArgumentNullException("target"); if (text == null) throw new ArgumentNullException("text"); if (encoding == null) throw new ArgumentNullException("textEncoding"); this.Source = source; this.Targets = new ReadOnlyCollection<IIrcMessageTarget>(targets); this.Text = text; this.Encoding = encoding; }
/// <inheritdoc/> public IrcPreviewMessageEventArgs(IIrcMessageSource source, IList<IIrcMessageTarget> targets, string text, Encoding encoding) : base(source, targets, text, encoding) { this.Handled = false; }
private void ProcessChatCommandZoneInfo( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { if (!this.executingRequestPlayfieldList) { this.executingRequestPlayfieldList = true; int numberOfZoneEnginesConnected = Program.ISCom.ClientCount; List<string> addressList = Program.ISCom.GetZoneEngineIds(); Program.ISCom.BroadCast(new RequestPlayfieldList()); StringBuilder sb = new StringBuilder(); var sourceUser = (IrcUser)source; IList<IIrcMessageTarget> replyTargets = this.GetDefaultReplyTarget(client, sourceUser, targets); DateTime startWait = DateTime.UtcNow; bool timeOut = true; while ((DateTime.UtcNow - startWait < TimeSpan.FromSeconds(10) && timeOut)) { lock (this.replyQueuePlayfieldList) { if (this.replyQueuePlayfieldList.Count == Program.ISCom.ClientCount) { timeOut = false; } } } if (timeOut) { client.LocalUser.SendMessage(replyTargets, "{0}", "Not all ZoneEngines replied."); } client.LocalUser.SendMessage( replyTargets, "{0}", "Number of ZoneEngines connected: " + numberOfZoneEnginesConnected); while (this.replyQueuePlayfieldList.Count > 0) { RequestPlayfieldList r = this.replyQueuePlayfieldList.Dequeue(); client.LocalUser.SendMessage( replyTargets, "{0}: Playfields {1}", r.ZoneEngineAddress, string.Join( ", ", r.PlayfieldIds.Select( x => PlayfieldLoader.PFData[x.Instance].Name.Trim() + " (" + x.Instance + ")") .ToArray())); } this.executingRequestPlayfieldList = false; } }
private void ReadChatCommand(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, string[] parameters) { var defaultReplyTarget = GetDefaultReplyTarget(client, source, targets); ChatCommandProcessor processor; if (this.chatCommandProcessors.TryGetValue(command, out processor)) { System.Threading.Tasks.Task.Factory.StartNew(() => { try { processor(client, source, targets, command, parameters); } catch (InvalidCommandParametersException exInvalidCommandParameters) { client.LocalUser.SendNotice(defaultReplyTarget, exInvalidCommandParameters.GetMessage(command)); } catch (Exception ex) { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice(defaultReplyTarget, "Error processing '{0}' command: {1}", command, ex.Message); } } }, System.Threading.Tasks.TaskCreationOptions.LongRunning); } else { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice(defaultReplyTarget, "Command '{0}' not recognized.", command); } } }
/// <inheritdoc/> public IrcPreviewMessageEventArgs(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text) : base(source, targets, text) { this.Handled = false; }
internal void HandleMessageReceived(IIrcMessageSource source, IList<IIrcMessageTarget> targets, string text) { var previewEventArgs = new IrcPreviewMessageEventArgs(source, targets, text); OnPreviewMessageReceived(previewEventArgs); if (!previewEventArgs.Handled) OnMessageReceived(new IrcMessageEventArgs(source, targets, text)); }
private void ProcessChatCommandTalk(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { // Send reply containing random message text (generated from Markov chain). int numSentences = -1; if (parameters.Count >= 1) numSentences = int.Parse(parameters[0]); string higlightNickName = null; if (parameters.Count >= 2) higlightNickName = parameters[1] + ": "; SendRandomMessage(client, GetDefaultReplyTarget(client, source, targets), higlightNickName, numSentences); }
/// <summary> /// Need to change Some Information in this code. Probably a Seperate MOTD for IRC or something to have the bot read and send for /// connection Info. /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandServerInfo( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { IList<IIrcMessageTarget> replyTarget = this.GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendMessage(replyTarget, "A How to Setup Connection to CellAO can be found here: TBA"); client.LocalUser.SendMessage( replyTarget, "This is the address for the server: " + Config.Instance.CurrentConfig.ListenIP + " On Port: " + Config.Instance.CurrentConfig.LoginPort); }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ReadChatCommand( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, string[] parameters) { IList<IIrcMessageTarget> defaultReplyTarget = this.GetDefaultReplyTarget(client, source, targets); ChatCommandProcessor processor; if (this.chatCommandProcessors.TryGetValue(command, out processor)) { try { processor(client, source, targets, command, parameters); } catch (InvalidCommandParametersException exInvalidCommandParameters) { client.LocalUser.SendNotice(defaultReplyTarget, exInvalidCommandParameters.GetMessage(command)); } catch (Exception ex) { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice( defaultReplyTarget, "Error processing '{0}' command: {1}", command, ex.Message); } } } else { if (source is IIrcMessageTarget) { client.LocalUser.SendNotice(defaultReplyTarget, "Command '{0}' not recognized.", command); } } }
private void ProcessChatCommandStats(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { // Send reply with bot statistics. var replyTargets = GetDefaultReplyTarget(client, source, targets); client.LocalUser.SendNotice(replyTargets, "Bot launch time: {0:f} ({1:g} ago)", this.launchTime, DateTime.Now - this.launchTime); client.LocalUser.SendNotice(replyTargets, "Number of training messages received: {0:#,#0} ({1:#,#0} words)", this.numTrainingMessagesReceived, this.numTrainingWordsReceived); client.LocalUser.SendNotice(replyTargets, "Number of unique words in vocabulary: {0:#,#0}", this.markovChain.Nodes.Count); }
internal void HandleNoticeReceived(IIrcMessageSource source, IList<IIrcMessageTarget> targets, string text) { var previewEventArgs = new IrcPreviewMessageEventArgs(source, targets, text, this.Client.TextEncoding); OnPreviewNoticeReceived(previewEventArgs); if (!previewEventArgs.Handled) OnNoticeReceived(new IrcMessageEventArgs(source, targets, text, this.Client.TextEncoding)); }
//TODO: Handle Playlist Requests //Request should look like this //https://www.googleapis.com/youtube/v3/playlists?id=id&key=key&part=snippet public bool handleURL(string URL, IrcDotNet.IrcClient ctx, CtcpClient client = null, IIrcMessageSource source = null) { string answer =""; var match = IsYtLink(URL); if(match != null) { string url = "https://www.googleapis.com/youtube/v3/videos"; // video ID url += "?id="; url += match; // API Token url += "&key="; url += "AIzaSyBQwWTl6Md5oOm858tKi4xIBGH3ELSaa_A"; // Fields url += "&fields="; url += "items%28id,snippet%28channelId,title,categoryId%29,statistics%29&part=snippet,statistics"; WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream receivedstream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(receivedstream, encode); Char[] read = new Char[1000000]; // setting max Chars for read (1M suffice aprox. 4700 Tickets) int count = readStream.Read(read, 0, 1000000); String str = ""; while (count > 0) { str = new String(read, 0, count); count = readStream.Read(read, 0, 1000000); } JObject obj = JObject.Parse(str); JArray jarr = (JArray)obj["items"]; foreach (var item in jarr) { answer = item["snippet"].SelectToken("title").ToString(); } ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, answer); return true; } else { if(URL.IndexOf("playlist?list") > 0) { string url = "https://www.googleapis.com/youtube/v3/playlists"; // video ID url += "?id="; url += URL.Substring(URL.IndexOf("playlist?list=") + 14, URL.Length - (URL.IndexOf("playlist?list=") + 14)); url += "&fields=items%2Fsnippet"; // API Token url += "&key="; url += "AIzaSyBQwWTl6Md5oOm858tKi4xIBGH3ELSaa_A"; // Fields url += "&part=snippet"; System.Diagnostics.Debug.WriteLine(url); WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream receivedstream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(receivedstream, encode); Char[] read = new Char[1000000]; // setting max Chars for read (1M suffice aprox. 4700 Tickets) int count = readStream.Read(read, 0, 1000000); String str = ""; while (count > 0) { str = new String(read, 0, count); count = readStream.Read(read, 0, 1000000); } JObject obj = JObject.Parse(str); JArray jarr = (JArray)obj["items"]; foreach (var item in jarr) { answer = item["snippet"].SelectToken("title").ToString(); } ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, answer); return true; } } return false; }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandSend( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; // var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 1) throw new InvalidCommandParametersException(1); //Send System Message. //TODO: Add GM Check and Sending System Message Code here //Twitter Code Delete this crap after new code is written. // var tweetStatus = twitterBotUser.SendTweet(parameters[0].TrimStart()); // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // client.LocalUser.SendMessage(replyTargets, "Tweet sent by {0} at {1}.", tweetStatus.User.ScreenName, // tweetStatus.CreatedDate.ToLongTimeString()); }
private void ProcessChatCommandSend(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 1) throw new InvalidCommandParametersException(1); // Send tweet from user. var tweetStatus = twitterBotUser.SendTweet(parameters[0].TrimStart()); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Tweet sent by {0} at {1}.", tweetStatus.User.ScreenName, tweetStatus.CreatedDate.ToLongTimeString()); }
private void ProcessChatCommandLogIn(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser); if (twitterUser != null) throw new InvalidOperationException(string.Format( "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName, twitterUser.TwitterUser.ScreenName)); if (parameters.Count != 2) throw new InvalidCommandParametersException(1); // Create new Twitter user and log in. var twitterBotUser = new TwitterBotUser(sourceUser); twitterBotUser.LogIn(parameters[0], parameters[1]); this.twitterUsers.Add(twitterBotUser); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.", twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name); }
void IIrcMessageReceiveHandler.HandleNoticeReceived(IIrcMessageSource source, IList<IIrcMessageTarget> targets, string text) { HandleNoticeReceived(source, targets, text); }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandLogIn( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; // var sourceUser = (IrcUser)source; // var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser); // if (twitterUser != null) // throw new InvalidOperationException(string.Format( // "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName, // twitterUser.TwitterUser.ScreenName)); // if (parameters.Count != 2) // throw new InvalidCommandParametersException(1); // // Create new Twitter user and log in to service. // var twitterBotUser = new TwitterBotUser(sourceUser); // var success = twitterBotUser.LogIn(parameters[0], parameters[1]); // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // if (success) // { // // Log-in succeeded. // this.twitterUsers.Add(twitterBotUser); // client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.", // twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name); // } // else // { // // Log-in failed. // client.LocalUser.SendMessage(replyTargets, "Invalid log-in username/password."); // } }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <returns> /// </returns> protected IList<IIrcMessageTarget> GetDefaultReplyTarget( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets) { if (targets.Contains(client.LocalUser) && source is IIrcMessageTarget) { return new[] { (IIrcMessageTarget)source }; } else { return targets; } }
void IIrcMessageReceiveHandler.HandleNoticeReceived(IIrcMessageSource source, IList <IIrcMessageTarget> targets, string text) { HandleNoticeReceived(source, targets, text); }
private void ProcessChatCommandListUsers(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; if (parameters.Count != 0) throw new InvalidCommandParametersException(1); // List all currently logged-in twitter users. var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Currently logged-in Twitter users ({0}):", this.twitterUsers.Count); foreach (var tu in this.twitterUsers) { client.LocalUser.SendMessage(replyTargets, "{0} / {1} ({2} @ {3})", tu.TwitterUser.ScreenName, tu.TwitterUser.Name, tu.IrcUser.NickName, tu.IrcUser.Client.ServerName); } }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="source"> /// </param> /// <param name="targets"> /// </param> /// <param name="command"> /// </param> /// <param name="parameters"> /// </param> private void ProcessChatCommandHome( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { // var sourceUser = (IrcUser)source; // var twitterBotUser = GetTwitterBotUser(sourceUser); // if (parameters.Count != 0) // throw new InvalidCommandParametersException(1); //// List tweets on Home timeline of user. // var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); // client.LocalUser.SendMessage(replyTargets, "Recent tweets on home timeline of '{0}':", // twitterBotUser.TwitterUser.ScreenName); // foreach (var tweet in twitterBotUser.ListTweetsOnHomeTimeline()) // { // SendTweetInfo(client, replyTargets, tweet); // } }
private void ProcessChatCommandLogOut(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 0) throw new InvalidCommandParametersException(1); // Log out Twitter user. twitterBotUser.LogOut(); this.twitterUsers.Remove(twitterBotUser); var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "You are now logged out."); }
/// <summary> /// Initializes a new instance of the <see cref="IrcMessage"/> structure. /// </summary> /// <param name="client">A client object that has sent/will receive the message.</param> /// <param name="prefix">The message prefix that represents the source of the message.</param> /// <param name="command">The command name; either an alphabetic word or 3-digit number.</param> /// <param name="parameters">A list of the parameters to the message. Can contain a maximum of 15 items. /// </param> public IrcMessage(IrcClient client, string prefix, string command, IList<string> parameters) { this.Prefix = prefix; this.Command = command; this.Parameters = parameters; this.Source = client.GetSourceFromPrefix(prefix); }
private void ProcessChatCommandMentions(IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { var sourceUser = (IrcUser)source; var twitterBotUser = GetTwitterBotUser(sourceUser); if (parameters.Count != 0) throw new InvalidCommandParametersException(1); // List tweets on Home timeline of user. var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets); client.LocalUser.SendMessage(replyTargets, "Recent tweets mentioning '{0}':", twitterBotUser.TwitterUser.ScreenName); foreach (var tweet in twitterBotUser.ListTweetsMentioningMe()) { SendTweetInfo(client, replyTargets, tweet); } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="source"></param> /// <param name="targets"></param> /// <param name="command"></param> /// <param name="parameters"></param> private void ProcessChatCommandRegister( IrcClient client, IIrcMessageSource source, IList<IIrcMessageTarget> targets, string command, IList<string> parameters) { //TODO: Add Command to register user for CellAO }