/// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            string botSkypeId = ConfigurationManager.AppSettings["botskypeid"];

            List<SkypeContact> contacts = chat.Contacts.Where(s => s.Id != botSkypeId).ToList();
            return contacts[(new Random()).Next(contacts.Count)].Id;
        }
Exemple #2
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string argument = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            try
            {
                if (!string.IsNullOrEmpty(argument))
                {
                    if (argument.Length > MaxFeedbackLength)
                    {
                        return
                            (string.Format(
                                 "The feedback message is too long. The maximum allowed length is 500. Your's is {0}",
                                 argument.Length));
                    }

                    this.dataManager.AddFeedback(contact.Id, argument);
                }
                else
                {
                    return("Please use feedback command with argument");
                }
            }
            catch (Exception)
            {
                return("Sorry, couldn't process your feedback");
            }

            return("Got your message. We will try to take a look at it asap. Thanks!");
        }
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string argument = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            string result = string.Empty;

            if (!string.IsNullOrWhiteSpace(argument))
            {
                Thread thread = new Thread(
                    () =>
                {
                    try
                    {
                        result = new Engine().Execute(argument).GetCompletionValue().ToString();
                    }
                    catch (Exception)
                    {
                        result = "Sorry, couldn't parse.";
                    }
                });

                thread.Start();

                if (!thread.Join(Timeout))
                {
                    thread.Abort();
                    result = "Sorry, your code took too long and has been aborted.";
                }
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            string botSkypeId = ConfigurationManager.AppSettings["botskypeid"];

            List <SkypeContact> contacts = chat.Contacts.Where(s => s.Id != botSkypeId).ToList();

            return(contacts[(new Random()).Next(contacts.Count)].Id);
        }
Exemple #5
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            if (this.dataManager.IsChatEnabled(chat.Id))
            {
                return(AlreadyListeningMessage);
            }

            this.dataManager.EnabledChat(chat.Id);
            return(HelloMessage);
        }
Exemple #6
0
        private void buttonAddChat_Click(object sender, EventArgs e)
        {
            SkypeChat selectedChat = listBoxAllChats.SelectedItem as SkypeChat;

            if (selectedChat != null && SkypeNotifier.Instance.Settings.SubscribedChats.Find(chat => chat.ID == selectedChat.ID) == null)
            {
                SkypeNotifier.Instance.Settings.SubscribedChats.Add(selectedChat);
                listBoxSelectedChats.Items.Add(selectedChat);
                RefreshListBox(listBoxSelectedChats, SkypeNotifier.Instance.Settings.SubscribedChats);
                buttonSave.Enabled = true;
            }
        }
Exemple #7
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            try
            {
                this.dataManager.UnsubscribeChat(chat.Id);
            }
            catch (Exception)
            {
                return("Oops, something went wrong with unsubscribing");
            }

            return(string.Format("You've successfully been unsubscribed from any project"));
        }
Exemple #8
0
        public Main()
        {
            InitializeComponent();
            _skype   = new Skype();
            _current = null;

            foreach (Chat c in _skype.RecentChats)
            {
                chatsListView.Items.Add(new ListViewItem(c.FriendlyName)
                {
                    Tag = new SkypeChat(c)
                });
            }

            _skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(_skype_MessageStatus);
        }
Exemple #9
0
        private void buttonRemoveChat_Click(object sender, EventArgs e)
        {
            SkypeChat selectedChat = listBoxSelectedChats.SelectedItem as SkypeChat;

            if (selectedChat != null)
            {
                SkypeChat chatToRemove = SkypeNotifier.Instance.Settings.SubscribedChats.Find(chat => chat.ID == selectedChat.ID);
                if (chatToRemove != null)
                {
                    SkypeNotifier.Instance.Settings.SubscribedChats.Remove(chatToRemove);
                }
                listBoxSelectedChats.Items.Remove(selectedChat);
                RefreshListBox(listBoxSelectedChats, SkypeNotifier.Instance.Settings.SubscribedChats);
                buttonSave.Enabled = true;
            }
        }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact sender, SkypeChat chat, string message)
        {
            string projectName = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);
            int    projectId   = this.dataManager.GetProjectId(projectName);

            if (projectId == 0)
            {
                return("No project with such name was found");
            }

            try
            {
                this.dataManager.SubscribeChat(chat.Id, projectId);
            }
            catch (Exception)
            {
                return("Oops, something went wrong with subscribing");
            }

            return(string.Format("You've successfully been subscribed to project {0}", projectName));
        }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (string.IsNullOrWhiteSpace(args))
            {
                var sb = new StringBuilder();
                sb.AppendLine("The commands supported by this bot:");
                sb.AppendLine("help - displays this help message");

                foreach (AbstractDirectCommand command in this.commands)
                {
                    sb.AppendLine(string.Format("{0} - {1}", command.Name, command.Help));
                }

                sb.AppendLine();
                sb.Append("To get more commands, you should be subscribed to some project.");
                sb.Append("To get detailed help for a certain command, type a command ");
                sb.AppendLine("name after the 'help' command. For example:");
                sb.AppendLine("help on");

                return(sb.ToString());
            }

            if (string.Equals(args, "help", StringComparison.CurrentCultureIgnoreCase))
            {
                return("Displays the main help page");
            }

            AbstractDirectCommand directCommand =
                this.commands.FirstOrDefault(c => string.Equals(c.Name, args, StringComparison.OrdinalIgnoreCase));

            if (directCommand != null)
            {
                return(directCommand.Usage);
            }

            return("The command is not found. Please type 'help' to see available commands");
        }
