当前位置: 首页>>代码示例>>C#>>正文


C# Core.Bot方法代码示例

本文整理汇总了C#中Core.Bot方法的典型用法代码示例。如果您正苦于以下问题:C# Core.Bot方法的具体用法?C# Core.Bot怎么用?C# Core.Bot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Core的用法示例。


在下文中一共展示了Core.Bot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        protected override void Parse(Core.Server aServer, string aRawData, string aMessage, string[] aCommands)
        {
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType + "(" + aServer.Name + ")");

            string tUserName = aCommands[0].Split('!')[0];

            Bot tBot = aServer.Bot(tUserName);
            if (tBot != null)
            {
                bool isParsed = false;
                Match tMatch;
                Match tMatch1;
                Match tMatch2 ;
                Match tMatch3;
                Match tMatch4;

                int valueInt;
                aMessage = RemoveSpecialIrcChars(aMessage);
                //double valueDouble;

                #region ALL SLOTS FULL / ADDING TO QUEUE

                if (true)
                {
                    tMatch1 = Regex.Match(aMessage,
                                          "(" + Magicstring +
                                          " All Slots Full, |)Added you to the main queue (for pack ([0-9]+) \\(\".*\"\\) |).*in positi(o|0)n (?<queue_cur>[0-9]+)\\. To Remove you(r|)self at a later time .*",
                                          RegexOptions.IgnoreCase);
                    tMatch2 = Regex.Match(aMessage,
                                          "Queueing you for pack [0-9]+ \\(.*\\) in slot (?<queue_cur>[0-9]+)/(?<queue_total>[0-9]+)\\. To remove you(r|)self from the queue, type: .*\\. To check your position in the queue, type: .*\\. Estimated time remaining in queue: (?<queue_d>[0-9]+) days, (?<queue_h>[0-9]+) hours, (?<queue_m>[0-9]+) minutes",
                                          RegexOptions.IgnoreCase);
                    tMatch3 = Regex.Match(aMessage,
                                          "(" + Magicstring +
                                          " |)Es laufen bereits genug .bertragungen, Du bist jetzt in der Warteschlange f.r Datei [0-9]+ \\(.*\\) in Position (?<queue_cur>[0-9]+)\\. Wenn Du sp.ter Abbrechen willst schreibe .*",
                                          RegexOptions.IgnoreCase);
                    if (tMatch1.Success || tMatch2.Success || tMatch3.Success)
                    {
                        tMatch = tMatch1.Success ? tMatch1 : tMatch2;
                        tMatch = tMatch.Success ? tMatch : tMatch3;
                        isParsed = true;
                        if (tBot.State == Bot.States.Idle)
                        {
                            tBot.State = Bot.States.Waiting;
                        }

                        tBot.InfoSlotCurrent = 0;
                        if (int.TryParse(tMatch.Groups["queue_cur"].ToString(), out valueInt))
                        {
                            tBot.QueuePosition = valueInt;
                            tBot.InfoQueueCurrent = tBot.QueuePosition;
                        }

                        if (int.TryParse(tMatch.Groups["queue_total"].ToString(), out valueInt))
                        {
                            tBot.InfoQueueTotal = valueInt;
                        }
                        else if (tBot.InfoQueueTotal < tBot.InfoQueueCurrent)
                        {
                            tBot.InfoQueueTotal = tBot.InfoQueueCurrent;
                        }

                        int time = 0;
                        if (int.TryParse(tMatch.Groups["queue_m"].ToString(), out valueInt))
                        {
                            time += valueInt * 60;
                        }
                        if (int.TryParse(tMatch.Groups["queue_h"].ToString(), out valueInt))
                        {
                            time += valueInt * 60 * 60;
                        }
                        if (int.TryParse(tMatch.Groups["queue_d"].ToString(), out valueInt))
                        {
                            time += valueInt * 60 * 60 * 24;
                        }
                        tBot.QueueTime = time;
                    }
                }

                #endregion

                #region REMOVE FROM QUEUE

                if (!isParsed)
                {
                    tMatch = Regex.Match(aMessage, Magicstring + " Removed From Queue: .*", RegexOptions.IgnoreCase);
                    if (tMatch.Success)
                    {
                        isParsed = true;
                        if (tBot.State == Bot.States.Waiting)
                        {
                            tBot.State = Bot.States.Idle;
                        }
                        FireCreateTimer(aServer, tBot, Settings.Instance.CommandWaitTime, false);
                    }
                }

                #endregion

                #region INVALID PACKET NUMBER

//.........这里部分代码省略.........
开发者ID:sstraus,项目名称:xdcc-grabscher,代码行数:101,代码来源:Notice.cs

示例2: Parse

        protected override void Parse(Core.Server aServer, string aRawData, string aMessage, string[] aCommands)
        {
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType + "(" + aServer.Name + ")");

            string tUserName = aCommands[0].Split('!')[0];
            Channel tChan = aServer.Channel(aCommands[2]);

            Bot tBot = aServer.Bot(tUserName);

            #region VERSION

            if (aMessage == "VERSION")
            {
                log.Info("Parse() VERSION: " + Settings.Instance.IrcVersion);
                FireSendData(aServer, "NOTICE " + tUserName + " :\u0001VERSION " + Settings.Instance.IrcVersion + "\u0001");
                return;
            }

                #endregion

                #region XGVERSION

            if (aMessage == "XGVERSION")
            {
                log.Info("Parse() XGVERSION: " + Settings.Instance.XgVersion);
                FireSendData(aServer, "NOTICE " + tUserName + " :\u0001XGVERSION " + Settings.Instance.XgVersion + "\u0001");
                return;
            }

                #endregion

                #region DCC DOWNLOAD MESSAGE

            if (aMessage.StartsWith("DCC") && tBot != null)
            {
                Packet tPacket = tBot.OldestActivePacket();
                if (tPacket != null)
                {
                    if (tPacket.Connected)
                    {
                        log.Error("Parse() ignoring dcc from " + tBot + " because " + tPacket + " is already connected");
                    }
                    else
                    {
                        bool isOk = false;

                        int tPort = 0;
                        Int64 tChunk = 0;

                        string[] tDataList = aMessage.Split(' ');
                        if (tDataList[1] == "SEND")
                        {
                            log.Info("Parse() DCC from " + tBot);

                            // if the name of the file contains spaces, we have to replace em
                            if (aMessage.StartsWith("DCC SEND \""))
                            {
                                Match tMatch = Regex.Match(aMessage, "DCC SEND \"(?<packet_name>.+)\"(?<bot_data>[^\"]+)$");
                                if (tMatch.Success)
                                {
                                    aMessage = "DCC SEND " + tMatch.Groups["packet_name"].ToString().Replace(" ", "_").Replace("'", "") + tMatch.Groups["bot_data"];
                                    tDataList = aMessage.Split(' ');
                                }
                            }

                            #region IP CALCULATING

                            try
                            {
                                // this works not in mono?!
                                tBot.Ip = IPAddress.Parse(tDataList[3]);
                            }
                            catch (FormatException)
                            {
                                #region WTF - FLIP THE IP BECAUSE ITS REVERSED?!

                                string ip;
                                try
                                {
                                    ip = new IPAddress(long.Parse(tDataList[3])).ToString();
                                }
                                catch (Exception ex)
                                {
                                    log.Fatal("Parse() " + tBot + " - can not parse bot ip from string: " + aMessage, ex);
                                    return;
                                }
                                string realIp = "";
                                int pos = ip.LastIndexOf('.');
                                try
                                {
                                    realIp += ip.Substring(pos + 1) + ".";
                                    ip = ip.Substring(0, pos);
                                    pos = ip.LastIndexOf('.');
                                    realIp += ip.Substring(pos + 1) + ".";
                                    ip = ip.Substring(0, pos);
                                    pos = ip.LastIndexOf('.');
                                    realIp += ip.Substring(pos + 1) + ".";
                                    ip = ip.Substring(0, pos);
                                    pos = ip.LastIndexOf('.');
                                    realIp += ip.Substring(pos + 1);
//.........这里部分代码省略.........
开发者ID:sstraus,项目名称:xdcc-grabscher,代码行数:101,代码来源:PrivateMessage.cs

示例3: Parse

        protected override void Parse(Core.Server aServer, string aRawData, string aMessage, string[] aCommands)
        {
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType + "(" + aServer.Name + ")");

            string tUserName = aCommands[0].Split('!')[0];
            string tComCodeStr = aCommands[1];
            string tChannelName = aCommands[2];

            Channel tChan = aServer.Channel(tChannelName);
            Bot tBot = aServer.Bot(tUserName);

            if (tBot != null)
            {
                tBot.LastContact = DateTime.Now;
            }

            #region PRIVMSG

            if (tComCodeStr == "PRIVMSG")
            {
                _privateMessage.ParseData(aServer, aRawData);
                return;
            }

                #endregion

                #region NOTICE

            if (tComCodeStr == "NOTICE")
            {
                if (tUserName.ToLower() == "nickserv")
                {
                    _nickserv.ParseData(aServer, aRawData);
                }
                else
                {
                    _notice.ParseData(aServer, aRawData);
                }
                return;
            }

                #endregion

                #region NICK

            if (tComCodeStr == "NICK")
            {
                if (tBot != null)
                {
                    tBot.Name = aMessage;
                    log.Info("con_DataReceived() bot " + tUserName + " renamed to " + tBot);
                }
                else if (tUserName == Settings.Instance.IrcNick)
                {
                    // what should i do now?!
                    log.Error("con_DataReceived() wtf? i was renamed to " + aMessage);
                }
            }

                #endregion

                #region KICK

            else if (tComCodeStr == "KICK")
            {
                if (tChan != null)
                {
                    tUserName = aCommands[3];
                    if (tUserName == Settings.Instance.IrcNick)
                    {
                        tChan.Connected = false;
                        log.Warn("con_DataReceived() kicked from " + tChan + (aCommands.Length >= 5 ? " (" + aCommands[4] + ")" : "") + " - rejoining");
                        log.Warn("con_DataReceived() " + aRawData);
                        FireJoinChannel(aServer, tChan);

                        // statistics
                        Statistic.Instance.Increase(StatisticType.ChannelsKicked);
                    }
                    else
                    {
                        tBot = aServer.Bot(tUserName);
                        if (tBot != null)
                        {
                            tBot.Connected = false;
                            tBot.LastMessage = "kicked from " + tChan;
                            log.Info("con_DataReceived() " + tBot + " is offline");
                        }
                    }
                }
            }

                #endregion

                #region KILL

            else if (tComCodeStr == "KILL")
            {
                tUserName = aCommands[2];
                if (tUserName == Settings.Instance.IrcNick)
                {
//.........这里部分代码省略.........
开发者ID:sstraus,项目名称:xdcc-grabscher,代码行数:101,代码来源:Parser.cs

示例4: Parse

        protected override void Parse(Core.Server aServer, string aRawData, string aMessage, string[] aCommands)
        {
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType + "(" + aServer.Name + ")");

            Bot tBot = aServer.Bot(aCommands[0].Split('!')[0]);
            Channel tChan = aServer.Channel(aCommands[2]);

            string tComCodeStr = aCommands[1];
            int tComCode;
            if (int.TryParse(tComCodeStr, out tComCode))
            {
                switch (tComCode)
                {
                        #region 4

                    case 4: //
                        aServer.Connected = true;
                        aServer.Commit();
                        break;

                        #endregion

                        #region RPL_WHOISCHANNELS

                    case 319: // RPL_WHOISCHANNELS
                        tBot = aServer.Bot(aCommands[3]);
                        if (tBot != null)
                        {
                            string chanName = "";
                            bool addChan = true;
                            string[] tChannelList = aRawData.Split(':')[2].Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string chan in tChannelList)
                            {
                                chanName = "#" + chan.Split('#')[1];
                                if (aServer.Channel(chanName) != null)
                                {
                                    addChan = false;
                                    FireRequestFromBot(aServer, tBot);
                                    break;
                                }
                            }
                            if (addChan)
                            {
                                log.Info("Parse() auto adding channel " + chanName);
                                aServer.AddChannel(chanName);
                            }
                        }
                        break;

                        #endregion

                        #region RPL_NAMREPLY

                    case 353: // RPL_NAMREPLY
                        tChan = aServer.Channel(aCommands[4]);
                        if (tChan != null)
                        {
                            string[] tUsers = aMessage.Split(' ');
                            foreach (string user in tUsers)
                            {
                                string tUser = Regex.Replace(user, "^(@|!|%|\\+){1}", "");
                                tBot = tChan.Bot(tUser);
                                if (tBot != null)
                                {
                                    tBot.Connected = true;
                                    tBot.LastMessage = "joined channel " + tChan.Name;
                                    if (tBot.State != Bot.States.Active)
                                    {
                                        tBot.State = Bot.States.Idle;
                                    }
                                    log.Info("Parse() " + tBot + " is online");
                                    tBot.Commit();
                                    FireRequestFromBot(aServer, tBot);
                                }
                            }
                        }
                        break;

                        #endregion

                        #region RPL_ENDOFNAMES

                    case 366: // RPL_ENDOFNAMES
                        tChan = aServer.Channel(aCommands[3]);
                        if (tChan != null)
                        {
                            tChan.ErrorCode = 0;
                            tChan.Connected = true;
                            log.Info("Parse() joined " + tChan);
                        }

                        // statistics
                        Statistic.Instance.Increase(StatisticType.ChannelConnectsOk);
                        break;

                        #endregion

                        #region RPL_ENDOFMOTD | ERR_NOMOTD

                    case 376: // RPL_ENDOFMOTD
//.........这里部分代码省略.........
开发者ID:sstraus,项目名称:xdcc-grabscher,代码行数:101,代码来源:IntValue.cs


注:本文中的Core.Bot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。