예제 #1
0
        public bool Execute(SlackBotCommand command)
        {
            try
            {
                string         name    = string.IsNullOrWhiteSpace(command.Text) ? "The Great Ranzuoni" : command.Text;
                HttpWebRequest request =
                    (HttpWebRequest)
                    WebRequest.Create("http://api.icndb.com/jokes/random");

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader    reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string          json     = reader.ReadToEnd();
                response.Dispose();

                JObject joResponse = JObject.Parse(json);
                if (joResponse["value"] != null)
                {
                    string joke = joResponse["value"]["joke"].ToString();
                    joke = joke.Replace("Chuck Norris", name);
                    slackBot.Reply(command, HttpUtility.HtmlDecode(joke));
                }
                else
                {
                    slackBot.Reply(command, "Crap. I forgot to handle that case.");
                }

                return(false);
            }
            catch (Exception)
            {
                slackBot.Reply(command, "Stop trying to break slackbot");
                return(false);
            }
        }
예제 #2
0
        public bool Execute(SlackBotCommand command)
        {
            string size    = string.Empty;
            int    sizeInt = 0;

            try
            {
                if (!int.TryParse(command.Text, out sizeInt))
                {
                    slackBot.Reply(command, "You disappoint your family");
                    return(false);
                }
                if (sizeInt > 33)
                {
                    slackBot.Reply(command, "The count is too high. Heck now its " + sizeInt * 9000 + "/9000");
                    return(false);
                }
                slackBot.Reply(command, printGlass(sizeInt));
            }
            catch (Exception)
            {
                slackBot.Reply(command, "You done gone broke the Nexus");
                return(false);
            }

            return(false);
        }
예제 #3
0
        private bool WaitForTimePeriod(double totalTimeToWait, SlackBotCommand command)
        {
            _message = null;
            foreach (double displayTime in DISPLAY_TIMES)
            {
                if (totalTimeToWait <= displayTime && totalTimeToWait > (displayTime - SECOND_IN_MILLISECONDS))
                {
                    _message = FormatTimeRemaining(totalTimeToWait);
                }
            }

            if (_message != null)
            {
                slackBot.Reply(command, _message);
            }

            lock (purposes)
                purposes[_purpose] = totalTimeToWait - SECOND_IN_MILLISECONDS;

            Thread.Sleep((int)SECOND_IN_MILLISECONDS);

            if (totalTimeToWait <= 0)
            {
                lock (purposes)
                    purposes.Remove(_purpose);

                return(false);
            }

            return(true);
        }
예제 #4
0
 public bool Execute(SlackBotCommand command)
 {
     try
     {
         slackBot.Reply(command, "This feature is temporarily out of order.");
         //System.Diagnostics.Process.Start(@"C:\Users\plafata\Documents\SlackbotProd\reboot.bat");
     }
     catch (Exception)
     {
         slackBot.Reply(command, "Something went wrong restarting the bot");
     }
     return(false);
 }
예제 #5
0
        private void Run(SlackBotCommand command)
        {
            m_Moves.Clear();
            foreach (string shout in new string[] { "Rock!", "Paper!", "Scissors!", "Shoot!" })
            {
                System.Threading.Thread.Sleep(1000);
                slackBot.Reply(command, shout);
            }

            m_ShootTime = DateTime.Now;
        }
