recca062

Untitled

Sep 10th, 2021
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #SingleInstance
  6. #Persistent
  7. #Include ImagePut.ahk
  8.  
  9. webhook := "https://discord.com/api/yourwebhook"
  10. F1::
  11. Send {PrintScreen}
  12. InputBox, caption, Caption, Caption for this image,,180, 130
  13. if (ErrorLevel = 0)
  14. {
  15.     Sleep 300
  16.     send2Disc(caption, webhook)
  17. }
  18.  
  19. return
  20. F5::ExitApp
  21. ;   SEND IMG TO DISC VIA WEBHOOK
  22. ; CreateFormData() by tmplinshi, AHK Topic: https://autohotkey.com/boards/viewtopic.php?t=7647
  23. ; Thanks to Coco: https://autohotkey.com/boards/viewtopic.php?p=41731#p41731
  24. ; Modified version by SKAN, 09/May/2016
  25. send2Disc(caption, webhook) {
  26.     ;   Wait for clipboard
  27.     while !DllCall("IsClipboardFormatAvailable", "Uint", 2)
  28.         Sleep 500
  29.     ;   Convert clipboard into base64 img string
  30.     screenshot64 := ImagePutBase64(Clipboard, "png")
  31.     ;   Save file
  32.     ImagePutFile(screenshot64, "full.png")
  33.     ;   Wait for file to be save
  34.     Loop
  35.         IfNotExist, full.png
  36.             Sleep 500
  37.         else
  38.             break
  39.     ;   Upload to discord
  40.     objParam := {file: ["full.png"], content: caption}
  41.     CreateFormData(PostData, hdr_ContentType, objParam)
  42.  
  43.     HTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
  44.     HTTP.Open("POST", webhook, true)
  45.     HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
  46.     HTTP.SetRequestHeader("Content-Type", hdr_ContentType)
  47.     HTTP.SetRequestHeader("Pragma", "no-cache")
  48.     HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
  49.     HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
  50.     HTTP.Send(PostData)
  51.     HTTP.WaitForResponse()
  52.     ;ToolTip, % HTTP.ResponseText
  53.     FileDelete, full.png
  54. }
  55. CreateFormData(ByRef retData, ByRef retHeader, objParam) {
  56.     New CreateFormData(retData, retHeader, objParam)
  57. }
  58. Class CreateFormData {
  59.  
  60.     __New(ByRef retData, ByRef retHeader, objParam) {
  61.  
  62.         Local CRLF := "`r`n", i, k, v, str, pvData
  63.         ; Create a random Boundary
  64.         Local Boundary := this.RandomBoundary()
  65.         Local BoundaryLine := "------------------------------" . Boundary
  66.  
  67.     this.Len := 0 ; GMEM_ZEROINIT|GMEM_FIXED = 0x40
  68.     this.Ptr := DllCall( "GlobalAlloc", "UInt",0x40, "UInt",1, "Ptr"  )          ; allocate global memory
  69.  
  70.         ; Loop input paramters
  71.         For k, v in objParam
  72.         {
  73.             If IsObject(v) {
  74.                 For i, FileName in v
  75.                 {
  76.                     str := BoundaryLine . CRLF
  77.                          . "Content-Disposition: form-data; name=""" . k . """; filename=""" . FileName . """" . CRLF
  78.                          . "Content-Type: " . this.MimeType(FileName) . CRLF . CRLF
  79.           this.StrPutUTF8( str )
  80.           this.LoadFromFile( Filename )
  81.           this.StrPutUTF8( CRLF )
  82.                 }
  83.             } Else {
  84.                 str := BoundaryLine . CRLF
  85.                      . "Content-Disposition: form-data; name=""" . k """" . CRLF . CRLF
  86.                      . v . CRLF
  87.         this.StrPutUTF8( str )
  88.             }
  89.         }
  90.  
  91.         this.StrPutUTF8( BoundaryLine . "--" . CRLF )
  92.  
  93.     ; Create a bytearray and copy data in to it.
  94.     retData := ComObjArray( 0x11, this.Len ) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
  95.     pvData  := NumGet( ComObjValue( retData ) + 8 + A_PtrSize )
  96.     DllCall( "RtlMoveMemory", "Ptr",pvData, "Ptr",this.Ptr, "Ptr",this.Len )
  97.  
  98.     this.Ptr := DllCall( "GlobalFree", "Ptr",this.Ptr, "Ptr" )                   ; free global memory
  99.  
  100.     retHeader := "multipart/form-data; boundary=----------------------------" . Boundary
  101.     }
  102.  
  103.   StrPutUTF8( str ) {
  104.     Local ReqSz := StrPut( str, "utf-8" ) - 1
  105.     this.Len += ReqSz                                  ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
  106.     this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len + 1, "UInt", 0x42 )  
  107.     StrPut( str, this.Ptr + this.len - ReqSz, ReqSz, "utf-8" )
  108.   }
  109.  
  110.   LoadFromFile( Filename ) {
  111.     Local objFile := FileOpen( FileName, "r" )
  112.     this.Len += objFile.Length                     ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
  113.     this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len, "UInt", 0x42 )
  114.     objFile.RawRead( this.Ptr + this.Len - objFile.length, objFile.length )
  115.     objFile.Close()      
  116.   }
  117.  
  118.     RandomBoundary() {
  119.         str := "0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z"
  120.         Sort, str, D| Random
  121.         str := StrReplace(str, "|")
  122.         Return SubStr(str, 1, 12)
  123.     }
  124.  
  125.     MimeType(FileName) {
  126.         n := FileOpen(FileName, "r").ReadUInt()
  127.         Return (n        = 0x474E5089) ? "image/png"
  128.              : (n        = 0x38464947) ? "image/gif"
  129.              : (n&0xFFFF = 0x4D42    ) ? "image/bmp"
  130.              : (n&0xFFFF = 0xD8FF    ) ? "image/jpeg"
  131.              : (n&0xFFFF = 0x4949    ) ? "image/tiff"
  132.              : (n&0xFFFF = 0x4D4D    ) ? "image/tiff"
  133.              : "application/octet-stream"
  134.     }
  135.  
  136. }
Add Comment
Please, Sign In to add comment