Inheritance: System.EventArgs
        void BotOnRawMessage(object sender, IrcEventArgs e)
        {
            if ((e.Data.ReplyCode == ReplyCode.IdentifiedToServices) && (e.Data.RawMessageArray[3] == nick) && (e.Data.Message.StartsWith("is signed on as account")))
            {
                bot.OnRawMessage -= BotOnRawMessage;
                identity = e.Data.MessageArray[5];
                lock (this) Monitor.Pulse(this);
            }
            if ((e.Data.ReplyCode == ReplyCode.IdentifiedFreenode) && (e.Data.RawMessageArray[3] == nick) && (e.Data.Message.StartsWith("is logged in as")))
            {
                bot.OnRawMessage -= BotOnRawMessage;
                identity = e.Data.RawMessageArray[4];
                lock (this) Monitor.Pulse(this);
            }
            if ((e.Data.ReplyCode == ReplyCode.WhoIsRegistered) && (e.Data.RawMessageArray[3] == nick) && (e.Data.Message.StartsWith("is a registered nick")))
            {
                bot.OnRawMessage -= BotOnRawMessage;
                identity = e.Data.RawMessageArray[3];
                lock (this) Monitor.Pulse(this);
            }
            if ((e.Data.ReplyCode == ReplyCode.EndOfWhoIs) && (e.Data.RawMessageArray[3] == nick))
            {
                bot.OnRawMessage -= BotOnRawMessage;
                lock (this) Monitor.Pulse(this);
            }

            if (e.Data.ReplyCode == ReplyCode.WhoIsRegistered)
            {
                Log.Instance.Log(e.Data.Message, Level.Trace);
            }
        }
 protected PiVoteAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
 {
     BotMethods = botMethods;
     Client = client;
     CertificateStorage = certificateStorage;
     EventArgs = eventArgs;
 }
        public void HandleAlpha(object sender, IrcEventArgs e)
        {
            string target = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;

            var document = new XDocument();
            var request = WebRequest.Create(RequestBase + InputQuery + HttpUtility.UrlEncode(string.Join(" ", e.Data.MessageArray.Skip(1))) + AmpersAnd + AppIDQuery) as HttpWebRequest;
            if (request == null) return;

            request.UserAgent = "Mozilla/5.0 (Huffelpuff)";
            document = XDocument.Load(request.GetResponse().GetResponseStream());

            foreach (var pod in document.Descendants("pod"))
            {
                string id = pod.Attribute("id").Value;
                string title = pod.Attribute("title").Value;

                foreach (var subpod in pod.Descendants("subpod"))
                {
                    string plaintext = subpod.Descendants("plaintext").First().Value.Replace("\n", " ");
                    if (!string.IsNullOrWhiteSpace(plaintext))
                    {
                        BotMethods.SendMessage(SendType.Message, target, title + ": " + plaintext);
                    }
                }
            }
        }