예제 #6
0
        public bool Execute(SlackBotCommand command)
        {
            string output = "";

            foreach (string part in command.Text.Split(' '))
            {
                string searchTerm = part.NormalizeSpace();
                if (searchTerm.Length >= 3 && searchTerm.Length <= 15)
                {
                    HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(String.Format("http://acronym-maker.com/generate/?w={0}&wl=", System.Uri.EscapeDataString(searchTerm)));
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    StreamReader    reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    string          xml      = reader.ReadToEnd();
                    response.Dispose();

                    XmlDocument doc = new XmlDocument();
                    if (request.Address.ToString().Contains("index.php"))
                    {
                        slackBot.Reply(command, "You dun sumthin real bad with them thar characters...");
                        return(true);
                    }

                    doc.LoadXml(xml.Substring(xml.IndexOf("<table"), xml.IndexOf("</table>") - xml.IndexOf("<table")) + "</table>");
                    XmlNode documentNode = doc.DocumentElement;
                    try
                    {
                        foreach (XmlNode acronymRow in documentNode.SelectNodes("//*[local-name() = 'table']//*[local-name()='tr']"))
                        {
                            output += acronymRow.SelectSingleNode(".//*[local-name()='th']").InnerText.Trim() + ": " +
                                      acronymRow.SelectSingleNode(".//*[local-name()='a' or local-name()='td']").InnerText.Trim() + "\n";
                        }
                    }
                    catch (Exception e)
                    {
                        slackBot.Reply(command, e.Message);
                        return(true);
                    }
                    output += "\n";
                }
                else
                {
                    slackBot.Reply(command, String.Format("The word has to be 3-15 characters. Violator: \"{0}\"", searchTerm));
                    return(true);
                }
            }
            slackBot.Reply(command, output);
            return(false);
        }
예제 #7
0
        public bool Execute(SlackBotCommand command)
        {
            string userToCheck;

            if (string.IsNullOrWhiteSpace(command.Text))
            {
                userToCheck = command.User.name;
            }
            else
            {
                userToCheck = command.Text;
            }

            PrivilegeLevel privilege = slackBot.GetUserPrivilege(userToCheck);

            string response;

            switch (privilege)
            {
            case PrivilegeLevel.Super:
                response = "Your privelege level is Super, that makes you in the 1% of privilege levels"; break;

            case PrivilegeLevel.Admin:
                response = "You got some privilege but not a lot.  You're an admin which is kind of like the guy in the factory that watches the other guys work." +
                           "On the one hand you're not the lowest level, but you're still in the factory son."; break;

            case PrivilegeLevel.Normal:
            default:
                response = "You're just a regular joe, p'ting.  But not like our Joe because he's actually kind of a big deal."; break;
            }

            slackBot.Reply(command, response);
            return(false);
        }
예제 #8
0
        public bool Execute(SlackBotCommand command)
        {
            if (string.IsNullOrWhiteSpace(command.Text))
            {
                string response = "";
                foreach (string commandName in slackBot.GetCommandNames().OrderBy(x => x))
                {
                    response += commandName + ": ";
                    response += slackBot.GetHelp(commandName) + "\n";
                }

                slackBot.Reply(command, response);
            }
            else
            {
                slackBot.Reply(command, slackBot.GetHelp(command.Text));
            }

            return(true);
        }
