Ejemplo n.º 1
0
        public void ErrorTest()
        {
            string errorMessage = "Server *.fi already exists.";
            string expected     = "ERROR :Server *.fi already exists.";

            Assert.AreEqual(expected, IrcCommand.Error(errorMessage));
        }
Ejemplo n.º 2
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);
            var helpCommand = new UserLoginHelpCommand();

            if (HandleNoParameters(helpCommand, forcePrivate: true))
                return;

            if (command.Parameters[0] == "help" || !ValidParameters())
            {
                helpCommand.Process(command);
                return;
            }

            var username = command.Parameters[0];
            var password = command.Parameters[1];
            string message = string.Empty;
            Data.User user;

            if (TryLogin(username, password, out message, out user))
            {
                command.Bot.RegisterUser(
                    new IrcBotUser {
                        UserName = username,
                        NickName = command.Source.Name,
                        IsAdmin = user.IsAdmin,
                        IsBotAdmin = user.IsBotAdmin
                    }
                );
            }

            SendPrivateMessage(message);
        }
Ejemplo n.º 3
0
     protected override void OnReceivedLine(string line)
 	{
 		var cmd = new IrcCommand();
 		cmd.Channel = line.SubString(x,y);
 		cmd.Message = line.SubString(z,a);
 		CommandReceived(this, new IrcCommandEventArgs(cmd));
 	}
Ejemplo n.º 4
0
        public string FindFileOLD(IrcCommand command)
        {
            string name         = command.Parameters[0];
            string searchstring = RevDBs[CurrentBranchOLD].FindFile(name);

            return("Done: " + searchstring.Haste());
        }
Ejemplo n.º 5
0
        public void PassTest()
        {
            const string password = "******";
            const string expected = "PASS TestPassword";

            Assert.AreEqual(expected, IrcCommand.Pass(password));
        }
Ejemplo n.º 6
0
        public void NoticeTest()
        {
            const string target  = "Angel";
            const string message = "yes I'm receiving it!";

            Assert.AreEqual("NOTICE Angel :yes I'm receiving it!", IrcCommand.Notice(target, message));
        }
Ejemplo n.º 7
0
 public void IsonTest()
 {
     Assert.AreEqual("ISON Wiz", IrcCommand.Ison("Wiz"));
     Assert.AreEqual("ISON Wiz Angel", IrcCommand.Ison(new List <string> {
         "Wiz", "Angel"
     }));
 }
Ejemplo n.º 8
0
        public string RegisterUser(IrcCommand command)
        {
            userdb.RegisterUser(command.Source.Nick, command.Parameters[0], command.Source.Hostmask);
            SaveDB();

            return("Done.  Your password is stored with SHA256");
        }
Ejemplo n.º 9
0
        public void AdminTest()
        {
            Assert.AreEqual("ADMIN", IrcCommand.Admin());
            string target = "tolsun.oulu.fi";

            Assert.AreEqual($"ADMIN {target}", IrcCommand.Admin(target));
        }
Ejemplo n.º 10
0
        public void NickTest()
        {
            const string nickname = "Tom";
            const string expected = "NICK Tom";

            Assert.AreEqual(expected, IrcCommand.Nick(nickname));
        }
Ejemplo n.º 11
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (!HasAdminUser())
                return;

            var message = string.Format("I'm going to need a little more information, {0}.", command.Source.Name);
            if (HandleNoParameters(message, new AwsElbRepairHelpCommand()))
                return;

            SendMessage("checking status...");
            this.states = GetInstanceStates();
            SendMessage(GetInstanceStatusMessage());

            var badInstances = GetBadInstances();
            if (badInstances.Count > 0)
            {
                RebootInstances(badInstances);
            }
            else
            {
                SendMessage(
                    string.Format(
                        "no out of service instances detected, {0}. celebrate!",
                        this.command.Source.Name
                    )
                );
            }
        }
Ejemplo n.º 12
0
        public void PrivateMessageTest()
        {
            const string target  = "Angel";
            const string message = "yes I'm receiving it!";

            Assert.AreEqual("PRIVMSG Angel :yes I'm receiving it!", IrcCommand.PrivateMessage(target, message));
        }
Ejemplo n.º 13
0
        public static BotCommand Parse(IrcCommand ircCommand)
        {
            BotCommand botCommand = new BotCommand();

            SetProperties(ircCommand, botCommand);
            return(botCommand);
        }
