Inheritance: CwIRC.IRCMessage
Esempio n. 1
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, @"^(calc(ulate)?)$", RegexOptions.IgnoreCase))
                return null;
            if (message.ParameterList.Count == 0)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give an expression to calculate!", message.ReplyTo) };

            try
            {
                string query = HttpUtility.UrlEncode(message.Parameters);
                Stream responseStream = URL.SendToServer("http://www.google.com/ig/calculator?hl=en&q=" + query);
                string jsonResponse = URL.ReceiveFromServer(responseStream);

                Result result = JsonConvert.DeserializeObject<Result>(jsonResponse);
                if (result.rhs.Length > 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Result: " + result.rhs, message.ReplyTo) };
                if (result.error.Length > 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Calculation Error or Unsupported Operations", message.ReplyTo) };

                return null;
            }
            catch (System.Exception ex)
            {
                Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                return null;
            }
        }
Esempio n. 2
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (Regex.IsMatch(message.Command, "^(nick(name)?|name)$", RegexOptions.IgnoreCase))
     {
         if (message.TargetType == IRCMessage.TargetTypes.CHANNEL && ChannelList.UserIsAnyOp(message.User.Name, message.ReplyTo))
         {
             if (message.ParameterList.Count > 0)
             {
                 return new List<IRCResponse>() { new IRCResponse(ResponseType.Raw, "NICK " + message.ParameterList[0], "") };
             }
             else
             {
                 return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Change my nick to what?", message.ReplyTo) };
             }
         }
         else
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You need to be an operator to change my name :P", message.ReplyTo) };
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 3
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if ((DateTime.UtcNow - _lastDate).Minutes < 5)
                return null;

            lock (Events.eventListLock)
            {
                for (int i = 0; i < Events.EventList.Count; i++)
                {
                    Events.EventStruct autoEvent = Events.EventList[i];

                    if (autoEvent.EventDate <= _lastDate || autoEvent.EventDate >= DateTime.UtcNow)
                        continue;

                    List<IRCResponse> responses = new List<IRCResponse>();
                    Events.EventStruct lastEvent = autoEvent;
                    while (autoEvent.EventDate < DateTime.UtcNow)
                    {
                        responses.Add(new IRCResponse(ResponseType.Say, "It's time for \"" + autoEvent.EventName + "\"!", message.ReplyTo));
                        lastEvent = autoEvent;
                        autoEvent = Events.EventList[++i];
                    }
                    _lastDate = lastEvent.EventDate;

                    if (responses.Count > 1)
                        return responses;

                    break;
                }
            }

            return null;
        }
Esempio n. 4
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (Regex.IsMatch(message.Command, "^(unignore)$", RegexOptions.IgnoreCase))
     {
         if (message.TargetType == IRCMessage.TargetTypes.CHANNEL && ChannelList.UserIsAnyOp(message.User.Name, message.ReplyTo))
         {
             foreach (string parameter in message.ParameterList)
             {
                 if (Settings.Instance.IgnoreList.Contains(parameter.ToUpper()))
                 {
                     Settings.Instance.IgnoreList.Remove(parameter.ToUpper());
                 }
             }
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, message.Parameters + (message.ParameterList.Count > 1 ? " are " : " is ") + "no longer ignored.", message.ReplyTo) };
         }
         else
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You need to be an operator to make me unignore people :P", message.ReplyTo) };
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 5
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (message.Type != "PRIVMSG"
                || message.TargetType != IRCMessage.TargetTypes.CHANNEL
                || ChannelList.ChannelHasMode(message.ReplyTo, 'U'))
                return null;

            Match match = Regex.Match(message.MessageString, @"https?://[^\s]+", RegexOptions.IgnoreCase);
            if (!match.Success)
                return null;

            if (Regex.IsMatch(match.Value, @"\.(jpe?g|gif|png|bmp)$"))
                return null;

            string response = null;

            Match youtubeMatch = Regex.Match(match.Value, @"www\.youtube\.com/watch\?v=([^&]+)");
            if (youtubeMatch.Success)
                response = FollowYouTube(youtubeMatch.Groups[1].Value);
            else
                response = FollowStandard(match.Value);

            if (response == null)
                return null;

            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, response, message.ReplyTo) };
        }
