Provides data for events that are raised when an IRC message or notice is sent or received.
Inheritance: System.EventArgs
Esempio n. 1
0
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            var wd = Directory.GetCurrentDirectory();
            var path = Path.Combine(wd, "Messages");
            Directory.CreateDirectory(path);

            var fpath = Path.Combine(path, from + ".txt");
            if (!File.Exists(fpath))
            {
                Channel.Message("There are no messages for you, what a surprise.",true);
                return;
            }
            var cur = File.ReadAllLines(fpath);
            if (cur.Length == 0)
            {
                Channel.Message("There are no messages for you, what a surprise.",true);
                return;
            }
            else
            {
                foreach (var s in cur)
                {
                    Channel.Message(s,true);
                    Channel.Message("Well that's about it. Now don't you feel special?");
                }
                File.WriteAllText(fpath,"");
            }
        }
Esempio n. 2
0
        protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
        {
            var client = channel.Client;

            if (e.Source is IrcUser)
            {
                // Train Markov generator from received message text.
                // Assume it is composed of one or more coherent sentences that are themselves are composed of words.
                var sentences = e.Text.Split(sentenceSeparators);
                foreach (var s in sentences)
                {
                    string lastWord = null;
                    foreach (var w in s.Split(' ').Select(w => cleanWordRegex.Replace(w, string.Empty)))
                    {
                        if (w.Length == 0)
                            continue;
                        // Ignore word if it is first in sentence and same as nick name.
                        if (lastWord == null && channel.Users.Any(cu => cu.User.NickName.Equals(w,
                            StringComparison.InvariantCultureIgnoreCase)))
                            break;

                        markovChain.Train(lastWord, w);
                        lastWord = w;
                        this.numTrainingWordsReceived++;
                    }
                    markovChain.Train(lastWord, null);
                }

                this.numTrainingMessagesReceived++;
            }
        }
Esempio n. 3
0
File: G.cs Progetto: jonbonne/OCTGN
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            if(string.IsNullOrWhiteSpace(message))
                throw new ArgumentException("I'm not a dummy.");

            Channel.Message("http://lmgtfy.com/?q=" + HttpUtility.UrlEncode(message));
        }
Esempio n. 4
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     var client = channel.Client;
     if (e.Source is IrcUser)
     {
         // TODO: keep log of recent chats?
     }
 }
Esempio n. 5
0
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     if (!File.Exists("gtc.txt")) File.Create("gtc.txt").Close();
     var numstr = File.ReadAllText("gtc.txt");
     int num = 0;
     int.TryParse(numstr, out num);
     Channel.Message("GTC=" + num,true);
 }
Esempio n. 6
0
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     if (!File.Exists("todo.txt")) File.Create("todo.txt").Close();
     if(string.IsNullOrWhiteSpace(message))throw new ArgumentException("You summoned me for nothing?");
     var fstr = File.ReadAllLines("todo.txt").ToList();
     fstr.Add(from + ": " + message);
     File.WriteAllLines("todo.txt",fstr);
     Channel.Message("I'll jot that down asshole.");
 }
Esempio n. 7
0
        private void ChannelOnMessageReceived(object sender, IrcMessageEventArgs ircMessageEventArgs)
        {
            if (ircMessageEventArgs.Source.Name == "botctgn") return;

            var commands = AppDomain.CurrentDomain.GetAssemblies()
                     .SelectMany(x => x.GetModules())
                     .SelectMany(x => x.GetTypes())
                     .Where(x => x.GetInterfaces().Any(y => y == typeof(ICommand)))
                     .ToList();

            var fullMess = ircMessageEventArgs.Text;
            var from = ircMessageEventArgs.Source.Name;

            if (string.IsNullOrWhiteSpace(fullMess)) return;

            if (!fullMess.StartsWith("."))
            {
                foreach (var com in commands)
                {
                    var ac = Activator.CreateInstance(com) as ICommand;
                    ac.CanProcessMessage(ircMessageEventArgs, fullMess);
                }
            }
            else
            {
                fullMess = fullMess.Substring(1);
                var firstSpace = fullMess.IndexOf(' ');
                if (firstSpace <= 0) firstSpace = fullMess.Length;
                var comstr = fullMess.Substring(0, firstSpace).Trim();

                var command = commands.FirstOrDefault(x => x.Name.ToLower() == comstr);
                if (command == null)
                {
                    Message("I don't understand '" + ircMessageEventArgs.Text + "'",true);
                    return;
                }

                var messstr = fullMess.Substring(comstr.Length).Trim();

                try
                {
                    var ac = Activator.CreateInstance(command) as ICommand;
                    ac.Channel = this;
                    ac.ProcessMessage(ircMessageEventArgs,from,messstr);
                }
                catch (ArgumentException e)
                {
                    this.Message("Paradox: " + e.Message,true);
                }
                catch(Exception e)
                {
                    Message("Something blew up...I'm scared.",true);
                    this.Message(e.ToString());
                }
            }
        }
