/** * 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); }
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); }
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); }
/** * 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); }
public Nekohandler(Discord.WebSocket.DiscordSocketClient Vensha) => client = new NekoClient(Vensha.CurrentUser.Username);