Esempio n. 6
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (Regex.IsMatch(message.Command, @"^(goo\.?gl|shorten)$", RegexOptions.IgnoreCase))
     {
         // URL given
         if (message.ParameterList.Count > 0)
         {
             string shortURL = URL.Shorten(message.Parameters);
             if (shortURL != null)
             {
                 return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, shortURL, message.ReplyTo) };
             }
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No URL detected in your message.", message.ReplyTo) };
         }
         // No URL given
         else
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a URL to shorten!", message.ReplyTo) };
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 7
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^((outstanding|s(ent)?)tells)$", RegexOptions.IgnoreCase))
                return null;

            List<IRCResponse> responses = new List<IRCResponse>();

            lock (Tell.tellMapLock)
            {
                foreach (KeyValuePair<string, List<Tell.TellMessage>> kvp in Tell.MessageMap)
                {
                    bool fromUser = false;
                    foreach (Tell.TellMessage msg in kvp.Value)
                    {
                        if (msg.From.ToLowerInvariant() != message.User.Name.ToLowerInvariant())
                            continue;

                        if (!fromUser)
                        {
                            fromUser = true;
                            responses.Add(new IRCResponse(ResponseType.Say, "To " + kvp.Key, message.ReplyTo));
                        }
                        responses.Add(new IRCResponse(ResponseType.Say, " > " + msg.Message, message.ReplyTo));
                    }
                }
            }

            if (responses.Count == 0)
            {
                responses.Add(new IRCResponse(ResponseType.Say, "There are no messages from you that have not already been received.", message.ReplyTo));
            }

            return responses;
        }
Esempio n. 8
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (Regex.IsMatch(message.Command, "^(translate)$", RegexOptions.IgnoreCase))
     {
         if (message.ParameterList.Count > 0)
         {
             string translatedString;
             try
             {
                 string translateTerm = message.Parameters.Replace('"', ' ');
                 translatedString = Gapi.Language.Translator.Translate(translateTerm, Gapi.Language.Language.English);
             }
             catch (Gapi.Core.GapiException ex)
             {
                 Logger.Write(ex.ToString(), Settings.Instance.ErrorFile);
                 translatedString = "Couldn't work out what language you're using.";
             }
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, translatedString, message.ReplyTo) };
         }
         else
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Translate what?", message.ReplyTo) };
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 9
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^((last)?(commit|change))$", RegexOptions.IgnoreCase))
            {
                URL.WebPage commitFeed;
                try
                {
                    commitFeed = URL.FetchURL("https://github.com/MatthewCox/MoronBot/commits/master.atom");
                }
                catch (System.Exception ex)
                {
                    Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                    commitFeed.Page = null;
                }

                if (commitFeed.Page != null)
                {
                    MatchCollection commitMessages = Regex.Matches(commitFeed.Page, @"width:81ex'>((?!Merge branch ')[^<]+?)\&lt;/pre>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    string lastMessage = Regex.Replace(commitMessages[0].Groups[1].Value, @"\n+", " | ");
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Last Commit Message: " + lastMessage, message.ReplyTo) };
                }
                else
                {
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Couldn't fetch the commit feed, GitHub may be down?", message.ReplyTo) };
                }
            }

            return null;
        }
Esempio n. 10
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(r(emove)?event)$", RegexOptions.IgnoreCase))
                return null;

            if (message.ParameterList.Count == 0)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't specify an event to remove!", message.ReplyTo) };

            List<IRCResponse> response = new List<IRCResponse>();

            int index = 0;
            lock (Events.eventListLock)
            {
                index = Events.EventList.FindIndex(s => Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));

                if (index < 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No event matching \"" + message.Parameters + "\" found in event list!", message.ReplyTo) };

                response.Add(new IRCResponse(ResponseType.Say, "Event \"" + Events.EventList[index].EventName + "\", with date \"" + Events.EventList[index].EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)") + "\" removed from the event list!", message.ReplyTo));
                Events.EventList.RemoveAt(index);
            }

            Events.SaveEvents();

            return response;
        }
Esempio n. 11
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, @"^dateof$", RegexOptions.IgnoreCase))
                return null;

            if (message.ParameterList.Count == 0)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Date of what?", message.ReplyTo) };

            List<Events.EventStruct> reversedList = null;
            Events.EventStruct eventStruct = new Events.EventStruct();

            lock (Events.eventListLock)
            {
                reversedList = new List<Events.EventStruct>(Events.EventList);

                eventStruct = Events.EventList.Find(s =>
                    s.EventDate > DateTime.UtcNow &&
                    Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));
            }

            reversedList.Reverse();

            if (eventStruct.EventName == null)
                eventStruct = reversedList.Find(s =>
                    s.EventDate <= DateTime.UtcNow &&
                    Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));

            if (eventStruct.EventName == null)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No event matching \"" + message.Parameters + "\" found in the events list.", message.ReplyTo) };

            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "The date for \"" + eventStruct.EventName + "\" is " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) };
        }