Esempio n. 8
0
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     var ret =new WebClient().DownloadString(
                         "https://raw.github.com/kellyelton/OCTGN/master/octgnFX/Octgn/CurrentReleaseVersion.txt").Trim();
     Channel.Message("Current live version is " + ret,true);
     ret =
         new WebClient().DownloadString(
             "https://raw.github.com/kellyelton/OCTGN/master/octgnFX/Octgn/CurrentTestVersion.txt").Trim();
     Channel.Message("Current test version is " + ret,true);
 }
Esempio n. 9
0
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            var num = -1;
            if (!int.TryParse(message, out num))
                throw new ArgumentException("Don't you know what a number is?");

            if(!File.Exists("todo.txt"))File.Create("todo.txt").Close();

            var filestr = File.ReadAllLines("todo.txt").ToList();
            var remstr = filestr[num];
            Channel.Message("[Removed " + num + "] " + remstr,true);
            filestr.RemoveAt(num);
            File.WriteAllLines("todo.txt",filestr);
        }
Esempio n. 10
0
File: H.cs Progetto: jonbonne/OCTGN
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     var commands = AppDomain.CurrentDomain.GetAssemblies()
              .SelectMany(x => x.GetModules())
              .SelectMany(x => x.GetTypes())
              .Where(x => x.GetInterfaces().Any(y => y == typeof(ICommand)))
              .ToList();
     Channel.Message("====================Help====================",true);
     foreach (var c in commands)
     {
         var com = (ICommand)Activator.CreateInstance(c);
         var argstring = string.Join(" ", com.Arguments.Select(x => "{" + x + "}"));
         Channel.Message("." + c.Name.ToLower() +  " " +  argstring + " - " + com.Usage,true);
     }
 }
Esempio n. 11
0
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            if(string.IsNullOrWhiteSpace(message))
                throw new ArgumentException("Yeah...so...I'll just murder no one then...");
            if(message.ToLower() == "kellyelton")
                throw new ArgumentException("I can't murder my creator!");
            if(message.ToLower() == Channel.Channel.Client.LocalUser.NickName.ToLower())
                throw new ArgumentException("That would be suicide, not murder!");

            new Task(() =>
            {
                Channel.Channel.Kick(message, from + " Told me to do it! I didn't mean it, I swear!");
                Thread.Sleep(2000);
                Channel.Message("Well that felt good.");
            }).Start();
        }
Esempio n. 12
0
        private void Form1_MessageReceived1(object sender, IrcMessageEventArgs e)
        {
            if (e.Text == "test")
                client.LocalUser.SendMessage(e.Targets,"testing");
            foreach (var a in client.Channels[0].Users)
            {
                //using (JsonWriter writer = new JsonTextWriter(sw))
                //{
                //    writer.Formatting = Formatting.Indented;

                //    writer.WriteStartObject();
                //    writer.WritePropertyName("username");
                //    writer.WriteValue(a.User.UserName);
                //    writer.WriteEnd();
                //    writer.WriteEndObject();

                //}
            }
        }
Esempio n. 13
0
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     if (from.ToLower() != "kellyelton")
     {
         Channel.Message("You wished " + from);
         return;
     }
     Channel.Message("I will never forget this " + from);
     var task = new Task(
         () =>
         {
             Thread.Sleep(5000);
             this.Channel.Channel.Leave("WHY DOES NOBODY LOVE ME FAAAAAWK!");
             Thread.Sleep(5000);
             Program.client.Quit("WAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
             Thread.Sleep(5000);
             Program.client.Disconnect();
         });
     task.Start();
 }
Esempio n. 14
0
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            var wd = Directory.GetCurrentDirectory();
            var path = Path.Combine(wd, "Messages");
            Directory.CreateDirectory(path);

            var firstSpace = message.IndexOf(' ');
            if(firstSpace <= 0) throw new ArgumentException("What the hell are you trying to do?");

            var to = message.Substring(0, firstSpace );
            var mess = message.Substring(firstSpace, message.Length - to.Length);

            var fpath = Path.Combine(path, to + ".txt");

            if(!File.Exists(fpath))File.Create(fpath).Close();
            var cur = File.ReadAllLines(fpath).ToList();

            cur.Add(DateTime.Now.ToShortTimeString() + " " + DateTime.Now.ToShortDateString() + " " + from + ": " + mess);
            File.WriteAllLines(fpath,cur);
            Channel.Message("So it shall be.");
        }
