Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/26/2021 in all areas

  1. LinkOut

    Telegram Bot UDF

    Hi! I wrote an UDF that can simplify the way you can control Telegram Bot with AutoIt. If you don't know what is a Telegram Bot, maybe you should read their official website here. All about this UDF is on my GitHub: what is, how it work, how to use and also a Test.au3 to see the script in action. But... let's talk about this UDF. What is: It's an UDF that contain functions to control a Telegram Bot. Send messages, photo, video, stickers, wait for incoming messages and answer to them. How it works: Insert you Token given from BotFather, initialize your bot with _InitBot() function and... you're ready! All functions are commented: You will find a description of what it does, an explanation for every argument that function has need and what it return. This is the test script, that initialize your bot, run all functions and write the return value. #include "Telegram UDF.au3" $ChatID = "Your_Chat_ID_For_Test" _InitBot("Bot_ID","Bot_Token") ConsoleWrite("Test _GetUpdates -> " & @TAB & _GetUpdates() & @CRLF) ConsoleWrite("Test _GetMe -> " & @TAB & _GetMe() & @CRLF) ConsoleWrite("Test _SendMsg -> " & @TAB & _SendMsg($ChatID,"Test _SendMsg") & @CRLF) ConsoleWrite("Test _ForwardMsg -> " & @TAB & _ForwardMsg($ChatID,$ChatID,'MsgID') & @CRLF) ConsoleWrite("Test _SendPhoto -> " & @TAB & _SendPhoto($ChatID,"C:\image.jpg","Test _SendPhoto") & @CRLF) ConsoleWrite("Test _SendVideo -> " & @TAB & _SendVideo($ChatID,"C:\video.mp4","Test _SendVideo") & @CRLF) ConsoleWrite("Test _SendAudio -> " & @TAB & _SendAudio($ChatID,"C:\audio.mp3","Test _SendAudio") & @CRLF) ConsoleWrite("Test _SendDocument -> " & @TAB & _SendDocument($ChatID,"C:\document.txt","Test _SendDocument") & @CRLF) ConsoleWrite("Test _SendVoice -> " & @TAB & _SendVoice($ChatID,"C:\voice.ogg","Test _SendVoice") & @CRLF) ConsoleWrite("Test _SendSticker -> " & @TAB & _SendSticker($ChatID,"C:\sticker.webp") & @CRLF) ConsoleWrite("Test _SendLocation -> " & @TAB & _SendLocation($ChatID,"74.808889","-42.275391") & @CRLF) ConsoleWrite("Test _SendContact -> " & @TAB & _SendContact($ChatID,"0123456789","Josh") & @CRLF) ConsoleWrite("Test _SendChatAction -> " & @TAB & _SendChatAction($ChatID,"typing") & @CRLF) ConsoleWrite("Test _GetUserProfilePhotos -> " & @TAB & _GetUserProfilePhotos($ChatID) & @CRLF) ConsoleWrite("Test _GetChat -> " & @TAB & _GetChat($ChatID) & @CRLF) While 1 $msgData = _Polling() _SendMsg($msgData[2],$msgData[3]) WEnd Last part of the script (While cycle) use Polling function to put the script in a wait-state for incoming messages: _Polling() function return an array ($msgData in this case) that contain information about the received message (for example, $msgData[2] is the Chat ID of the user that send the message, important to send a reply. See GitHub page for other info. So, finally, here you can find and download the library -> https://github.com/xLinkOut/telegram-udf-autoit <- UPDATE: Thanks to @mLipok to added my Telegram UDF on AutoItScript Wiki! UPDATE 2: Functions that send files to Telegram Servers (photos, videos..) don't need anymore cURL executable file. Thanks to @Jos that suggested how to use WinHttp UDF by trancexx. If you have question, bug report or anything else just contact me or reply to this Thread Don't forget to follow me on GitHub for future updates. Bye!
    1 point
  2. @samibb 1) This is the UDF development thread. Please post your question to the correct thread in GH&S (see my sig) 2) I gave you the best answer available based upon the very limited information you supplied (Chrome usage). 3) You should provide more details regarding your situation if you want better responses. P.S. You could try adding the following line at the beginning of your script (before calling _WD_Startup) -- _WD_Option('DriverClose', False)
    1 point
  3. yes. ... but you have to show the script and/or tell us what is does before you can get any serious answer.
    1 point
  4. Thanks @pixelsearchfor the quick response I checked it a few more times. All three options work very well. It's hard to say which is better in terms of functionality, but the second variant (with +6 Pxl) looks really better.
    1 point
  5. mikell

    Format strings

    I love the way this topic was marked as solved
    1 point
  6. Hi Norm73, Thanks for the detailed report The issue can be easily fixed with a little modification. I got 2 possibilities for that : * Actual code in "2y" : this is the issue you described, because $iKeep_Left = $tRect.Left only for right-aligned or centered columns (not really good) ; Subitem rectangle for right and center aligned columns If $g_aColAligns[$iCol] Then ; $HDF_LEFT = 0, $HDF_RIGHT = 1, $HDF_CENTER = 2 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 ; Keep left coord of subitem before it's lost $iKeep_Left = $tRect.Left Switch $g_aColAligns[$iCol] Case 1 ; $HDF_RIGHT DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tSize, "X" ) - 6 ) Case 2 ; $HDF_CENTER DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tRect, "Left" ) - DllStructGetData( $tSize, "X" ) ) / 2 - 3 ) EndSwitch EndIf 1) 1st possible way to fix this : $iKeep_Left no more in the "If $g_aColAligns" test, so it will have a correct value even for left-aligned columns, as soon as you move the line $iKeep_Left = $tRect.Left before the "If $g_aColAligns" test ; Keep left coord of subitem before it's lost $iKeep_Left = $tRect.Left ; Subitem rectangle for right and center aligned columns If $g_aColAligns[$iCol] Then ; $HDF_LEFT = 0, $HDF_RIGHT = 1, $HDF_CENTER = 2 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 Switch $g_aColAligns[$iCol] Case 1 ; $HDF_RIGHT DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tSize, "X" ) - 6 ) Case 2 ; $HDF_CENTER DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tRect, "Left" ) - DllStructGetData( $tSize, "X" ) ) / 2 - 3 ) EndSwitch EndIf 2) 2nd possible way : Case 0 has been added ($HDF_LEFT) and the If $g_aColAligns" test is commented, then the +6 (pixels) found in Case 0 brings some space at the beginning of the left-aligned column, it seems enjoyable to bring a little distance between columns. ; Subitem rectangle for right and center aligned columns ;~ If $g_aColAligns[$iCol] Then ; $HDF_LEFT = 0, $HDF_RIGHT = 1, $HDF_CENTER = 2 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 ; Keep left coord of subitem before it's lost $iKeep_Left = $tRect.Left Switch $g_aColAligns[$iCol] Case 0 ; $HDF_LEFT DllStructSetData( $tRect, "Left", $tRect.Left + 6) Case 1 ; $HDF_RIGHT DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tSize, "X" ) - 6 ) Case 2 ; $HDF_CENTER DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tRect, "Left" ) - DllStructGetData( $tSize, "X" ) ) / 2 - 3 ) EndSwitch ;~ EndIf 3) But as the message GetTextExtentPoint32W seems superfluous at this stage for left-aligned columns (in 2), then what follows seems better : ; Keep left coord of subitem before it's lost $iKeep_Left = $tRect.Left If $g_aColAligns[$iCol] Then ; $HDF_RIGHT = 1, $HDF_CENTER = 2 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 Switch $g_aColAligns[$iCol] Case 1 ; $HDF_RIGHT DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tSize, "X" ) - 6 ) Case 2 ; $HDF_CENTER DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tRect, "Left" ) - DllStructGetData( $tSize, "X" ) ) / 2 - 3 ) EndSwitch Else ; $HDF_LEFT = 0 DllStructSetData( $tRect, "Left", $tRect.Left + 6) ; if left-aligned column, add some space between columns EndIf Please try any possibility and tell us which one suits you best, ok ? Thanks
    1 point
  7. Using StringReplace() is fine to blanket convert all commas. In case there are any commas in the string that don't need converting, here is a conditional converting method. Local $sOrigString = 'When a comma is between digits, replace with a point e.g. StringReplace("1,62918,", ",", ".")' Local $sString = StringRegExpReplace($sOrigString, "(?<=\d),(?=\d)", ".") Local $iReplacements = @extended MsgBox(4096, "", $iReplacements & " replacement" & _ ; $MB_SYSTEMMODAL is 4096 ($iReplacements = 1 ? " was" : "s were") & _ ; Allow for plural or singular grammatically. " made and the new string is:" & _ @CRLF & @CRLF & $sString) ; The RE Pattern:- ; "(?<=\d)," - (Lookbehind assertions) Match an occurrence of a comma, ",", that is preceded by a digit, "\d", but does not include the digit in the match; and, ; ",(?=\d)" - (Lookahead assertions) Matches a comma followed by a digit, "\d", but does not include the digit in the match. ; So, to match a particular comma to convert, there must be a digit on either side of the comma. ; Returns :- ; 1 replacement was made and the new string is: ; ; When a comma is between digits, replace with a point e.g. StringReplace("1.62918,", ",", ".") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ : Replacement : Comma converted to point.
    1 point
  8. Flag 8 creates the folder path, you need to be combine it with either: Append text to file Overwrite existing file This could also be a result of not having rights to create the folder, in which case you could add #RequireAdmin to the top of your script, here is a basic example which works for me: ;~ Place some text into clipboard ClipPut("Clipboard example text") ;~ Path to file Local $sFileName = @ScriptDir & "\Documents\test123.txt" ;~ Create folder path + open in write mode, appending to file Local $hFileName = FileOpen($sFileName, 9) ;~ Write clipboard to the file FileWrite($hFileName, ClipGet() & @CRLF) FileClose($hFileName) ;~ Open the file in your preferred text editor. ShellExecute($sFileName)
    1 point
  9. Dan_555

    Dan's misc. Scripts

    Hi, this is my version of the Peg Solitaire Game in Autoit It was inspired by the http://www.mathematische-basteleien.de/solitaire.htm game (which is, by the look, almost identical). It has the Standard Board and additionally 14 different Board setups. The Game starts with randomly selected challenge. It has an Undo and Edit functions. ;This game was inspired by the http://www.mathematische-basteleien.de/solitaire.htm #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> Global $Appname = "Peg Solitaire", $Appname01 = $Appname $Form1 = GUICreate($Appname, 510, 416, 255, 271) $Group1 = GUICtrlCreateGroup("Presets", 383, 2, 124, 413) Dim $Button[14] Dim $GameType[17][2] $GameType[00][0] = "" $GameType[01][0] = "Standard" $GameType[02][0] = "Pyramid 16" $GameType[03][0] = "Pyramid 9" $GameType[04][0] = "Mirror" $GameType[05][0] = "Greek Cross" $GameType[06][0] = "Latin Cross" $GameType[07][0] = "Ship" $GameType[08][0] = "Submarine" $GameType[09][0] = "Y-Pentomino" $GameType[10][0] = "T-Pentomino" $GameType[11][0] = "V-Pentomino" $GameType[12][0] = "P-Pentomino" $GameType[13][0] = "L-Pentomino" $GameType[14][0] = "O-Pentomino" $GameType[15][0] = "Pasted Level" $GameType[00][1] = "000000000000000000000000000000000" $GameType[01][1] = "111111111111111101111111111111111" $GameType[02][1] = "000010001110001111101111111000000" $GameType[03][1] = "000010001110001111100000000000000" $GameType[04][1] = "000000001110000111000011100010000" $GameType[05][1] = "000010000100001111100001000010000" $GameType[06][1] = "000000000100000111000001000010000" $GameType[07][1] = "000000001100001111000000000000000" $GameType[08][1] = "000000000100001111100000000000000" $GameType[09][1] = "000000000100000011000000100001000" $GameType[10][1] = "000000000000000111000001000010000" $GameType[11][1] = "000000000000000011100001000010000" $GameType[12][1] = "000000000110000011000001000000000" $GameType[13][1] = "000000000100000010000001100000000" $GameType[14][1] = "000000000000000011000001100000000" $GameType[15][1] = "000000000000000000000000000000000" $Button[00] = GUICtrlCreateButton("Standard", 391, 25, 108, 22) For $x = 1 To 13 $Button[$x] = GUICtrlCreateButton($GameType[$x + 1][0], 391, 50 + (26 * $x), 108, 22) Next GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Edit", 4, 2, 132, 44) $B_Edit = GUICtrlCreateButton("Off", 6, 15, 32, 22) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetTip(-1, "On : Edit levels (Click to toggle)" & @CRLF & "Off: Play the Game" & @CRLF & "Resets the Undo !") $B_Cls = GUICtrlCreateButton("Cls", 38, 15, 32, 22) $B_UsePasted = GUICtrlCreateButton("Use Pasted", 70, 15, 64, 22) GUICtrlSetTip(-1, "Play the Game from the 'Level Data' input box.") GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateLabel("Level Data:", 18, 50, 55, 20) $i_Numbers = GUICtrlCreateInput("", 75, 48, 210, 20, $ES_Number) GUICtrlSetLimit($i_Numbers, 33) $Label1 = GUICtrlCreateLabel("Peg Solitaire", 138, 0, 245, 45) GUICtrlSetFont(-1, 30, 800, 0, "Arial") $Group3 = GUICtrlCreateGroup("Game", 3, 65, 377, 350) GUICtrlCreateGroup("", -99, -99, 1, 1) $b_Undo = GUICtrlCreateButton("Undo", 339, 49, 41, 19) Local $x, $y, $ox = -1, $oy = -1, $cx, $cy Local $edit = -1 GUICtrlSetState($B_Cls, $GUI_DISABLE) Dim $GameField[8][8] Dim $UndoBuffer[200] $UndoBuffer[0] = 0 For $y = 1 To 7 For $x = 1 To 7 If $y = 1 Or $y = 2 Or $y = 6 Or $y = 7 Then $tmptxt = " " If $x >= 3 And $x <= 5 Then $GameField[$x][$y] = GUICtrlCreateButton($tmptxt, (-30) + ($x * 48), 26 + ($y * 48), 48, 48) GUICtrlSetFont(-1, 30, 800, 0, "Arial") Else $GameField[$x][$y] = -1 EndIf Else $GameField[$x][$y] = GUICtrlCreateButton($tmptxt, (-30) + ($x * 48), 26 + ($y * 48), 48, 48) GUICtrlSetFont(-1, 30, 800, 0, "Arial") EndIf Next Next BoardSetup(Random(1, 14)) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $b_Undo if $ox > -1 Then ChangeSquare($ox, $oy, "o") $ox=-1 $oy=-1 EndIf Undo() WinSetTitle($Form1, "", $Appname01) Case $B_UsePasted $tmptxt = GUICtrlRead($i_Numbers) $GameType[15][1] = $tmptxt BoardSetup(15) Case $B_Cls $ox = -1 $oy = -1 BoardSetup() Case $B_Edit $edit = -$edit If $ox > -1 Then ChangeSquare($ox, $oy, "o") $ox = -1 $oy = -1 EndIf OnOff(($edit < 0) ? 0 : 1) $Appname01 = $Appname & " - Playing: Edited board." WinSetTitle($Form1, "", $Appname01) $UndoBuffer[0] = 0 Case Else If $nMsg > 0 Then ;Check Game type Buttons: For $x = 0 To 13 If $nMsg = $Button[$x] Then BoardSetup($x + 1) $ox = -1 $oy = -1 $UndoBuffer[0] = 0 EndIf Next ;Check Board buttons: For $btny = 1 To 7 For $btnx = 1 To 7 If $nMsg = $GameField[$btnx][$btny] Then $tmp = GUICtrlRead($GameField[$btnx][$btny]) If $edit = -1 Then ;Game play code: If $tmp = " " Then If Jump($btnx, $btny, $ox, $oy) = 1 Then ;Successful jump $ox = -1 $oy = -1 EndIf $tmptxt = GetBoard() GUICtrlSetData($i_Numbers, $tmptxt) If StringFind($tmptxt, "1") = 1 Then WinSetTitle($Form1, "", $Appname & " : *** Well Done ***") ElseIf $tmp == "o" Then If $ox = -1 Then $ox = $btnx $oy = $btny ChangeSquare($ox, $oy, "O") Else ChangeSquare($ox, $oy, "o") $ox = $btnx $oy = $btny ChangeSquare($ox, $oy, "O") EndIf EndIf Else ;Edit board: If $tmp = " " Then ChangeSquare($btnx, $btny, "o") ElseIf $tmp = "o" Then ChangeSquare($btnx, $btny, " ") EndIf $tmptxt = GetBoard() GUICtrlSetData($i_Numbers, $tmptxt) WinSetTitle($Form1, "", $Appname01) EndIf EndIf Next Next EndIf EndSwitch WEnd Func UndoAdd() If $UndoBuffer[0] < 998 Then $UndoBuffer[0] = $UndoBuffer[0] + 1 $tmptxt = GetBoard() $UndoBuffer[$UndoBuffer[0]] = $tmptxt EndIf EndFunc ;==>UndoAdd Func Undo() If $UndoBuffer[0] >= 1 Then $tmptxt = $UndoBuffer[$UndoBuffer[0]] $UndoBuffer[0] = $UndoBuffer[0] - 1 $GameType[16][1] = $tmptxt BoardSetup(16) EndIf EndFunc ;==>Undo Func StringFind($txt, $s) Local $nr = 0 For $x = 1 To StringLen($txt) If StringMid($txt, $x, 1) == $s Then $nr = $nr + 1 Next Return $nr EndFunc ;==>StringFind Func OnOff($x) Local $tmp = "on" If $x = 0 Then $tmp = "off" GUICtrlSetState($B_Cls, $GUI_DISABLE) Else GUICtrlSetState($B_Cls, $GUI_ENABLE) EndIf GUICtrlSetData($B_Edit, $tmp) EndFunc ;==>OnOff Func Jump($x, $y, $ox, $oy) Local $tmpx = Abs($ox - $x) Local $tmpy = Abs($oy - $y) Local $dir = 0 If $tmpx = 0 And $tmpy = 2 Then $dir = ($oy - $y) > 0 ? $y + 1 : $y - 1 If GUICtrlRead($GameField[$x][$dir]) == "o" Then UndoAdd() ChangeSquare($x, $y, "o") ChangeSquare($x, $dir, " ") ChangeSquare($ox, $oy, " ") Return 1 EndIf ElseIf $tmpy = 0 And $tmpx = 2 Then $dir = ($ox - $x) > 0 ? $x + 1 : $x - 1 If GUICtrlRead($GameField[$dir][$y]) == "o" Then UndoAdd() ChangeSquare($x, $y, "o") ChangeSquare($dir, $y, " ") ChangeSquare($ox, $oy, " ") Return 1 EndIf EndIf Return 0 EndFunc ;==>Jump Func ChangeSquare($x, $y, $txt) GUICtrlSetData($GameField[$x][$y], $txt) EndFunc ;==>ChangeSquare Func BoardSetup($a = 0) Local $w = 0, $x, $y, $z Local $tmptxt = "", $tmptxt1 = "" If $a < 16 Then $Appname01 = $Appname & " - Playing: " & $GameType[$a][0] WinSetTitle($Form1, "", $Appname01) $UndoBuffer[0] = 0 EndIf For $y = 1 To 7 For $x = 1 To 7 $z = 0 $tmptxt = " " If $y = 1 Or $y = 2 Or $y = 6 Or $y = 7 Then If $x >= 3 And $x <= 5 Then $z = 1 Else $z = 1 EndIf If $z = 1 Then $w = $w + 1 $tmptxt1 = StringMid($GameType[$a][1], $w, 1) $tmptxt = ($tmptxt1 = "1") ? "o" : " " ChangeSquare($x, $y, $tmptxt) EndIf Next Next GUICtrlSetData($i_Numbers, GetBoard()) EndFunc ;==>BoardSetup Func GetBoard() Local $tmptxt = "" For $y = 1 To 7 For $x = 1 To 7 $z = 0 If $y = 1 Or $y = 2 Or $y = 6 Or $y = 7 Then If $x >= 3 And $x <= 5 Then $z = 1 Else $z = 1 EndIf If $z = 1 Then $tmptxt = $tmptxt & _Txt2num(GUICtrlRead($GameField[$x][$y])) EndIf Next Next Return $tmptxt EndFunc ;==>GetBoard Func _Txt2num($txt) If $txt = " " Then Return "0" If $txt = "o" Then Return "1" EndFunc ;==>_Txt2num Func CW($txt, $crlf = 1) Local $nl = "" If $crlf = 1 Then $nl = @CRLF ConsoleWrite($txt & $nl) EndFunc ;==>CW Have Fun !
    1 point
  10. Jos

    Telegram Bot UDF

    Try this version: $msreply= "Wellcome To 'Zoo World'.%0AYou can control by sending these commands: ......" _SendMsg($msgData[2],$msreply ) Jos
    1 point
  11. mLipok

    Telegram Bot UDF

    Added to UDF List on AutoIt WikiPage, here: https://www.autoitscript.com/wiki/User_Defined_Functions#Social_Media_and_other_Website_API
    1 point
×
×
  • Create New...