示例#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 ImageService(IServiceProvider services)
        {
            _discord    = services.GetRequiredService <Discord.WebSocket.DiscordSocketClient>();
            _game       = services.GetRequiredService <GameService>();
            _services   = services;
            _webService = services.GetRequiredService <WebService>();

            _channels = ConfigService.Config.WhitelistedChannel;
            ImgPath   = Path.Combine(Directory.GetCurrentDirectory(), ConfigService.Config.ImgFolder);
        }
示例#3
0
 private Program(string userToken)
 {
     End      = false;
     stateLog = new Logger(DuckData.StateLogFile.CreateText(), Console.Out);
     client   = new Discord.WebSocket.DiscordSocketClient(new Discord.WebSocket.DiscordSocketConfig()
     {
         DefaultRetryMode = RetryMode.AlwaysRetry,
         LogLevel         = LogSeverity.Info
     });
     client.Log += Log;
     token       = userToken;
     data        = new DuckData();
     HardCmds    = HardCmd.CreateDefault();
     bgCancel    = new CancellationTokenSource();
     loopTask    = AsyncSaver(bgCancel.Token).ConfigureAwait(false);
 }
示例#4
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)
        {
            //This is from another namespace. I don't intend to include a using namespace because it would look messy on the long run
            Discord.WebSocket.
            DiscordSocketClient client;

            client = new Discord.WebSocket.
                     DiscordSocketClient();

            client.Log             += on_client_log; //client.Log is like a delegate function (a list of function, or an event)
            client.MessageReceived += on_message_received;
            await client.LoginAsync(TokenType.Bot, bot_const.token);

            await client.StartAsync();

            await Task.Delay(-1);
        }
示例#5
0
 public Nekohandler(Discord.WebSocket.DiscordSocketClient Vensha) => client = new NekoClient(Vensha.CurrentUser.Username);