예제 #9
0
        public bool Execute(SlackBotCommand command)
        {
            Random random = new Random();
            int    die1   = random.Next(6) + 1;
            int    die2   = random.Next(6) + 1;

            int roll = die1 + die2;

            slackBot.Reply(command, string.Format("{0} rolled a {1}", command.User.name, roll), iconUrl: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/2-Dice-Icon.svg/2000px-2-Dice-Icon.svg.png");

            return(false);
        }
예제 #10
0
        public bool Execute(SlackBotCommand command)
        {
            User userToMock;

            if (string.IsNullOrWhiteSpace(command.Text))
            {
                userToMock = command.User;
            }
            else
            {
                string userId = command.Text;
                userToMock = slackBot.GetUsers().Find(user => user.name == userId);
                if (userToMock == null)
                {
                    userToMock = slackBot.GetUsers().Find(user => user.profile.real_name == userId);
                }

                if (userToMock == null)
                {
                    userId = userId.Replace("\"", "");
                    userId = "\"" + userId + "\"";
                    slackBot.Reply(command, string.Format("Sorry {0}, I cannot find user {1}", command.User.name, userId));
                    return(false);;
                }
            }

            string userName;

            if (!string.IsNullOrWhiteSpace(userToMock.profile.real_name))
            {
                userName = userToMock.profile.real_name;
            }
            else
            {
                userName = userToMock.name;
            }

            slackBot.Reply(command, string.Format("I'm {0} and I'm dumb", userName), userName, userToMock.profile.image_32);
            return(false);
        }
예제 #11
0
        public bool Execute(SlackBotCommand command)
        {
            if (string.IsNullOrWhiteSpace(command.Text))
            {
                slackBot.Reply(command, "You did not specify a new name");
            }
            else
            {
                slackBot.RenameBot(command.Text);
            }

            return(false);
        }
예제 #12
0
        public bool Execute(SlackBotCommand command)
        {
            Random random  = new Random();
            int    slicesX = random.Next(5) + 1;
            int    slicesY = random.Next(5) + 1;
            int    slicesZ = random.Next(5) + 1;

            int pieces = slicesX * slicesY * slicesZ;

            slackBot.Reply(command, string.Format("{0} diced the rolls into {1} pieces", command.User.name, pieces), iconUrl: "https://upload.wikimedia.org/wikipedia/commons/2/28/13-08-31-wien-redaktionstreffen-EuT-by-Bi-frie-134.jpg");

            return(false);
        }
예제 #13
0
        public bool Execute(SlackBotCommand command)
        {
            if (command.Name == "makevote")
            {
                if (string.IsNullOrWhiteSpace(command.Text))
                {
                    slackBot.Reply(command, "What do you want to vote on?");
                    return(false);
                }
                else if (VotingTopic != null)
                {
                    slackBot.Reply(command, "There is already an ongoing vote.");
                    return(true);
                }

                VotingTopic = command.Text;
                return(true);
            }
            else
            {
                if (VotingTopic == null)
                {
                    slackBot.Reply(command, "There is no vote going on currently");
                    return(false);
                }
                if (!(command.Text == "yes" || command.Text == "no"))
                {
                    slackBot.Reply(command, "You must vote 'yes' or 'no'");
                    return(true);
                }
                else if (Voted.Contains(command.User.id))
                {
                    slackBot.Reply(command, "You already voted");
                    return(true);
                }

                if (command.Text == "yes")
                {
                    YesVotes++;
                }
                else
                {
                    NoVotes++;
                }
                Voted.Add(command.User.id);

                int difference = Math.Abs(YesVotes - NoVotes);
                int votes      = YesVotes + NoVotes;
                int votesLeft  = Array.FindAll(command.Channel.members, userId => slackBot.GetUser(userId).presence == "active" && !slackBot.GetUser(userId).is_bot).Length - votes;

                if (difference > votesLeft)
                {
                    string result = (YesVotes > NoVotes) ? "yes" : "no";
                    slackBot.Reply(command, "The people have spoken, the vote is " + result + " to " + VotingTopic);
                    return(false);
                }
                else if (votesLeft == 0)
                {
                    slackBot.Reply(command, "The vote was inconclusive.");
                    return(false);
                }

                return(true);
            }
        }
예제 #14
0
 public bool Execute(SlackBotCommand command)
 {
     slackBot.Reply(command, "http://lmgtfy.com/?q=" + System.Uri.EscapeDataString(command.Text));
     return(false);
 }
예제 #15
0
        public bool Execute(SlackBotCommand command)
        {
            string commandText = command.Text;

            if (string.IsNullOrWhiteSpace(commandText))
            {
                slackBot.Reply(command, "Please supply some text to emojify.");
            }

            string[] commandSplit = commandText.Split(' ');
            Regex    emojiRegex   = new Regex(":.+:");
            int      startOutput  = 0;
            string   emojiFront   = ":filled:";
            string   emojiBack    = ":blank:";

            if (emojiRegex.IsMatch(commandSplit[0]))
            {
                emojiFront = commandSplit[0];
                startOutput++;
            }
            if (commandSplit.Length > 1 && emojiRegex.IsMatch(commandSplit[1]))
            {
                emojiBack = commandSplit[1];
                startOutput++;
            }

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

            for (int wordIndex = startOutput; wordIndex < commandSplit.Length; wordIndex++)
            {
                char[]        letters = commandSplit[wordIndex].ToLower().ToCharArray();
                StringBuilder output  = new StringBuilder();
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < letters.Length; j++)
                    {
                        if (letters[j] == '\n')
                        {
                            output.AppendLine();
                        }
                        else
                        {
                            if (LetterMap.ContainsKey(letters[j]))
                            {
                                output.Append(String.Format(LetterMap[letters[j]][i], emojiBack, emojiFront));
                            }
                            else
                            {
                                output.Append(letters[j] + emojiBack);
                            }

                            if (j + 1 < letters.Length)
                            {
                                output.Append(emojiBack);
                            }
                        }

                        if (output.Length > 4000)
                        {
                            slackBot.Reply(command, "Message has word that is too large: " + commandSplit[wordIndex]);
                            return(true);
                        }
                    }
                    output.AppendLine();
                }
                messages.Add(output.ToString());
            }
            Thread processThread = new Thread(ReplyMessages);

            processThread.Start(new Parameter(command, messages));
            return(false);
        }
