示例#1
0
 public SegmentTypeReader(ServiceDependencyMap depMap)
 {
     _dbContext = depMap.Get <WelcomeDbContext>();
 }
示例#2
0
        private async Task handler(SocketMessage arg)
        {
            if (!_isReady)
            {
                return;
            }

            var msg = arg as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            if (msg.Author.IsBot)
            {
                return;
            }

            int argPos = 0;

            if (!msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                return;
            }

            var context = new SocketCommandContext(_client, msg);

            _logger.Info($"Command ran by {context.User} in {context.Channel.Name} - {context.Message.Content}");

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

            if (result.IsSuccess)
            {
                await _dependencyMap.Get <WelcomeDbContext>().SaveChangesAsync();

                return;
            }

            string response = null;

            switch (result)
            {
            case ParseResult parseResult:
                response = $":warning: There was an error parsing your command: `{parseResult.ErrorReason}`";
                break;

            case PreconditionResult preconditionResult:
                response = $":warning: A prerequisite of your command failed: `{preconditionResult.ErrorReason}`";
                break;

            case ExecuteResult executeResult:
                response = $":warning: Your command failed to execute. If this persists, contact a Discord Host.\n`{executeResult.Exception.Message}`";
                _logger.Error(executeResult.Exception);
                break;
            }

            if (response != null)
            {
                await context.ReplyAsync(response);
            }
        }