Ejemplo n.º 14
0
        public void InviteTest()
        {
            const string nickname = "Wiz";
            const string channel  = "#Twilight_Zone";

            Assert.AreEqual("INVITE Wiz #Twilight_Zone", IrcCommand.Invite(nickname, channel));
        }
Ejemplo n.º 15
0
        public void QuitTest()
        {
            const string message  = "Gone to have lunch";
            const string expected = "QUIT :Gone to have lunch";

            Assert.AreEqual("QUIT", IrcCommand.Quit());
            Assert.AreEqual(expected, IrcCommand.Quit(message));
        }
Ejemplo n.º 16
0
        public void TopicTest()
        {
            const string channel = "#test";

            Assert.AreEqual("TOPIC #test :another topic", IrcCommand.Topic(channel, "another topic"));
            Assert.AreEqual("TOPIC #test :", IrcCommand.ClearTopic(channel));
            Assert.AreEqual("TOPIC #test", IrcCommand.GetTopic(channel));
        }
Ejemplo n.º 17
0
        public void OperTest()
        {
            const string name     = "foo";
            const string password = "******";
            const string expected = "OPER foo bar";

            Assert.AreEqual(expected, IrcCommand.Oper(name, password));
        }
Ejemplo n.º 18
0
        public void UserModeTest()
        {
            const string nickname   = "WiZ";
            const string modeString = "-w";
            const string expected   = "MODE WiZ -w";

            Assert.AreEqual(expected, IrcCommand.UserMode(nickname, modeString));
        }
Ejemplo n.º 19
0
        public void SquitTest()
        {
            const string server   = "tolsun.oulu.fi";
            const string message  = "Bad Link";
            const string expected = "SQUIT tolsun.oulu.fi :Bad Link";

            Assert.AreEqual(expected, IrcCommand.Squit(server, message));
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Create an INCOMPLETE IrcMessage only carrying username
 /// </summary>
 /// <param name="user"></param>
 public IrcMessage(string user)
 {
     _parameters = null;
     User        = user;
     Hostmask    = null;
     Command     = IrcCommand.Unknown;
     Tags        = null;
 }
Ejemplo n.º 21
0
 public void UserHostTest()
 {
     Assert.AreEqual("USERHOST Wiz", IrcCommand.UserHost("Wiz"));
     Assert.AreEqual("USERHOST Wiz Michael syrk",
                     IrcCommand.UserHost(new List <string> {
         "Wiz", "Michael", "syrk"
     }));
 }
Ejemplo n.º 22
0
        public void AwayTest()
        {
            Assert.AreEqual("AWAY", IrcCommand.Away());
            string message  = "Gone to lunch.";
            string expected = "AWAY :Gone to lunch.";

            Assert.AreEqual(expected, IrcCommand.Away(message));
        }
Ejemplo n.º 23
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            SendMessage(
                "It's easy! Just type this: aws elb status <load balancer name>. If you need a list of load balancers, that command is: aws elb list."
            );
        }
Ejemplo n.º 24
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            SendMessage("retrieving list of load balancers...");
            var descriptions = this.elb.List(command.Parameters.FirstOrDefault());
            SendMessages(GetMessages(descriptions));
            SendMessage("use \"aws elb status <elb name>\" to see more information");
        }
Ejemplo n.º 25
0
        public string SendMessage(IrcCommand command)
        {
            string username = command.Parameters[0];
            string message  = command.Message.Remove(0, username.Length + 1);

            message = "From " + command.Source.Nick + " on " + DateTime.Now.ToString() + ": " + message;

            return(SendMemo(username, message) ? "Message Sent" : "User does not exist");
        }
Ejemplo n.º 26
0
        public void InfoTest()
        {
            string target   = "csd.bu.edu";
            string expected = "INFO csd.bu.edu";

            Assert.AreEqual(expected, IrcCommand.Info(target));
            expected = "INFO";
            Assert.AreEqual(expected, IrcCommand.Info());
        }
Ejemplo n.º 27
0
        public void ServiceTest()
        {
            const string serviceName  = "dict";
            const string distribution = "*.fr";
            const string info         = "French Dictionary";
            const string expected     = "SERVICE dict * *.fr 0 0 :French Dictionary";

            Assert.AreEqual(expected, IrcCommand.Service(serviceName, distribution, info));
        }
