alopezlago / QuizBowlDiscordScoreTracker

MIT License
6 stars 4 forks source link

#53: Don't allow bots to export #57

Closed Sam-per closed 3 years ago

Sam-per commented 3 years ago

Previously, the exportToFile command could only be called by a reader or admin. Now the command can only be called by a reader or admin who is not a bot

This uses discord's isBot flag (the blue "BOT" tag)

Sam-per commented 3 years ago

resolves #53

alopezlago commented 3 years ago

We'll want to add this to a few other commands (newer export commands coming in), so it'd be nice if it could be an method attribute, specifically a PreconditionFilter. I have an unpublished branch that does this. The class looks like:

[AttributeUsage(AttributeTargets.Method)] public class HumanOnlyAttribute : PreconditionAttribute { [SuppressMessage( "Design", "CA1062:Validate arguments of public methods", Justification = "Discord.Net will pass in non-null CommandContext")] public override Task CheckPermissionsAsync( ICommandContext context, CommandInfo command, IServiceProvider services) { if (context.User.IsBot) { return Task.FromResult(PreconditionResult.FromError("Bots are not allowed to run this command.")); }

        return Task.FromResult(PreconditionResult.FromSuccess());
    }
}
Sam-per commented 3 years ago

Assuming that your changes are already near completion, it might be more beneficial to close/reject this PR and add the attribute to the appropriate method with your changes.

Alternatively, I could change this PR to incorporate your attribute? Up to you

alopezlago commented 3 years ago

I can split out what I have in the next couple days and send out a PR

alopezlago commented 3 years ago

See #64

Sam-per commented 3 years ago

Assuming that none of the code here is needed and this PR is unnecessary, it can be closed