/// <inheritdoc /> protected override async Task MessageReceived(SocketMessage arg) { if (!(arg is SocketUserMessage message)) { return; } if (arg.Author.IsBot || arg.Author.IsWebhook) { return; } var argumentPos = 0; if (!(message.HasCharPrefix('!', ref argumentPos) || message.HasMentionPrefix(this.Client.CurrentUser, ref argumentPos))) { return; } if (message.Content.Length < 2) { return; } if (!message.Content.Any(char.IsLetterOrDigit)) { return; } var context = new SocketCommandContext(this.Client, message); // Perform first-time user checks, making sure the user has their default permissions, has consented, etc if (!await _privacy.HasUserConsentedAsync(context.User) && !IsPrivacyExemptCommand(context, argumentPos)) { // Ask for consent var userDMChannel = await arg.Author.GetOrCreateDMChannelAsync(); var result = await _privacy.RequestConsentAsync(userDMChannel); if (result.IsSuccess) { return; } const string response = "It seems like you're not accepting DMs from non-friends. Please enable " + "this, so you can read the bot's privacy policy and consent to data " + "handling and processing."; await _feedback.SendWarningAsync(context, response); return; } // Create a service scope for this command using (var scope = _services.CreateScope()) { var result = await _commands.ExecuteAsync(context, argumentPos, scope.ServiceProvider); await HandleCommandResultAsync(context, result, argumentPos); } }
/// <summary> /// Determines whether or not the user has consented to data storage and handling under the GDPR, or if the /// command that is being executed is exempt from GDPR considerations. /// </summary> /// <param name="context">The context.</param> /// <returns>true if the user has consented or the command does not require consent; otherwise, false.</returns> private async Task <bool> HasConsentedOrCommandDoesNotRequireConsentAsync(SocketCommandContext context) { // Find the argument pos if (!FindCommandStartPosition(context.Message, out var argumentPos)) { return(true); } if (await _privacy.HasUserConsentedAsync(context.User) || IsPrivacyExemptCommand(context, argumentPos)) { return(true); } // Ask for consent var userDMChannel = await context.User.GetOrCreateDMChannelAsync(); var result = await _privacy.RequestConsentAsync(userDMChannel); if (result.IsSuccess) { return(false); } const string response = "It seems like you're not accepting DMs from non-friends. Please enable " + "this, so you can read the bot's privacy policy and consent to data " + "handling and processing."; await _feedback.SendWarningAsync(context, response); return(false); }
/// <inheritdoc /> public async Task <Result> BeforeExecutionAsync(ICommandContext context, CancellationToken ct = default) { var hasConsented = await _privacy.HasUserConsentedAsync(context.User.ID, ct); IReadOnlyList <BoundCommandNode> potentialCommands; switch (context) { case MessageContext messageContext: { if (!messageContext.Message.Content.IsDefined(out var content)) { potentialCommands = Array.Empty <BoundCommandNode>(); break; } // Strip off the prefix if (_options.Prefix is not null) { content = content