Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark command for deletion with the new . command prefix #232

Merged
merged 1 commit into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CompatBot/Commands/Attributes/LimitedToHelpChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
if (ctx.Channel.Name.Equals("help", StringComparison.InvariantCultureIgnoreCase))
return true;

await ctx.RespondAsync($"`{Config.CommandPrefix}{ctx.Command.QualifiedName}` is limited to help channel and DMs").ConfigureAwait(false);
await ctx.RespondAsync($"`{ctx.Prefix}{ctx.Command.QualifiedName}` is limited to help channel and DMs").ConfigureAwait(false);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion CompatBot/Commands/Attributes/LimitedToSpamChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
catch {}

var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
await ctx.RespondAsync($"`{Config.CommandPrefix}{ctx.Command.QualifiedName}` is limited to {spamChannel.Mention} and DMs").ConfigureAwait(false);
await ctx.RespondAsync($"`{ctx.Prefix}{ctx.Command.QualifiedName}` is limited to {spamChannel.Mention} and DMs").ConfigureAwait(false);
return false;
}

Expand Down
8 changes: 8 additions & 0 deletions CompatBot/Commands/BaseCommandModuleCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ internal class BaseCommandModuleCustom : BaseCommandModule

public override async Task BeforeExecutionAsync(CommandContext ctx)
{
try
{
await ctx.Message.DeleteAsync().ConfigureAwait(false);
}
catch (Exception e)
{
Config.Log.Warn(e, "Failed to delete command message with the autodelete command prefix");
}
var disabledCmds = DisabledCommandsProvider.Get();
if (disabledCmds.Contains(ctx.Command.QualifiedName) && !disabledCmds.Contains("*"))
{
Expand Down
2 changes: 1 addition & 1 deletion CompatBot/Commands/Explain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task ShowExplanation(CommandContext ctx, [RemainingText, Descriptio
var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
inSpecificLocation = $" in {spamChannel.Mention} or bot DMs";
}
var msg = $"Unknown term `{term.Sanitize()}`. Use `{Config.CommandPrefix}explain list` to look at defined terms{inSpecificLocation}";
var msg = $"Unknown term `{term.Sanitize()}`. Use `{ctx.Prefix}explain list` to look at defined terms{inSpecificLocation}";
await ctx.RespondAsync(msg).ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion CompatBot/Commands/Sudo.Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Add(CommandContext ctx, [Description("Discord user to add to t
{
await ctx.ReactWithAsync(Config.Reactions.Success,
$"{user.Mention} was successfully added as moderator!\n" +
$"Try using `{Config.CommandPrefix}help` to see new commands available to you"
$"Try using `{ctx.Prefix}help` to see new commands available to you"
).ConfigureAwait(false);
}
else
Expand Down
1 change: 1 addition & 0 deletions CompatBot/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace CompatBot
internal static class Config
{
public static readonly string CommandPrefix = "!";
public static readonly string AutoRemoveCommandPrefix = ".";
public static readonly ulong BotGuildId = 272035812277878785; // discord server where the bot is supposed to be
public static readonly ulong BotGeneralChannelId = 272035812277878785;// #rpcs3; main or general channel where noobs come first thing
public static readonly ulong BotChannelId = 291679908067803136; // #compatbot; this is used for !compat/!top results and new builds announcements
Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/AppveyorLinksHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ internal sealed class AppveyorLinksHandler

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
return;

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

var matches = BuildLinks.Matches(args.Message.Content);
Expand Down
3 changes: 3 additions & 0 deletions CompatBot/EventHandlers/BotReactionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static async Task OnMessageCreated(MessageCreateEventArgs args)
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

if (args.Message.Channel.IsPrivate)
return;

#if DEBUG
if (args.Message.Content == "emoji test")
{
Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/GithubLinksHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ internal static class GithubLinksHandler

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
return;

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

var lastBotMessages = await args.Channel.GetMessagesBeforeAsync(args.Message.Id, 20, DateTime.UtcNow.AddSeconds(-30)).ConfigureAwait(false);
Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/IsTheGamePlayableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static class IsTheGamePlayableHandler

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

#if !DEBUG
Expand All @@ -43,9 +43,6 @@ public static async Task OnMessageCreated(MessageCreateEventArgs args)
&& DateTime.UtcNow - lastCheck < CooldownThreshold)
return;

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
return;

#if !DEBUG
if (args.Author.IsSmartlisted(args.Client, args.Guild))
return;
Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/LogAsTextMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ internal static class LogAsTextMonitor

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
return;

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

if (!"help".Equals(args.Channel.Name, StringComparison.InvariantCultureIgnoreCase))
Expand Down
6 changes: 1 addition & 5 deletions CompatBot/EventHandlers/LogParsingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ static LogParsingHandler()

public static Task OnMessageCreated(MessageCreateEventArgs args)
{
var message = args.Message;
if (message.Author.IsBot)
return Task.CompletedTask;

if (!string.IsNullOrEmpty(message.Content) && message.Content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return Task.CompletedTask;

OnNewLog(args.Client, args.Channel, args.Message);
Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/PostLogHelpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class PostLogHelpHandler

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

#if !DEBUG
Expand All @@ -31,9 +31,6 @@ public static async Task OnMessageCreated(MessageCreateEventArgs args)
return;
#endif

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
return;

if (!UploadLogMention.IsMatch(args.Message.Content))
return;

Expand Down
5 changes: 1 addition & 4 deletions CompatBot/EventHandlers/ProductCodeLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ internal static class ProductCodeLookup

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
return;

if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

var lastBotMessages = await args.Channel.GetMessagesBeforeAsync(args.Message.Id, 20, DateTime.UtcNow.AddSeconds(-30)).ConfigureAwait(false);
Expand Down
8 changes: 3 additions & 5 deletions CompatBot/EventHandlers/TableFlipMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus.EventArgs;

namespace CompatBot.EventHandlers
Expand All @@ -10,11 +11,7 @@ internal static class TableFlipMonitor

public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot)
return;

var content = args.Message.Content;
if (string.IsNullOrEmpty(content) || content.StartsWith(Config.CommandPrefix))
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

/*
Expand All @@ -33,6 +30,7 @@ public static async Task OnMessageCreated(MessageCreateEventArgs args)
*/
try
{
var content = args.Message.Content;
if (!(content.Contains("┻━┻") ||
content.Contains("┻━┻")))
return;
Expand Down
4 changes: 4 additions & 0 deletions CompatBot/EventHandlers/UnknownCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal static class UnknownCommandHandler
{
public static async Task OnError(CommandErrorEventArgs e)
{
if (e.Context.User.IsBot)
return;

if (!(e.Exception is CommandNotFoundException cnfe))
{
Config.Log.Error(e.Exception);
Expand All @@ -25,6 +28,7 @@ public static async Task OnError(CommandErrorEventArgs e)
return;

if (e.Context.Prefix != Config.CommandPrefix
&& e.Context.Prefix != Config.AutoRemoveCommandPrefix
&& (e.Context.Message.Content?.EndsWith("?") ?? false)
&& e.Context.CommandsNext.RegisteredCommands.TryGetValue("8ball", out var cmd))
{
Expand Down
2 changes: 1 addition & 1 deletion CompatBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal static async Task Main(string[] args)
{
var commands = client.UseCommandsNext(new CommandsNextConfiguration
{
StringPrefixes = new[] {Config.CommandPrefix},
StringPrefixes = new[] {Config.CommandPrefix, Config.AutoRemoveCommandPrefix},
Services = new ServiceCollection().BuildServiceProvider(),
});
commands.RegisterConverter(new CustomDiscordChannelConverter());
Expand Down
7 changes: 3 additions & 4 deletions CompatBot/Utils/DefaultHandlerFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ internal static class DefaultHandlerFilter
{
internal static bool IsFluff(DiscordMessage message)
{
if (message.Channel.IsPrivate)
return true;

if (message.Author.IsBot)
return true;

if (string.IsNullOrEmpty(message.Content) || message.Content.StartsWith(Config.CommandPrefix))
if (string.IsNullOrEmpty(message.Content)
|| message.Content.StartsWith(Config.CommandPrefix)
|| message.Content.StartsWith(Config.AutoRemoveCommandPrefix))
return true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion CompatBot/Utils/DiscordClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static Task RemoveReactionAsync(this CommandContext ctx, DiscordEmoji emo

public static Task ReactWithAsync(this CommandContext ctx, DiscordEmoji emoji, string fallbackMessage = null, bool? showBoth = null)
{
return ReactWithAsync(ctx.Message, ctx.Client, emoji, fallbackMessage, showBoth);
return ReactWithAsync(ctx.Message, ctx.Client, emoji, fallbackMessage, showBoth ?? (ctx.Prefix == Config.AutoRemoveCommandPrefix));
}

public static async Task<IReadOnlyCollection<DiscordMessage>> GetMessagesBeforeAsync(this DiscordChannel channel, ulong beforeMessageId, int limit = 100, DateTime? timeLimit = null)
Expand Down