Custom reactions will no longer trigger if user/server is blacklisted or if there is a filtered word or invite in it. If custom reaction is triggered, no commands will be attempted to be triggered after it (if your CR has the same name as some command, only your CR will be ran)
This commit is contained in:
parent
5c20c88253
commit
a7fefead64
@ -19,6 +19,7 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
{
|
||||
public static ConcurrentHashSet<CustomReaction> GlobalReactions { get; } = new ConcurrentHashSet<CustomReaction>();
|
||||
public static ConcurrentDictionary<ulong, ConcurrentHashSet<CustomReaction>> GuildReactions { get; } = new ConcurrentDictionary<ulong, ConcurrentHashSet<CustomReaction>>();
|
||||
|
||||
static CustomReactions()
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
@ -30,18 +31,14 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
}
|
||||
public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
||||
{
|
||||
client.MessageReceived += (imsg) =>
|
||||
{
|
||||
var umsg = imsg as IUserMessage;
|
||||
if (umsg == null || imsg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public static async Task<bool> TryExecuteCustomReaction(IUserMessage umsg)
|
||||
{
|
||||
var channel = umsg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
return false;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
var content = umsg.Content.Trim().ToLowerInvariant();
|
||||
ConcurrentHashSet<CustomReaction> reactions;
|
||||
GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
|
||||
@ -55,7 +52,7 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
if (reaction != null)
|
||||
{
|
||||
try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
var greaction = GlobalReactions.Where(cr =>
|
||||
@ -68,11 +65,9 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
if (greaction != null)
|
||||
{
|
||||
try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -18,6 +18,7 @@ using static NadekoBot.Modules.Permissions.Permissions;
|
||||
using System.Collections.Concurrent;
|
||||
using NadekoBot.Modules.Help;
|
||||
using static NadekoBot.Modules.Administration.Administration;
|
||||
using NadekoBot.Modules.CustomReactions;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
@ -121,6 +122,17 @@ namespace NadekoBot.Services
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// maybe this message is a custom reaction
|
||||
var crExecuted = await CustomReactions.TryExecuteCustomReaction(usrMsg).ConfigureAwait(false);
|
||||
|
||||
//if it was, don't execute the command
|
||||
if (crExecuted)
|
||||
return;
|
||||
}
|
||||
catch { }
|
||||
|
||||
var throwaway = Task.Run(async () =>
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
|
Loading…
Reference in New Issue
Block a user