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

            Assert.AreEqual(expected, IrcCommand.Error(errorMessage));
        }
Example #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);
        }
     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));
 	}
Example #4
0
        public string FindFileOLD(IrcCommand command)
        {
            string name         = command.Parameters[0];
            string searchstring = RevDBs[CurrentBranchOLD].FindFile(name);

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

            Assert.AreEqual(expected, IrcCommand.Pass(password));
        }
Example #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));
        }
Example #7
0
 public void IsonTest()
 {
     Assert.AreEqual("ISON Wiz", IrcCommand.Ison("Wiz"));
     Assert.AreEqual("ISON Wiz Angel", IrcCommand.Ison(new List <string> {
         "Wiz", "Angel"
     }));
 }
Example #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");
        }
Example #9
0
        public void AdminTest()
        {
            Assert.AreEqual("ADMIN", IrcCommand.Admin());
            string target = "tolsun.oulu.fi";

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

            Assert.AreEqual(expected, IrcCommand.Nick(nickname));
        }
Example #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
                    )
                );
            }
        }
        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));
        }
Example #13
0
        public static BotCommand Parse(IrcCommand ircCommand)
        {
            BotCommand botCommand = new BotCommand();

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

            Assert.AreEqual("INVITE Wiz #Twilight_Zone", IrcCommand.Invite(nickname, channel));
        }
Example #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));
        }
Example #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));
        }
Example #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));
        }
Example #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));
        }
Example #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));
        }
Example #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;
 }
Example #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"
     }));
 }
Example #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));
        }
        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."
            );
        }
Example #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");
        }
Example #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");
        }
Example #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());
        }
Example #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));
        }
Example #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));
        }
Example #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;
        }
Example #30
0
        public string DumpRevs(IrcCommand command)
        {
            string data = "";

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

            return("Done: " + data.Haste());
        }
Example #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());
        }
Example #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));
        }
Example #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."));
        }
Example #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);
        }
Example #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);
        }
Example #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");
        }
Example #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);
            }
        }
Example #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();
        }
Example #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);
        }
Example #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));
                }
            }
        }
        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();
        }
        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
                    )
                );
            }
        }
        public override void Process(IrcCommand command)
        {
            base.Process(command);

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

            SendPrivateMessage("usage: register <username> <password> <email>");
        }
Example #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;
 }
Example #46
0
 internal void UnregisterRawCommand(IrcCommand cmd, IrcMessageHandler callback)
 {
     con.UnregisterRawCommand(this, cmd, callback);
 }
Example #47
0
 public BotCommand(IrcCommand ircCommand)
 {
     this.Parameters = new List<string>();
     SetProperties(ircCommand, this);
 }
Example #48
0
 public static BotCommand Parse(IrcCommand ircCommand)
 {
     BotCommand botCommand = new BotCommand();
     SetProperties(ircCommand, botCommand);
     return botCommand;
 }
Example #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;
        }
Example #50
0
 public void addCommand(string command, IrcCommand ircCommand)
 {
     this.commandList.Add(command, ircCommand);
 }