示例#1
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            // Don't process the command if it was a System Message
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            await Task.WhenAll(
                RmtScanner.ScanForNoNoLinks(message),
                PoeProfileScanner.ScanForProfileUrls(message));

            // Create a number to track where the prefix ends and the command begins
            int argPos = 0;

            // Determine if the message is a command, based on if it starts with '!' or a mention prefix
            if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)))
            {
                return;
            }
            // Create a Command Context
            var context = new SocketCommandContext(_client, message);
            // Execute the command. (result does not indicate a return value,
            // rather an object stating if the command executed successfully)
            var result = await _commands.ExecuteAsync(context, argPos, _services);

            if (!result.IsSuccess && result.Error.HasValue && result.Error.Value != CommandError.UnknownCommand)
            {
                await context.Channel.SendMessageAsync(result.ErrorReason);
            }
        }
示例#2
0
        public Client(string token)
        {
            _token = token;

            var config = new DiscordSocketConfig
            {
                AlwaysDownloadUsers = true,
            };

            _client = new DiscordSocketClient(config);
#if DEBUG
            _client.Log += LogAsync;
#endif
            _commands = new CommandService();
            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .AddSingleton(new PasteBinFetcher())
                        .AddSingleton(new Parser())
                        .BuildServiceProvider();
            _rmtScanner = new RmtScanner();
        }