Esempio n. 15
0
        public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
        {
            if (!File.Exists("todo.txt"))
            {
                Channel.Message("Nothing to do.",true);
                return;
            }

            var lines = File.ReadAllLines("todo.txt");
            if (lines.Length == 0)
            {
                Channel.Message("Nothing to do.",true);
                return;
            }
            Channel.Message("==============TODO==============",true);
            var i = 0;
            foreach (var l in lines)
            {
                Channel.Message("[" + i + "] " + l,true);
                i++;
            }
        }
Esempio n. 16
0
        private void ChannelOnMessageReceived(object sender, IrcMessageEventArgs ircMessageEventArgs)
        {
            if (ircMessageEventArgs.Source.Name == "GaryBot") return;
            //if (ircMessageEventArgs.Text.Trim().EndsWith("?"))
            //{
            //    this.Message("http://lmgtfy.com/?q=" + HttpUtility.UrlEncode(ircMessageEventArgs.Text));
            //}
            return;
            var from = ircMessageEventArgs.Source.Name.ToLower();
            var num = random.Next(0, 100);
            if (from.Contains(Who.ToLower()) || from.Contains("brine") || num > 55)
            {
                noDb0Counter = 0;
                dboResponded = true;
                var reply = "";

                while (String.IsNullOrWhiteSpace(reply))
                {
                    try
                    {
                        reply = Bot.Think(ircMessageEventArgs.Text);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            Bot = new ChatterBotAPI.ChatterBotFactory().Create(ChatterBotType.CLEVERBOT).CreateSession();
                        }
                        catch
                        {

                        }
                    }
                }

                this.Message(reply);
            }
        }
Esempio n. 17
0
        public bool CanProcessMessage(IrcMessageEventArgs args, string message)
        {
            if(args.Source.Name.ToLower().Contains("grave"))
                if (message.ToLower().Contains(":p"))
                {
                    int count = 0, n = 0;

                    while ((n = message.ToLower().IndexOf(":p", n, StringComparison.InvariantCulture)) != -1)
                    {
                        n += ":p".Length;
                        ++count;
                    }

                    if (!File.Exists("gtc.txt")) File.Create("gtc.txt").Close();
                    var numstr = File.ReadAllText("gtc.txt");
                    int num = 0;
                    int.TryParse(numstr, out num);
                    num+= count;
                    File.WriteAllText("gtc.txt", num.ToString());
                    return true;
                }
            return false;
        }
Esempio n. 18
0
        private static void IrcClient_Channel_MessageReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = (IrcChannel) sender;
              if (e.Source is IrcUser) {
            var user = (IrcUser) e.Source;
            var hostName = user.HostName;
            var text = e.Text;
            if (user.HostName == "head.against.the.heart" && e.Text[0] == '~') {
              hostName = "heart.against.the.head";
              text = e.Text.Substring(1);
            }
            Console.WriteLine("[{0}]({1}): {2}.", channel.Name, e.Source.Name, text);

            if (text[0] == '<') {
              return;
            }

            var meDetection = new Regex(@"\u0001ACTION (.*)\u0001").Match(text);
            if (meDetection.Success) {
              text = $"/me {meDetection.Groups[1]}";
            }

            if (PrivateConstants.HostNameToDggKey.ContainsKey(hostName)) {
              if (!_hostNameToWebSockets.ContainsKey(hostName)) {
            _hostNameToWebSockets.Add(hostName, new WebSocketClient(PrivateConstants.HostNameToDggKey[hostName]));
            SendToEcho($"Connecting {user.NickName} with {hostName}...");
            _hostNameToWebSockets[hostName].Run(doNothingProcessor);
            Thread.Sleep(3000); // TODO fix, this is hacky
              }
              _hostNameToWebSockets[hostName].Visit(new PublicMessage(text));
            }

              } else {
            Console.WriteLine("[{0}]({1}) Message: {2}.", channel.Name, e.Source.Name, e.Text);
              }
        }
Esempio n. 19
0
        private void IrcClient_Channel_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = (IrcChannel)sender;

            OnChannelNoticeReceived(channel, e);
        }
Esempio n. 20
0
        private void IrcClient_LocalUser_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var localUser = (IrcLocalUser)sender;

            OnLocalUserNoticeReceived(localUser, e);
        }
