public void DoTrackKickPlugin(IrcConnection conn, IrcLine line)
        {
            Regex r = new Regex(@"^(?<channel>#[^ ]+) (?<idiot>.*)$", RegexOptions.ExplicitCapture);
            Match m = r.Match(line.IrcCommandArgsRaw);

            if (m.Success)
            {
                string channelName = m.Groups["channel"].Value;
                string idiot       = m.Groups["idiot"].Value;

                Nick    banner    = conn.Server.ConnectedNicks.FirstOrDefault(x => x.Name == line.Nick.ToLower());
                Nick    idiotNick = conn.Server.ConnectedNicks.FirstOrDefault(x => x.Name == idiot.ToLower());
                Channel channel   = conn.Server.ConnectedChannels.FirstOrDefault(x => x.Name == channelName.ToLower());

                Ban ban = Ban.Fetch(channel, idiotNick);
                if (ban != null)
                {
                    if (ban.BannerAccount == null && banner.Account != null)
                    {
                        ban.BannerAccount = banner.Account;
                    }
                    ban.Nick = idiotNick;
                    if (idiotNick.Account != null)
                    {
                        ban.Account = idiotNick.Account;
                    }
                    ban.Channel    = channel;
                    ban.BanMessage = line.Trail;

                    LumbricusContext.db.SaveChanges();
                }
            }
        }
        public override void HandleCommand(IrcLine line, Nick nick, Channel channel)
        {
            try {
                Seen     seen      = Seen.Fetch(nick);
                DateTime checkTime = DateTime.Now;
                checkTime.AddDays(-7);
                if (seen.FirstSeenAt == DateTime.MinValue || seen.FirstSeenAt > checkTime)
                {
                    conn.SendPrivmsg(nick.Name, String.Format("Sorry, {0}, but you aren't allowed to use the mugshots functions yet. :(", nick.DisplayName));
                    return;
                }

                Mugshot mugshot = Mugshot.Fetch(nick.Account);
                if (mugshot == null)
                {
                    conn.SendPrivmsg(nick.Name, "You don't have a mugshot in the database to clear! :o");
                    return;
                }

                nick.Account.MostRecentNick = nick;

                mugshot.IsDeleted = true;
                mugshot.Save();

                conn.SendPrivmsg(nick.Name, "Your mugshot has been cleared. :(");
            } catch (Exception e) {
                logger.Error(e);
                conn.SendPrivmsg(nick.Name, "Oof… I've got indigestion or something, I can't do that right now. :(");
            }
        }
Beispiel #3
0
 /// <summary>
 /// 去除首位空格
 /// </summary>
 public void Trim()
 {
     Psw        = Psw.Trim();
     PswConfirm = PswConfirm.Trim();
     UserName   = UserName.Trim();
     Nick       = Nick.Trim();
 }
 public void CapitalizeNick()
 {
     if (!nickInt.NullOrEmpty())
     {
         nickInt = char.ToUpper(Nick[0]) + Nick.Substring(1);
     }
 }
Beispiel #5
0
        public override void HandleCommand(IrcLine line, Nick nick, Channel channel)
        {
            try {
                Seen     seen      = Seen.Fetch(nick);
                DateTime checkTime = DateTime.Now;
                checkTime.AddDays(-7);
                if (seen.FirstSeenAt == DateTime.MinValue || seen.FirstSeenAt > checkTime)
                {
                    conn.SendPrivmsg(nick.Name, String.Format("Sorry, {0}, but you aren't allowed to use the mugshots functions yet. :(", nick.DisplayName));
                    return;
                }

                Regex r = new Regex(@"^!setinfo ?");
                line.Args = r.Replace(line.Args, "").Trim();
                if (line.Args.Length <= 0)   // Whaaaat??
                {
                    conn.SendPrivmsg(nick.Name, "Usage: !setinfo <your message here>");
                }
                else
                {
                    nick.Account.MostRecentNick = nick;

                    Info info = Info.FetchOrCreate(nick.Account);
                    info.InfoTxt   = line.Args;
                    info.IsActive  = true;
                    info.IsDeleted = false;
                    info.Save();

                    conn.SendPrivmsg(nick.Name, "Your info has been saved! :D");
                }
            } catch (Exception e) {
                logger.Error(e);
                conn.SendPrivmsg(nick.Name, "Oof… My neck is killing me, I can't do that right now. :(");
            }
        }
