Пример #1
0
        public bool handleURL(string url, IrcClient ctx, CtcpClient ctpcclient = null, IIrcMessageSource source = null )
        {
            var title = GetPageTitle(url).Trim();
            if (!string.IsNullOrWhiteSpace(title))
            {
                if(title.ToLower().Contains("Domainpark - Bitte den Rasen nicht betreten".ToLower()))
                {
                    int roll = random.Next(0, 101);
                    if(roll < 5)
                    {
                        if(ctpcclient != null)
                        {
                            string textMessage = "slaps " + source.Name + " and screamed:";
                            BotDeathmicMessageTarget target = new BotDeathmicMessageTarget();
                            target.Name = Properties.Settings.Default.Channel.ToString();
                            ctpcclient.SendAction(target, textMessage);
                            ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, "Runter vom Rasen!");
                        }
                    }
                }
                else
                {
                    if(title.ToLower() == "Imgur: The most awesome images on the Internet".ToLower())
                    {

                    }
                    else
                    {
                        ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, title);
                    }

                }
            }
            return true;
        }
Пример #2
0
        public bool handleURL(string url, IrcDotNet.IrcClient ctx, CtcpClient ctpcclient = null, IIrcMessageSource source = null)
        {
            var match = _imgurreg.Match(url);

            if (match.Success)
            {
                var id = match.Groups[2].Value;
                url = "http://imgur.com/gallery/" + id;
                website.handleURL(url, ctx, ctpcclient, source);
                return true;
            }
            return false;
        }
Пример #3
0
        private void Connect()
        {
            _userInitiatedDisconnect = false;

            _ircClient = new global::IrcDotNet.IrcClient();
            _ctcpClient = new CtcpClient(_ircClient);

            _ircClient.Registered += ClientRegisteredWithIrcd;
            _ircClient.RawMessageReceived += IrcClient_RawMessageReceived;
            _ircClient.RawMessageSent += IrcClient_RawMessageSent;

            _ircClient.Connect(Server.Host, Server.Port ?? 6667, false, new IrcUserRegistrationInfo
            {
                NickName = Network.BotNickname,
                UserName = Network.BotUsername,
                RealName = Network.BotRealname
            });

            _ircClient.Disconnected += Disconnected;
        }
Пример #4
0
        void IRCRestart(CommandArgs e)
        {
            IrcUsers.Clear();
            IrcClient.Quit("Restarting...");
            Connecting = true;
            IrcClient = new IrcClient();
            IrcClient.Connect(Config.Server, Config.Port, Config.SSL,
                new IrcUserRegistrationInfo()
                {
                    NickName = Config.Nick,
                    RealName = Config.RealName,
                    UserName = Config.UserName,
                    UserModes = new List<char> { 'i', 'w' }
                });
            IrcClient.Registered += OnIRCRegistered;
            CtcpClient = new CtcpClient(IrcClient) { ClientVersion = "TShockIRC v" + Version };

            e.Player.SendInfoMessage("Restarted the IRC bot.");
        }
Пример #5
0
        void Connect()
        {
            if (Connecting)
                return;

            Connecting = true;
            IrcUsers.Clear();
            IrcClient = new IrcClient();
            IrcClient.Connect(Config.Server, Config.Port, Config.SSL,
                new IrcUserRegistrationInfo()
                {
                    NickName = Config.Nick,
                    RealName = Config.RealName,
                    UserName = Config.UserName,
                    UserModes = new List<char> { 'i', 'w' }
                });
            IrcClient.Disconnected += OnIRCDisconnected;
            IrcClient.Registered += OnIRCRegistered;
            CtcpClient = new CtcpClient(IrcClient) { ClientVersion = "TShockIRC v" + Version };
        }
