Exemplo n.º 1
0
        /// <summary>
        /// New user from string.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="network">The Network.</param>
        /// <returns></returns>
        public static IrcUser NewFromString(string source, IIrc network)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            string user, host;
            string nick = user = host = null;
            try
            {
                if ((source.Contains("@")) && (source.Contains("!")))
                {
                    char[] splitSeparators = {'!', '@'};
                    string[] sourceSegment = source.Split(splitSeparators, 3);
                    nick = sourceSegment[0];
                    user = sourceSegment[1];
                    host = sourceSegment[2];
                }
                else if (source.Contains("@"))
                {
                    char[] splitSeparators = {'@'};
                    string[] sourceSegment = source.Split(splitSeparators, 2);
                    nick = sourceSegment[0];
                    host = sourceSegment[1];
                }
                else
                {
                    nick = source;
                }
            }
            catch (IndexOutOfRangeException)
            {
                //TODO: do soemthing;
            }

            var ret = new IrcUser
                           {
                               HostName = host,
                               Nickname = nick,
                               UserName = user,
                               Network = network,
                           };
            return ret;
        }
Exemplo n.º 2
0
        protected IrcClientWriterBase(StreamWriter writer, IIrc network)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            _network = network;
            _writer = writer;

            _writer.AutoFlush = true;
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            Console.WriteLine("Badime Bot v2.00");
            string server         = "127.0.0.1";
            string channel        = "#badimebottest";
            string AuthorizedNick = "hova";

            if (args.Length == 2)
            {
                server  = args[0];
                channel = args[1];
            }
            if (args.Length >= 3)
            {
                AuthorizedNick = args[2];
            }

            si = new BasicIrc();
            si.Connect(server, "badimebot");
            Console.WriteLine("Connected");
            si.Join(channel);
            Console.WriteLine($"Joined channel {channel}");
            CountdownTimer animetimer = new CountdownTimer();

            animetimer.MessageEvent += (x, y) =>
            {
                si.SendMessage(y.CountdownMessage);
            };

            si.ChannelMessageReceived += (x, y) =>
            {
                //Only respond to the !badime trigger
                if (IsValidBotCommand(y.Message, "badime"))
                {
                    si.SendMessage(string.Format("Time Elapsed {0}", animetimer.GetElapsedTime()));
                }
            };
            si.PrivateMessageReceived += (x, y) =>
            {
                if (IsValidBotCommand(y.Message, "badime"))
                {
                    si.PrivateMessage(y.From, string.Format("Time Elapsed {0}", animetimer.GetElapsedTime()));
                }
                if (y.From == "hova")
                {
                    if (y.Message == "shutdown")
                    {
                        PrintToConsoleWithColor("Shutdown request received, exiting program", ConsoleColor.Red);
                        si.Disconnect($"{y.From} told me to quit");
                        animetimer.Stop();
                        Environment.Exit(0);
                    }

                    if (y.Message.StartsWith("add"))
                    {
                        CountdownItem ci = CountdownTimer.Parse(y.Message);

                        if (ci != CountdownItem.Empty)
                        {
                            animetimer.Enqueue(ci);
                            si.PrivateMessage(y.From, $"Enqueued {ci.Title} for {ci.Length}");
                        }
                    }
                }
            };
            animetimer.Start();
            Console.WriteLine("Press Enter to quit...");
            Console.ReadLine();
            animetimer.Stop();
            si.Disconnect("Someone pressed enter on the console");
            return(0);
        }
 public NaiveIrcClientWriter(StreamWriter writer, IIrc network)
     : base(writer, network)
 {
 }