forked from Invertex/UDHBot
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from Unity-Developer-Community/feat/more-misc…
…-fixes Feature: More misc fixes
- Loading branch information
Showing
21 changed files
with
308 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Discord.Commands; | ||
using DiscordBot.Settings; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace DiscordBot.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class BotCommandChannelAttribute : PreconditionAttribute | ||
{ | ||
public override async Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
var settings = services.GetRequiredService<BotSettings>(); | ||
|
||
if (context.Channel.Id == settings.BotCommandsChannel.Id) | ||
{ | ||
return await Task.FromResult(PreconditionResult.FromSuccess()); | ||
} | ||
|
||
Task task = context.Message.DeleteAfterSeconds(seconds: 10); | ||
return await Task.FromResult(PreconditionResult.FromError($"This command can only be used in <#{settings.BotCommandsChannel.Id.ToString()}>.")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Discord.Commands; | ||
|
||
namespace DiscordBot.Attributes; | ||
|
||
/// <summary> | ||
/// Simple attribute, if the command is used by a bot, it escapes early and doesn't run the command. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class IgnoreBotsAttribute : PreconditionAttribute | ||
{ | ||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
if (context.Message.Author.IsBot) | ||
{ | ||
return Task.FromResult(PreconditionResult.FromError(string.Empty)); | ||
} | ||
|
||
return Task.FromResult(PreconditionResult.FromSuccess()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Discord.Commands; | ||
using Discord.WebSocket; | ||
using DiscordBot.Settings; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace DiscordBot.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class RequireAdminAttribute : PreconditionAttribute | ||
{ | ||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
var user = (SocketGuildUser)context.Message.Author; | ||
|
||
if (user.Roles.Any(x => x.Permissions.Administrator)) return Task.FromResult(PreconditionResult.FromSuccess()); | ||
return Task.FromResult(PreconditionResult.FromError(user + " attempted to use admin only command!")); | ||
} | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class RequireModeratorAttribute : PreconditionAttribute | ||
{ | ||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
var user = (SocketGuildUser)context.Message.Author; | ||
var settings = services.GetRequiredService<BotSettings>(); | ||
|
||
if (user.Roles.Any(x => x.Id == settings.ModeratorRoleId)) return Task.FromResult(PreconditionResult.FromSuccess()); | ||
return Task.FromResult(PreconditionResult.FromError(user + " attempted to use a moderator command!")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Discord.Commands; | ||
using DiscordBot.Attributes; | ||
using DiscordBot.Services; | ||
using DiscordBot.Settings; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.