Esempio n. 12
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(np|nowplaying)$", RegexOptions.IgnoreCase))
                return null;

            string lastfmName = "";

            if (message.ParameterList.Count > 0)
            {
                if (AccountMap.ContainsKey(message.ParameterList[0].ToUpper()))
                {
                    lastfmName = AccountMap[message.ParameterList[0].ToUpper()];
                }
                else
                {
                    lastfmName = message.ParameterList[0];
                }
            }
            else
            {
                if (AccountMap.ContainsKey(message.User.Name.ToUpper()))
                {
                    lastfmName = AccountMap[message.User.Name.ToUpper()];
                }
                else
                {
                    lastfmName = message.User.Name;
                }
            }

            URL.WebPage recentFeed = new URL.WebPage();

            try
            {
                recentFeed = URL.FetchURL("http://ws.audioscrobbler.com/1.0/user/" + lastfmName + "/recenttracks.rss");
            }
            catch (System.Net.WebException ex)
            {
                Logger.Write(ex.ToString(), Settings.Instance.ErrorFile);
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "User \"" + lastfmName + "\" not found on LastFM", message.ReplyTo) };
            }

            Match track = Regex.Match(recentFeed.Page, @"<item>\s*?<title>(?<band>.+?)–(?<song>.+?)</title>\s*?<link>(?<link>.+?)</link>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (track.Success)
            {
                string band = track.Groups["band"].Value;
                string song = track.Groups["song"].Value;

                string songMessage = "\"" + song.Trim() + "\" by " + band.Trim();

                songMessage += " (" + /*ChannelList.EvadeChannelLinkBlock(message, URL.Shorten(*/track.Groups["link"].Value/*))*/ + ")";

                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, songMessage, message.ReplyTo) };
            }
            else
            {
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "User \"" + lastfmName + "\" exists on LastFM, but hasn't scrobbled any music to it", message.ReplyTo) };
            }
        }
Esempio n. 13
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (userList.Contains(message.User.Name) && rand.Next(0, 5) == 0)
     {
         return new List<IRCResponse>() { new IRCResponse(ResponseType.Raw, "KICK " + message.ReplyTo + " " + message.User.Name + " ::D", "") };
     }
     return null;
 }
Esempio n. 14
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(lp)$", RegexOptions.IgnoreCase))
                return null;

            // Specific thing requested
            if (message.ParameterList.Count == 0)
            {
                if (lpList.Count > 0)
                {
                    // Return a random thing
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, lpList[rand.Next(lpList.Count)], message.ReplyTo) };
                }
                else
                {
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "There is currently no LP data!", message.ReplyTo) };
                }
            }

            switch (message.ParameterList[0].ToLower())
            {
                case "add": // Adding something to the LP list
                    string msg = message.Parameters.Substring(message.ParameterList[0].Length + 1);

                    int index;
                    lock (fileLock)
                    {
                        index = lpList.Count + 1;
                        lpList.Add(index + ". " + msg);
                    }

                    SaveList();

                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Message added at index " + index, message.ReplyTo) };

                case "list": // Post the list to pastebin, give link
                    string list = "";
                    foreach (string item in lpList)
                    {
                        list += item + "\n";
                    }
                    string url = URL.Pastebin(list, "Let's Play List", "10M", "text", "1");
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Let's Play list posted: " + url + " (link expires in 10 mins)", message.ReplyTo) };

                default:
                    int number = 0;
                    if (Int32.TryParse(message.ParameterList[0], out number))
                    {
                        number -= 1;
                        if (number >= 0 && number < lpList.Count)
                        {
                            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, lpList[number], message.ReplyTo) };
                        }
                    }
                    // Number too large or small, or not a number at all
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Invalid number, range is 1-" + lpList.Count, message.ReplyTo) };
            }
        }
