mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-04-02 12:21:38 +00:00
Merge pull request #127 from 13xforever/vnext
Reduce spam for !explain when users refuse to read
This commit is contained in:
commit
38a5211286
@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using CompatBot.Utils;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.CommandsNext;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
|
||||||
namespace CompatBot.Commands.Attributes
|
namespace CompatBot.Commands.Attributes
|
||||||
{
|
{
|
||||||
@ -10,14 +13,27 @@ namespace CompatBot.Commands.Attributes
|
|||||||
{
|
{
|
||||||
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
|
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
|
||||||
{
|
{
|
||||||
if (ctx.Channel.IsPrivate || help)
|
if (help || IsSpamChannel(ctx.Channel))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (ctx.Channel.Name.Contains("spam", StringComparison.InvariantCultureIgnoreCase))
|
try
|
||||||
return true;
|
{
|
||||||
|
var msgList = await ctx.Channel.GetMessagesAsync(10).ConfigureAwait(false);
|
||||||
|
if (msgList.Any(m => m.Author.IsCurrent && m.Content is string s && s.Contains("explain list")))
|
||||||
|
{
|
||||||
|
await ctx.ReactWithAsync(Config.Reactions.Failure).ConfigureAwait(false);
|
||||||
|
return false; // we just explained to use #bot-spam or DMs, can't help if people can't read
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
|
||||||
await ctx.RespondAsync($"`{Config.CommandPrefix}{ctx.Command.QualifiedName}` is limited to bot spam channel and DMs").ConfigureAwait(false);
|
await ctx.RespondAsync($"`{Config.CommandPrefix}{ctx.Command.QualifiedName}` is limited to bot spam channel and DMs").ConfigureAwait(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsSpamChannel(DiscordChannel channel)
|
||||||
|
{
|
||||||
|
return channel.IsPrivate || channel.Name.Contains("spam", StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,10 +22,15 @@ namespace CompatBot.Commands
|
|||||||
public async Task ShowExplanation(CommandContext ctx, [RemainingText, Description("Term to explain")] string term)
|
public async Task ShowExplanation(CommandContext ctx, [RemainingText, Description("Term to explain")] string term)
|
||||||
{
|
{
|
||||||
await ctx.TriggerTypingAsync().ConfigureAwait(false);
|
await ctx.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
if (string.IsNullOrEmpty(term))
|
string inSpecificLocation = null;
|
||||||
|
if (!LimitedToSpamChannel.IsSpamChannel(ctx.Channel))
|
||||||
{
|
{
|
||||||
var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
|
var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
|
||||||
await ctx.RespondAsync($"You may want to look at available terms by using `{Config.CommandPrefix}explain list` in {spamChannel.Mention} or bot DMs").ConfigureAwait(false);
|
inSpecificLocation = $" in {spamChannel.Mention} or bot DMs";
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(term))
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync($"You may want to look at available terms by using `{Config.CommandPrefix}explain list`{inSpecificLocation}").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +72,8 @@ namespace CompatBot.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var spamCh = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
|
var msg = $"Unknown term `{term.Sanitize()}`. Use `{Config.CommandPrefix}explain list` to look at defined terms{inSpecificLocation}";
|
||||||
await ctx.RespondAsync($"Unknown term `{term.Sanitize()}`. Use `!explain list` to look at defined terms in {spamCh.Mention} or bot DMs").ConfigureAwait(false);
|
await ctx.RespondAsync(msg).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("add"), RequiresBotModRole]
|
[Command("add"), RequiresBotModRole]
|
||||||
@ -151,10 +156,11 @@ namespace CompatBot.Commands
|
|||||||
await ctx.ReactWithAsync(Config.Reactions.Failure).ConfigureAwait(false);
|
await ctx.ReactWithAsync(Config.Reactions.Failure).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("list"), LimitedToSpamChannel, TriggersTyping]
|
[Command("list"), LimitedToSpamChannel]
|
||||||
[Description("List all known terms that could be used for !explain command")]
|
[Description("List all known terms that could be used for !explain command")]
|
||||||
public async Task List(CommandContext ctx)
|
public async Task List(CommandContext ctx)
|
||||||
{
|
{
|
||||||
|
await ctx.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
using (var db = new BotDb())
|
using (var db = new BotDb())
|
||||||
{
|
{
|
||||||
var keywords = await db.Explanation.Select(e => e.Keyword).OrderBy(t => t).ToListAsync().ConfigureAwait(false);
|
var keywords = await db.Explanation.Select(e => e.Keyword).OrderBy(t => t).ToListAsync().ConfigureAwait(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user