Beispiel #6
0
 public static long FetchTotal(Nick nick)
 {
     return((from l in IrcLogContext.db.Logs
             where (l.Nick != null && l.Nick.Id == nick.Id) ||
             (nick.Account != null && l.Account != null && l.Account.Id == nick.Account.Id)
             select l).Count());
 }
Beispiel #7
0
        public void IDs_should_be_not_equals_if_used_constructor()
        {
            var nick1 = new Nick(_user, "name");
            var nick2 = new Nick(_user, "name");

            Assert.AreNotEqual(nick1.Id, nick2.Id);
        }
Beispiel #8
0
        public void AddNick(Nick nick)
        {
            // Let's see if the nick already is added
            string search = "SELECT * FROM `nicks` WHERE " +
                            "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}) AND " +
                            "`nickname` = {1}";
            List <Dictionary <string, object> > results = Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nick.Nickname });

            if (!results.Any())
            {
                string insert = "INSERT INTO `nicks` SET " +
                                "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                                "`nickname` = {1}";
                Bot.Database.Execute(insert, new object[] { Bot.ServerConfig.Name, nick.Nickname });
            }
            // search for the nick's modes (if any)
            List <Channel> tmpChannels = new List <Channel>(Bot.IRC.Channels);

            foreach (Channel channel in tmpChannels)
            {
                if (channel.Nicks.Exists(chn => chn.Nickname == nick.Nickname))
                {
                    Nick foundNick = channel.Nicks.Find(chn => chn.Nickname == nick.Nickname);
                    nick.AddModes(foundNick.Modes);
                    nick.AddPrivileges(foundNick.Privileges);
                }
            }

            // Now add that nick's info to the db
            AddNickInfo(nick);
        }
Beispiel #9
0
 public void Constructor_Should_Work()
 {
     const string nickName = @"Name";
     var nick = new Nick(_user, nickName);
     Assert.AreEqual(nick.Name, nickName);
     Assert.AreNotEqual(nick.Id, Guid.Empty);
 }
Beispiel #10
0
 public void Connect()
 {
     Logger.Info("Connecting to {0}:{1} as {2}...", Hostname, Port, Nick);
     ExtendedUser = String.Format("{0}!{0}@{0}.tmi.twitch.tv", Nick.ToLower());
     _serverComm  = new ServerComm();
     _serverComm.StartClient(this);
 }
Beispiel #11
0
        public override void HandleCommand(IrcLine line, Nick nick, Channel channel)
        {
            try {
                if (!isOp(nick))
                {
                    conn.SendPrivmsg(nick.Name, String.Format("Sorry, {0}, but that command doesn't exist. Try !help.", nick.DisplayName));
                    return;
                }

                string target = nick.Name;
                if (channel != null && channel.AllowCommandsInChannel)
                {
                    target = channel.Name;
                }

                Regex r = new Regex(@"^!join ?");
                line.Args = r.Replace(line.Args, "").Trim();
                if (line.Args.Length <= 1)   // Whaaaat??
                {
                    conn.SendPrivmsg(target, String.Format("Usage(1): !join <channel>"));
                }
                else
                {
                    r = new Regex(@"^#+[a-zA-Z0-9_`\-]+$");
                    Match m = r.Match(line.Args);
                    if (!m.Success)
                    {
                        conn.SendPrivmsg(target, String.Format("Usage(1): !join <channel> — Channel should start with a # and contain no spaces"));
                    }
                    else
                    {
                        Channel ircChannel = conn.Server.ConnectedChannels.FirstOrDefault(x => x.Name == line.Args.ToLower());
                        if (ircChannel != null)
                        {
                            conn.SendPrivmsg(target, String.Format("Uh… {0}… I'm already /in/ {1}… o.o", nick.DisplayName, line.Args));
                        }
                        else
                        {
                            ircChannel = Channel.FetchOrCreate(line.Args, conn.Server);
                            if (ircChannel != null)
                            {
                                List <Channel> channels = new List <Channel>();
                                logger.Debug("Joining " + ircChannel.Name);
                                conn.SendPrivmsg(target, String.Format("Joining {0}! :D", line.Args));
                                conn.Send("JOIN " + ircChannel.Name);
                                channels.Add(ircChannel);
                                conn.LoadUserDataForJoinedChannels(channels);
                            }
                            else
                            {
                                conn.SendPrivmsg(target, String.Format("Sorry, {0}, but I couldn't join `{1}` as I couldn't fetch it from the database.", nick.DisplayName, line.Args));
                            }
                        }
                    }
                }
            } catch (Exception e) {
                logger.Error(e);
                conn.SendPrivmsg(nick.Name, "¡Ay caray! It's Lupus! D:");
            }
        }