Esempio n. 15
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^event$", RegexOptions.IgnoreCase))
                return null;

            if (message.ParameterList.Count <= 1)
            {
                if (message.ParameterList.Count > 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give an event!", message.ReplyTo) };
                else
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a date and event!", message.ReplyTo) };
            }

            Events.EventStruct eventStruct = new Events.EventStruct();
            bool parseSuccess = false;

            if (message.ParameterList[0].StartsWith("("))
            {
                Match dateMessage = Regex.Match(message.Parameters, @"^\((.+)\) (.+)");
                if (dateMessage.Success)
                {
                    DateTimeOffset dateTimeOffset;
                    parseSuccess = DateTimeOffset.TryParse(dateMessage.Groups[1].Value, new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset);

                    eventStruct.EventDate = dateTimeOffset.UtcDateTime;

                    eventStruct.EventName = dateMessage.Groups[2].Value;
                }
            }
            else
            {
                DateTimeOffset dateTimeOffset;
                parseSuccess = DateTimeOffset.TryParse(message.ParameterList[0], new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset);

                eventStruct.EventDate = dateTimeOffset.UtcDateTime;

                eventStruct.EventName = message.Parameters.Remove(0, message.ParameterList[0].Length + 1);
            }

            if (!parseSuccess)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Parsing of date: " + message.ParameterList[0] + " failed, expected format is (yyyy-MM-dd HH:mm +/-offset)", message.ReplyTo) };

            eventStruct.EventName = StringUtils.StripIRCFormatChars(eventStruct.EventName);

            lock (Events.eventListLock)
            {
                int index = Events.EventList.FindIndex(s => s.EventName == eventStruct.EventName);
                if (index >= 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Event \"" + eventStruct.EventName + "\" is already in the event list, on " + Events.EventList[index].EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) };

                Events.EventList.Add(eventStruct);
                Events.EventList.Sort(Events.EventStruct.CompareEventStructsByDate);
            }

            Events.SaveEvents();

            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Added event \"" + eventStruct.EventName + "\" on " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) };
        }
Esempio n. 16
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            //foreach (KeyValuePair<string, Feed> feed in FeedMap)
            //{

            URL.WebPage feedPage;
            try
            {
                feedPage = URL.FetchURL(FeedMap["Homestuck"].URL);
            }
            catch (System.Exception ex)
            {
                Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                return null;
            }

            XmlDocument feedDoc = new XmlDocument();

            feedDoc.LoadXml(feedPage.Page);

            XmlNode firstItem = feedDoc.SelectSingleNode(@"/rss/channel/item");

            DateTime newestDate = new DateTime();
            DateTime.TryParse(firstItem.SelectSingleNode("pubDate").FirstChild.Value, out newestDate);

            if (newestDate > FeedMap["Homestuck"].LastUpdate)
            {
                XmlNode oldestNew = feedDoc.SelectSingleNode(@"/rss/channel/item");

                int numUpdates = 0;

                foreach (XmlNode item in feedDoc.SelectNodes(@"/rss/channel/item"))
                {
                    DateTime itemDate = new DateTime();
                    DateTime.TryParse(item.SelectSingleNode("pubDate").FirstChild.Value, out itemDate);

                    if (itemDate > FeedMap["Homestuck"].LastUpdate)
                    {
                        oldestNew = item;
                        numUpdates++;
                    }
                    else
                    {
                        break;
                    }
                }

                FeedMap["Homestuck"] = new Feed(FeedMap["Homestuck"].URL, newestDate);

                string itemTitle = oldestNew.SelectSingleNode("title").FirstChild.Value;
                string itemLink = ChannelList.EvadeChannelLinkBlock(message, oldestNew.SelectSingleNode("link").FirstChild.Value);

                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Homestuck has updated, " + numUpdates + " new pages! New ones start here: " + itemTitle + " (" + itemLink + ")", message.ReplyTo) };
            }
            //}
            return null;
        }