Пример #6
0
        //TODO: Handle Playlist Requests
        //Request should look like this
        //https://www.googleapis.com/youtube/v3/playlists?id=id&key=key&part=snippet
        public bool handleURL(string URL, IrcDotNet.IrcClient ctx, CtcpClient client = null, IIrcMessageSource source = null)
        {
            string answer ="";
            var match = IsYtLink(URL);
            if(match != null)
            {
                string url = "https://www.googleapis.com/youtube/v3/videos";
                // video ID
                url += "?id=";
                url += match;
                // API Token
                url += "&key=";
                url += "AIzaSyBQwWTl6Md5oOm858tKi4xIBGH3ELSaa_A";
                // Fields
                url += "&fields=";
                url += "items%28id,snippet%28channelId,title,categoryId%29,statistics%29&part=snippet,statistics";
                WebRequest request = WebRequest.Create(url);
                WebResponse response = request.GetResponse();
                Stream receivedstream = response.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                StreamReader readStream = new StreamReader(receivedstream, encode);
                Char[] read = new Char[1000000];
                // setting max Chars for read (1M suffice aprox. 4700 Tickets)
                int count = readStream.Read(read, 0, 1000000);
                String str = "";
                while (count > 0)
                {
                    str = new String(read, 0, count);
                    count = readStream.Read(read, 0, 1000000);
                }
                JObject obj = JObject.Parse(str);
                JArray jarr = (JArray)obj["items"];

                foreach (var item in jarr)
                {
                    answer = item["snippet"].SelectToken("title").ToString();

                }
                ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, answer);
                return true;
            }
            else
            {
                if(URL.IndexOf("playlist?list") > 0)
                {
                    string url = "https://www.googleapis.com/youtube/v3/playlists";
                    // video ID
                    url += "?id=";
                    url += URL.Substring(URL.IndexOf("playlist?list=") + 14, URL.Length - (URL.IndexOf("playlist?list=") + 14));
                    url += "&fields=items%2Fsnippet";
                    // API Token
                    url += "&key=";
                    url += "AIzaSyBQwWTl6Md5oOm858tKi4xIBGH3ELSaa_A";
                    // Fields
                    url += "&part=snippet";
                    System.Diagnostics.Debug.WriteLine(url);
                    WebRequest request = WebRequest.Create(url);
                    WebResponse response = request.GetResponse();
                    Stream receivedstream = response.GetResponseStream();
                    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                    StreamReader readStream = new StreamReader(receivedstream, encode);
                    Char[] read = new Char[1000000];
                    // setting max Chars for read (1M suffice aprox. 4700 Tickets)
                    int count = readStream.Read(read, 0, 1000000);
                    String str = "";
                    while (count > 0)
                    {
                        str = new String(read, 0, count);
                        count = readStream.Read(read, 0, 1000000);
                    }
                    JObject obj = JObject.Parse(str);
                    JArray jarr = (JArray)obj["items"];

                    foreach (var item in jarr)
                    {
                        answer = item["snippet"].SelectToken("title").ToString();

                    }
                    ctx.LocalUser.SendMessage(Properties.Settings.Default.Channel, answer);
                    return true;
                }
            }
            return false;
        }