Beispiel #12
0
 public override void HandleCommand(IrcLine line, Nick nick, Channel channel)
 {
     try {
         Setting helpUriSetting = Setting.Fetch("Help", "Uri");
         if (helpUriSetting == null)
         {
             conn.SendPrivmsg(nick.Name, String.Format("Oh dear… I'm afraid I don't seem to be able to answer that right now, {0}!", nick.DisplayName));
             return;
         }
         if (nick.Account != null && isOp(nick))
         {
             string target = nick.Name;
             if (channel != null && channel.AllowCommandsInChannel)
             {
                 target = channel.Name;
             }
             conn.SendPrivmsg(target, String.Format("Hi, @{0}. Main help is at {1}. You also have access to these op-only commands: !seen, !baninfo, !botban, !restart", nick.DisplayName, helpUriSetting.Value));
         }
         else
         {
             conn.SendPrivmsg(nick.Name, String.Format("Hi, {0}. Help is at {1}.", nick.DisplayName, helpUriSetting.Value));
             if (channel != null && !channel.AllowCommandsInChannel)
             {
                 conn.SendPrivmsg(nick.Name, "Also, please try to only interact with me directly through this window. Bot commands in the main channel are against channel policy, and some people get really annoyed about it. :(");
             }
         }
     } catch (Exception e) {
         logger.Error(e);
         conn.SendPrivmsg(nick.Name, "Oof… I really shouldn't have had that second slice of cake, I can't do that right now. :(");
     }
 }
Beispiel #13
0
        private void UpdateSeen(string channel, Nick nick, string message, DateTime time)
        {
            List <Dictionary <string, object> > results = GetSeenList(channel, nick.Nickname);

            if (channel == null)
            {
                channel = "--Server--";
            }
            if (results.Any())
            {
                foreach (Dictionary <string, object> row in results)
                {
                    // Update the table
                    string query = "UPDATE `seen` SET " +
                                   "`message` = {0}, " +
                                   "`date_seen` = {1} " +
                                   "WHERE `id` = {2}";
                    Bot.Database.Execute(query, new object[] { message, time, row["id"].ToString() });
                }
            }
            else
            {
                // Add a new record
                AddNick(nick);
                AddChannel(channel);
                string query = "INSERT INTO `seen` SET " +
                               "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                               "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
                               "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
                               "`message` = {5}, " +
                               "`date_seen` = {6}";
                Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, Bot.ServerConfig.Name, nick.Nickname, message, time });
            }
        }
Beispiel #14
0
 public void GetHashcode_should_return_equals_values_for_equals_Names()
 {
     var nick1 = new Nick(_user, "Name");
     var nick2 = new Nick(_user, "NamE");
     
     Assert.AreEqual(nick1.GetHashCode(), nick2.GetHashCode());
 }
Beispiel #15
0
        public void SameIdentityAs_should_return_true_for_equals_Names()
        {
            var nick1 = new Nick(_user, "name");
            var nick2 = new Nick(_user, "NamE");

            Assert.IsTrue(nick1.SameIdentityAs(nick2));
            Assert.IsTrue(nick2.SameIdentityAs(nick1));
        }