Esempio n. 21
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="eventArgs">
        /// </param>
        /// <returns>
        /// </returns>
        private bool ReadChatCommand(IrcClient client, IrcMessageEventArgs eventArgs)
        {
            // Check if given message represents chat command.
            string line = eventArgs.Text;
            if (line.Length > 1 && line.StartsWith("."))
            {
                // Process command.
                string[] parts = commandPartsSplitRegex.Split(line.Substring(1)).Select(p => p.TrimStart('/')).ToArray();
                string command = parts.First();
                string[] parameters = parts.Skip(1).ToArray();
                this.ReadChatCommand(client, eventArgs.Source, eventArgs.Targets, command, parameters);
                return true;
            }

            return false;
        }
Esempio n. 22
0
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="e">
        /// </param>
        private void IrcClient_LocalUser_MessageReceived(object sender, IrcMessageEventArgs e)
        {
            var localUser = (IrcLocalUser)sender;

            if (e.Source is IrcUser)
            {
                // Read message and process if it is chat command.
                if (this.ReadChatCommand(localUser.Client, e))
                {
                    return;
                }
            }

            this.OnLocalUserMessageReceived(localUser, e);
        }
Esempio n. 23
0
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="e">
        /// </param>
        private void IrcClient_Channel_MessageReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = (IrcChannel)sender;

            if (e.Source is IrcUser)
            {
                // Read message and process if it is chat command.
                if (this.ReadChatCommand(channel.Client, e))
                {
                    return;
                }
            }

            this.OnChannelMessageReceived(channel, e);
        }
 protected override void OnLocalUserMessageReceived(IrcLocalUser localUser, IrcMessageEventArgs e)
 {
     //
 }
Esempio n. 25
0
 private void MessageReceived(object sender, IrcMessageEventArgs e, IrcClient client)
 {
     handleCommands(sender, e, client);
     handleRegexes(sender, e, client);
 }
Esempio n. 26
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="e">
 /// </param>
 protected abstract void OnChannelNoticeReceived(IrcChannel channel, IrcMessageEventArgs e);
Esempio n. 27
0
 /// <summary>
 /// </summary>
 /// <param name="localUser">
 /// </param>
 /// <param name="e">
 /// </param>
 protected abstract void OnLocalUserNoticeReceived(IrcLocalUser localUser, IrcMessageEventArgs e);
Esempio n. 28
0
        private static void IrcClient_LocalUser_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var localUser = (IrcLocalUser)sender;

            Console.WriteLine("Notice: {0}.", e.Text);
        }
Esempio n. 29
0
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="e">
        /// </param>
        private void IrcClient_Channel_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = (IrcChannel)sender;

            this.OnChannelNoticeReceived(channel, e);
        }
Esempio n. 30
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     //
 }
Esempio n. 31
0
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="e">
        /// </param>
        private void IrcClient_LocalUser_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var localUser = (IrcLocalUser)sender;

            this.OnLocalUserNoticeReceived(localUser, e);
        }
Esempio n. 32
0
 protected virtual void OnLocalUserMessageReceived(IrcLocalUser localUser, IrcMessageEventArgs e)
 {
 }
Esempio n. 33
0
        private void handleRegexes(object sender, IrcMessageEventArgs e, IrcClient client)
        {
            string channel = "";
            foreach (var messageTarget in e.Targets)
            {
                if (messageTarget is IrcChannel)
                {
                    channel = messageTarget.Name;
                    break;
                }
            }

            foreach (var regex in handlers.regexes)
            {
                if (regex.Key.IsMatch(e.Text))
                {
                    regex.Value(client, channel, e.Source as IrcUser, e.Text);
                }
            }
        }
Esempio n. 34
0
 protected virtual void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
 }
Esempio n. 35
0
        private void handleCommands(object sender, IrcMessageEventArgs e, IrcClient client)
        {
            var parts = e.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            var cmd = parts[0].Substring(1);

            if (!handlers.commands.ContainsKey(cmd))
            {
                return;
            }

            var processedMessage = "";
            if (e.Text.Length >= (cmd.Length + 2))
            {
                processedMessage = e.Text.Substring(cmd.Length + 2);
            }

            string channel = "";

            foreach (var messageTarget in e.Targets)
            {
                if (messageTarget is IrcChannel)
                {
                    channel = messageTarget.Name;
                    break;
                }
            }

            if (channel == "")
            {
                return;
            }

            // let's check ignores!
            if (ignoreFeature.IsIgnored(e.Source as IrcUser, channel))
            {
                return;
            }

            handlers.commands[cmd](client, channel, e.Source as IrcUser, processedMessage);
        }
Esempio n. 36
0
 protected override void OnLocalUserMessageReceived(IrcLocalUser localUser, IrcMessageEventArgs e)
 {
     //
 }
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     //
 }
Esempio n. 38
0
        private static void IrcClient_Channel_NoticeReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = (IrcChannel)sender;

            Console.WriteLine("[{0}] Notice: {1}.", channel.Name, e.Text);
        }