コード例 #1
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            if (Irc.ChannelList.ServerLog == null)
            {
                await Irc.AddChannel("Server");
            }

            if (parsedLine.PrefixMessage.IsUser && parsedLine.PrefixMessage.Nickname == Irc.Nickname)
            {
                Irc.Server.Username = parsedLine.TrailMessage.HasTrail ? parsedLine.TrailMessage.TrailingContent : Irc.Nickname;
            }
            else if (parsedLine.PrefixMessage.IsUser && parsedLine.TrailMessage.HasTrail)
            {
                var username = parsedLine.PrefixMessage.Nickname;
                foreach (var channel in Irc.ChannelList)
                {
                    var users = channel.Store;
                    if (users.HasUser(username))
                    {
                        var msg = new Message
                        {
                            Type = MessageType.JoinPart,
                            User = parsedLine.PrefixMessage.Nickname,
                            Text = string.Format("({0}) {1} {2}", parsedLine.PrefixMessage.Prefix, "changed nick to", parsedLine.TrailMessage.TrailingContent)
                        };
                        Irc.AddMessage(channel.Name, msg);

                        users.RemoveUser(username);
                        users.AddUser(parsedLine.TrailMessage.TrailingContent);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            if (parsedLine.CommandMessage.Command == "353")
            {
                var channel = parsedLine.CommandMessage.Parameters[2];

                var list = parsedLine.TrailMessage.TrailingContent.Split(' ').ToList();
                if (!_namesTable.ContainsKey(channel))
                {
                    _namesTable.Add(channel, list);
                }
                else
                {
                    _namesTable[channel].AddRange(list);
                }
            }
            else if (parsedLine.CommandMessage.Command == "366")
            {
                var channel = parsedLine.CommandMessage.Parameters[1];

                if (!Irc.ChannelList.Contains(channel))
                {
                    await Irc.AddChannel(channel);
                }

                Irc.ChannelList[channel].Store.ReplaceUsers(_namesTable[channel]);

                _namesTable.Remove(channel);
            }
            return(true);
        }
コード例 #3
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle messages to this irc client
            var destination = parsedLine.CommandMessage.Parameters[0];
            var reciever    = parsedLine.CommandMessage.Parameters[1];
            var content     = parsedLine.TrailMessage.TrailingContent;

            if (!Irc.ChannelList.Contains(destination))
            {
                await Irc.AddChannel(destination);
            }

            var msg = new Message();

            msg.Type = MessageType.Info;

            if (reciever == Irc.Server.Username)
            {
                msg.User = parsedLine.PrefixMessage.Nickname;
                msg.Text = "kicked you from the channel: " + content;
            }
            else
            {
                msg.User = parsedLine.PrefixMessage.Nickname;
                msg.Text = string.Format("kicked {0} from the channel: {1}", reciever, content);
            }

            Irc.AddMessage(destination, msg);

            return(true);
        }
コード例 #4
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            var channel = parsedLine.TrailMessage.TrailingContent;

            if (parsedLine.PrefixMessage.Nickname == Irc.Server.Username)
            {
                await Irc.AddChannel(channel);
            }

            if (parsedLine.CommandMessage.Parameters != null)
            {
                channel = parsedLine.CommandMessage.Parameters[0];
            }

            var msg = new Message
            {
                Type = MessageType.JoinPart,
                User = parsedLine.PrefixMessage.Nickname,
                Text = string.Format("({0}) {1}", parsedLine.PrefixMessage.Prefix, "joined the channel")
            };

            Irc.AddMessage(channel, msg);

            Irc.ChannelList[channel].Store.AddUser(parsedLine.PrefixMessage.Nickname);
            return(true);
        }
コード例 #5
0
ファイル: CommandHandler.cs プロジェクト: MattBDev/WinIRC
        internal void QueryCommandHandler(Irc irc, string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            irc.AddChannel(args[1]);
        }
コード例 #6
0
        public override void RunCommand(string channel, string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            Irc.AddChannel(args[1]);
        }
コード例 #7
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle topic recieved
            var topic      = parsedLine.TrailMessage.TrailingContent;
            var channelPos = (parsedLine.CommandMessage.Command == "332") ? 1 : 0;
            var channel    = parsedLine.CommandMessage.Parameters[channelPos];

            if (!Irc.ChannelList.Contains(channel))
            {
                await Irc.AddChannel(channel);
            }

            var msg = new Message();

            msg.Type = MessageType.Info;

            msg.User = "";
            msg.Text = string.Format("Topic for channel {0}: {1}", channel, topic);
            Irc.AddMessage(channel, msg);
            Irc.ChannelList[channel].Store.Topic = topic;
            return(true);
        }
コード例 #8
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            if (Irc.ChannelList.ServerLog == null)
            {
                await Irc.AddChannel("Server");
            }

            var msg = new Message
            {
                Text    = parsedLine.OriginalMessage,
                Type    = MessageType.Info,
                Channel = "Server",
                User    = ""
            };

            if (Irc.DebugMode)
            {
                Debug.WriteLine(parsedLine.OriginalMessage);
            }
            Irc.ChannelList.ServerLog?.Buffers.Add(msg);
            return(true);
        }
コード例 #9
0
 public override async Task <bool> HandleLine(IrcMessage parsedLine)
 {
     Irc.RemoveChannel(parsedLine.CommandMessage.Parameters[1]);
     return(await Irc.AddChannel(parsedLine.CommandMessage.Parameters[2]));
 }
コード例 #10
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle messages to this irc client
            var destination = parsedLine.CommandMessage.Parameters[0];
            var content     = parsedLine.TrailMessage.TrailingContent;

            if (content == "")
            {
                content = parsedLine.CommandMessage.Parameters.Last();
            }

            if (destination == Irc.Server.Username)
            {
                destination = parsedLine.PrefixMessage.Nickname;
            }

            var msg = new Message();

            msg.Channel = destination;
            msg.Type    = Type;
            msg.User    = parsedLine.PrefixMessage.Nickname ?? parsedLine.PrefixMessage.Prefix;

            if (destination.StartsWith("@#"))
            {
                msg.OpOnlyMessage = true;
                msg.Channel       = destination = destination.Substring(1);
            }

            if (msg.User == null)
            {
                msg.User = "";
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Time))
            {
                var time = DateTime.Parse(parsedLine.Metadata[IrcMessage.Time]);
                msg.Date = time;
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Id))
            {
                msg.MessageId = parsedLine.Metadata[IrcMessage.Id];
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Reply))
            {
                msg.ReplyTo = parsedLine.Metadata[IrcMessage.Reply];
            }

            if (content.Contains("ACTION"))
            {
                msg.Text = content.Replace("ACTION ", "");
                msg.Type = MessageType.Action;
            }
            else
            {
                msg.Text = content;
            }

            if ((parsedLine.TrailMessage.TrailingContent.Contains(Irc.Server.Username) || parsedLine.CommandMessage.Parameters[0] == Irc.Server.Username))
            {
                msg.Mention = true;
                Irc.AddMention(msg);
            }

            if (destination == "*")
            {
                Irc.ChannelList.ServerLog?.Buffers.Add(msg);
            }
            else
            {
                if (!Irc.ChannelList.Contains(destination))
                {
                    await Irc.AddChannel(destination);
                }

                Irc.AddMessage(destination, msg);

                if (Type == MessageType.Notice)
                {
                    Irc.InfoBuffer.Add(msg);
                }
            }
            return(true);
        }