Exemple #1
0
        static async Task Main(string[] args)
        {
            try
            {
                Logger.Start();
                AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnExit);

                Client = new DiscordClient(new DiscordConfiguration
                {
                    Token     = Resources.BOT_TOKEN,
                    TokenType = TokenType.Bot
                });

                foreach (var evnt in _botEvents)
                {
                    Client.AddEvent(evnt);
                    Logger.Log($"{evnt.EventName} event added.", "bootup");
                }

                await Client.ConnectAsync();

                await Client.InitializeAsync();

                await Client.UpdateStatusAsync(new DiscordGame($"{BotName} v{Version}"), UserStatus.Online); // This doesn't work

                var status = Client.CurrentUser.Presence.Game.Name;

                Logger.Log($"Bot is running with version {Version}.", "bootup");

                _startTime = DateTime.Now;
            }
            catch (Exception e)
            {
                Logger.LogError(e, "bootup");
            }

            var consoleIn  = Task.Run(() => Console.ReadLine());
            var commandRun = new CommandEvent();

            while (true)
            {
                foreach (var evnt in _timeEvents)
                {
                    await evnt.OnEvent(_secondsAlive);
                }

                if (consoleIn.IsCompleted)
                {
                    var result = consoleIn.Result;
                    if (!string.IsNullOrEmpty(result))
                    {
                        await commandRun.ParseCommand(result, new CommandContext(Context.CONS));

                        consoleIn = null;
                        consoleIn = Task.Run(() => Console.ReadLine());
                    }
                }

                _secondsAlive = _startTime.Difference(DateTime.Now).TotalSeconds;
            }
        }