Fixed .crca .crdm and .crad for global custom reactions on multiple shards.
This commit is contained in:
parent
37106e5613
commit
4327741ebc
@ -297,11 +297,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
|
|
||||||
var setValue = reaction.ContainsAnywhere = !reaction.ContainsAnywhere;
|
var setValue = reaction.ContainsAnywhere = !reaction.ContainsAnywhere;
|
||||||
|
|
||||||
using (var uow = _db.UnitOfWork)
|
await _service.SetCrCaAsync(reaction.Id, setValue).ConfigureAwait(false);
|
||||||
{
|
|
||||||
uow.CustomReactions.Get(id).ContainsAnywhere = setValue;
|
|
||||||
uow.Complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setValue)
|
if (setValue)
|
||||||
{
|
{
|
||||||
@ -348,11 +344,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
|
|
||||||
var setValue = reaction.DmResponse = !reaction.DmResponse;
|
var setValue = reaction.DmResponse = !reaction.DmResponse;
|
||||||
|
|
||||||
using (var uow = _db.UnitOfWork)
|
await _service.SetCrDmAsync(reaction.Id, setValue).ConfigureAwait(false);
|
||||||
{
|
|
||||||
uow.CustomReactions.Get(id).DmResponse = setValue;
|
|
||||||
uow.Complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setValue)
|
if (setValue)
|
||||||
{
|
{
|
||||||
@ -399,11 +391,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
|
|
||||||
var setValue = reaction.AutoDeleteTrigger = !reaction.AutoDeleteTrigger;
|
var setValue = reaction.AutoDeleteTrigger = !reaction.AutoDeleteTrigger;
|
||||||
|
|
||||||
using (var uow = _db.UnitOfWork)
|
await _service.SetCrAdAsync(reaction.Id, setValue).ConfigureAwait(false);
|
||||||
{
|
|
||||||
uow.CustomReactions.Get(id).AutoDeleteTrigger = setValue;
|
|
||||||
uow.Complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setValue)
|
if (setValue)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,31 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
|||||||
var id = int.Parse(msg);
|
var id = int.Parse(msg);
|
||||||
GlobalReactions = GlobalReactions.Where(cr => cr?.Id != id).ToArray();
|
GlobalReactions = GlobalReactions.Where(cr => cr?.Id != id).ToArray();
|
||||||
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
||||||
|
sub.Subscribe(_client.CurrentUser.Id + "_crad.toggle", (ch, msg) =>
|
||||||
|
{
|
||||||
|
var obj = new { Id = 0, Value = false };
|
||||||
|
obj = JsonConvert.DeserializeAnonymousType(msg, obj);
|
||||||
|
var gcr = GlobalReactions.FirstOrDefault(x => x.Id == obj.Id);
|
||||||
|
if (gcr != null)
|
||||||
|
gcr.AutoDeleteTrigger = obj.Value;
|
||||||
|
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
||||||
|
sub.Subscribe(_client.CurrentUser.Id + "_crdm.toggle", (ch, msg) =>
|
||||||
|
{
|
||||||
|
var obj = new { Id = 0, Value = false };
|
||||||
|
obj = JsonConvert.DeserializeAnonymousType(msg, obj);
|
||||||
|
var gcr = GlobalReactions.FirstOrDefault(x => x.Id == obj.Id);
|
||||||
|
if(gcr != null)
|
||||||
|
gcr.DmResponse = obj.Value;
|
||||||
|
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
||||||
|
sub.Subscribe(_client.CurrentUser.Id + "_crca.toggle", (ch, msg) =>
|
||||||
|
{
|
||||||
|
var obj = new { Id = 0, Value = false };
|
||||||
|
obj = JsonConvert.DeserializeAnonymousType(msg, obj);
|
||||||
|
var gcr = GlobalReactions.FirstOrDefault(x => x.Id == obj.Id);
|
||||||
|
if (gcr != null)
|
||||||
|
gcr.ContainsAnywhere = obj.Value;
|
||||||
|
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
||||||
|
|
||||||
|
|
||||||
var items = uow.CustomReactions.GetAll();
|
var items = uow.CustomReactions.GetAll();
|
||||||
|
|
||||||
@ -123,7 +148,11 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
|||||||
return false;
|
return false;
|
||||||
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
||||||
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
||||||
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger);
|
return ((cr.ContainsAnywhere &&
|
||||||
|
(content.GetWordPosition(trigger) != WordPosition.None))
|
||||||
|
|| (hasTarget && content.StartsWith(trigger + " "))
|
||||||
|
|| (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " "))
|
||||||
|
|| content == trigger);
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
if (grs.Length == 0)
|
if (grs.Length == 0)
|
||||||
return null;
|
return null;
|
||||||
@ -171,5 +200,44 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SetCrDmAsync(int id, bool setValue)
|
||||||
|
{
|
||||||
|
using (var uow = _db.UnitOfWork)
|
||||||
|
{
|
||||||
|
uow.CustomReactions.Get(id).DmResponse = setValue;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sub = _cache.Redis.GetSubscriber();
|
||||||
|
var data = new { Id = id, Value = setValue };
|
||||||
|
return sub.PublishAsync(_client.CurrentUser.Id + "_crdm.toggle", JsonConvert.SerializeObject(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetCrAdAsync(int id, bool setValue)
|
||||||
|
{
|
||||||
|
using (var uow = _db.UnitOfWork)
|
||||||
|
{
|
||||||
|
uow.CustomReactions.Get(id).AutoDeleteTrigger = setValue;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sub = _cache.Redis.GetSubscriber();
|
||||||
|
var data = new { Id = id, Value = setValue };
|
||||||
|
return sub.PublishAsync(_client.CurrentUser.Id + "_crad.toggle", JsonConvert.SerializeObject(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetCrCaAsync(int id, bool setValue)
|
||||||
|
{
|
||||||
|
using (var uow = _db.UnitOfWork)
|
||||||
|
{
|
||||||
|
uow.CustomReactions.Get(id).ContainsAnywhere = setValue;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sub = _cache.Redis.GetSubscriber();
|
||||||
|
var data = new { Id = id, Value = setValue };
|
||||||
|
return sub.PublishAsync(_client.CurrentUser.Id + "_crca.toggle", JsonConvert.SerializeObject(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user