public override void Process(IrcCommand command)
        {
            base.Process(command);

            const string url = "http://google.com/complete/search?q={0}&output=toolbar";
            var uri = new Uri(string.Format(url, string.Join(" ", command.Parameters)));

            var task = uri.Download();
            if (task.IsFaulted || task.IsCanceled)
            {
                SendMessage("Sorry master, I could not complete the phrase");
            }
            else
            {
                var xml = XDocument.Parse(task.Result);
                var suggestions = xml.Descendants("suggestion");
                if (!suggestions.Any())
                {
                    SendMessage("Sorry master, I have no suggestions.");
                    return;
                }

                foreach (var node in suggestions)
                {
                    SendMessage(node.Attribute("data").Value);
                }
            }
        }
Exemple #2
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            SendMessage(
                string.Join(" ", command.Parameters)
            );
        }
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            var statusMessages = GetBuildStatus();
            foreach (var message in statusMessages)
                SendMessage(message);
        }
        public IIrcCommandProcessor CreateByCommand(IrcCommand channelCommand)
        {
            if (!string.IsNullOrEmpty(channelCommand.Name) && this.commandMap.ContainsKey(channelCommand.Name))
            {
                var type = this.commandMap[channelCommand.Name];
                var instance = Activator.CreateInstance(type);
                return (IIrcCommandProcessor)instance;
            }

            return new UnsupportedCommand();
        }
Exemple #5
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            command.Bot.Resume();
            SendMessage(
                string.Format(
                    "What are the legal ramifications of bringing me back from the dead, {0}?",
                    command.Source.Name
                )
            );
        }
Exemple #6
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            command.Bot.Pause();
            SendMessage(
                string.Format(
                    "Without the great sacrifices you've made, {0}, we wouldn't be here to share this nice pot of tea.",
                    command.Source.Name
                )
            );
        }
Exemple #7
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            const int dice = 2;
            const int sides = 6;

            var random = new Random();
            var roll = random.Next(1, dice * sides);
            var result = "I rolled a " + roll;

            SendMessage(result);
        }
        public void Process(IrcCommand command)
        {
            var rand = new Random(DateTime.Now.Millisecond);
            var index = rand.Next(0, messages.Count);
            var message = messages[index];

            command.Client.LocalUser.SendMessage(
                command.Target,
                string.Format(
                    message,
                    command.Source.Name
                )
            );
        }
Exemple #9
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (!HasAdminUser())
                return;

            if (command.Parameters.Length < 2)
            {
                SendMessage(
                    "You have to tell me what to say and where to say it: say <channel | user> message"
                );
                return;
            }

            var target = command.Parameters[0];
            var message = string.Join(" ", command.Parameters, 1, command.Parameters.Length - 1);
            command.Client.LocalUser.SendMessage(
                target,
                message
            );
        }
Exemple #10
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (!HasAdminUser())
                return;

            SendMessage(
                string.Format("Ok {0}, I'm outta here!", command.Source.Name)
            );

            Thread.Sleep(250);

            command.Client.Quit(
                string.Format(
                    "{0} made me do it",
                    command.Source.Name
                )
            );

            Thread.Sleep(250);

            command.Client.Disconnect();
        }
Exemple #11
0
        private void OnChannelMessageReceived(object sender, IrcMessageEventArgs e)
        {
            var channel = sender as IrcChannel;
            var parts = e.Text.Trim().Split(' ');

            if (IsValidChannelCommand(parts)) {
                var command = new IrcCommand(
                    this,
                    GetUser(e.Source.Name),
                    this.client,
                    parts,
                    channel,
                    e.Source
                );

                ProcessCommand(command);
            }
        }
Exemple #12
0
        private void NotifyAdmins(IrcCommand command)
        {
            var targets = this.users.Values
                .Where(u => u.IsBotAdmin)
                .Select(u => u.NickName)
                .ToArray();

            if (targets.Length > 0)
            {
                this.client.LocalUser.SendMessage(
                    targets,
                    string.Format(
                            "command - source: {0} target: {1} name: {2} params: {3}",
                            command.Source.Name,
                            command.Target.Name,
                            command.Name,
                            string.Join(" ", command.Parameters)
                        )
                    );
            }
        }
Exemple #13
0
        private void HandleCommandException(IrcCommand command, Exception ex)
        {
            try
            {
                var message = string.Format(
                    "{0}, I ran into a bit of a problem with that last request: {1}",
                    command.Source.Name,
                    ex.Message
                );

                if (ex.InnerException != null)
                {
                    message = string.Format(
                        "{0} {1}",
                        message,
                        ex.InnerException.Message
                    );
                }

                this.client.LocalUser.SendMessage(
                    command.Target,
                    message.Replace(Environment.NewLine, " ")
                );
            }
            catch (Exception secondException)
            {
                // HACK: log, console for now
                Console.WriteLine(
                    "Exception occured while handling exception from command ({0}): {1}",
                    command.Name,
                    secondException.Message
                );
            }
        }
Exemple #14
0
 public bool TryResumeTask(int taskNumber, IrcCommand command, out IIrcTask task)
 {
     if (TryFindTask(taskNumber - 1, command, out task) && task.IsPaused)
     {
         task.Resume();
         return true;
     }
     return false;
 }
Exemple #15
0
 public bool TryPauseTask(int taskNumber, IrcCommand command, out IIrcTask task)
 {
     if (TryFindTask(taskNumber - 1, command, out task) && task.IsRunning)
     {
         task.Pause();
         return true;
     }
     return false;
 }
Exemple #16
0
 public override void Process(IrcCommand command)
 {
     base.Process(command);
     SendMessage(Responses.Random());
 }
Exemple #17
0
 private void ProcessCommand(IrcCommand command)
 {
     NotifyAdmins(command);
     Task.Run(() =>
     {
         try
         {
             var processor = commandProcessorFactory.CreateByCommand(command);
             processor.Process(command);
         }
         catch (Exception ex)
         {
             HandleCommandException(command, ex);
         }
     });
 }
Exemple #18
0
        private bool TryFindTask(int index, IrcCommand command, out IIrcTask task)
        {
            task = this.tasks.ElementAtOrDefault(index);

            if (task == null)
            {
                var message = string.Format(
                    "I'm sorry, {0}, but I could not find the specified task: {1}",
                    command.Source.Name,
                    index
                );
                command.Client.LocalUser.SendMessage(
                    command.Target,
                    message
                );

                return false;
            }

            return true;
        }
 public virtual void Process(IrcCommand command)
 {
     this.command = command;
 }