Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| guides:apps:discord [2024-01-19 12:51] – created geek | guides:apps:discord [2024-06-06 18:18] (current) – add date geek | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Webhooks ===== | ===== Webhooks ===== | ||
| - | Send a file: https:// | + | <tabbox AutoHoktey v2> |
| + | Send a message: | ||
| + | |||
| + | <code AutoHotkey> | ||
| + | #Requires AutoHotkey v2 | ||
| + | webhookURL := " | ||
| + | http := ComObject(" | ||
| + | http.Open(" | ||
| + | http.SetRequestHeader(" | ||
| + | http.Send(' | ||
| + | </ | ||
| + | |||
| + | Send files/ | ||
| + | <code AutoHotkey> | ||
| + | #Requires AutoHotkey v2.0 | ||
| + | |||
| + | data := CreateFormData(Map( | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | )) | ||
| + | http := ComObject(" | ||
| + | http.Open(" | ||
| + | http.SetRequestHeader(" | ||
| + | http.Send(data.body) | ||
| + | |||
| + | /** | ||
| + | * Creates a COM WinHttpRequest compatible `multipart/ | ||
| + | * supporting | ||
| + | * | ||
| + | * CreateFormData() by tmplinshi, AHK Topic: https:// | ||
| + | * Thanks to Coco: https:// | ||
| + | * Modified version by SKAN, 09/ | ||
| + | * Ported to AHKv2 and modified by G33kDude 06/ | ||
| + | * | ||
| + | * @param {Map} formData The fields to encode in the form body | ||
| + | * | ||
| + | * @return {Object} An object with properties `body` and `contentType` | ||
| + | * | ||
| + | * @example | ||
| + | * data := CreateFormData(Map( | ||
| + | | ||
| + | | ||
| + | | ||
| + | * )) | ||
| + | * http := ComObject(" | ||
| + | * http.Open(" | ||
| + | * http.SetRequestHeader(" | ||
| + | * http.Send(data.body) | ||
| + | */ | ||
| + | CreateFormData(formData) { | ||
| + | boundary := Random(2**60, | ||
| + | for k, v in formData { | ||
| + | if v ~= " | ||
| + | filePath := LTrim(v, " | ||
| + | file := FileOpen(filePath, | ||
| + | AddStr " | ||
| + | . '"; | ||
| + | . " | ||
| + | AddFile(file), | ||
| + | } else { ; Regular text | ||
| + | AddStr " | ||
| + | . '" | ||
| + | } | ||
| + | } | ||
| + | AddStr " | ||
| + | |||
| + | return { | ||
| + | body: SafeArrayFromBuffer(buf), | ||
| + | contentType: | ||
| + | } | ||
| + | |||
| + | AddStr(str) { | ||
| + | oldSize := buf.Size, buf.Size += strSize := StrPut(str, " | ||
| + | StrPut(str, buf.Ptr + oldSize, strSize, " | ||
| + | } | ||
| + | AddFile(file) { | ||
| + | oldSize := buf.Size, buf.Size += file.Length | ||
| + | file.Pos := 0, file.RawRead(buf.ptr + oldSize, file.Length) | ||
| + | } | ||
| + | MimeType(file) => ( | ||
| + | file.Pos := 0, n := file.ReadUInt(), | ||
| + | (n = 0x474E5089) ? " | ||
| + | (n = 0x38464947) ? " | ||
| + | (n & 0xFFFF = 0x4D42 | ||
| + | (n & 0xFFFF = 0xD8FF | ||
| + | (n & 0xFFFF = 0x4949 | ||
| + | (n & 0xFFFF = 0x4D4D | ||
| + | " | ||
| + | ) | ||
| + | SafeArrayFromBuffer(buf) { | ||
| + | arr := ComObjArray(0x11, | ||
| + | DllCall(" | ||
| + | " | ||
| + | " | ||
| + | return arr | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <tabbox AutoHoktey v1> | ||
| + | Send a message: | ||
| + | |||
| + | <code AutoHotkey> | ||
| + | #Requires AutoHotkey v1 | ||
| + | webhookURL := " | ||
| + | http := ComObject(" | ||
| + | http.Open(" | ||
| + | http.SetRequestHeader(" | ||
| + | http.Send(" | ||
| + | </ | ||
| + | |||
| + | Send files/ | ||
| + | </ | ||
| + | |||