Esempio n. 17
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(roll)$", RegexOptions.IgnoreCase))
            {
                if (message.ParameterList.Count == 0)
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Roll what?", message.ReplyTo) };

                AllOperators.Operators = Operators;

                verboseRolls.Clear();

                string stringExpr = message.Parameters.Replace(" ", "");
                bool verbose = stringExpr.EndsWith("v");
                if (verbose)
                    stringExpr = stringExpr.TrimEnd('v');

                Expression expr = Tokenizer.Split(stringExpr);

                List<Token> postfixTokens = new List<Token>();
                bool isError = false;
                int errorTokenIndex = -1;
                string errorMessage = string.Empty;

                Evaluator.Validate(expr, ref postfixTokens, out isError, out errorTokenIndex, out errorMessage);

                string output = message.User.Name + " rolled: ";

                if (CalcUtilities.IsArithmeticExpression(expr))
                {
                    if (!isError)
                    {
                        double result = Evaluator.EvaluateBasic(postfixTokens);
                        if (verbose)
                        {
                            string verboseOutput = "[" + string.Join(" | ", verboseRolls) + "] ";
                            if (verboseOutput.Length < 400)
                                output += verboseOutput;
                            else
                                output += "[LOTS O' DICE] ";
                        }
                        output += result.ToString();
                    }
                    else
                    {
                        output = "Error at Token " + (errorTokenIndex + 1) + " ['" + expr.Tokens[errorTokenIndex].LinearToken + "']. " + errorMessage;
                    }
                }
                else
                {
                    output = "Not a recognized dice expression.";
                }

                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, output, message.ReplyTo) };
            }

            return null;
        }
Esempio n. 18
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(events|upcoming)$", RegexOptions.IgnoreCase))
                return null;

            double daysAhead = 7;
            if (message.ParameterList.Count > 0)
            {
                if (!Double.TryParse(message.ParameterList[0], out daysAhead))
                    daysAhead = 7;
                if (Math.Abs(daysAhead) > 36500)
                    daysAhead = 36500;
                daysAhead = Math.Abs(daysAhead);
            }

            List<string> weekEvents = new List<string>();

            lock (eventListLock)
            {
                foreach (EventStruct weekEvent in EventList)
                {
                    if (weekEvent.EventDate > DateTime.UtcNow &&
                        weekEvent.EventDate < DateTime.UtcNow.AddDays(daysAhead))
                    {
                        weekEvents.Add(weekEvent.EventName);
                    }
                }
            }

            if (weekEvents.Count == 0)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "There are no events in the coming " + daysAhead + " days!", message.ReplyTo) };

            List<IRCResponse> responses = new List<IRCResponse>();
            responses.Add(new IRCResponse(ResponseType.Say, "Events in the next " + daysAhead + " days:", message.ReplyTo));

            string events = weekEvents[0];
            weekEvents.RemoveAt(0);
            foreach (string weekEvent in weekEvents)
            {
                if ((events + " | " + weekEvent).Length < 400)
                {
                    events += " | " + weekEvent;
                }
                else
                {
                    responses.Add(new IRCResponse(ResponseType.Say, events, message.ReplyTo));
                    events = weekEvent;
                }
            }
            responses.Add(new IRCResponse(ResponseType.Say, events, message.ReplyTo));

            return responses;
        }
Esempio n. 19
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (userList.Contains(message.User.Name) && rand.Next(0, 10) == 0)
     {
         switch (rand.Next(1,3))
         {
             case 1:
                 return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, sayList[rand.Next(sayList.Count)], message.ReplyTo) };
             case 2:
                 return new List<IRCResponse>() { new IRCResponse(ResponseType.Do, doList[rand.Next(doList.Count)], message.ReplyTo) };
         }
     }
     return null;
 }
Esempio n. 20
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (message.Type != "PRIVMSG")
                return null;

            List<IRCResponse> responses = new List<IRCResponse>();

            List<string> keysToDelete = new List<string>();
            Dictionary<string, List<Tell.TellMessage>> keysToKeep = new Dictionary<string, List<Tell.TellMessage>>();

            lock (Tell.tellMapLock)
            {
                foreach (KeyValuePair<string, List<Tell.TellMessage>> kvp in Tell.MessageMap)
                {
                    if (Regex.IsMatch(message.User.Name, kvp.Key, RegexOptions.IgnoreCase))
                    {
                        foreach (Tell.TellMessage msg in kvp.Value)
                        {
                            if (msg.Target == "PM" || msg.Target == message.ReplyTo)
                            {
                                responses.Add(new IRCResponse(ResponseType.Say, message.User.Name + ": " + msg.Message, msg.Target == "PM" ? message.User.Name : msg.Target));
                                responses.Add(new IRCResponse(ResponseType.Say, "^ from " + msg.From + " on " + msg.SentDate, msg.Target == "PM" ? message.User.Name : msg.Target));
                            }
                            else
                            {
                                if (!keysToKeep.ContainsKey(kvp.Key))
                                    keysToKeep.Add(kvp.Key, new List<Tell.TellMessage>());
                                keysToKeep[kvp.Key].Add(msg);
                            }
                        }

                        keysToDelete.Add(kvp.Key);
                    }
                }
                foreach (string key in keysToDelete)
                {
                    Tell.MessageMap[key].Clear();
                    Tell.MessageMap.Remove(key);
                }
                Tell.MessageMap = Tell.MessageMap.Concat(keysToKeep).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            if (responses.Count == 0)
                return null;

            Tell.WriteMessages();

            return responses;
        }
