/** * 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); }
private async void StartAsync() { Log(LogSeverity.Info, string.Format(ResourceManager.GetString("start_info"), Console.Title)); Console.CancelKeyPress += Console_CancelKeyPress; client.MessageReceived += MessageRecieved; client.GuildMemberUpdated += GuildMemberUpdated; client.GuildAvailable += (guild) => { CreateSession(guild).AutoJoinAudioAsync(guild).ConfigureAwait(false); return(Task.CompletedTask); }; await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); }
/** * 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); }