You can now use permissions module to disable individual custom reactions. Not fully tested, seems to work. public bot global cooldown reduced to 750ms, slot cooldown from 2 to 1 second
This commit is contained in:
@@ -13,9 +13,27 @@ using Discord.WebSocket;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NadekoBot.DataStructures;
|
||||
using NLog.Fluent;
|
||||
|
||||
namespace NadekoBot.Modules.CustomReactions
|
||||
{
|
||||
public static class CustomReactionExtensions
|
||||
{
|
||||
public static Task<IUserMessage> Send(this CustomReaction cr, IUserMessage context)
|
||||
{
|
||||
var channel = context.Channel;
|
||||
|
||||
CustomReactions.ReactionStats.AddOrUpdate(cr.Trigger, 1, (k, old) => ++old);
|
||||
|
||||
CREmbed crembed;
|
||||
if (CREmbed.TryParse(cr.Response, out crembed))
|
||||
{
|
||||
return channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "");
|
||||
}
|
||||
return channel.SendMessageAsync(cr.ResponseWithContext(context));
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoModule("CustomReactions", ".")]
|
||||
public class CustomReactions : NadekoTopLevelModule
|
||||
{
|
||||
@@ -25,7 +43,7 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
|
||||
public static ConcurrentDictionary<string, uint> ReactionStats { get; } = new ConcurrentDictionary<string, uint>();
|
||||
|
||||
private static new readonly Logger _log;
|
||||
private new static readonly Logger _log;
|
||||
|
||||
static CustomReactions()
|
||||
{
|
||||
@@ -43,11 +61,11 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
|
||||
public void ClearStats() => ReactionStats.Clear();
|
||||
|
||||
public static async Task<bool> TryExecuteCustomReaction(SocketUserMessage umsg)
|
||||
public static async Task<CustomReaction> TryGetCustomReaction(SocketUserMessage umsg)
|
||||
{
|
||||
var channel = umsg.Channel as SocketTextChannel;
|
||||
if (channel == null)
|
||||
return false;
|
||||
return null;
|
||||
|
||||
var content = umsg.Content.Trim().ToLowerInvariant();
|
||||
CustomReaction[] reactions;
|
||||
@@ -70,26 +88,9 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
|
||||
if (reaction != null)
|
||||
{
|
||||
if (reaction.Response != "-")
|
||||
{
|
||||
CREmbed crembed;
|
||||
if (CREmbed.TryParse(reaction.Response, out crembed))
|
||||
{
|
||||
try { await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn("Sending CREmbed failed");
|
||||
_log.Warn(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
ReactionStats.AddOrUpdate(reaction.Trigger, 1, (k, old) => ++old);
|
||||
return true;
|
||||
if (reaction.Response == "-")
|
||||
return null;
|
||||
return reaction;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,29 +104,10 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
|
||||
}).ToArray();
|
||||
if (grs.Length == 0)
|
||||
return false;
|
||||
return null;
|
||||
var greaction = grs[new NadekoRandom().Next(0, grs.Length)];
|
||||
|
||||
if (greaction != null)
|
||||
{
|
||||
CREmbed crembed;
|
||||
if (CREmbed.TryParse(greaction.Response, out crembed))
|
||||
{
|
||||
try { await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn("Sending CREmbed failed");
|
||||
_log.Warn(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
|
||||
}
|
||||
ReactionStats.AddOrUpdate(greaction.Trigger, 1, (k, old) => ++old);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return greaction;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@@ -223,7 +223,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
await Task.Delay(1500);
|
||||
_runningUsers.Remove(Context.User.Id);
|
||||
});
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ using Discord.WebSocket;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.DataStructures;
|
||||
using NadekoBot.TypeReaders;
|
||||
using NLog;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions
|
||||
@@ -89,6 +90,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
var gc = uow.GuildConfigs.For(oc.Key, set => set.Include(x => x.Permissions));
|
||||
|
||||
var oldPerms = oc.Value.RootPermission.AsEnumerable().Reverse().ToList();
|
||||
uow._context.Set<Permission>().RemoveRange(oldPerms);
|
||||
gc.RootPermission = null;
|
||||
if (oldPerms.Count > 2)
|
||||
{
|
||||
@@ -316,27 +318,27 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task SrvrCmd(CommandInfo command, PermissionAction action)
|
||||
public async Task SrvrCmd(CommandOrCrInfo command, PermissionAction action)
|
||||
{
|
||||
await AddPermissions(Context.Guild.Id, new Permissionv2
|
||||
{
|
||||
PrimaryTarget = PrimaryPermissionType.Server,
|
||||
PrimaryTargetId = 0,
|
||||
SecondaryTarget = SecondaryPermissionType.Command,
|
||||
SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
|
||||
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
|
||||
if (action.Value)
|
||||
{
|
||||
await ReplyConfirmLocalized("sx_enable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command")).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalized("sx_disable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command")).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -370,28 +372,28 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task UsrCmd(CommandInfo command, PermissionAction action, [Remainder] IGuildUser user)
|
||||
public async Task UsrCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IGuildUser user)
|
||||
{
|
||||
await AddPermissions(Context.Guild.Id, new Permissionv2
|
||||
{
|
||||
PrimaryTarget = PrimaryPermissionType.User,
|
||||
PrimaryTargetId = user.Id,
|
||||
SecondaryTarget = SecondaryPermissionType.Command,
|
||||
SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
|
||||
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
|
||||
if (action.Value)
|
||||
{
|
||||
await ReplyConfirmLocalized("ux_enable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(user.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalized("ux_disable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(user.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
@@ -428,7 +430,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RoleCmd(CommandInfo command, PermissionAction action, [Remainder] IRole role)
|
||||
public async Task RoleCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IRole role)
|
||||
{
|
||||
if (role == role.Guild.EveryoneRole)
|
||||
return;
|
||||
@@ -438,21 +440,21 @@ namespace NadekoBot.Modules.Permissions
|
||||
PrimaryTarget = PrimaryPermissionType.Role,
|
||||
PrimaryTargetId = role.Id,
|
||||
SecondaryTarget = SecondaryPermissionType.Command,
|
||||
SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
|
||||
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
|
||||
if (action.Value)
|
||||
{
|
||||
await ReplyConfirmLocalized("rx_enable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(role.Name)).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalized("rx_disable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(role.Name)).ConfigureAwait(false);
|
||||
}
|
||||
@@ -493,28 +495,28 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ChnlCmd(CommandInfo command, PermissionAction action, [Remainder] ITextChannel chnl)
|
||||
public async Task ChnlCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] ITextChannel chnl)
|
||||
{
|
||||
await AddPermissions(Context.Guild.Id, new Permissionv2
|
||||
{
|
||||
PrimaryTarget = PrimaryPermissionType.Channel,
|
||||
PrimaryTargetId = chnl.Id,
|
||||
SecondaryTarget = SecondaryPermissionType.Command,
|
||||
SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
|
||||
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
|
||||
if (action.Value)
|
||||
{
|
||||
await ReplyConfirmLocalized("cx_enable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(chnl.Name)).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalized("cx_disable",
|
||||
Format.Code(command.Aliases.First()),
|
||||
Format.Code(command.Name),
|
||||
GetText("of_command"),
|
||||
Format.Code(chnl.Name)).ConfigureAwait(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user