コード例 #1
0
ファイル: Command.cs プロジェクト: ponglesesquire/Assbot
        public static List<Command> GetCommands(Bot parent)
        {
            Assembly assembly = Assembly.GetCallingAssembly();
            IEnumerable<Type> types = assembly.GetExportedTypes().Where(type => type.IsSubclassOf(typeof(Command)));

            return types.Select(type => (Command)Activator.CreateInstance(type, parent)).ToList();
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: ponglesesquire/Assbot
 protected Command(Bot parent)
 {
     Parent = parent;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: ponglesesquire/Assbot
        public static void Main(string[] args)
        {
            #if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => Console.WriteLine(eventArgs.ExceptionObject);
            #endif

            Assembly assembly = Assembly.GetExecutingAssembly();
            Console.WriteLine("Assbot v{0}", assembly.GetName().Version);

            Bot bot = new Bot();

            Thread botThread = new Thread(
                () =>
                {
                    if (!bot.Connect(Configuration.Server))
                    {
                        Console.WriteLine("Cannot connect to {0}!", Configuration.Server);
                        Console.ReadKey();
                        return;
                    }

                    if (!bot.JoinChannel(Configuration.Channel))
                    {
                        Console.WriteLine("Cannot join channel {0}!", Configuration.Channel);
                        Console.ReadKey();
                        return;
                    }

                    while(bot.IsRunning)
                        Thread.Sleep(1);

                    Console.WriteLine("Graceful shutdown, IsRunning = {0}", bot.IsRunning);

                    bot.Shutdown();
                });

            botThread.Start();

            while(botThread.IsAlive)
            {
                if (!bot.IsInChannel || !bot.IsIdentified)
                {
                    Thread.Sleep(1);
                    continue;
                }

                Console.Write("> ");
                string command = Console.ReadLine();

                switch(command)
                {
                    case "quit":
                        Console.WriteLine("Shutting down...");
                        bot.Quit("Shutdown from console.");

                        while(botThread.IsAlive)
                            Thread.Sleep(1);
                        break;
                }
            }
        }