Beispiel #16
0
        public void SameIdentityAs_should_return_false_for_not_equals_Names()
        {
            var nick1 = new Nick(_user, "name1");
            var nick2 = new Nick(_user, "name");

            Assert.IsFalse(nick1.SameIdentityAs(nick2));
            Assert.IsFalse(nick1.SameIdentityAs(null));
        }
Beispiel #17
0
 public static Log Fetch(Nick nick, Log ignoreLogLine = null, Channel excludeChannel = null)
 {
     return((from l in IrcLogContext.db.Logs
             where ((l.Nick != null && l.Nick.Id == nick.Id) ||
                    (nick.Account != null && l.Account != null && l.Account.Id == nick.Account.Id)) &&
             (ignoreLogLine == null || l.Id != ignoreLogLine.Id) &&
             (excludeChannel == null || (l.Channel != null && l.Channel.Id != excludeChannel.Id))
             select l).FirstOrDefault());
 }
Beispiel #18
0
 public override bool Equals(Object obj)
 {
     if (obj is User ob)
     {
         return(Id.Equals(ob.Id) && Name.Equals(ob.Name) && Nick.Equals(ob.Nick) &&
                IsBot.Equals(ob.IsBot));
     }
     return(false);
 }
Beispiel #19
0
 public CommandMessage()
 {
     Location    = string.Empty;
     MessageType = MessageType.Channel;
     Nick        = new Nick();
     TimeStamp   = DateTime.Now;
     Command     = string.Empty;
     Arguments   = new Dictionary <string, dynamic>();
     Access      = new List <AccessType>();
 }
        public Nick FetchIrcNick(string nick)
        {
            Nick ircNick = Server.ServerNicks.FirstOrDefault(x => x.Name == nick.ToLower());

            if (ircNick != null)
            {
                Server.AddNick(ircNick);
            }
            return(ircNick);
        }
Beispiel #21
0
        public static Mugshot Fetch(Nick nick)
        {
            if (nick.Account == null)
            {
                return(null);
            }

            return((from s in MugshotsContext.db.Mugshots
                    where s.Account != null && s.Account.Id == nick.Account.Id
                    select s).FirstOrDefault());
        }
Beispiel #22
0
        public static Info Fetch(Nick nick)
        {
            if (nick.Account == null)
            {
                return(null);
            }

            return((from s in InfoContext.db.Infos
                    where s.Account != null && s.Account.Id == nick.Account.Id
                    select s).FirstOrDefault());
        }
        public Nick FetchOrCreateIrcNick(string nick)
        {
            Nick ircNick =
                Server.ConnectedNicks.FirstOrDefault(x => x.Name == nick.ToLower())
                ?? Nick.FetchOrCreate(nick, Server);

            if (ircNick != null)
            {
                Server.AddNick(ircNick);
            }
            return(ircNick);
        }
Beispiel #24
0
        public override void HandleCommand(IrcLine line, Nick nick, Channel channel)
        {
            try {
                if (!isOp(nick))
                {
                    conn.SendPrivmsg(nick.Name, String.Format("Sorry, {0}, but that command doesn't exist. Try !help.", nick.DisplayName));
                    return;
                }

                string target = nick.Name;
                if (channel != null && channel.AllowCommandsInChannel)
                {
                    target = channel.Name;
                }

                Regex r = new Regex(@"^!part ?");
                line.Args = r.Replace(line.Args, "").Trim();
                if (line.Args.Length <= 1)   // Whaaaat??
                {
                    conn.SendPrivmsg(target, String.Format("Usage(1): !part <channel>"));
                }
                else
                {
                    r = new Regex(@"^#+[a-zA-Z0-9_`\-]+$");
                    Match m = r.Match(line.Args);
                    if (!m.Success)
                    {
                        conn.SendPrivmsg(target, String.Format("Usage(1): !part <channel> — Channel should start with a # and contain no spaces"));
                    }
                    else
                    {
                        Channel ircChannel = conn.Server.ConnectedChannels.FirstOrDefault(x => x.Name == line.Args.ToLower());
                        if (ircChannel == null)
                        {
                            conn.SendPrivmsg(target, String.Format("Uh… {0}… I'm not /in/ {1}… o.o", nick.DisplayName, line.Args));
                        }
                        else
                        {
                            conn.SendPrivmsg(target, String.Format("Parting {0}. :(", line.Args));
                            logger.Debug("Parting " + ircChannel.Name);
                            conn.Send("PART " + ircChannel.Name);
                        }
                    }
                }
            } catch (Exception e) {
                logger.Error(e);
                conn.SendPrivmsg(nick.Name, "¡Ay caray! It's Lupus! D:");
            }
        }