예제 #16
0
        private bool ReadFeatures(SlackBotCommand command)
        {
            int    noOfLines    = 0;
            bool   returnStatus = false;
            string newline      = "\n";       //Environment.NewLine;??
            int    charSize     = encoding.IsSingleByte ? 1 : 2;

            byte[] buffer  = null;
            bool   printed = false;
            string temp    = string.Empty;

            FileStream stream = null;

            try
            {
                stream = new FileStream(GetRelFilePath(RequestListFileName), FileMode.Open,
                                        FileAccess.Read, FileShare.Write);
                long endPos = stream.Length / charSize, oldPos = 0;
                long posLength;
                printed   = false;
                noOfLines = 0;
                buffer    = new byte[charSize];
                endPos    = stream.Length / charSize;
                if (endPos <= oldPos)
                {
                    oldPos = endPos;                                        // if file's content is
                }
                //deleted, reset position
                posLength = endPos - oldPos;

                for (long pos = charSize; pos <= posLength; pos += charSize)
                {
                    stream.Seek(-pos, SeekOrigin.End);
                    stream.Read(buffer, 0, charSize);
                    temp = encoding.GetString(buffer);
                    if (temp == newline)
                    {
                        noOfLines++;
                    }
                    if (noOfLines == 11)
                    {
                        buffer = new byte[endPos - stream.Position];
                        stream.Read(buffer, 0, buffer.Length);
                        slackBot.Reply(command, FormatRequestList(encoding.GetString(buffer)));
                        printed = true;
                        oldPos  = endPos;
                        break;
                    }
                }
                if (!printed)
                {
                    buffer = new byte[endPos - oldPos];
                    stream.Seek(-1, SeekOrigin.Current);
                    stream.Read(buffer, 0, buffer.Length);
                    slackBot.Reply(command, FormatRequestList(encoding.GetString(buffer)));
                    oldPos = endPos;
                }
            }
            catch (Exception)
            {
                slackBot.Reply(command, "Whoops, someone did something with the feature list file :(");
                returnStatus = true;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            return(returnStatus);
        }
예제 #17
0
 public bool Execute(SlackBotCommand command)
 {
     slackBot.Reply(command, "http://www.sadtrombone.com/");
     return(false);
 }
예제 #18
0
 public bool Execute(SlackBotCommand command)
 {
     slackBot.Reply(command, "http://www.urbandictionary.com/define.php?term=" + System.Uri.EscapeDataString(command.Text));
     return(false);
 }
예제 #19
0
 public bool Execute(SlackBotCommand command)
 {
     slackBot.Reply(command, string.Format(":ok_hand::eyes::ok_hand::eyes::ok_hand::eyes::ok_hand::eyes::ok_hand::eyes: good shit go౦ԁ sHit:ok_hand: thats :heavy_check_mark: some good:ok_hand::ok_hand:shit right:ok_hand::ok_hand:th :ok_hand: ere:ok_hand::ok_hand::ok_hand: right:heavy_check_mark:there :heavy_check_mark::heavy_check_mark:if i do ƽaү so my self :100: i say so :100: thats what im talking about right there right there (chorus: ʳᶦᵍʰᵗ ᵗʰᵉʳᵉ) mMMMMᎷМ:100: :ok_hand::ok_hand: :ok_hand:НO0ОଠOOOOOОଠଠOoooᵒᵒᵒᵒᵒᵒᵒᵒᵒ:ok_hand: :ok_hand::ok_hand: :ok_hand: :100: :ok_hand: :eyes: :eyes: :eyes: :ok_hand::ok_hand:Good shit"));
     return(false);
 }
예제 #20
0
        public bool Execute(SlackBotCommand command)
        {
            try
            {
                string         city    = String.IsNullOrWhiteSpace(command.Text) ? "Conshohocken" : command.Text;
                HttpWebRequest request =
                    (HttpWebRequest)
                    WebRequest.Create(
                        String.Format("http://api.openweathermap.org/data/2.5/weather?q=" + city +
                                      "&appid=bd82977b86bf27fb59a04b61b657fb6f"));

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader    reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string          json     = reader.ReadToEnd();
                response.Dispose();

                JObject joResponse = JObject.Parse(json);
                if (joResponse["main"] != null)
                {
                    string kelvinTemp     = joResponse["main"]["temp"].ToString();
                    string farentheitTemp = ((Double.Parse(kelvinTemp) - 273) * 9 / 5 + 32).ToString();
                    city = joResponse["name"].ToString();
                    string emoji;
                    switch (((int)Double.Parse(farentheitTemp)) / 10)
                    {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                        emoji = ":snowman:";
                        break;

                    case 4:
                    case 5:
                    case 6:
                        emoji = ":partly_sunny:";
                        break;

                    case 7:
                    case 8:
                    case 9:
                        emoji = ":sunny:";
                        break;

                    default:
                        emoji = ":skull:";
                        break;
                    }
                    slackBot.Reply(command, city + " : " + farentheitTemp + "F  " + emoji);
                }
                else
                {
                    slackBot.Reply(command, "Are you some kind of stupid? " + city + " is not a city...");
                }

                return(false);
            }
            catch (Exception)
            {
                slackBot.Reply(command, "Stop trying to break slackbot");
                return(false);
            }
        }
예제 #21
0
        public bool Execute(SlackBotCommand command)
        {
            if (!(command.Channel.name == "the-bureau-of-anarchy" || command.Channel.name == "slackbot-test" || command.Channel.name == "the-anarchy"))
            {
                return(false);
            }

            string[] commandSplit = command.Text.Split(' ');

            string username = "";

            if (commandSplit.Length >= 1 && !String.IsNullOrEmpty(commandSplit[0]))
            {
                username = GetUsername(command, commandSplit[0]);
                if (username == null)
                {
                    slackBot.Reply(command, String.Format("You messed up, {0}. You get a bad job.", command.User.name));
                    if (!JobMatrix.ContainsKey(command.User.name))
                    {
                        JobMatrix.Add(command.User.name, new[] { 0, 0 });
                    }

                    JobMatrix[command.User.name][BadJobIndex]++;
                    WriteJobMatrix(GetRelFilePath(JobMatrixFileName));
                    return(false);
                }
            }

            if (command.Name == "checkjobs")
            {
                Random ran          = new Random();
                string userToLookup = string.IsNullOrWhiteSpace(username) ? command.User.name : username;
                if (JobMatrix.ContainsKey(userToLookup))
                {
                    slackBot.Reply(command, String.Format("{2}\nGood jobs: {0}\nBad jobs:{1}\n{3}", FormatJobs(JobMatrix[userToLookup][GoodJobIndex], GoodJobIndex), FormatJobs(JobMatrix[userToLookup][BadJobIndex], BadJobIndex), userToLookup, Responses[ran.Next(Responses.Length)]));
                }
                else
                {
                    slackBot.Reply(command, "No jobs yet, get working!");
                }
                return(false);
            }

            if (!JobMatrix.ContainsKey(username))
            {
                JobMatrix.Add(username, new[] { 0, 0 });
            }

            bool goodJob;

            if (command.Name == "goodjob" || command.Name == "gj")
            {
                JobMatrix[username][GoodJobIndex]++;
                goodJob = true;
            }
            else
            {
                JobMatrix[username][BadJobIndex]++;
                goodJob = false;
            }
            if (!JobMatrix.ContainsKey(command.User.name))
            {
                JobMatrix.Add(command.User.name, new[] { 0, 0 });
            }

            JobMatrix[command.User.name][GoodJobIndex]++;

            WriteJobMatrix(GetRelFilePath(JobMatrixFileName));

            slackBot.Reply(command, String.Format("You've given a {0} to {1} for {2}. Good job on giving out jobs.", goodJob ? "good job" : "bad job", username, GetJobDescription(commandSplit)));
            return(false);
        }