public async Task Run() { try { Stopwatch sw = new Stopwatch(); sw.Start(); log.Info(Resources.ResourceManager.GetString("Initializing", Resources.Culture)); DiscordHttpClient client = new DiscordHttpClient(config.Token); await InitShards(client).ConfigureAwait(true); sw.Stop(); log.Info(string.Format(Resources.Culture, Resources.ResourceManager.GetString("InitialConnectionTime", Resources.Culture), sw.Elapsed.ToString("s\\.f", Resources.Culture))); log.Info(Resources.ResourceManager.GetString("LoadingCoreModules", Resources.Culture)); sw.Reset(); sw.Start(); List <Type> modules = Assembly.GetExecutingAssembly().GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(BaseModule))).ToList(); foreach (Type type in modules) { log.Info(string.Format(Resources.Culture, Resources.ResourceManager.GetString("LoadingModule", Resources.Culture), type.FullName)); MethodInfo[] possiblecommands = type.GetMethods( BindingFlags.DeclaredOnly | BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static ).Where(pcmd => pcmd.GetCustomAttribute <CommandAttribute>() != null) .ToArray(); foreach (MethodInfo cmd in possiblecommands) { if (cmd.ReturnType != typeof(Task)) { log.Info(string.Format(Resources.Culture, Resources.ResourceManager.GetString("FoundCommandRejected", Resources.Culture), cmd.Name)); } else { if (type.FullName == typeof(AzukiCore).FullName) { AdminCommands.Add("Core." + cmd.Name, new Tuple <BaseModule, ILog, MethodInfo>(this, log, cmd)); } else { AdminCommands.Add("Core." + cmd.Name, new Tuple <BaseModule, ILog, MethodInfo>(Activator.CreateInstance(type) as BaseModule, LogManager.GetLogger("Azuki", type.FullName), cmd)); } log.Debug(string.Format(Resources.Culture, Resources.ResourceManager.GetString("FoundCommand", Resources.Culture), cmd.Name)); } } } sw.Stop(); log.Info(string.Format(Resources.Culture, Resources.ResourceManager.GetString("LoadedCoreModules", Resources.Culture), sw.Elapsed.ToString("s\\.f", Resources.Culture))); log.Info(Resources.ResourceManager.GetString("StartupComplete", Resources.Culture)); log.Info(Resources.ResourceManager.GetString("AutoLoadingModules", Resources.Culture)); await LoadModules(null, null).ConfigureAwait(true); stopsignal.WaitOne(); log.Info(Resources.ResourceManager.GetString("ShuttingDown", Resources.Culture)); await UnLoadModules(null, null).ConfigureAwait(true); client.Dispose(); log.Info(Resources.ResourceManager.GetString("SutdownComplete", Resources.Culture)); } catch (Exception ex) { log.Fatal(ex.ToString()); Environment.Exit(-1); } }