Esempio n. 21
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            List<IRCResponse> responses = new List<IRCResponse>();

            List<string> feeds = new List<string>(FeedMap.Keys);
            foreach (string feed in feeds)
            {
                if (FeedMap[feed].LastCheck > DateTime.Now.AddMinutes(-10))
                    continue;

                FeedMap[feed].LastCheck = DateTime.Now;

                URL.WebPage feedPage;
                try
                {
                    feedPage = URL.FetchURL(FeedMap[feed].URL);
                }
                catch (System.Exception ex)
                {
                    Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                    continue;
                }

                XmlDocument feedDoc = new XmlDocument();

                feedDoc.LoadXml(feedPage.Page);

                XmlNode firstItem = feedDoc.SelectSingleNode(@"/rss/channel/item");

                DateTime newestDate = new DateTime();
                DateTime.TryParse(firstItem.SelectSingleNode("pubDate").FirstChild.Value, out newestDate);

                FeedMap[feed].LatestTitle = firstItem.SelectSingleNode("title").FirstChild.Value;
                FeedMap[feed].LatestLink = URL.Shorten(ChannelList.EvadeChannelLinkBlock(message, firstItem.SelectSingleNode("link").FirstChild.Value));

                if (newestDate > FeedMap[feed].LastUpdate)
                {
                    FeedMap[feed].LastUpdate = newestDate;

                    responses.Add(new IRCResponse(ResponseType.Say, "New " + feed + "! Title: " + FeedMap[feed].LatestTitle + " (" + FeedMap[feed].LatestLink + ")", message.ReplyTo));
                }
            }

            if (responses.Count == 0)
                return null;

            return responses;
        }
Esempio n. 22
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, @"^weather$", RegexOptions.IgnoreCase))
                return null;
            string query = string.Empty;
            if (message.ParameterList.Count == 0)
            {
                URL.WebPage page = URL.FetchURL("http://www.tsukiakariusagi.net/chatmaplookup.php?nick=" + message.User.Name);
                if (page.Page == ",")
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a location, and you're not registered on the !chatmap", message.ReplyTo) };
                else
                    query = page.Page;
            }
            else
            {
                query = HttpUtility.UrlEncode(message.Parameters);
            }

            try
            {
                Stream responseStream = URL.SendToServer("http://free.worldweatheronline.com/feed/weather.ashx?format=json&num_of_days=0&key=f31c15f2f7142209122801&q=" + query);
                string jsonResponse = URL.ReceiveFromServer(responseStream);

                WeatherData data = JsonConvert.DeserializeObject<WeatherRoot>(jsonResponse).data;
                Request location = data.request[0];
                CurrentCondition weather = data.current_condition[0];

                return new List<IRCResponse>() { new IRCResponse(
                    ResponseType.Say,
                    String.Format("{0}: {1} | {2} | {3}ºC ({4}ºF) | Humidity: {5}% | Wind: {6}kph ({7}mph) {8}",
                        location.type,
                        location.query,
                        String.Join(", ", weather.weatherDesc),
                        weather.temp_C,
                        weather.temp_F,
                        weather.humidity,
                        weather.windspeedKmph,
                        weather.windspeedMiles,
                        weather.winddir16Point),
                    message.ReplyTo) };
            }
            catch (System.Exception ex)
            {
                Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                return null;
            }
        }
Esempio n. 23
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (message.Type != "PRIVMSG")
                return null;

            if (rand.Next(0, 500) == 0)
            {
                List<IRCResponse> responses = new List<IRCResponse>();
                foreach (Response response in GetInsult(message.User.Name))
                {
                    responses.Add(new IRCResponse(response.RType, response.Text, message.ReplyTo));
                }
                responses.Add(null);
                return responses;
            }
            return null;
        }