Ejemplo n.º 28
0
        public void NamesTest()
        {
            Assert.AreEqual("NAMES", IrcCommand.Names());
            Assert.AreEqual("NAMES #42", IrcCommand.Names("#42"));
            List <string> channels = new List <string> {
                "#twilight_zone", "#42"
            };

            Assert.AreEqual("NAMES #twilight_zone,#42", IrcCommand.Names(channels));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Create an IrcMessage
        /// </summary>
        /// <param name="command">IRC Command</param>
        /// <param name="parameters">Command params</param>
        /// <param name="hostmask">User</param>
        /// <param name="tags">IRCv3 tags</param>
        public IrcMessage(IrcCommand command, string[] parameters, string hostmask, Dictionary <string, string> tags = null)
        {
            var idx = hostmask.IndexOf('!');

            User        = idx != -1 ? hostmask.Substring(0, idx) : hostmask;
            Hostmask    = hostmask;
            _parameters = parameters;
            Command     = command;
            Tags        = tags;
        }
Ejemplo n.º 30
0
        public string DumpRevs(IrcCommand command)
        {
            string data = "";

            foreach (Revision rev in RevDBs[CurrentBranchOLD].AllRevisions)
            {
                data += rev.name + "\n";
            }

            return("Done: " + data.Haste());
        }
Ejemplo n.º 31
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            var message = string.Format("I'm going to need a little more information, {0}.", command.Source.Name);
            if (HandleNoParameters(message, new AwsElbStatusHelpCommand()))
                return;

            SendMessage("checking status...");
            SendMessage(GetInstanceStatusMessage());
        }
Ejemplo n.º 32
0
        public void UserTest()
        {
            const string user       = "******";
            const string modeString = "-i+a";
            const string realname   = "Ronnie Reagan";
            string       expected   = "USER guest 0 * :Ronnie Reagan";


            expected = "USER guest -i+a * :Ronnie Reagan";
            Assert.AreEqual(expected, IrcCommand.User(user, modeString, realname));
        }
Ejemplo n.º 33
0
        public void PartTest()
        {
            Assert.AreEqual("PART #twilight_zone", IrcCommand.Part("#twilight_zone"));
            List <string> channels = new List <string> {
                "#oz-ops", "&group5"
            };

            Assert.AreEqual("PART #oz-ops,&group5", IrcCommand.Part(channels));
            Assert.AreEqual("PART #twilight_zone :Lunch Time.", IrcCommand.Part("#twilight_zone", "Lunch Time."));
            Assert.AreEqual("PART #oz-ops,&group5 :Lunch Time.", IrcCommand.Part(channels, "Lunch Time."));
        }
Ejemplo n.º 34
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (HandleNoParameters(new AwsElbHelpCommand()))
                return;

            command.Shift();
            var processor = processorFactory.CreateByCommand(command);
            processor.Process(command);
        }
Ejemplo n.º 35
0
        public string OpenRevisionOLD(IrcCommand command)
        {
            if (RevDBs[CurrentBranchOLD].RevisionOpen)
            {
                return("Cannot open revision while " + RevDBs[CurrentBranchOLD].openRev + " is Open");
            }
            string name = command.Parameters[0];

            RevDBs[CurrentBranchOLD].OpenRevision(name);

            return("Opened " + name);
        }
Ejemplo n.º 36
0
        public string DeleteRevision(IrcCommand command)
        {
            Revision rev = RevDBs[CurrentBranchOLD].GetRevisionByName(command.Parameters[0]);

            if (rev == null)
            {
                return("No Revision " + command.Parameters[0]);
            }
            RevDBs[CurrentBranchOLD].DeleteRevision(rev);

            return("Done");
        }
Ejemplo n.º 37
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (!HasParameters)
            {
                PrintTaskList();
            }
            else
            {
                command.Shift();
                var processor = processorFactory.CreateByCommand(command);
                processor.Process(command);
            }
        }
Ejemplo n.º 38
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);
            var helpCommand = new UserRegisterHelpCommand();

            if (HandleNoParameters(helpCommand, forcePrivate: true))
                return;

            if (command.Parameters[0] == "help" || !ValidParameters())
            {
                helpCommand.Process(command);
                return;
            }

            CreateUser();
        }
Ejemplo n.º 39
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            var message = string.Format(
                "I need more information, {0}.",
                command.Source.Name
            );

            if (HandleNoParameters(message, new UserHelpCommand()))
                return;

            command.Shift();
            var processor = processorFactory.CreateByCommand(command);
            processor.Process(command);
        }
Ejemplo n.º 40
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            if (HandleNoParameters("usage: pause <task #>"))
                return;

            int taskNumber = 0;
            if (int.TryParse(command.Parameters.FirstOrDefault(), out taskNumber))
            {
                IIrcTask task;
                if (command.Bot.TryPauseTask(taskNumber, command, out task))
                {
                    SendMessage(string.Format("{0} has been paused.", task.Name));
                }
            }
        }
