Пример #1
0
        private static async Task Main()
        {
            Unity.RegisterTypes();

            var commandHandler = Unity.Resolve <DiscordCommandHandler>();
            await commandHandler.InstallCommands();

            var connection = Unity.Resolve <Connection>();
            await connection.ConnectAsync(Unity.Resolve <BotConfiguration>());
        }
Пример #2
0
        public async Task HandleCommand(SocketUserMessage message, SocketCommandContext context)
        {
            int argPos = 0;

            // If the message doesn't start with a prefix nor a mention of this bot
            if (!(message.HasStringPrefix(_botConfiguration.Prefix, ref argPos) ||
                  message.HasMentionPrefix(context.Client.CurrentUser, ref argPos)))
            {
                return;
            }

            var result = await _commandService.ExecuteAsync(context, argPos);

            if (result.IsSuccess)
            {
                return;
            }

            switch (result.Error)
            {
            case CommandError.UnknownCommand:
                Unity.Resolve <Loggers.StatusLogger>().LogToConsole(result.ErrorReason);
                break;

            default:
                Unity.Resolve <Loggers.StatusLogger>().LogToConsole($"[ERROR] {result.ErrorReason}");

                var embedBuilder = new EmbedBuilder()
                                   .WithTitle("An error occured.")
                                   .WithDescription($"Error reason: __{result.ErrorReason}__")
                                   .WithColor(255, 79, 79)
                                   .WithFooter($"Try {_botConfiguration.Prefix}help {message.Content.Split(' ')[0].Remove(0, _botConfiguration.Prefix.Length)} to get more information");

                await context.Channel.SendMessageAsync("", embed : embedBuilder.Build());

                break;
            }
        }
Пример #3
0
        public async Task InstallCommands()
        {
            await _commandService.AddModulesAsync(Assembly.GetEntryAssembly());

            Unity.Resolve <Loggers.StatusLogger>().LogToConsole("Installed command modules");
        }