コード例 #1
0
        /// <inheritdoc />
        public override Task <IReadOnlyCollection <Channel> > MapChannels(IEnumerable <ChatChannel> channels, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
        {
            if (channels.Any(x => x.IrcChannel == null))
            {
                throw new InvalidOperationException("ChatChannel missing IrcChannel!");
            }
            lock (this)
            {
                var hs = new HashSet <string>();                // for unique inserts
                foreach (var I in channels)
                {
                    hs.Add(I.IrcChannel);
                }
                var toPart = new List <string>();
                foreach (var I in client.JoinedChannels)
                {
                    if (!hs.Remove(I))
                    {
                        toPart.Add(I);
                    }
                }

                foreach (var I in toPart)
                {
                    client.RfcPart(I, "Pretty nice abscond!");
                }
                foreach (var I in hs)
                {
                    client.RfcJoin(I);
                }

                return((IReadOnlyCollection <Channel>)channels.Select(x =>
                {
                    ulong?id = null;
                    if (!channelIdMap.Any(y =>
                    {
                        if (y.Value != x.IrcChannel)
                        {
                            return false;
                        }
                        id = y.Key;
                        return true;
                    }))
                    {
                        id = channelIdCounter++;
                        channelIdMap.Add(id.Value, x.IrcChannel);
                    }

                    return new Channel
                    {
                        RealId = id.Value,
                        IsAdminChannel = x.IsAdminChannel == true,
                        ConnectionName = address,
                        FriendlyName = channelIdMap[id.Value],
                        IsPrivateChannel = false,
                        Tag = x.Tag
                    };
                }).ToList());
            }
        }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
コード例 #2
0
        /// <summary>
        /// Baut eine Verbindung mit den angegebenen Daten auf
        /// </summary>
        public void Connect()
        {
            _connection = new IrcFeatures();

            _connection.ActiveChannelSyncing = true;

            _connection.CtcpSource       = "Frag Suchiman in freenode";
            _connection.CtcpUrl          = _connection.CtcpSource;
            _connection.CtcpUserInfo     = "Ich bin ein automatisch denkendes Wesen auch bekannt als Bot";
            _connection.CtcpVersion      = "FritzBot:v3:" + Environment.OSVersion.Platform.ToString();
            _connection.Encoding         = Encoding.GetEncoding("iso-8859-1");
            _connection.EnableUTF8Recode = true;

            _connection.OnChannelAction  += _connection_OnMessage;
            _connection.OnChannelMessage += _connection_OnMessage;
            _connection.OnChannelNotice  += _connection_OnMessage;

            _connection.OnQueryAction  += _connection_OnMessage;
            _connection.OnQueryMessage += _connection_OnMessage;
            _connection.OnQueryNotice  += _connection_OnMessage;

            _connection.OnNickChange += _connection_OnNickChange;
            _connection.OnJoin       += _connection_OnJoin;
            _connection.OnKick       += _connection_OnKick;
            _connection.OnPart       += _connection_OnPart;
            _connection.OnQuit       += _connection_OnQuit;

            _connection.OnConnectionError += _connection_OnConnectionError;

            _connection.Connect(Settings.Address, Settings.Port);
            _connection.Login(Settings.Nickname, Settings.Nickname, 0, Settings.Nickname);

            if (Settings.NickServPassword != null)
            {
                _connection.SendMessage(SendType.Message, "nickserv", "identify " + Settings.NickServPassword);
            }

            foreach (ServerChannel channel in Settings.Channels)
            {
                _connection.RfcJoin(channel.Name, Priority.Critical);
            }

            _listener = Toolbox.SafeThreadStart("ListenThread " + Settings.Address, true, _connection.Listen);

            Connected = true;
        }
コード例 #3
0
        /// <summary>
        /// Betritt den gewünschten Channel und speichert ihn in der Datenbank
        /// </summary>
        /// <param name="channel">Der #channel</param>
        public void JoinChannel(string channel)
        {
            if (Settings.Channels.Any(x => x.Name == channel))
            {
                return;
            }

            _connection.RfcJoin(channel);

            using (var context = new BotContext())
            {
                context.Servers.Attach(Settings);
                Settings.Channels.Add(new ServerChannel {
                    Name = channel
                });
                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: IrcEngine.cs プロジェクト: anwarul/yok
        /// <summary>
        ///     Read line callback
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnReadLine(object sender, ReadLineEventArgs e)
        {
            try
            {
                var command = e.Line.Split(' ')[1];

                if (command.Equals("PING"))
                {
                    var server = e.Line.Split(' ')[2];

                    _irc.WriteLine("PONG " + server, Priority.Critical);
                }
                else if (command.Equals("422") || command.Equals("376")) // 422: motd missing // 376: end of motd
                {
                    _irc.RfcJoin(_ircChannel);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
コード例 #5
0
        /// <summary>
        /// Joins all channels specified in <see cref="IRCConfig"/>
        /// </summary>
        void JoinChannels()
        {
            var hs = new HashSet <string>();            //for unique inserts

            foreach (var I in IRCConfig.AdminChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.DevChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.GameChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.WatchdogChannels)
            {
                hs.Add(I);
            }
            var ToPart = new List <string>();

            foreach (var I in irc.JoinedChannels)
            {
                if (!hs.Remove(I))
                {
                    ToPart.Add(I);
                }
            }
            foreach (var I in ToPart)
            {
                irc.RfcPart(I);
            }
            foreach (var I in hs)
            {
                irc.RfcJoin(I);
            }
        }