Beispiel #1
0
        private static async Task AsyncMain()
        {
            CancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = CancellationTokenSource.Token;

            Console.CancelKeyPress += (x, y) =>
            {
                CancellationTokenSource.Cancel();
            };

            Discord = new DiscordClient(new DiscordConfiguration()
            {
                Token     = BotDetails.Token,
                TokenType = TokenType.Bot
            });

            await Discord.ConnectAsync();

            Logger.Log("Discord Connected");

            await Discord.UpdateStatusAsync(new DiscordGame(BotDetails.CommandPrefix + "doc"));

            foreach (var functionality in ReflectiveEnumerator.GetInheritedFromAbstractClass <Functionality>())
            {
                functionality.Start(Discord);
            }

            CommandConfiguration.Initialize();
            Discord.MessageCreated += async x =>
            {
                if (x.Message.Content.IndexOf(BotDetails.CommandPrefix) == 0)
                {
                    string command = GetFirstWord(x.Message.Content);
                    if (!CommandConfiguration.Get.ContainsKey(command))
                    {
                        return;
                    }
                    string reply = string.Empty;
                    try
                    {
                        reply = await CommandConfiguration.Get[command].ProcessAsync(x.Message);
                    }
                    catch { }
                    Logger.Log($"<Message: {x.Message.Content}>\t<Author: {x.Author.Id}>\t<Name: {x.Author.Username}>\t<Reply: {reply}>");
                    await x.Message.RespondAsync(reply);
                }
            };
            await Task.Delay(-1, cancellationToken);
        }