public WebhookRequest(string webhookUrl) { sb.Append("/personal/webhook"); bodyObj = new WebhookBody { WebHookUrl = webhookUrl }; }
/// <summary> /// https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token /// Modifies a webhook WITHOUT a token and requires the entire webhook URL. /// </summary> /// <param name="webhookurl"></param> /// <param name="webhookBody"></param> /// <returns></returns> public static ChannelWebhook ModifyWebhook(string webhookurl, WebhookBody webhookBody) { var client = new RestClient(webhookurl); client.Timeout = -1; var request = new RestRequest(Method.PATCH); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", js.Serialize(webhookBody), ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); return(js.Deserialize <ChannelWebhook>(response.Content)); }
/// <summary> /// https://discord.com/developers/docs/resources/webhook#modify-webhook /// Modifies a webhook using a token with "MANAGE_WEBHOOKS" permission. /// </summary> /// <param name="token"></param> /// <param name="WebhookID"></param> /// <param name="webhookBody"></param> /// <returns></returns> public static ChannelWebhook ModifyWebhook(string token, ulong WebhookID, WebhookBody webhookBody) { var client = new RestClient($"{APIURL}/webhooks/{WebhookID}"); client.Timeout = -1; var request = new RestRequest(Method.PATCH); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", js.Serialize(webhookBody), ParameterType.RequestBody); request.AddHeader("Authorization", $"Bot {token}"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); return(js.Deserialize <ChannelWebhook>(response.Content)); }
/// <summary> /// Creates a <see cref="JObject"/> used as the <see cref="HttpRequestMessage"/> entity body for a <see cref="WebHook"/>. /// </summary> /// <param name="workItem">The <see cref="WebHookWorkItem"/> representing the data to be sent.</param> /// <returns>An initialized <see cref="JObject"/>.</returns> protected virtual void CreateWebHookRequestBody(WebHookWorkItem workItem, StreamWriter writer) { if (workItem == null) { throw new ArgumentNullException(nameof(workItem)); } // Set notifications var webhookBody = new WebhookBody { Id = workItem.Id, Attempt = workItem.Offset + 1, }; var properties = workItem.WebHook.Properties; if (properties != null) { webhookBody.Properties = new Dictionary <string, object>(properties); } webhookBody.Notifications = workItem.Notifications.ToArray(); _serializer.Serialize(writer, webhookBody); }
/// <summary> /// Create a webhook. /// </summary> /// <param name="webhookBody">New webhook.</param> /// <returns>Webhook</returns> public Webhook PostWebhook(WebhookBody webhookBody) { // verify the required parameter 'webhookBody' is set if (webhookBody == null) { throw new ApiException(400, "Missing required parameter 'webhookBody' when calling PostWebhook"); } var path = "/webhooks"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(webhookBody); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "Token" }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling PostWebhook: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling PostWebhook: " + response.ErrorMessage, response.ErrorMessage); } return((Webhook)ApiClient.Deserialize(response.Content, typeof(Webhook), response.Headers)); }
private void SendReport(IPlayer reporter, IPlayer suspect, string subject, string message) { var authorIconURL = string.Empty; var author = _config.IsReporterIcon ? reporter : suspect; if (_config.AuthorIcon) { authorIconURL = PluginData.UserCache.Find(author.Id)?.ImageURL ?? string.Empty; UpdateCachedImage(author); // Won't get update now but will be for any other reports for this user } const string type = "rich"; var body = new WebhookBody { Embeds = new[] { new EmbedBody { Title = _config.EmbedTitle, Description = _config.EmbedDescription, Type = type, Color = _config.EmbedColor, Author = new EmbedBody.AuthorBody { AuthorIconURL = authorIconURL, AuthorURL = string.Format(SteamProfile, author.Id), Name = author.Name }, Fields = new[] { new EmbedBody.FieldBody { Name = GetMsg("Webhook: Report Subject"), Value = subject, Inline = false }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Report Message"), Value = string.IsNullOrEmpty(message) ? GetMsg("Webhook: Report Message If Empty") : message, Inline = false }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Reporter Data Title"), Value = FormatUserDetails(new StringBuilder(GetMsg("Webhook: Reporter Data")), reporter), Inline = false }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Suspect Data Title"), Value = FormatUserDetails(new StringBuilder(GetMsg("Webhook: Suspect Data")), suspect), Inline = false } } } } }; #if RUST if (_config.ShowCombatlog && suspect.Object is BasePlayer) { var events = CombatLog.Get(((BasePlayer)suspect.Object).userID).ToArray(); for (var i = 1; i <= _config.CombatlogEntries && i <= events.Length; i++) { var combat = events[events.Length - i]; Array.Resize(ref body.Embeds, 1 + i); body.Embeds[i] = new EmbedBody { Title = GetMsg("Webhook: Combatlog Title").Replace("{n}", $"{i}"), Type = type, Color = _config.EmbedColor, Fields = new[] { new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Attacker Title"), Value = combat.attacker, Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Target Title"), Value = combat.target, Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Time Title"), Value = (UnityEngine.Time.realtimeSinceStartup - combat.time).ToString("0.0s"), Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Weapon Title"), Value = combat.weapon, Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Ammo Title"), Value = combat.ammo, Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Distance Title"), Value = combat.distance.ToString("0.0m"), Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Old HP Title"), Value = combat.health_old.ToString("0.0"), Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog New HP Title"), Value = combat.health_new.ToString("0.0"), Inline = true }, new EmbedBody.FieldBody { Name = GetMsg("Webhook: Combatlog Info Title"), Value = string.IsNullOrEmpty(combat.info) ? "none" : combat.info, Inline = true } } }; } } #endif webrequest.Enqueue(_config.Webhook, JObject.FromObject(body).ToString(), (code, result) => SetCooldown(reporter), this, RequestMethod.POST, new Dictionary <string, string> { { "Content-Type", "application/json" } }); }
public void Post(int channelId, [FromBody] WebhookBody body) { _logger.LogInformation("Channel {0} received {1} events for {2}", channelId, body.Events.Count, body.Destination); }