Perms added to custom reactions, actually commit
This commit is contained in:
parent
2d9fc9893b
commit
7704569c36
@ -23,10 +23,12 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Draw(int num = 1)
|
public async Task Draw(int num = 1)
|
||||||
{
|
{
|
||||||
|
if (num < 1)
|
||||||
|
num = 1;
|
||||||
var cards = _allDecks.GetOrAdd(Context.Guild, (s) => new Cards());
|
var cards = _allDecks.GetOrAdd(Context.Guild, (s) => new Cards());
|
||||||
var images = new List<Image>();
|
var images = new List<Image>();
|
||||||
var cardObjects = new List<Cards.Card>();
|
var cardObjects = new List<Cards.Card>();
|
||||||
if (num > 5) num = 5;
|
if (num > 10) num = 10;
|
||||||
for (var i = 0; i < num; i++)
|
for (var i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
if (cards.CardPool.Count == 0 && i != 0)
|
if (cards.CardPool.Count == 0 && i != 0)
|
||||||
|
@ -8,6 +8,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using NadekoBot.Services.Permissions;
|
||||||
|
|
||||||
namespace NadekoBot.Services.CustomReactions
|
namespace NadekoBot.Services.CustomReactions
|
||||||
{
|
{
|
||||||
@ -21,12 +22,14 @@ namespace NadekoBot.Services.CustomReactions
|
|||||||
private readonly Logger _log;
|
private readonly Logger _log;
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly DiscordShardedClient _client;
|
private readonly DiscordShardedClient _client;
|
||||||
|
private readonly PermissionsService _perms;
|
||||||
|
|
||||||
public CustomReactionsService(DbService db, DiscordShardedClient client)
|
public CustomReactionsService(PermissionsService perms, DbService db, DiscordShardedClient client)
|
||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
_db = db;
|
_db = db;
|
||||||
_client = client;
|
_client = client;
|
||||||
|
_perms = perms;
|
||||||
|
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
@ -48,32 +51,31 @@ namespace NadekoBot.Services.CustomReactions
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var content = umsg.Content.Trim().ToLowerInvariant();
|
var content = umsg.Content.Trim().ToLowerInvariant();
|
||||||
CustomReaction[] reactions;
|
|
||||||
|
|
||||||
GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
|
if (GuildReactions.TryGetValue(channel.Guild.Id, out CustomReaction[] reactions))
|
||||||
if (reactions != null && reactions.Any())
|
if (reactions != null && reactions.Any())
|
||||||
{
|
|
||||||
var rs = reactions.Where(cr =>
|
|
||||||
{
|
{
|
||||||
if (cr == null)
|
var rs = reactions.Where(cr =>
|
||||||
return false;
|
|
||||||
|
|
||||||
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
|
||||||
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
|
||||||
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
|
|
||||||
}).ToArray();
|
|
||||||
|
|
||||||
if (rs.Length != 0)
|
|
||||||
{
|
|
||||||
var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
|
|
||||||
if (reaction != null)
|
|
||||||
{
|
{
|
||||||
if (reaction.Response == "-")
|
if (cr == null)
|
||||||
return null;
|
return false;
|
||||||
return reaction;
|
|
||||||
|
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
||||||
|
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
||||||
|
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
|
if (rs.Length != 0)
|
||||||
|
{
|
||||||
|
var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
|
||||||
|
if (reaction != null)
|
||||||
|
{
|
||||||
|
if (reaction.Response == "-")
|
||||||
|
return null;
|
||||||
|
return reaction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var grs = GlobalReactions.Where(cr =>
|
var grs = GlobalReactions.Where(cr =>
|
||||||
{
|
{
|
||||||
@ -99,19 +101,18 @@ namespace NadekoBot.Services.CustomReactions
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//todo permissions
|
//todo permissions
|
||||||
//if (guild != null)
|
if (guild is SocketGuild sg)
|
||||||
//{
|
{
|
||||||
// PermissionCache pc = Permissions.GetCache(guild.Id);
|
PermissionCache pc = _perms.GetCache(guild.Id);
|
||||||
|
|
||||||
// if (!pc.Permissions.CheckPermissions(usrMsg, cr.Trigger, "ActualCustomReactions",
|
if (!pc.Permissions.CheckPermissions(msg, cr.Trigger, "ActualCustomReactions",
|
||||||
// out int index))
|
out int index))
|
||||||
// {
|
{
|
||||||
// var returnMsg =
|
var returnMsg = $"Permission number #{index + 1} **{pc.Permissions[index].GetCommand(sg)}** is preventing this action.";
|
||||||
// $"Permission number #{index + 1} **{pc.Permissions[index].GetCommand(guild)}** is preventing this action.";
|
_log.Info(returnMsg);
|
||||||
// _log.Info(returnMsg);
|
return true;
|
||||||
// return;
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
await cr.Send(msg, _client, this).ConfigureAwait(false);
|
await cr.Send(msg, _client, this).ConfigureAwait(false);
|
||||||
|
|
||||||
if (cr.AutoDeleteTrigger)
|
if (cr.AutoDeleteTrigger)
|
||||||
|
Loading…
Reference in New Issue
Block a user