Esempio n. 24
0
 public override List<IRCResponse> GetResponse(BotMessage message)
 {
     if (Regex.IsMatch(message.Command, "^(do)$", RegexOptions.IgnoreCase))
     {
         if (message.ParameterList.Count > 0)
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Do, message.Parameters, message.ReplyTo) };
         }
         else
         {
             return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Do what?", message.ReplyTo) };
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 25
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(r(emove)?tell)$", RegexOptions.IgnoreCase))
                return null;

            if (message.ParameterList.Count == 0)
                return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't specify a message to remove!", message.ReplyTo) };

            List<string> keysToRemove = new List<string>();

                foreach (string user in Tell.MessageMap.Keys)
                {
                    List<IRCResponse> response = new List<IRCResponse>();

                    lock (Tell.tellMapLock)
                    {
                        int index = Tell.MessageMap[user].FindIndex(s =>
                            s.From.ToLowerInvariant() == message.User.Name.ToLowerInvariant() &&
                            Regex.IsMatch(s.Message, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));

                        if (index < 0)
                            continue;

                        response.Add(new IRCResponse(ResponseType.Say, "Message \"" +
                            Tell.MessageMap[user][index].Message +
                            "\", sent on date \"" +
                            Tell.MessageMap[user][index].SentDate +
                            "\" to \"" +
                            user +
                            "\" removed from the message database!", message.ReplyTo));

                        Tell.MessageMap[user].RemoveAt(index);

                        if (Tell.MessageMap[user].Count == 0)
                            Tell.MessageMap.Remove(user);
                    }

                    Tell.WriteMessages();

                    return response;
            }

            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No message sent by you containing \"" + message.Parameters + "\" found in the message database!", message.ReplyTo) };
        }
Esempio n. 26
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(m(odd)?t(unes)?)$", RegexOptions.IgnoreCase))
            {
                Mpc mpc = new Mpc();

                var addresses = System.Net.Dns.GetHostAddresses("moddington.net");
                if (addresses.Length > 0)
                {
                    mpc.Connection = new MpcConnection(new IPEndPoint(addresses[0], 6600));

                    var song = mpc.CurrentSong();
                    string songMsg = "";
                    if (song.HasTitle || song.HasArtist)
                    {
                        if (song.HasTitle) songMsg += song.Title;
                        else songMsg += "<Unknown Title>";
                        if (song.HasArtist) songMsg += " - " + song.Artist;
                        else songMsg += "<Unknown Artist>";
                    }
                    else
                    {
                        songMsg += song.File;
                    }

                    var status = mpc.Status();
                    TimeSpan elapsed = TimeSpan.FromSeconds(status.TimeElapsed);
                    TimeSpan total = TimeSpan.FromSeconds(status.TimeTotal);
                    string timeMsg = (elapsed.Hours > 0 ? elapsed.Hours + ":" : "") + elapsed.Minutes + ":" + elapsed.Seconds.ToString("D2") + "/" +
                        (total.Hours > 0 ? total.Hours + ":" : "") + total.Minutes + ":" + total.Seconds.ToString("D2");

                    string output = "Playing: " + songMsg +
                        " [" + timeMsg + "] - Listen here: " + ChannelList.EvadeChannelLinkBlock(message, "http://moddington.net:8000/moddtunes.ogg");

                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, output, message.ReplyTo) };
                }
                else
                {
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Moddington's internet radio seems to be down", message.ReplyTo) };
                }
            }

            return null;
        }
Esempio n. 27
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, @"^l(r|l)r$", RegexOptions.IgnoreCase))
                return null;

            List<string> feeds = new List<string>(LRRChecker.FeedMap.Keys);

            if (message.Parameters.Trim().Length > 0)
            {
                string feed = ReplaceAliases(message.Parameters);

                feed = feeds.Find(s =>
                    s.ToLowerInvariant() == feed.ToLowerInvariant());
                if (feed == String.Empty)
                    return new List<IRCResponse>() { new IRCResponse(
                        ResponseType.Say,
                        "\"" + message.Parameters + "\" is not one of the LRR series being monitored.",
                        message.ReplyTo) };

                return new List<IRCResponse>() { new IRCResponse(
                    ResponseType.Say,
                    "Latest " + feed + ": " + LRRChecker.FeedMap[feed].LatestTitle + " (" + LRRChecker.FeedMap[feed].LatestLink + ")",
                    message.ReplyTo) };
            }
            else
            {
                string newest = String.Empty;
                DateTime newestDate = DateTime.MinValue;
                foreach (string feed in feeds)
                {
                    if (LRRChecker.FeedMap[feed].LastUpdate > newestDate)
                    {
                        newestDate = LRRChecker.FeedMap[feed].LastUpdate;
                        newest = feed;
                    }
                }

                return new List<IRCResponse>() { new IRCResponse(
                    ResponseType.Say,
                    "Latest " + newest + ": " + LRRChecker.FeedMap[newest].LatestTitle + " (" + LRRChecker.FeedMap[newest].LatestLink + ")",
                    message.ReplyTo) };
            }
        }