Beispiel #25
0
        public bool Equals(Player p)
        {
            if (p is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, p))
            {
                return(true);
            }

            return(Nick.Equals(p.Nick) && Name.Equals(p.Name) && Class.Equals(p.Class) &&
                   Level.Equals(p.Level) && UHost.Equals(p.UHost) && Pos.Equals(p.Pos));
        }
        protected bool isOp(IrcConnection conn, Nick nick)
        {
            if (nick.Account == null)
            {
                return(false);
            }
            else if (nick.Account.IsOp)
            {
                return(true);
            }

            Setting opsSetting = Setting.Fetch("Ops", "Nicks");

            if (opsSetting != null)
            {
                string[] nicks = opsSetting.Value.Split(" ".ToArray());
                foreach (string n in nicks)
                {
                    if (n.ToLower() == nick.Name.ToLower())
                    {
                        return(true);
                    }
                }
            }

            Setting opsChannelSetting = Setting.Fetch("Ops", "Channels");

            if (opsChannelSetting != null)
            {
                string[] channels = opsChannelSetting.Value.Split(" ".ToArray());
                foreach (string c in channels)
                {
                    Channel opsChannel = conn.Server.ConnectedChannels.FirstOrDefault(x => x.Name == c);
                    if (opsChannel == null)
                    {
                        throw new Exception(string.Format("Unable to find ops channel `{0}` in conn.Server.Channels", c));
                    }

                    if (opsChannel.ConnectedNicks.Contains(nick))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #27
0
    public void SaveGame()
    {
        ClearPlaceBlocks();
        Save save = CreateSaveGameObject();

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/gamesave.save");

        bf.Serialize(file, save);
        file.Close();

        if (Nick != null && !Nick.Equals(""))
        {
            StartCoroutine(SendScoreToRemote());
        }
        Debug.Log("Game Saved");
    }
Beispiel #28
0
        protected virtual void SetDefaultValues()
        {
            if (string.IsNullOrEmpty(Ident))
            {
                Ident = Nick.ToLower();
            }

            if (string.IsNullOrEmpty(RealName))
            {
                RealName = Nick;
            }

            if (Port == 0)
            {
                Port = 6667;
            }
        }
        static bool CheckBans(Nick nick, Account account, string user, string host)
        {
            if (string.IsNullOrEmpty(nick.UserName))
            {
                nick.UserName = user;
            }
            if (string.IsNullOrEmpty(nick.Host))
            {
                nick.Host = host;
            }
            Ban ban = Ban.Fetch(nick, account);

            if (ban != null && ban.IsActive)
            {
                logger.Info("Ignoring {0} because they're banned by ban id {1}.", nick, ban.Id);
                return(true);
            }
            return(false);
        }
Beispiel #30
0
 public void ResolveMissingPieces(string overrideLastName = null)
 {
     if (First.NullOrEmpty() && Nick.NullOrEmpty() && Last.NullOrEmpty())
     {
         Log.Error("Cannot resolve misssing pieces in PawnName: No name data.");
         firstInt = (nickInt = (lastInt = "Empty"));
     }
     else
     {
         if (First == null)
         {
             firstInt = string.Empty;
         }
         if (Last == null)
         {
             lastInt = string.Empty;
         }
         if (overrideLastName != null)
         {
             lastInt = overrideLastName;
         }
         if (Nick.NullOrEmpty())
         {
             if (Last == string.Empty)
             {
                 nickInt = First;
             }
             else
             {
                 if (Rand.ValueSeeded(Gen.HashCombine(First.GetHashCode(), Last)) < 0.5f)
                 {
                     nickInt = First;
                 }
                 else
                 {
                     nickInt = Last;
                 }
                 CapitalizeNick();
             }
         }
     }
 }
Beispiel #31
0
        private void ParseFromUrl(string infoPageUrl)
        {
            var htmlWeb = new HtmlWeb();
            var htmlDoc = htmlWeb.Load(infoPageUrl);

            Nick = htmlDoc.DocumentNode.SelectSingleNode("//h2[@class='']").InnerHtml;
            Nick = Nick.Remove(0, 6);
            Nick = Nick.Remove(Nick.Length - 1, 1);

            string tmpVills = htmlDoc.DocumentNode.SelectSingleNode("//table[@id='villages_list']//th").InnerText;

            tmpVills = tmpVills.Replace("Wioski (", "").Replace(")", "");
            Villages = Convert.ToInt32(tmpVills);

            var    infoTable = htmlDoc.DocumentNode.SelectNodes("//table[@id='player_info']//tr");
            string tmpPoints = infoTable[1].InnerText;

            tmpPoints = tmpPoints.Replace("Punkty:", "").Replace(".", "");
            string tmpRank = infoTable[2].InnerText;

            tmpRank = tmpRank.Replace("Ranking:", "");
            string tmpAlly = "";

            if (infoTable.Count > 4)
            {
                tmpAlly = infoTable[4].InnerText;
                ForkOutDefeated(infoTable[3].InnerHtml);
            }
            else // nie ma pokonanych przeciwników
            {
                tmpAlly          = infoTable[3].InnerText;
                Points_Aggresor  = 0; Rank_Aggresor = 0;
                Points_Defender  = 0; Rank_Defender = 0;
                Points_Supporter = 0; Rank_Supporter = 0;
            }

            tmpAlly = tmpAlly.Replace("Plemię:", "").Replace("\n", "").Replace("\t", "");

            Points      = Convert.ToInt64(tmpPoints);
            Rank_Points = Convert.ToInt32(tmpRank);
            Ally        = tmpAlly;
        }
Beispiel #32
0
        private void ExecuteCommand(MessageType messageType, string location, Nick nick, Dictionary <string, object> trigger)
        {
            string type    = trigger["type"].ToString();
            string message = trigger["response"].ToString();

            switch (type.ToLower())
            {
            case "response":
                message = "\u200B" + message;
                SendResponse(messageType, location, nick.Nickname, message);
                break;

            case "command":
                Bot.ExecuteCommand(Bot.ServerConfig.CommandPrefix + message, location, messageType, nick);
                break;

            case "list":
                // todo handle list commands
                break;
            }
        }
Beispiel #33
0
        public void DoSeenPlugin(IrcConnection conn, IrcLine line)
        {
            // :[email protected] JOIN #channel
            // :Nick!~User@unaffiliated/Nick JOIN #channel
            // :Nick!~User@unaffiliated/Nick PART #channel
            // :Nick!~User@unaffiliated/Nick PART #channel :"screw you"
            // :[email protected] QUIT :Quit: Quit!
            // :[email protected] NICK :FourHalfWorms
            // :[email protected] PRIVMSG Lumbricus :!info Nick2
            Channel    channel    = null;
            IrcCommand ircCommand = (IrcCommand)Enum.Parse(typeof(IrcCommand), line.IrcCommand);

            switch (ircCommand)
            {
            case IrcCommand.JOIN:
            case IrcCommand.PART:
            case IrcCommand.PRIVMSG:
                if (line.IrcCommandArgsRaw.StartsWith("#"))
                {
                    channel = conn.GetChannel(line.IrcCommandArgsRaw);
                }
                goto case IrcCommand.NICK;

            case IrcCommand.NICK:
            case IrcCommand.NOTICE:
            case IrcCommand.QUIT:
                Nick nick = Nick.FetchOrCreate(line.Nick, conn.Server);
                if (nick == null)
                {
                    throw new Exception(String.Format("Unable to fetch or create nick `{0}`", nick));
                }

                Seen.Update(conn.Server, nick, nick.Account, channel);

                break;
            }
        }
Beispiel #34
0
        private void AddMessage(CommandMessage command, bool anonymous = false)
        {
            List <Dictionary <string, object> > currentMessages = GetSentMessages(command.Arguments["Nickname"], command.Nick.Nickname);
            int numMessages = currentMessages.Count();
            int maxMessages = Convert.ToInt32(GetOptionValue("Max Messages"));

            if (numMessages < maxMessages)
            {
                AddNick(command.Nick);
                Nick    newNick      = new Nick();
                Channel foundChannel = Bot.IRC.Channels.Find(chan => chan.Nicks.Exists(nick => nick.Nickname == command.Arguments["Nickname"]));
                if (foundChannel != null)
                {
                    newNick = foundChannel.GetNick(command.Arguments["Nickname"]);
                }
                else
                {
                    newNick.Nickname = command.Arguments["Nickname"];
                }
                AddNick(newNick);
                string query = "INSERT INTO `messages` SET " +
                               "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                               "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nicks`.`nickname` = {2}), " +
                               "`sender_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nicks`.`nickname` = {4}), " +
                               "`message` = {5}, " +
                               "`anonymous` = {6}, " +
                               "`date_posted` = {7}";
                Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, command.Arguments["Nickname"], Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], anonymous, command.TimeStamp });
                string message = string.Format("I will send your message to \u0002{0}\u0002 as soon as I see them.", command.Arguments["Nickname"]);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
            }
            else
            {
                string maxMessage = string.Format("You already have sent the maximum number of messages to \u0002{0}\u0002.  Wait until they have read their messages before sending another.", command.Arguments["Nickname"]);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, maxMessage, true);
            }
        }
Beispiel #35
0
            public static IrcResponse[] HandleCommand(string req, IrcSession session)
            {
                string[] parts = req.Split(' ');
                string   cmd   = parts[0].ToUpper();

                string[] args = parts.Skip(1).ToArray();
                switch (cmd)
                {
                case "PASS":
                    return(Pass.Handle(args, session));

                case "NICK":
                    return(Nick.Handle(args, session));

                case "JOIN":
                    return(Join.Handle(args, session));

                case "QUIT":
                    return(Quit.Handle(session));

                default:
                    return(new IrcResponse[] { new UnknownCommandResponse(session, cmd) });
                }
            }
Beispiel #36
0
        private void PopulateNicks()
        {
            if (sortedNickNames != null)
            {
                sortedNickNames.Clear();
                sortedNickNames = null;
            }

            sortedNickNames = new List<Nick>();

            try
            {
                foreach (User nick in currentWindow.Nicks.Values)
                {
                    Nick n = new Nick();
                    n.nick = nick.ToString();
                    n.selected = nick.Selected;
                    n.nickColor = nick.nickColor;
                    n.Level = nick.Level;

                    if (currentWindow.Connection.ServerSetting.IAL.ContainsKey(nick.NickName))
                        n.host = ((InternalAddressList)currentWindow.Connection.ServerSetting.IAL[nick.NickName]).Host;
                    else
                        n.host = "";

                    sortedNickNames.Add(n);

                }

                sortedNickNames.Sort();

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message + ":" + e.Source);
            }
        }
Beispiel #37
0
 public void GetHashcode_should_return_not_equals_values_for_not_equals_Names()
 {
     var nick1 = new Nick(_user, "Opa");
     var nick2 = new Nick(_user, "Opa1");
     Assert.AreNotEqual(nick2.GetHashCode(), nick1.GetHashCode()); 
 }
Beispiel #38
0
 public void Equals_should_return_true_for_equals_Names()
 {
     var nick1 = new Nick(_user, "Opa");
     var nick2 = new Nick(_user, "OpA");
     Assert.IsTrue(nick1.Equals(nick2));
 }
Beispiel #39
0
 public void Equals_should_return_false_for_not_equals_Names()
 {
     var nick1 = new Nick(_user, "Opa");
     var nick2 = new Nick(_user, "OpA1");
     Assert.IsFalse(nick1.Equals(nick2));
     Assert.IsFalse(nick1.Equals(1));
     Assert.IsFalse(nick1.Equals(null));
 }