more replacements
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good

idk what else I would want
This commit is contained in:
adam 2025-05-15 00:11:42 -04:00
parent bbf94d215f
commit 7c10b00110

View File

@ -100,6 +100,7 @@ public class Webhook : Behavior
Console.Error.WriteLine($"{message.Id} was supposed to act, but authedCache doesn't have it! it has {authedCache?.Count()} other stuff, though."); Console.Error.WriteLine($"{message.Id} was supposed to act, but authedCache doesn't have it! it has {authedCache?.Count()} other stuff, though.");
return false; return false;
} }
var msg = translate(actionOrder, message);
var req = new HttpRequestMessage(new HttpMethod(actionOrder.Conf.Method.ToString()), actionOrder.Conf.Uri); var req = new HttpRequestMessage(new HttpMethod(actionOrder.Conf.Method.ToString()), actionOrder.Conf.Uri);
var theContentHeader = actionOrder.Conf.Headers?.FirstOrDefault(h => h[0]?.ToLower() == "content-type"); var theContentHeader = actionOrder.Conf.Headers?.FirstOrDefault(h => h[0]?.ToLower() == "content-type");
if (theContentHeader != null) if (theContentHeader != null)
@ -108,17 +109,17 @@ public class Webhook : Behavior
{ {
//json content is constructed some other weird way. //json content is constructed some other weird way.
case "multipart/form-data": case "multipart/form-data":
req.Content = new System.Net.Http.MultipartFormDataContent(translate(actionOrder)); req.Content = new System.Net.Http.MultipartFormDataContent(msg);
break; break;
default: default:
req.Content = new System.Net.Http.StringContent(translate(actionOrder)); req.Content = new System.Net.Http.StringContent(msg);
break; break;
} }
req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(theContentHeader[1]?.ToLower()); req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(theContentHeader[1]?.ToLower());
} }
if (req.Content == null) if (req.Content == null)
{ {
req.Content = new System.Net.Http.StringContent(translate(actionOrder)); req.Content = new System.Net.Http.StringContent(msg);
} }
Console.WriteLine($"survived translating string content. request content: {req.Content}"); Console.WriteLine($"survived translating string content. request content: {req.Content}");
if (actionOrder.Conf.Headers?.ToList().Count > 0) if (actionOrder.Conf.Headers?.ToList().Count > 0)
@ -157,10 +158,15 @@ public class Webhook : Behavior
} }
return true; return true;
} }
private string translate(WebhookActionOrder actionOrder) private string translate(WebhookActionOrder actionOrder, Message message)
{ {
//TODO: message author, etc. if(string.IsNullOrWhiteSpace(actionOrder.Conf.Content))
return actionOrder.Conf.Content?.Replace("{text}", actionOrder.webhookContent); return "";
var msgContent = actionOrder.Conf.Content.Replace("{text}", actionOrder.webhookContent);
msgContent = msgContent.Replace("{msgid}", message.Id.ToString());
msgContent = msgContent.Replace("{account}", message.Author.DisplayName.ToString());
msgContent = msgContent.Replace("{user}", message.Author.IsUser.DisplayName.ToString());
return msgContent;
} }
} }