コード例 #1
0
ファイル: BotCore.cs プロジェクト: RoidRunner/IW_Bot_Csharp
        /// <summary>
        /// Main Programs method running asynchronously
        /// </summary>
        /// <returns></returns>
        public async Task MainAsync()
        {
            Console.Title = "Ciridium Wing Bot v" + Var.VERSION.ToString();
            Thread.CurrentThread.CurrentCulture = Var.Culture;

            Var.client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel = LogSeverity.Info
            });

            bool filesExist = false;
            bool foundToken = false;

            if (ResourcesModel.CheckSettingsFilesExistence())
            {
                filesExist = true;
                if (await SettingsModel.LoadSettingsAndCheckToken(Var.client))
                {
                    foundToken = true;
                }
            }

            if (foundToken)
            {
                await MissionSettingsModel.LoadMissionSettings();

                await MissionModel.LoadMissions();

                await QuoteService.LoadQuotes();

                Var.client = new DiscordSocketClient(new DiscordSocketConfig
                {
                    LogLevel = LogSeverity.Info
                });

                InitCommands();

#if WELCOMING_MESSAGES
                Var.client.UserJoined += HandleUserJoined;
                Var.client.UserLeft   += HandleUserLeft;
#endif
                Var.client.Log             += Logger;
                SettingsModel.DebugMessage += Logger;
                Var.client.Connected       += ScheduleConnectDebugMessage;
                Var.client.ReactionAdded   += HandleReactionAdded;
                QuoteReactions quoteReact = new QuoteReactions();

                await Var.client.LoginAsync(TokenType.Bot, SettingsModel.token);

                await Var.client.StartAsync();

                await TimingThread.UpdateTimeActivity();

                while (Var.running)
                {
                    await Task.Delay(100);
                }

                if (string.IsNullOrEmpty(Var.RestartPath))
                {
                    await SettingsModel.SendDebugMessage("Shutting down ...", DebugCategories.misc);
                }
                else
                {
                    await SettingsModel.SendDebugMessage("Restarting ...", DebugCategories.misc);
                }

                Var.client.Dispose();
            }
            else
            {
                if (!filesExist)
                {
                    await Logger(new LogMessage(LogSeverity.Critical, "SETTINGS", string.Format("Could not find config files! Standard directory is \"{0}\".\nReply with 'y' if you want to generate basic files now!", ResourcesModel.BaseDirectory)));

                    if (Console.ReadLine().ToCharArray()[0] == 'y')
                    {
                        await ResourcesModel.InitiateBasicFiles();
                    }
                }
                else
                {
                    await Logger(new LogMessage(LogSeverity.Critical, "SETTINGS", string.Format("Could not find a valid token in Settings file ({0}). Press any key to exit!", ResourcesModel.SettingsFilePath)));

                    Console.ReadLine();
                }
            }

            if (!string.IsNullOrEmpty(Var.RestartPath))
            {
                System.Diagnostics.Process.Start(Var.RestartPath);
            }
        }
コード例 #2
0
ファイル: BotCore.cs プロジェクト: RoidRunner/IW_Bot_Csharp
 /// <summary>
 /// Sending the connect message immediately on login fails. This schedules the debug connect message 500ms ahead.
 /// </summary>
 private Task ScheduleConnectDebugMessage()
 {
     TimingThread.AddScheduleDelegate(SendConnectDebugMessage, 500);
     return(Task.CompletedTask);
 }