Skip to content

Commit

Permalink
Allow overlaying apps to control bot via IgnoreAllPermissions in config
Browse files Browse the repository at this point in the history
  • Loading branch information
berichan committed May 12, 2021
1 parent de4c3a0 commit d9aa345
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Bot/Config/CrossBotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public sealed record CrossBotConfig : SwitchConnectionConfig

public List<ulong> LoggingChannels { get; set; } = new();

// Should we ignore all permissions for commands and allow inter-bot talk? This should only be used for debug/apps that layer on top of the acnh bot through discord.
public bool IgnoreAllPermissions { get; set; } = false;

#endregion

#region Features
Expand Down
2 changes: 1 addition & 1 deletion Discord/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class RequireQueueRoleAttribute : PreconditionAttribute
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
var mgr = Globals.Bot.Config;
if (mgr.CanUseSudo(context.User.Id) || Globals.Self.Owner == context.User.Id)
if (mgr.CanUseSudo(context.User.Id) || Globals.Self.Owner == context.User.Id || mgr.IgnoreAllPermissions)
return Task.FromResult(PreconditionResult.FromSuccess());

// Check if this user is a Guild User, which is the only context where roles exist
Expand Down
2 changes: 1 addition & 1 deletion Discord/RequireSudoAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class RequireSudoAttribute : PreconditionAttribute
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
var mgr = Globals.Bot.Config;
if (mgr.CanUseSudo(context.User.Id) || context.User.Id == Globals.Self.Owner)
if (mgr.CanUseSudo(context.User.Id) || context.User.Id == Globals.Self.Owner || mgr.IgnoreAllPermissions)
return Task.FromResult(PreconditionResult.FromSuccess());

// Check if this user is a Guild User, which is the only context where roles exist
Expand Down
21 changes: 12 additions & 9 deletions Discord/SysCord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private async Task HandleMessageAsync(SocketMessage arg)
return;

// We don't want the bot to respond to itself or other bots.
if (msg.Author.Id == _client.CurrentUser.Id || msg.Author.IsBot)
if (msg.Author.Id == _client.CurrentUser.Id || (!Bot.Config.IgnoreAllPermissions && msg.Author.IsBot))
return;

// Create a number to track where the prefix ends and the command begins
Expand Down Expand Up @@ -233,15 +233,18 @@ private async Task<bool> TryHandleCommandAsync(SocketUserMessage msg, int pos)

// Check Permission
var mgr = Bot.Config;
if (!mgr.CanUseCommandUser(msg.Author.Id))
if (!Bot.Config.IgnoreAllPermissions)
{
await msg.Channel.SendMessageAsync("You are not permitted to use this command.").ConfigureAwait(false);
return true;
}
if (!mgr.CanUseCommandChannel(msg.Channel.Id) && msg.Author.Id != Owner)
{
await msg.Channel.SendMessageAsync("You can't use that command here.").ConfigureAwait(false);
return true;
if (!mgr.CanUseCommandUser(msg.Author.Id))
{
await msg.Channel.SendMessageAsync("You are not permitted to use this command.").ConfigureAwait(false);
return true;
}
if (!mgr.CanUseCommandChannel(msg.Channel.Id) && msg.Author.Id != Owner)
{
await msg.Channel.SendMessageAsync("You can't use that command here.").ConfigureAwait(false);
return true;
}
}

// Execute the command. (result does not indicate a return value,
Expand Down

0 comments on commit d9aa345

Please sign in to comment.