Пример #7
0
        public static void ClassInitialize()
        {
            stateManager = new TestStateManager<IrcClientTestState>();

            // Create instances of IRC clients.
            ircClient1 = new StandardIrcClient();
#if DEBUG
            ircClient1.ClientId = "1";
#endif
            ircClient1.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            ircClient1.Connected += ircClient1_Connected;
            ircClient1.ConnectFailed += ircClient1_ConnectFailed;
            ircClient1.Disconnected += ircClient1_Disconnected;
            ircClient1.Error += ircClient1_Error;
            ircClient1.ProtocolError += ircClient1_ProtocolError;
            ircClient1.Registered += ircClient1_Registered;
            ircClient1.MotdReceived += ircClient1_MotdReceived;
            ircClient1.NetworkInformationReceived += ircClient1_NetworkInformationReceived;
            ircClient1.ServerVersionInfoReceived += ircClient1_ServerVersionInfoReceived;
            ircClient1.ServerTimeReceived += ircClient1_ServerTimeReceived;
            ircClient1.ServerLinksListReceived += ircClient1_ServerLinksListReceived;
            ircClient1.ServerStatsReceived += ircClient1_ServerStatsReceived;
            ircClient1.WhoReplyReceived += ircClient1_WhoReplyReceived;
            ircClient1.WhoIsReplyReceived += ircClient1_WhoIsReplyReceived;
            ircClient1.WhoWasReplyReceived += ircClient1_WhoWasReplyReceived;
            ircClient1.ChannelListReceived += ircClient1_ChannelListReceived;

            ircClient2 = new StandardIrcClient();
#if DEBUG
            ircClient2.ClientId = "2";
#endif
            ircClient2.Connected += ircClient2_Connected;
            ircClient2.ConnectFailed += ircClient2_ConnectFailed;
            ircClient2.Disconnected += ircClient2_Disconnected;
            ircClient2.Error += ircClient2_Error;
            ircClient2.ProtocolError += ircClient2_ProtocolError;
            ircClient2.Registered += ircClient2_Registered;


            // Create instances of CTCP clients over IRC clients.
            ctcpClient1 = new CtcpClient(ircClient1);
            ctcpClient1.ClientVersion = clientVersionInfo;
            ctcpClient1.PingResponseReceived += ctcpClient1_PingResponseReceived;
            ctcpClient1.VersionResponseReceived += ctcpClient1_VersionResponseReceived;
            ctcpClient1.TimeResponseReceived += ctcpClient1_TimeResponseReceived;
            ctcpClient1.ActionReceived += ctcpClient1_ActionReceived;

            ctcpClient2 = new CtcpClient(ircClient2);
            ctcpClient2.ClientVersion = clientVersionInfo;
            ctcpClient2.PingResponseReceived += ctcpClient2_PingResponseReceived;
            ctcpClient2.VersionResponseReceived += ctcpClient2_VersionResponseReceived;
            ctcpClient2.TimeResponseReceived += ctcpClient2_TimeResponseReceived;
            ctcpClient2.ActionReceived += ctcpClient2_ActionReceived;

            // Initialize wait handles for all events.
            GetAllWaitHandlesFields().ForEach(fieldInfo => fieldInfo.SetValue(null, new AutoResetEvent(false)));

            // Nick name length limit on irc.freenode.net is 16 chars.
            Func<string> getRandomUserId = () => Guid.NewGuid().ToString().Substring(0, 8);

            serverPassword = TestSettings.ServerPassword;
            if (string.IsNullOrEmpty(serverPassword))
                serverPassword = null;
            nickName1 = userName1 = string.Format(TestSettings.NickNameFormat, getRandomUserId());
            nickName2 = userName2 = string.Format(TestSettings.NickNameFormat, getRandomUserId());
            realName = TestSettings.RealName;

            Debug.WriteLine("Client users have real name '{0}'", realName);
            Debug.WriteLine("Client 1 user has nick name '{0}' and user name '{1}'.", nickName1, userName1);
            Debug.WriteLine("Client 2 user has nick name '{0}' and user name '{1}'.", nickName2, userName2);

            stateManager.SetStates(IrcClientTestState.Client1Initialized, IrcClientTestState.Client2Initialized);
            ircClient1.Connect(TestSettings.ServerHostName, false, new IrcUserRegistrationInfo()
            {
                Password = serverPassword,
                NickName = nickName1,
                UserName = userName1,
                RealName = realName,
            });
            ircClient2.Connect(TestSettings.ServerHostName, false, new IrcUserRegistrationInfo()
            {
                Password = serverPassword,
                NickName = nickName2,
                UserName = userName2,
                RealName = realName,
            });
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CtcpRawMessageEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message that was sent/received.</param>
 public CtcpRawMessageEventArgs(CtcpClient.CtcpMessage message)
     : base()
 {
     this.Message = message;
 }
Пример #9
0
        /// <summary>
        /// Attempt to connect to our pre-configured network. Does nothing if you're already connected.
        /// </summary>
        /// 
        /// <remarks>
        /// 
        /// <para>
        /// This will need to be refactored to allow multi-network support. This will perform a no-op
        /// if you are already connected.
        /// </para>
        ///
        /// <para>
        /// Unfortunately there's a rather annoying bug with Thresher's IRC library: when you re-use the same
        /// connection object, it maintains a cache of capability options, as sent as part of the registration
        /// preamble from the IRCD. There's no way (so far) to flush this cache, and it's not a very intelligent
        /// cache - it doesn't look for hits, only misses - so we wind up trying to cache something twice and
        /// an exception resulting from said behavior.
        /// </para>
        /// 
        /// <para>
        /// So... In order to support a reconnect ability you need to create a NEW connection object. This requires
        /// unsubscribing your old event handlers (to prevent memory leaks), and re-registering them. Painful duplication,
        /// crappy mixing of responsibility... name your reason why this is bad. Unfortunately there's not much choice.
        /// </para>
        /// 
        /// </remarks>
        public void Connect()
        {
            if (!IsConnected)
            {
                // Just grab the first entry until we have proper multi server support
                Network network = NetworkList[0];
                Server server = network.ServerList[0];

                _ircClient = new IrcClient();
                _ctcpClient = new CtcpClient(_ircClient);

                // Subscribe our events
                _ircClient.Registered += ClientRegisteredWithIrcd;
                _ircClient.RawMessageReceived += RawMessageReceived;
                _ircClient.RawMessageSent += RawMessageSent;

                _ircClient.Connect(server.Host, server.Port ?? 6667, false, new IrcUserRegistrationInfo
                {
                    NickName = network.BotNickname,
                    UserName = network.BotUsername,
                    RealName = network.BotRealname
                });

                // Make sure we don't get any random disconnected events before we're connected
                _ircClient.Disconnected += Disconnected;
            }
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultIrcClient"/> class.
 /// </summary>
 /// <param name="userService">
 /// The user service.
 /// </param>
 /// <param name="moduleFactory">
 /// The module factory.
 /// </param>
 public DefaultIrcClient(IUserService userService, IModuleFactory moduleFactory)
     : base(moduleFactory)
 {
     this.userService = userService;
     this.ircClient = new IrcClient();
     this.ctcpClient = new CtcpClient(this.ircClient);
 }
Пример #11
0
        public void ConnectBot()
        {
            if(bIsStream)
            {
                RegistrationInfo.NickName = "bobdeathmic";
                RegistrationInfo.Password = "******";
            }
            Connect(sServer, RegistrationInfo);
            if (Settings.Default.Server.Contains("quakenet") && !bIsStream)
            {
                string quakeservername = null;
                foreach (var _client in Clients)
                {
                    while (_client.ServerName == null)
                    {
                        Thread.Sleep(50);
                    }
                    if (_client.ServerName.Contains("quakenet"))
                    {
                        quakeservername = _client.ServerName;
                        thisclient = _client;
                        thisclient.FloodPreventer = new IrcStandardFloodPreventer(1, 4000);
                        /*
                        ctcpClient1 = new CtcpClient(_client);
                        ctcpClient1.ClientVersion = clientVersionInfo;
                        ctcpClient1.PingResponseReceived += ctcpClient_PingResponseReceived;
                        ctcpClient1.VersionResponseReceived += ctcpClient_VersionResponseReceived;
                        ctcpClient1.TimeResponseReceived += ctcpClient_TimeResponseReceived;
                        ctcpClient1.ActionReceived += ctcpClient_ActionReceived;
                        */
                    }

                }
                IrcClient quakeclient = null;
                quakeclient = GetClientFromServerNameMask(quakeservername);

                System.Diagnostics.Debug.WriteLine(Properties.Settings.Default.Channel + " " + quakeservername);
                quakeclient.Channels.Join(Properties.Settings.Default.Channel);
            }
            else
            {
                foreach (var _client in Clients)
                {
                    if(sChannel != null)
                    {
                        _client.Channels.Join(sChannel);
                    }
                    else
                    {
                        _client.Channels.Join(Properties.Settings.Default.Channel);
                    }

                    thisclient = _client;
                    thisclient.FloodPreventer = new IrcStandardFloodPreventer(1, 1500);
                    ctcpClient1 = new CtcpClient(_client);
                }
            }
        }
Пример #12
0
        private INetwork RegisterNetwork(IrcClient ircClient, INetwork network)
        {
            this.connections.Add(network, ircClient);

            ircClient.RawMessageReceived += ircClient_RawMessageReceived;
            ircClient.RawMessageSent += ircClient_RawMessageSent;
            ircClient.Registered += ircClient_Registered;
            ircClient.Disconnected += ircClient_Disconnected;

            CtcpClient ctcpClient = new CtcpClient(ircClient);

            this.ctcpConnections.Add(network, ctcpClient);

            ctcpClient.ClientVersion = "Skyscraper v" + Assembly.GetEntryAssembly().GetName().Version.ToString();

            Application.Current.Dispatcher.InvokeAsync(() =>
            {
                this.client.Networks.Add(network);
            });

            return network;
        }
Пример #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CtcpRawMessageEventArgs" /> class.
 /// </summary>
 /// <param name="message">The message that was sent/received.</param>
 public CtcpRawMessageEventArgs(CtcpClient.CtcpMessage message)
 {
     Message = message;
 }