Exemple #12
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            IEnumerable <ProjectStatus> statuses = this.client.GetProjectStatus();

            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (!string.IsNullOrEmpty(args))
            {
                statuses = statuses.Where(s => string.Equals(s.Name, args, StringComparison.CurrentCultureIgnoreCase));
            }

            var sb = new StringBuilder();

            foreach (ProjectStatus status in statuses)
            {
                if (this.buildNames.Contains(status.Name))
                {
                    sb.AppendLine(string.Format("{0}: {1}", status.Name, status.BuildStatus));
                }
            }

            return(sb.ToString());
        }
Exemple #13
0
        private void chatsListView_DoubleClick(object sender, EventArgs e)
        {
            if (chatsListView.SelectedItems.Count != 1)
            {
                return;
            }

            lock (messagesListView)
            {
                messagesListView.Items.Clear();
                _current = (SkypeChat)chatsListView.SelectedItems[0].Tag;

                foreach (SkypeMessage s in ((SkypeChat)chatsListView.SelectedItems[0].Tag).Messages.Values)
                {
                    ListViewItem lvi = new ListViewItem(new string[] { s.Message.Sender.FullName, s.Body, s.Message.Timestamp.ToString() })
                    {
                        Tag = s
                    };
                    lvi.BackColor = getBackColor(lvi);
                    messagesListView.Items.Add(lvi);
                }
            }
        }
Exemple #14
0
 /// <summary>
 /// The execute.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public abstract string Execute(SkypeContact contact, SkypeChat chat, string message);
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            IEnumerable<ProjectStatus> statuses = this.client.GetProjectStatus();

            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);
            if (!string.IsNullOrEmpty(args))
            {
                statuses = statuses.Where(s => string.Equals(s.Name, args, StringComparison.CurrentCultureIgnoreCase));
            }

            var sb = new StringBuilder();
            foreach (ProjectStatus status in statuses)
            {
                if (this.buildNames.Contains(status.Name))
                {
                    sb.AppendLine(string.Format("{0}: {1}", status.Name, status.BuildStatus));
                }
            }

            return sb.ToString();
        }
Exemple #16
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string json = string.Empty;

            string argument = this.regex.Match(message).Value;

            try
            {
                var request = WebRequest.Create(this.url + "rest/api/latest/issue/" + argument) as HttpWebRequest;
                request.ContentType = "application/json";
                request.Method      = "GET";

                string base64Credentials = this.GetEncodedCredentials();
                request.Headers.Add("Authorization", "Basic " + base64Credentials);

                var response = request.GetResponse() as HttpWebResponse;

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    json = reader.ReadToEnd();
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }

            if (!string.IsNullOrEmpty(json))
            {
                JObject jsonObj = JObject.Parse(json);
                string  key     = jsonObj["key"].ToString().ToUpper();
                string  summary = jsonObj["fields"]["summary"].ToString();
                string  status;
                string  assignee;

                if (summary[0] == '{')
                {
                    summary  = jsonObj["fields"]["summary"]["value"].ToString();
                    status   = jsonObj["fields"]["status"]["value"]["name"].ToString();
                    assignee = jsonObj["fields"]["assignee"]["value"]["displayName"].ToString();
                }
                else
                {
                    status   = jsonObj["fields"]["status"]["name"].ToString();
                    assignee = jsonObj["fields"]["assignee"].HasValues
                                   ? jsonObj["fields"]["assignee"]["displayName"].ToString()
                                   : "Unassigned";
                }

                var sb = new StringBuilder();

                if (!message.StartsWith("http"))
                {
                    sb.AppendLine(this.url + "browse/" + key);
                }

                sb.AppendLine('"' + summary + '"');
                sb.AppendLine(string.Format("Status: {0}", status));
                sb.AppendLine(string.Format("Assignee: {0}", assignee));
                return(sb.ToString());
            }

            return(string.Empty);
        }
 /// <summary>
 /// Executes the command on answer to the specified chat name.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <returns>
 /// The result string to send back as the answer.
 /// </returns>
 public override string Execute(SkypeContact contact, SkypeChat chat, string args)
 {
     this.dataManager.DisableChat(chat.Id);
     return GoodbyeMessage;
 }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (string.IsNullOrWhiteSpace(args))
            {
                var sb = new StringBuilder();
                sb.AppendLine("The commands supported by this bot:");
                sb.AppendLine("help - displays this help message");

                foreach (AbstractDirectCommand command in this.commands)
                {
                    sb.AppendLine(string.Format("{0} - {1}", command.Name, command.Help));
                }

                sb.AppendLine();
                sb.Append("To get more commands, you should be subscribed to some project.");
                sb.Append("To get detailed help for a certain command, type a command ");
                sb.AppendLine("name after the 'help' command. For example:");
                sb.AppendLine("help on");

                return sb.ToString();
            }

            if (string.Equals(args, "help", StringComparison.CurrentCultureIgnoreCase))
            {
                return "Displays the main help page";
            }

            AbstractDirectCommand directCommand =
                this.commands.FirstOrDefault(c => string.Equals(c.Name, args, StringComparison.OrdinalIgnoreCase));
            if (directCommand != null)
            {
                return directCommand.Usage;
            }

            return "The command is not found. Please type 'help' to see available commands";
        }
Exemple #19
0
 /// <summary>
 /// Executes the command on answer to the specified chat name.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <returns>
 /// The result string to send back as the answer.
 /// </returns>
 public override string Execute(SkypeContact contact, SkypeChat chat, string args)
 {
     this.dataManager.DisableChat(chat.Id);
     return(GoodbyeMessage);
 }