Esempio n. 28
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(commands?|help|functions?)$", RegexOptions.IgnoreCase))
            {
                moronBot = Program.moronBot;

                // Specific function asked for
                if (message.ParameterList.Count > 0)
                {
                    // Check function exists
                    string command = moronBot.CommandList.Find(s => Regex.IsMatch(s, @"^" + Regex.Escape(message.ParameterList[0]) + @"$", RegexOptions.IgnoreCase));
                    if (command != null)
                    {
                        // Check function has help text
                        if (moronBot.HelpLibrary[command] != null)
                        {
                            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, moronBot.HelpLibrary[command], message.ReplyTo) };
                        }
                        return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "\"" + command + "\" doesn't have any help text specified.", message.ReplyTo) };
                    }
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "\"" + message.ParameterList[0] + "\" not found, try \"" + message.Command + "\" without parameters to see a list of loaded functions.", message.ReplyTo) };
                }
                // List of loaded functions asked for
                else
                {
                    List<IRCResponse> responses = new List<IRCResponse>();
                    responses.Add(new IRCResponse(ResponseType.Say, "Functions loaded are:", message.ReplyTo));
                    moronBot.CommandList.Sort();
                    string output = moronBot.CommandList[0];
                    for (int i = 1; i < moronBot.CommandList.Count; i++)
                    {
                        output += ", " + moronBot.CommandList[i];
                    }
                    responses.Add(new IRCResponse(ResponseType.Say, output, message.ReplyTo));
                    return responses;
                }
            }
            else
            {
                return null;
            }
        }
Esempio n. 29
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(time(un)?till|countdown)$", RegexOptions.IgnoreCase))
                return null;

            Events.EventStruct eventStruct;
            TimeSpan timeSpan;

            lock (Events.eventListLock)
            {
                if (message.ParameterList.Count > 0) // Parameters given
                {
                    // If an event in EventList is in the future, and the event name and command parameters match exactly,
                    // assign to eventStruct
                    eventStruct = Events.EventList.Find(s =>
                        s.EventDate > DateTime.UtcNow &&
                        s.EventName == message.Parameters);

                    // If no matching message found
                    if (eventStruct.EventName == null)
                    {
                        // Same search as above, but using regex to match messages this time.
                        eventStruct = Events.EventList.Find(s =>
                            s.EventDate > DateTime.UtcNow &&
                            Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));
                    }

                    // No matching events found
                    if (eventStruct.EventName == null)
                        return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No event matching \"" + message.Parameters + "\" found in the future events list!", message.ReplyTo) };
                }
                else // Parameters not given, assign next Desert Bus to eventStruct.
                {
                    eventStruct = Events.EventList.Find(s =>
                        s.EventDate > DateTime.UtcNow &&
                        s.EventName.StartsWith("DB"));
                }
            }

            timeSpan = eventStruct.EventDate - DateTime.UtcNow;
            return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, eventStruct.EventName + " will occur in " + timeSpan.Days + " day(s) " + timeSpan.Hours + " hour(s) " + timeSpan.Minutes + " minute(s)", message.ReplyTo) };
        }
Esempio n. 30
0
        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            string url = "http://localhost:8080/message";

            string json = JsonConvert.SerializeObject(message);

            try
            {
                Stream responseStream = URL.SendToServer(url, json);
                string jsonResponse = URL.ReceiveFromServer(responseStream);

                List<IRCResponse> ircResponses = JsonConvert.DeserializeObject<List<IRCResponse>>(jsonResponse);

                return ircResponses;
            }
            catch (System.Exception /*ex*/)
            {
                //return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "PythonInterface Exception: " + ex.Message, message.ReplyTo) };
                return null;
            }
        }
Esempio n. 31
0
 public abstract List <IRCResponse> GetResponse(BotMessage message);