Example #4
0
 public static void IrcClientListCallback(object sender, IrcEventArgs e)
 {
     if (e.Data.ReplyCode == ReplyCode.List)
     {
         Console.WriteLine("On the IRC channel " + CHANNEL + " are " + e.Data.RawMessageArray[4] + " users");
         e.Data.Irc.Disconnect();
     }
 }
        private void ChangeNick(object sender, IrcEventArgs e)
        {
            if (e.Data.MessageArray.Length <= 1) { return; }
            if (!isValidNick(e.Data.MessageArray[1])) { return; }

            bot.RfcNick(e.Data.MessageArray[1]);
            Settings.Default.Nick = e.Data.MessageArray[1];
            Settings.Default.Save();
        }
 private void CalculateHandler(object sender, IrcEventArgs e)
 {
     var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
     try
     {
         var result = magicCalculator.Calculate(e.Data.Message.Substring(6));
         if (result.HasResult)
         {
             BotMethods.SendMessage(SendType.Message, sendto, "[" + result.ResultProvider.ToString()[0] + "] Result: " + result.Result);
             return;
         }
     }
     catch (Exception) { }
     BotMethods.SendMessage(SendType.Message, sendto, "no result!");
 }
        public TallyAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
            : base(botMethods, client, certificateStorage, eventArgs)
        {
            if (eventArgs.Data.MessageArray.Length == 2)
            {
                int votingNumberTemp;

                if (int.TryParse(eventArgs.Data.MessageArray[1], out votingNumberTemp))
                {
                    if (votingNumberTemp >= 0)
                    {
                        votingNumber = votingNumberTemp;
                    }
                }
            }
        }
 private void ConfigGet(object sender, IrcEventArgs e)
 {
     string sendto = e.Data.Channel.IsNullOrEmpty() ? e.Data.Nick : e.Data.Channel;
     if (e.Data.MessageArray.Length < 2)
     {
         foreach (var line in bot.Properties.GetType().GetProperties().Where(property => property.CanRead).Select(property => property.Name).ToLines(350))
         {
             bot.SendMessage(SendType.Message, sendto, line);
         }
     }
     else
     {
         var propertyInfos = bot.Properties.GetType().GetProperties().Where(property => property.CanRead && property.Name == e.Data.MessageArray[1]).SingleOrDefault();
         if (propertyInfos != null)
             bot.SendMessage(SendType.Message, sendto, "Current Value: " + propertyInfos.GetValue(bot.Properties, null));
         else
             bot.SendMessage(SendType.Message, sendto, "Dont know that property");
     }
 }
        void BotEvents_OnChannelMessage(object sender, IrcEventArgs e)
        {
            if (!e.Data.Message.ToLower().Contains(BotMethods.Nickname.ToLower())) return;

            var msg = e.Data.Message.ToLower().Trim().StartsWith(BotMethods.Nickname.ToLower())
                             ? e.Data.Message.Trim().Substring(BotMethods.Nickname.Length + 1)
                             : e.Data.Message.Trim();
            User myUser;
            if (myUsers.ContainsKey(e.Data.Nick))
            {
                myUser = myUsers[e.Data.Nick];
            }
            else
            {
                myUser = new User(e.Data.Nick, myAimlBot);
                myUser.Predicates.addSetting("name", e.Data.Nick);

                myUsers.Add(e.Data.Nick, myUser);
            }
            var r = new Request(msg, myUser, myAimlBot);
            var res = myAimlBot.Chat(r);
            BotMethods.SendMessage(SendType.Message, e.Data.Channel, res.Output);
        }
        private void Utf8Handler(object sender, IrcEventArgs e)
        {
            var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;

            if (e.Data.MessageArray.Length > 1)
            {
                BotMethods.SendMessage(SendType.Message, sendto,
                                       e.Data.MessageArray[1] == "äöü"
                                           ? "Yes your text is in UTF-8"
                                           : "Sorry thats either not UTF-8 or you havent typed !utf8 äöü");
            }
        }
 internal void HandleOnUnAway(object sender, IrcEventArgs e)
 {
     if (OnUnAway != null)
         OnUnAway(this, e);
 }
        private void TweetStatsHandler(object sender, IrcEventArgs e)
        {
            string sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
            if (e.Data.MessageArray.Length < 2)
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Too few arguments for 'add'! Try '!help !tweet-stats'.");
                return;
            }

            if (twitterAccounts.ContainsKey(e.Data.MessageArray[1].ToLower()))
            {
                var user = twitterAccounts[e.Data.MessageArray[1].ToLower()].GetStats();
                BotMethods.SendMessage(SendType.Message, sendto, "Followers: {0}, Friends: {1}, Statuses: {2}, -> {3}"
                                       .Fill(user.FollowersCount, user.FriendsCount, user.StatusesCount, user.Url));
            }
            else
            {
                BotMethods.SendMessage(SendType.Message, sendto, "I dont know a tweet with the name: {0}.".Fill(e.Data.MessageArray[1].ToLower()));
            }
        }
        private void TweetTrendsHandler(object sender, IrcEventArgs e)
        {
            var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;

            var trends = TwitterWrapper.GetTrends();
            if (trends != null)
            {
                foreach (var line in trends.Trends.Select(trend => trend.Name).ToLines(350, ", ", "Current trends: ", ""))
                {
                    BotMethods.SendMessage(SendType.Message, sendto, line);
                }
                return;
            }
        }
        private void ImportHandler(object sender, IrcEventArgs e)
        {
            if (e != null) { return; }

            var importer = new KewlQuizImport();

            importer.ImportFile(new FileInfo("Z:\\Chats\\mirc\\kewlquiz\\Apophis.txt"), quizData);
        }
        private void StatusHandler(object sender, IrcEventArgs e)
        {
            if (actionQueue.Count == 0)
            {
                BotMethods.SendMessage(SendType.Message, e.Data.Channel, "Pi-Vote: No action currently executing.");
            }
            else
            {
                var action = actionQueue.Peek();
                BotMethods.SendMessage(SendType.Message, e.Data.Channel, "Pi-Vote: " + action.StatusMessage);

                if (actionQueue.Count > 1)
                {
                    BotMethods.SendMessage(SendType.Message, e.Data.Channel, string.Format("Pi-Vote: {0} more action queued.", actionQueue.Count - 1));
                }
            }
        }
 internal void HandleOnUserModeChange(object sender, IrcEventArgs e)
 {
     if (OnUserModeChange != null)
         OnUserModeChange(this, e);
 }
 private void SetFormat(object sender, IrcEventArgs e)
 {
     var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
     if (e.Data.MessageArray.Length < 2)
     {
         BotMethods.SendMessage(SendType.Message, sendto, MessageFormat);
     }
     else
     {
         TwitterSettings.Default.TweetFormat = e.Data.MessageArray[1] == "RESET" ? null : e.Data.Message.Substring(e.Data.MessageArray[0].Length + 1);
     }
 }
        private void AdminTweet(object sender, IrcEventArgs e)
        {
            var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;

            switch (e.Data.MessageArray[0].ToLower())
            {
                case "!+tweet":
                    if (e.Data.MessageArray.Length < 3)
                    {
                        BotMethods.SendMessage(SendType.Message, sendto, "Too few arguments for 'add'! Try '!help !+tweet'.");
                        return;
                    }
                    var friendlyname = e.Data.MessageArray[1].ToLower();
                    if (twitterAccounts.ContainsKey(friendlyname))
                    {
                        BotMethods.SendMessage(SendType.Message, sendto, "Tweet '{0}' already exists.".Fill(twitterAccounts[e.Data.MessageArray[1].ToLower()].FriendlyName));
                        break;
                    }
                    twitterAccounts.Add(friendlyname, new TwitterWrapper(friendlyname, e.Data.MessageArray[2]));

                    BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' successfully added. Please go to {1} validate account and activate account by !tweet-pin {0} <pin>".Fill(friendlyname, twitterAccounts[friendlyname].AuthenticationUrl));
                    break;
                case "!-tweet":
                    if (e.Data.MessageArray.Length < 2)
                    {
                        BotMethods.SendMessage(SendType.Message, sendto, "Too few arguments for 'remove'! Try '!help !-tweet'.");
                        return;
                    }
                    if (twitterAccounts.ContainsKey(e.Data.MessageArray[1].ToLower()))
                    {
                        twitterAccounts[e.Data.MessageArray[1].ToLower()].RemoveAccount();
                        twitterAccounts.Remove(e.Data.MessageArray[1].ToLower());
                        BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' successfully removed.".Fill(e.Data.MessageArray[1].ToLower()));
                    }
                    else
                    {
                        BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' does not exists! Try '!tweet'.".Fill(e.Data.MessageArray[1].ToLower()));
                    }
                    break;
                default:
                    break;
            }
        }
 private void CountdownHandler(object sender, IrcEventArgs e)
 {
 }
 private void SetOption(object sender, IrcEventArgs e)
 {
 }
 private void GetList(object sender, IrcEventArgs e)
 {
 }
 private void TallyHandler(object sender, IrcEventArgs e)
 {
     var action = new TallyAction(BotMethods, client, certificateStorage, e);
     AddAction(action);
 }
 private void HandleRequest(object sender, IrcEventArgs e)
 {
     //TODO: Request Handler
 }
        private void TagHandler(object sender, IrcEventArgs e)
        {
            string sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
            if (e.Data.MessageArray[0].ToLower() == "!+tag")
            {
                var tag = new TwitterTag { Tag = e.Data.MessageArray[1] };
                TwitterData.TwitterTags.InsertOnSubmit(tag);
                TwitterData.SubmitChanges();

                BotMethods.SendMessage(SendType.Message, sendto, "Automatic Search activated: " + "http://search.twitter.com/search?q=" + HttpUtility.UrlEncode(e.Data.MessageArray[1]));
            }
            if (e.Data.MessageArray[0].ToLower() == "!-tag")
            {
                var tag = TwitterData.TwitterTags.Where(t => t.Tag == e.Data.MessageArray[1]).FirstOrDefault();

                if (tag != null)
                {
                    TwitterData.TwitterTags.DeleteOnSubmit(tag);
                    TwitterData.SubmitChanges();
                }

            }
            if (e.Data.MessageArray[0].ToLower() == "!tags")
            {
                foreach (string line in TwitterData.TwitterTags.Select(t => t.Tag).ToLines(350))
                {
                    BotMethods.SendMessage(SendType.Message, sendto, line);
                }
            }
        }
        private void ReloadPlugins(object sender, IrcEventArgs e)
        {
            pluginManager.ReloadPlugins();

            // The following call prevents the OnChannelMessage/OnQueryMessage Event to be processed further,
            // cause at this points its not guaranteed that the other Event Handlers still exists.
            // Because all objects out of this AppDomain are destroyed now. However we are still in the
            // Event Handling. We stop that here.
            // This means that "!reload" gets special treating and cannot be used for anything else.
            Thread.CurrentThread.Abort();
        }
        private void TweetHandler(object sender, IrcEventArgs e)
        {
            string sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
            bool retweet = (e.Data.MessageArray[0] == "!retweet");

            if (e.Data.MessageArray.Length < 2)
            {
                foreach (string line in twitterAccounts.Select(item => item.Value.FriendlyName).ToLines(350, ", ", "Tweet accounts loaded: ", "."))
                {
                    BotMethods.SendMessage(SendType.Message, sendto, line);
                }
                return;
            }
            if (e.Data.MessageArray.Length < 3 && twitterAccounts.Count > 1)
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Nothing to say? I don't tweet empty messages! try !help !tweet.");
                return;
            }
            if (twitterAccounts.ContainsKey(e.Data.MessageArray[1].ToLower()))
            {
                string status = e.Data.Message.Substring(e.Data.MessageArray[0].Length + e.Data.MessageArray[1].Length + 2);
                try
                {
                    status = Shorten(status);
                    if (status.Length > 140)
                    {
                        BotMethods.SendMessage(SendType.Message, sendto, "Error on feed '{0}': Message longer than 140 characters(140+{1}), try rewriting and tweet again, nothing was tweeted.".Fill(twitterAccounts[e.Data.MessageArray[1].ToLower()].FriendlyName, status.Length - 140));
                        return;
                    }
                    var returnFromTwitter = twitterAccounts[e.Data.MessageArray[1].ToLower()].SendStatus(status, retweet);

                    if (IsFail(Enumerable.Repeat(returnFromTwitter, 1), sendto, twitterAccounts[e.Data.MessageArray[1].ToLower()].FriendlyName))
                    {
                        if (!twitterAccounts[e.Data.MessageArray[1].ToLower()].IsAuthenticated)
                        {
                            BotMethods.SendMessage(SendType.Message, sendto, "Error on feed '{0}': not authorized yet. New token generated: Please go to {1} validate account and activate account by !tweet-pin {0} <pin>".Fill(e.Data.MessageArray[1].ToLower(), twitterAccounts[e.Data.MessageArray[1].ToLower()].AuthenticationUrl));
                        }

                    }
                    else
                    {
                        string statusUrl = "http://twitter.com/{0}/status/{1}".Fill(returnFromTwitter.Author.ScreenName, returnFromTwitter.Id);

                        BotMethods.SendMessage(SendType.Message, sendto, "successfully tweeted on feed '{0}', Link to Status: {1}".Fill(twitterAccounts[e.Data.MessageArray[1].ToLower()].FriendlyName, statusUrl));
                        return;
                    }
                    return;
                }
                catch (Exception exception)
                {
                    Log.Instance.Log(exception);
                }
            }
            else if (twitterAccounts.Count == 1)
            {

            }
            else
            {
                BotMethods.SendMessage(SendType.Message, sendto, "I dont know a tweet with the name: {0}.".Fill(e.Data.MessageArray[1].ToLower()));
                return;
            }
        }
        private void PinHandler(object sender, IrcEventArgs e)
        {
            var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
            if (e.Data.MessageArray.Length < 3)
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Too few arguments: use !tweet-pin <feed> <pin>");
                return;
            }
            var friendlyname = e.Data.MessageArray[1];
            if (!twitterAccounts.ContainsKey(friendlyname))
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Unknown feed: use !tweet-pin <feed> <pin>");
                return;
            }
            var pin = e.Data.MessageArray[2];

            if (twitterAccounts[friendlyname].AuthenticateToken(pin))
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' is authorized, you can tweet now!".Fill(friendlyname));
            }
            else
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' authorization failed. Please go to {1} validate account and activate account by !tweet-pin {0} <pin>".Fill(friendlyname, twitterAccounts[friendlyname].AuthenticationUrl));
            }
        }
 private void ListVotingsHandler(object sender, IrcEventArgs e)
 {
     var action = new ListVotingsAction(BotMethods, client, certificateStorage, e);
     AddAction(action);
 }
 private void NowHandler(object sender, IrcEventArgs e)
 {
     BotMethods.SendMessage(SendType.Message, e.Data.Nick, "Es ist jetzt " + DateTime.Now.ToString("HH:mm:ss") + "Uhr" + DateTime.Now.ToString("K") + ".");
 }
        private void ResetHandler(object sender, IrcEventArgs e)
        {
            var sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;
            if (e.Data.MessageArray.Length < 2)
            {
                BotMethods.SendMessage(SendType.Message, sendto, "Too few arguments! Try '!help !tweet-reset'.");
            }

            TwitterWrapper account;
            if (twitterAccounts.TryGetValue(e.Data.MessageArray[1].ToLower(), out account))
            {
                account.ResetToken();
                BotMethods.SendMessage(SendType.Message, sendto, "Feed '{0}' successfully reset. Please go to {1} validate account and activate account by !tweet-pin {0} <pin>".Fill(account.FriendlyName, account.AuthenticationUrl));
            }
            else
            {
                BotMethods.SendMessage(SendType.Message, sendto, "No account with name '{0}'.".Fill(e.Data.MessageArray[1].ToLower()));
            }
        }