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


C# IrcClient.OnModeChanged方法代码示例

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


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

示例1: HandleMode

        public static void HandleMode(IrcClient client, IrcMessage message)
        {
            string target, mode = null;
            int i = 2;
            if (message.Command == "MODE")
            {
                target = message.Parameters[0];
                mode = message.Parameters[1];
            }
            else
            {
                target = message.Parameters[1];
                mode = message.Parameters[2];
                i++;
            }

            var eventArgs = new ModeChangeEventArgs(target, new IrcUser(message.Prefix), mode);
            client.OnModeChanged(eventArgs);
            // Handle change
            bool add = mode[0] == '+';
            mode = mode.Substring(1);
            if (target.StartsWith("#"))
            {
                var channel = client.Channels[target];
                foreach (char c in mode)
                {
                    // TODO: Handle other types of MODEs
                    if (channel.Mode == null)
                        channel.Mode = string.Empty;
                    if (add)
                    {
                        if (!channel.Mode.Contains(c))
                            channel.Mode += c.ToString();
                    }
                    else
                        channel.Mode = channel.Mode.Replace(c.ToString(), string.Empty);
                }
                if (message.Command == "324")
                {
                    var operation = client.RequestManager.DequeueOperation("MODE " + channel.Name);
                    operation.Callback(operation);
                }
            }
            else
            {
                // TODO: Handle user modes other than ourselves?
                foreach (char c in mode)
                {
                    if (add)
                    {
                        if (!client.User.Mode.Contains(c))
                            client.User.Mode += c;
                    }
                    else
                        client.User.Mode = client.User.Mode.Replace(c.ToString(), string.Empty);
                }
            }
        }
开发者ID:randacc,项目名称:ChatSharp,代码行数:58,代码来源:MessageHandlers.cs

示例2: HandleMode

 public static void HandleMode(IrcClient client, IrcMessage message)
 {
     string target, mode = null;
     int i = 2;
     if (message.Command == "MODE")
     {
         target = message.Parameters[0];
         mode = message.Parameters[1];
     }
     else
     {
         target = message.Parameters[1];
         mode = message.Parameters[2];
         i++;
     }
     // Handle change
     bool add = true;
     if (target.StartsWith("#"))
     {
         var channel = client.Channels[target];
         try
         {
             foreach (char c in mode)
             {
                 if (c == '+')
                 {
                     add = true;
                     continue;
                 }
                 if (c == '-')
                 {
                     add = false;
                     continue;
                 }
                 if (channel.Mode == null)
                     channel.Mode = string.Empty;
                 // TODO: Support the ones here that aren't done properly
                 if (client.ServerInfo.SupportedChannelModes.ParameterizedSettings.Contains(c))
                 {
                     client.OnModeChanged(new ModeChangeEventArgs(channel.Name, new IrcUser(message.Prefix),
                         (add ? "+" : "-") + c.ToString() + " " + message.Parameters[i++]));
                 }
                 else if (client.ServerInfo.SupportedChannelModes.ChannelLists.Contains(c))
                 {
                     client.OnModeChanged(new ModeChangeEventArgs(channel.Name, new IrcUser(message.Prefix),
                         (add ? "+" : "-") + c.ToString() + " " + message.Parameters[i++]));
                 }
                 else if (client.ServerInfo.SupportedChannelModes.ChannelUserModes.Contains(c))
                 {
                     if (!channel.UsersByMode.ContainsKey(c)) channel.UsersByMode.Add(c, new UserCollection());
                     var user = new IrcUser(message.Parameters[i]);
                     if (add)
                     {
                         if (!channel.UsersByMode[c].Contains(user.Nick))
                             channel.UsersByMode[c].Add(user);
                     }
                     else
                     {
                         if (channel.UsersByMode[c].Contains(user.Nick))
                             channel.UsersByMode[c].Remove(user);
                     }
                     client.OnModeChanged(new ModeChangeEventArgs(channel.Name, new IrcUser(message.Prefix),
                         (add ? "+" : "-") + c.ToString() + " " + message.Parameters[i++]));
                 }
                 if (client.ServerInfo.SupportedChannelModes.Settings.Contains(c))
                 {
                     if (add)
                     {
                         if (!channel.Mode.Contains(c))
                             channel.Mode += c.ToString();
                     }
                     else
                         channel.Mode = channel.Mode.Replace(c.ToString(), string.Empty);
                     client.OnModeChanged(new ModeChangeEventArgs(channel.Name, new IrcUser(message.Prefix),
                         (add ? "+" : "-") + c.ToString()));
                 }
             }
         }
         catch { }
         if (message.Command == "324")
         {
             var operation = client.RequestManager.DequeueOperation("MODE " + channel.Name);
             operation.Callback(operation);
         }
     }
     else
     {
         // TODO: Handle user modes other than ourselves?
         foreach (char c in mode)
         {
             if (add)
             {
                 if (!client.User.Mode.Contains(c))
                     client.User.Mode += c;
             }
             else
                 client.User.Mode = client.User.Mode.Replace(c.ToString(), string.Empty);
         }
     }
 }