Ejemplo n.º 41
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            var message = string.Format(
                "I need the name of the load balancer, {0}.",
                command.Source.Name
            );

            if (HandleNoParameters(message))
            {
                SendMessage("Try: aws elb instances <load balancer name>. If you need a list of load balancers, that command is: aws elb list.");
                return;
            }

            SendMessage("retrieving elb status and ec2 instance urls...");
            GetInstanceStates();
            GetDescriptions();
            PrintUrls();
        }
Ejemplo n.º 42
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            var message = string.Format(
                "I need the name of the load balancer, {0}.",
                command.Source.Name
            );

            if (HandleNoParameters(message))
            {
                SendMessage("Try: aws elb instances <load balancer name>. If you need a list of load balancers, that command is: aws elb list.");
                return;
            }

            var loadBalancerName = command.Parameters[0];
            var elb = new ELB();
            var ec2 = new EC2();
            var instances = elb.Instances(loadBalancerName);
            var outOfLB = ElbState.GetStates(loadBalancerName).ToDictionary(s => s.State.InstanceId, s => s);
            var descriptions = ec2.InstanceDescriptions(instances.Select(i => i.InstanceId));

            foreach (var description in descriptions)
            {
                var timeOutString = outOfLB.ContainsKey(description.InstanceId) ? "Out For: " + outOfLB[description.InstanceId].TimeSincePulled() : "InService";
                SendNotice(
                    string.Format(
                        @"id: {0} / ip: {1} / state: {2} / type: {3} / ami: {4} / dns: {5} / Elb State: {6}",
                        description.InstanceId,
                        description.IpAddress,
                        description.InstanceState.Name,
                        description.InstanceType,
                        description.ImageId,
                        description.PublicDnsName,
                        timeOutString
                    )
                );
            }
        }
Ejemplo n.º 43
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            SendPrivateMessage("usage: login <username> <password>");
        }
Ejemplo n.º 44
0
        public override void Process(IrcCommand command)
        {
            base.Process(command);

            SendPrivateMessage("usage: register <username> <password> <email>");
        }
Ejemplo n.º 45
0
 /*/// <summary>
 /// Return wether or not a command may be triggered.
 /// Is called everytime, a command is triggered
 /// By default Squishy is set to do nothing until you override this and add an auth system
 /// </summary>
 public bool MayTriggerCommand(CmdTrigger<IrcCmdArgs> cmdTrigger)
 {
     return MayTriggerCommand(cmdTrigger, cmdTrigger.Command.RootCmd);
 }*/
 /// <summary>
 /// Return wether or not a command may be triggered.
 /// Is called everytime, a command is triggered
 /// By default Squishy is set to do nothing until you override this and add an auth system
 /// </summary>
 /// <param name="cmd">A command.</param>
 public virtual bool MayTriggerCommand(CmdTrigger<IrcCmdArgs> trigger, IrcCommand cmd)
 {
     return trigger.Args.User == null || trigger.Args.User == Me;
 }
Ejemplo n.º 46
0
 internal void UnregisterRawCommand(IrcCommand cmd, IrcMessageHandler callback)
 {
     con.UnregisterRawCommand(this, cmd, callback);
 }
Ejemplo n.º 47
0
 public BotCommand(IrcCommand ircCommand)
 {
     this.Parameters = new List<string>();
     SetProperties(ircCommand, this);
 }
Ejemplo n.º 48
0
 public static BotCommand Parse(IrcCommand ircCommand)
 {
     BotCommand botCommand = new BotCommand();
     SetProperties(ircCommand, botCommand);
     return botCommand;
 }
Ejemplo n.º 49
0
        public static void SetProperties(IrcCommand source, BotCommand target)
        {
            if (source == null) throw new ArgumentNullException("source");
            if (target == null) throw new ArgumentNullException("target");

            string[] botCommandParts = source.Parameter.Split(' ');

            target.Command = botCommandParts[0];
            target.IrcCommand = source.Command;
            target.Nick = source.Nick;

            foreach (var parameter in botCommandParts.Skip(1))
            {
                target.Parameters.Add(parameter);
            }

            target.User = source.User;
        }
Ejemplo n.º 50
0
 public void addCommand(string command, IrcCommand ircCommand)
 {
     this.commandList.Add(command, ircCommand);
 }