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 branch 'dev' into dependabot/nuget/MySql.Data-8.2.0
- Loading branch information
Showing
44 changed files
with
2,341 additions
and
648 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,48 @@ | ||
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()); | ||
} | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class IgnoreBotsAndWebhooksAttribute : PreconditionAttribute | ||
{ | ||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
if (context.Message.Author.IsBot || context.Message.Author.IsWebhook) | ||
{ | ||
return Task.FromResult(PreconditionResult.FromError(string.Empty)); | ||
} | ||
|
||
return Task.FromResult(PreconditionResult.FromSuccess()); | ||
} | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class IgnoreWebhooksAttribute : PreconditionAttribute | ||
{ | ||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | ||
{ | ||
if (context.Message.Author.IsWebhook) | ||
{ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Data.Common; | ||
using Insight.Database; | ||
|
||
namespace DiscordBot.Extensions; | ||
|
||
public static class DBConnectionExtension | ||
{ | ||
public static async Task<bool> ColumnExists(this DbConnection connection, string tableName, string columnName) | ||
{ | ||
// Execute the query `SHOW COLUMNS FROM `{tableName}` LIKE '{columnName}'` and check if any rows are returned | ||
var query = $"SHOW COLUMNS FROM `{tableName}` LIKE '{columnName}'"; | ||
var response = await connection.QuerySqlAsync(query); | ||
return response.Count > 0; | ||
} | ||
} |
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,45 @@ | ||
namespace DiscordBot.Extensions; | ||
|
||
public static class EmbedBuilderExtension | ||
{ | ||
|
||
public static EmbedBuilder FooterRequestedBy(this EmbedBuilder builder, IUser requestor) | ||
{ | ||
builder.WithFooter( | ||
$"Requested by {requestor.GetUserPreferredName()}", | ||
requestor.GetAvatarUrl()); | ||
return builder; | ||
} | ||
|
||
public static EmbedBuilder FooterQuoteBy(this EmbedBuilder builder, IUser requestor, IChannel channel) | ||
{ | ||
builder.WithFooter( | ||
$"Quoted by {requestor.GetUserPreferredName()}, • From channel #{channel.Name}", | ||
requestor.GetAvatarUrl()); | ||
return builder; | ||
} | ||
|
||
public static EmbedBuilder FooterInChannel(this EmbedBuilder builder, IChannel channel) | ||
{ | ||
builder.WithFooter( | ||
$"In channel #{channel.Name}", null); | ||
return builder; | ||
} | ||
|
||
public static EmbedBuilder AddAuthor(this EmbedBuilder builder, IUser user, bool includeAvatar = true) | ||
{ | ||
builder.WithAuthor( | ||
user.GetUserPreferredName(), | ||
includeAvatar ? user.GetAvatarUrl() : null); | ||
return builder; | ||
} | ||
|
||
public static EmbedBuilder AddAuthorWithAction(this EmbedBuilder builder, IUser user, string action, bool includeAvatar = true) | ||
{ | ||
builder.WithAuthor( | ||
$"{user.GetUserPreferredName()} - {action}", | ||
includeAvatar ? user.GetAvatarUrl() : null); | ||
return builder; | ||
} | ||
|
||
} |
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.