forked from adam/discord-bot-shtik
webhooks aren't triggered by "!hook"; triggered by their own configured value
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
This commit is contained in:
parent
e0d5369823
commit
323d6fa521
@ -69,22 +69,25 @@ public class Webhook : Behavior
|
|||||||
|
|
||||||
public override bool ShouldAct(Message message, List<UAC> matchedUACs)
|
public override bool ShouldAct(Message message, List<UAC> matchedUACs)
|
||||||
{
|
{
|
||||||
if (!base.ShouldAct(message, matchedUACs))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Console.WriteLine("webhook checking");
|
|
||||||
|
|
||||||
if (configuredWebhooks?.Count() < 1)
|
if (configuredWebhooks?.Count() < 1)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("no webhooks configured!");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var webhookableMessageContent = message.Content.Substring(message.Content.IndexOf(Trigger) + Trigger.Length + 1);
|
|
||||||
Console.WriteLine($"webhookable content: {webhookableMessageContent}");
|
|
||||||
foreach (var wh in configuredWebhooks)
|
foreach (var wh in configuredWebhooks)
|
||||||
{
|
{
|
||||||
if (webhookableMessageContent.StartsWith(wh.Trigger))
|
var triggerTarget = wh.Trigger;
|
||||||
|
foreach (var uacMatch in matchedUACs)
|
||||||
{
|
{
|
||||||
|
foreach (var substitution in uacMatch.CommandAlterations)
|
||||||
|
{
|
||||||
|
triggerTarget = new Regex(substitution.Key).Replace(triggerTarget, substitution.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Regex.IsMatch(message.TranslatedContent, $"\\b{triggerTarget}\\b", RegexOptions.IgnoreCase))
|
||||||
|
{
|
||||||
|
var webhookableMessageContent = message.Content.Substring(message.Content.IndexOf(triggerTarget) + triggerTarget.Length + 1);
|
||||||
|
Console.WriteLine($"webhookable content: {webhookableMessageContent}");
|
||||||
var uacConf = Rememberer.SearchUAC(uac => uac.OwnerId == wh.uacID);
|
var uacConf = Rememberer.SearchUAC(uac => uac.OwnerId == wh.uacID);
|
||||||
if (uacConf.Users.Contains(message.Author.IsUser) || uacConf.Channels.Contains(message.Channel) || uacConf.AccountInChannels.Contains(message.Author))
|
if (uacConf.Users.Contains(message.Author.IsUser) || uacConf.Channels.Contains(message.Channel) || uacConf.AccountInChannels.Contains(message.Author))
|
||||||
{
|
{
|
||||||
@ -92,7 +95,7 @@ public class Webhook : Behavior
|
|||||||
authedCache.TryAdd(message.Id, new WebhookActionOrder()
|
authedCache.TryAdd(message.Id, new WebhookActionOrder()
|
||||||
{
|
{
|
||||||
Conf = wh,
|
Conf = wh,
|
||||||
webhookContent = webhookableMessageContent.Substring(wh.Trigger.Length + 1),
|
webhookContent = webhookableMessageContent,
|
||||||
});
|
});
|
||||||
Console.WriteLine($"added {message.Id} to authedcache");
|
Console.WriteLine($"added {message.Id} to authedcache");
|
||||||
return true;
|
return true;
|
||||||
@ -164,7 +167,7 @@ public class Webhook : Behavior
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Behaver.Instance.Reply(message.Id, await response.Content.ReadAsStringAsync());
|
Behaver.Instance.Reply(message.Id, await response.Content.ReadAsStringAsync());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user