开发者ID:pdelvo,项目名称:ChatSharp,代码行数:100,代码来源:MessageHandlers.cs

示例3: HandleMode

        public static void HandleMode(IrcClient client, IrcMessage message)
        {
            string target, mode;
            if (message.Command == "MODE")
            {
                target = message.Parameters[0];
                mode = message.Payload.Substring(message.Payload.IndexOf(' ') + 1);
            }
            else
            {
                target = message.Parameters[1];
                mode = message.Payload.Substring(message.Payload.IndexOf(' ') + 1);
                mode = mode.Substring(mode.IndexOf(' ') + 1);
            }

            var eventArgs = new ModeChangeEventArgs(target, new IrcUser(message.Prefix), mode);
            client.OnModeChanged(eventArgs);
            // Handle change
            var change = mode;
            var parameters = new string[0];
            if (change.Contains(' '))
            {
                parameters = change.Substring(change.IndexOf(' ') + 1).Split(' ');
                change = change.Remove(change.IndexOf(' '));
            }
            bool add = change[0] == '+';
            change = change.Substring(1);
            if (target.StartsWith("#"))
            {
                var channel = client.Channels[target];
                int i = 0;
                foreach (char c in change)
                {
                    if (c == 'o')
                    {
                        var user = parameters[i++];
                        if (add)
                            channel.Operators.Add(channel.Users[user]);
                        else
                            channel.Operators.Remove(user);
                    }
                    else if (c == 'v')
                    {
                        var user = parameters[i++];
                        if (add)
                            channel.Voiced.Add(channel.Users[user]);
                        else
                            channel.Voiced.Remove(user);
                    }
                    else if (c == 'b')
                    {
                        var mask = new Mask(parameters[i++], new IrcUser(message.Prefix), DateTime.Now);
                        if (add)
                            channel.Bans.Add(mask);
                        else
                        {
                            if (channel.Bans.ContainsMask(mask))
                                channel.Bans.Remove(mask);
                        }
                    }
                    else if (c == 'e')
                    {
                        var mask = new Mask(parameters[i++], new IrcUser(message.Prefix), DateTime.Now);
                        if (add)
                            channel.Exceptions.Add(mask);
                        else
                        {
                            if (channel.Exceptions.ContainsMask(mask))
                                channel.Exceptions.Remove(mask);
                        }
                    }
                    else if (c == 'q')
                    {
                        var mask = new Mask(parameters[i++], new IrcUser(message.Prefix), DateTime.Now);
                        if (add)
                            channel.Quiets.Add(mask);
                        else
                        {
                            if (channel.Quiets.ContainsMask(mask))
                                channel.Quiets.Remove(mask);
                        }
                    }
                    else if (c == 'I')
                    {
                        var mask = new Mask(parameters[i++], new IrcUser(message.Prefix), DateTime.Now);
                        if (add)
                            channel.Invites.Add(mask);
                        else
                        {
                            if (channel.Invites.ContainsMask(mask))
                                channel.Invites.Remove(mask);
                        }
                    }
                    else
                    {
                        if (channel.Mode == null)
                            channel.Mode = string.Empty;
                        if (add)
                        {
                            if (!channel.Mode.Contains(c))
//.........这里部分代码省略.........
开发者ID:angelog,项目名称:ChatSharp,代码行数:101,代码来源:MessageHandlers.cs


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