Пример #1
0
        /**
         * Basically, this calls an asynchronous main loop.
         * Because we assume the program run so fast that it runs asynchronously, there's nothing wrong with this.
         */
        /**
         * From here, I'll try to make the code looks neat and explanatory :)
         * */
        public async Task MainAsync(string[] args)
        {
#if BUILD
            SerializableUpdateInfo build_info = new SerializableUpdateInfo();
            build_info.Serialize(constants.path_here);
#else
            Updater.Program.start(args);
#endif
            //Initialize elements
            client = new Discord.WebSocket.
                     DiscordSocketClient(bot_conf.socket_config);
            command_serv = new Discord.Commands.CommandService();
            service      = new ServiceCollection().BuildServiceProvider();

            //Delegates
            client.Log             += on_client_log;
            client.MessageReceived += on_message_received;
            client.Ready           += start;
#if TRACE
            Console.WriteLine("Path.Location = " + program_const.execution_path[0] + "\n" + "Path.CodeBase = " + program_const.execution_path[1] + "");
            //Console.WriteLine("main_dev_channel = " + main_dev_channel.Name);
#endif
            await load_commands();

            Amonikano.Library.AmonikanoCommands.CoreModule.InitializeHelpNoReply();
            await client.LoginAsync(TokenType.Bot, bot_const.token);

            Console.WriteLine("client.LoginAsync() called, awaiting client.StartAsync()");
            await client.StartAsync();

            Console.WriteLine("client.StartAsync() finished, awaiting Task.Delay(-1)");
            //AssignMainDevChannel();

            while (true)
            {
                string input;
                input = Console.ReadLine();
#if TRACE
                Console.WriteLine("Input was: " + input);
#endif
                //Command
                //Amonikano.Library.ConsoleCommands.GeneralExecution.ExecuteCommand(input.Split(' '));
                switch (input)
                {
                case "inv_web":
                    Console.WriteLine(inv_webpage);
                    break;

                case "force_shutdown":
                    goto shutdown;
                }
            }
shutdown:
            Console.WriteLine("main() ended");
            await main_dev_channel.SendMessageAsync(bot_conf.shutdown_message);
        }
Пример #2
0
        public async Task MainAsync()
        {
            m_client = new DiscordSocketClient();
            // Attaching the logger function to our client.
            m_client.Log   += Log;
            m_client.Ready += GreetUser;

            // Login with the bot. Ideally, the client should be a singleton, and the token should be secured somewhere else. But this will do.
            await m_client.LoginAsync(TokenType.Bot, TOKEN);

            await m_client.StartAsync();

            m_service = new Discord.Commands.CommandService();

            CommandHandler cmdh = new CommandHandler(m_client, m_service);

            this.m_handler = cmdh;

            await cmdh.InstallCommandsAsync();
        }