Newb Posted April 9 Share Posted April 9 (edited) As I asked a few months ago, but never got a response, i will try again in case someone had an idea this time: Hello, I was trying to use autoit to interact with telegram desktop because I need to automate file uploading, expecially for folders with a lot of files. I saw there are various UDF libs for Telegram already (to my pleasure, I must say), but looks like they're for direct interaction with telegram API, so kinda to use them with a bot. Unfortunately bot file management is severely limited in size of files (20mb compared to 4gb on premium normal user) and other aspects. Therefore my last choice was to automate in some way telegram desktop in a way that directly interacts with the window (WinGetHandle, WinExists, etc etc.). Unfortunately, probably due to the fact that as I understood telegram is packed with electron, and electron AFAIK just displays a webapp into an exe,, trying to use Window Info tool doesn't give any result beside a main window, which has the current chat name and a random number. The only way to grab it is by classname like this: Func Window_Telegram_GetHandle() Return WinGetHandle("[CLASS:" & $WindowClass_Telegram & "]") EndFunc Func Window_Telegram_GetHandle() Return WinGetHandle("[CLASS:" & $WindowClass_Telegram & "]") EndFunc But I'm unable to catch any other button/UI element info with the telegram application. They all give the same handle info of the main page. I tried to disable/enable Spy++ detection logic but nothing changed. This leaves me to 3 roads: 1) Maybe there is another way to detect the handles and I don't know? 2) Trying some injector (https://github.com/itsKaynine/electron-injector for example) to inject html/js directly and interact with it 3) Download telegram desktop source code and do it by yself but I think it will take too much time. Anyone has suggestions/help? Additional considerations: The only way i can actually think of working with this right now, with autoit, unless someone has a better idea, is to sandbox the whole thing to have a fixed resolution, then work heavily with PixelChecksums and pixel detection methods Is there any other particular reason on how we can work through autoit detecting controls in it? I'm interested in digging the matter For the records, I see they use "Qt widgets" for the UI, and I see someone else digged into the matter Edited April 9 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 9 Moderators Share Posted April 9 I remember when QT widgets came out... those ... lol I have no clue if it'd work, but The first 3 words are "Automate all windows" ... maybe... could be? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Newb Posted April 9 Author Share Posted April 9 (edited) 6 minutes ago, SmOke_N said: I remember when QT widgets came out... those ... lol I have no clue if it'd work, but The first 3 words are "Automate all windows" ... maybe... could be? Oh well.... that post looks... dense. Lot of infos there. I will check it in the morning. I already tought to use the AutoIT browser automation libs with chrome or FF with webdriver udfs or such, but the whole "just make a windows GUI and click buttons on the desktop app was much more straightforward and just took like 150 lines of code to do a good part of the automation I needed ahahahah, I guess I'm lazy that's why I automate with less code possible, Thanks for the help I will let you know Edited April 9 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Newb Posted April 9 Author Share Posted April 9 (edited) 5 hours ago, SmOke_N said: I remember when QT widgets came out... those ... lol I have no clue if it'd work, but The first 3 words are "Automate all windows" ... maybe... could be? So, I took a look at the guy's work. It's a bit of a hot mess described in broken english actually. I work as a senior dev so I'm familiar with the concepts he marks as prerequisites (unit testing, testing frameworks and so on). Basically he build a Windows UI automation wrapper for autoit. The whole thing is quite confiusing expecially in the part of having "logic names" (I found difficult to even do some notepad automation with his examples in front of me) for controls detected and looks like a whole overhead effort to click a few buttons. Moreover, I tried his "simplespy" tool on telegram desktop and doesn't seems, at least at first sight, to do a much better work than Au3Info. It's kinda of a bet trying to learn how to actually use this and getting nowhere with the final goal I have, when a bit of old pixel color and pixel checksum work could get the job done. Guy seems a genuine high level technical person but this thing he did just rubs me in the wrong way. As a dev it gives the feeling that learning this will give me far more trouble than benefits. Thanks anyway Edited April 9 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 9 Developers Share Posted April 9 Maybe this could work for you using docker? https://github.com/Nekmo/telegram-upload SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 9 Share Posted April 9 Interesting and understanding opinion and assessment, I like that @Newb 👍 . Do you have to stick to AutoIt to automated the Electron App? As you described yourself as a Dev I don't think so. Please have a look at the google search results for "test automation electron app". This will lead you to several approaches, including GitHub boilerplate template repositories for a quick start 😀 . Otherwise thanks for the interesting topic and discussion so far 🤝 . Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
Newb Posted April 9 Author Share Posted April 9 (edited) 6 hours ago, Jos said: Maybe this could work for you using docker? https://github.com/Nekmo/telegram-upload Ok, I forgot to mention, but I have already evaluated these kind of solutions and I don't like them simply because they're in that kind of grey area of their TOS that could get your account banned. Since I uploaded literally terabytes of stuff and my account is like 10 years old, I don't feel like risking. They boast unlimited cloud storage and actively encourage you to use telegram as such and it worked quite weil for that purpose (beside being a wonderful messaging app that all my friends have) without never having a trouble with the telegram community/staff. To be honest, they seem like pretty random in taking actions against who uses these kind of bot stuff, but I don't want to lose my account. Whatever automates a real number profile (profile that should belong to a user and be used manually and instead you're using the telegram API to make it what they call a "userbot") gets a bit too much attention from them. They don't care instead, if actions looks like are taken from a user (so autoit clicking the UI is a good thing because it simulates a user behind the screen) That's why I didn't use any of these solutions. 6 hours ago, SOLVE-SMART said: Interesting and understanding opinion and assessment, I like that @Newb 👍 . Do you have to stick to AutoIt to automated the Electron App? As you described yourself as a Dev I don't think so. Please have a look at the google search results for "test automation electron app". This will lead you to several approaches, including GitHub boilerplate template repositories for a quick start 😀 . Otherwise thanks for the interesting topic and discussion so far 🤝 . Best regards Sven Hello, No, telegram isn't actually a necessity. It was more because in the years I automated a number of things with it and I was more aquainted to it than any other solution. I will try to get a look in automating electron apps just for the sake of knowledge, because, still, proceeding with autoit and writing just a few stupid pixel checking functions seems a much quicker way to proceed than setting up a whole electron testing battery. Thanks for the clue though. I will let you know if I get any advance with electron testing What actually bothers me more is that there isn't a clear way to get handles on these kind of controls because they're wrapped into an electron app, which is kinda bad. On the other side, telegram has, like whatsapp a web version of the app. I clearly remember automating various websites through the IE.au3, embedding the browser directly into the Autoit application and automating stuff in there. Of course IE is not an option anymore, but I guess other libs for chrome and FF came out (I saw some chrome webdriver libs for autoit here in the forum) could be a valid solution too, with a much more predictable control detection Edited April 9 by Newb SOLVE-SMART 1 I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 9 Share Posted April 9 Fair enough @Newb . If you really want to start with the WebDriver in AutoIt, use these references to get in touch with that topic: GitHub project "au3WebDriver" (by Danp2) FAQ section in the WebDriver wiki wd_demo.au3 to see several usage examples --------------- I also want to suggest the following: Please check out my repository au3webdriver-boilerplate* which should help you starting your webdriver actions. In case you're familiar with GitHub, just clone the repo and go ahead (by reading the README.md file, using branches and so on). Otherwise download the release (zip), and start there (also by reading the README.md file). Please let me know if this is helpful in any way or even if not, what can I improve 🤝 . Best regards Sven * Advantages: All dependencies included; setup only few settings and start the browser automation; predefined wrapper functions in webdriver-actions-handler.au3 Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
Danyfirex Posted April 9 Share Posted April 9 I think you can handle easily with this. Its a python library. if you need to mix with AutoIt probably compile it and pass parameters with command line will work. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 9 Share Posted April 9 Jos has already suggested this repository @Danyfirex few posts above. Newb wrote that he don't want to use it. But I am on your page => this python repository looks really promising 👍 . Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
junkew Posted April 9 Share Posted April 9 The uiwrappers logic is indeed a wrapper around MS UI automation with some concepts that can be done by just plain coding but if integrated in a more mature testing framework all kinds of abstraction layers can make life much easier certainly during maintenance Unfortunately never took the time to fix issues in the wrapper functions. But if simplespy is not highlighting controls then most likely you need commercial tools to do the automation stuff or fallback to bitblt and other pixel functions combined with mousemove and mouseclick. Maybe search findbmp function in examples section can help a little. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Danyfirex Posted April 10 Share Posted April 10 Hello again. I did this for uploading files to my own chat in Telegram (Portable Version and Installed Version) expandcollapse popup#include <WinAPIProc.au3> #include <File.au3> #include <WinAPIShellEx.au3> _Test_TelegramPortable() _Test_TelegramInstalled() Func _Test_TelegramPortable() Local $sFolderWithMyFilesToUpload = @DesktopDir & "\FilesToUpload" Local $sChatNameToSearch = "Saved Messages" ;get telegam portable window handle Local $aWindows = WinList("[CLASS:Qt51513QWindowIcon]") Local $hWinTelegram = 0 For $i = 1 To $aWindows[0][0] If (Not StringRegExp($aWindows[$i][0], "Media viewer|TelegamDesktop")) And _WinAPI_GetProcessName(WinGetProcess($aWindows[1][1])) = "Telegram.exe" Then $hWinTelegram = $aWindows[$i][1] ExitLoop EndIf Next WinActivate($hWinTelegram) Send("{ESC}") Sleep(200) Send("{ESC}") Sleep(200) Send("{ESC}") Send("{ESC 5}") ;this will let me go back from any chat and get Search chat selected Send("{BS 15}") Send($sChatNameToSearch) Send("{ENTER}") Local $aList = _FileListToArray($sFolderWithMyFilesToUpload, '*.*', 1) If IsArray($aList) Then _WinAPI_ShellOpenFolderAndSelectItems($sFolderWithMyFilesToUpload, $aList, 1) Sleep(100) Send("^c") Sleep(100) WinActivate($hWinTelegram) Sleep(100) Send("^v") Sleep(1000) Send("This are my file from the folder " & BinaryToString("0xF09F93A2",4)) Sleep(100) Send("{ENTER}") EndIf EndFunc ;==>_Test_TelegramPortable Func _Test_TelegramInstalled() Local $sFolderWithMyFilesToUpload = @DesktopDir & "\FilesToUpload" ShellExecute(@UserProfileDir & "\AppData\Local\Programs\Telegram A\Telegram A.exe", "tg://resolve?domain=Danyfirex") ;Saved Messages use own username Local $hWinTelegram=WinWaitActive("Saved Messages · Telegram A") ;when open my own chat Its Saved Messages Local $aList = _FileListToArray($sFolderWithMyFilesToUpload, '*.*', 1) If IsArray($aList) Then _WinAPI_ShellOpenFolderAndSelectItems($sFolderWithMyFilesToUpload, $aList, 1) Sleep(100) Send("^c") Sleep(100) WinActivate($hWinTelegram) Sleep(100) Send("^v") Sleep(1000) Send("This are my file from the folder " & BinaryToString("0xF09F93A2",4)) Sleep(100) Send("{ENTER}") EndIf EndFunc ;==>_Test_TelegramInstalled Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Newb Posted April 11 Author Share Posted April 11 On 4/9/2024 at 9:51 PM, SOLVE-SMART said: Fair enough @Newb . If you really want to start with the WebDriver in AutoIt, use these references to get in touch with that topic: GitHub project "au3WebDriver" (by Danp2) FAQ section in the WebDriver wiki wd_demo.au3 to see several usage examples --------------- I also want to suggest the following: Please check out my repository au3webdriver-boilerplate* which should help you starting your webdriver actions. In case you're familiar with GitHub, just clone the repo and go ahead (by reading the README.md file, using branches and so on). Otherwise download the release (zip), and start there (also by reading the README.md file). Please let me know if this is helpful in any way or even if not, what can I improve 🤝 . Best regards Sven * Advantages: All dependencies included; setup only few settings and start the browser automation; predefined wrapper functions in webdriver-actions-handler.au3 Thanks a lot, but for now just going with the old MouseClick is working far better and it's far faster and easier. The final idea is to make a program with configurable actions and the coords of the controls stored in a config so that it can adapt to other resolutions. On 4/10/2024 at 12:12 AM, junkew said: The uiwrappers logic is indeed a wrapper around MS UI automation with some concepts that can be done by just plain coding but if integrated in a more mature testing framework all kinds of abstraction layers can make life much easier certainly during maintenance Unfortunately never took the time to fix issues in the wrapper functions. But if simplespy is not highlighting controls then most likely you need commercial tools to do the automation stuff or fallback to bitblt and other pixel functions combined with mousemove and mouseclick. Maybe search findbmp function in examples section can help a little. Too clunky and works poor. Not considering this solution anytime soon for any application. Sorry 19 hours ago, Danyfirex said: Hello again. I did this for uploading files to my own chat in Telegram (Portable Version and Installed Version) expandcollapse popup#include <WinAPIProc.au3> #include <File.au3> #include <WinAPIShellEx.au3> _Test_TelegramPortable() _Test_TelegramInstalled() Func _Test_TelegramPortable() Local $sFolderWithMyFilesToUpload = @DesktopDir & "\FilesToUpload" Local $sChatNameToSearch = "Saved Messages" ;get telegam portable window handle Local $aWindows = WinList("[CLASS:Qt51513QWindowIcon]") Local $hWinTelegram = 0 For $i = 1 To $aWindows[0][0] If (Not StringRegExp($aWindows[$i][0], "Media viewer|TelegamDesktop")) And _WinAPI_GetProcessName(WinGetProcess($aWindows[1][1])) = "Telegram.exe" Then $hWinTelegram = $aWindows[$i][1] ExitLoop EndIf Next WinActivate($hWinTelegram) Send("{ESC}") Sleep(200) Send("{ESC}") Sleep(200) Send("{ESC}") Send("{ESC 5}") ;this will let me go back from any chat and get Search chat selected Send("{BS 15}") Send($sChatNameToSearch) Send("{ENTER}") Local $aList = _FileListToArray($sFolderWithMyFilesToUpload, '*.*', 1) If IsArray($aList) Then _WinAPI_ShellOpenFolderAndSelectItems($sFolderWithMyFilesToUpload, $aList, 1) Sleep(100) Send("^c") Sleep(100) WinActivate($hWinTelegram) Sleep(100) Send("^v") Sleep(1000) Send("This are my file from the folder " & BinaryToString("0xF09F93A2",4)) Sleep(100) Send("{ENTER}") EndIf EndFunc ;==>_Test_TelegramPortable Func _Test_TelegramInstalled() Local $sFolderWithMyFilesToUpload = @DesktopDir & "\FilesToUpload" ShellExecute(@UserProfileDir & "\AppData\Local\Programs\Telegram A\Telegram A.exe", "tg://resolve?domain=Danyfirex") ;Saved Messages use own username Local $hWinTelegram=WinWaitActive("Saved Messages · Telegram A") ;when open my own chat Its Saved Messages Local $aList = _FileListToArray($sFolderWithMyFilesToUpload, '*.*', 1) If IsArray($aList) Then _WinAPI_ShellOpenFolderAndSelectItems($sFolderWithMyFilesToUpload, $aList, 1) Sleep(100) Send("^c") Sleep(100) WinActivate($hWinTelegram) Sleep(100) Send("^v") Sleep(1000) Send("This are my file from the folder " & BinaryToString("0xF09F93A2",4)) Sleep(100) Send("{ENTER}") EndIf EndFunc ;==>_Test_TelegramInstalled Saludos Hello, your solution is basically what I am already doing: controlling the UI with the classic mouse/keyboard controls that autoit gives. Thanks for the hint, the problem is I need a far more complex solution that create groups and organizes files with complex naming and like a catalogue. I ended up writing my own solution with the old method of controlling mouse and keyboard with autoit and a few of UI checks here and there: I need to manage trees of deep folders and carefully categorize them so I had to work on a fully complex solution that recognizes and categorize media carefully, often listing files or providing meaningful descriptions and other stuff. Lot of them are courses I bought and that I watch when I'm travelling or gym courses that I use to do follow-along workouts or courses that I watch when I have time. But there are also lot of documents that require careful categorization. I will add necessary pieces in my free time and planning to add OpenAI API integration for some more advanced AI planners/agent if needed, probably through a .NET minimal API using Semantic Kernel. But time will tell what my needs will actually be and what I need to implement. For now I'm quite satisfied like this. The whole point on being so obsessed to actually be able to get handles on telegram controls was because being able to directly interact with controls gives you a much more precise way of doing stuff without having to do shenaningans with PixelGetColor, PixelChecksum and stuff like that, which are a much more clunky way of detecting stuff onscreen. Thanks for the help. For now I think I've found my solution and I won't move to any other, unless we find a direct way to interact with telegram desktop controls in a precise way. Farewell, Newb But heck, just being able to automate all that I've already automated saved me tons of HOURS of manually categorizing stuff and uploading it I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 11 Share Posted April 11 2 hours ago, Newb said: Thanks a lot, but for now just going with the old MouseClick is working far better and it's far faster and easier. The final idea is to make a program with configurable actions and the coords of the controls stored in a config so that it can adapt to other resolutions. Fair enough @Newb. When you finished your program, I would be interested in how you finally did it. If you want to and could do, please share your solution or at least pseudo code which let us learn too, thanks 🤝 . Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
junkew Posted April 11 Share Posted April 11 Just check a little further if UIAutomation out of the box can help you more. see faq 31 for example but just to see if uiautomation can help test with simplespy or a more mature advanced one. UIASpy (or try inspect.exe from Microsoft) I just tried to install telegram desktop for windows and its "seeing" some controls (but definitely not all) SOLVE-SMART 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Newb Posted April 11 Author Share Posted April 11 (edited) 9 hours ago, SOLVE-SMART said: Fair enough @Newb. When you finished your program, I would be interested in how you finally did it. If you want to and could do, please share your solution or at least pseudo code which let us learn too, thanks 🤝 . Best regards Sven I can share the code, no problem dude, it's just a bunch of methods and clicks. BIG WARNING: I put up the fastest and ugliest code to make the thing work because I needed to upload a lot of stuff. Even if it's horrible code, it still saved me a TON of time and I uploaded in an afternoon what would have took me 2 weeks. So I'm happy for the result anyway. That said, I also need to tell you that it needs a lot of polishing and testing. If you wish I can post more as I progress into developing it, but I do it in my free time and it will take some time to add missing features and refactor the code in a more ordered and organized way. It's far from perfect and completed and I plan to add a ton of stuff, but here you go: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> ;TODO ;F-01 Filtro lista file? ;F-02 Gestione cartelle ;DONE - F-03 Flag resetta numero file dopo caricamento cartella ;F-04 Btn selezione deseleziona tutte le opzioni ;F-05 Flag scrivi lista dei file ;F-06 Eventuale index per corsi caricati a topic singolo ;BUGS ;B-01: Alcune immagini sono renderizzate nel popup di upload diversamente (vedi corso L1 Calimove) e questo fa saltare l'upload, andrebbe considerato un detect ;grafico del bottone save visto che la UI non si riesce a catturare? ;B-02 BIG FIX: I made a lot of mess for finding "Send" button in upload screen. Instead ;it's just sufficient to send {ENTER} and no detection at all is needed. Damn :D Opt('GUIOnEventMode', '1') HotKeySet('!p', '_Exit') #Region ### START Koda GUI section ### Form= ;CREATE FORM $TgUpperForm = GUICreate("TGUpper", 713, 677, 192, 124) ;CREATE LISTVIEW $ListView1 = GUICtrlCreateListView("", 208, 32, 490, 574) _GUICtrlListView_InsertColumn($ListView1, 0, "File", 380) _GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 400) ;CREATE TOP BUTTONS $btnSelectFolder = GUICtrlCreateButton("Select Folder", 8, 8, 195, 25) $btnSelectFile = GUICtrlCreateButton("Select File", 8, 40, 195, 25) $btnCreateTopic = GUICtrlCreateButton("Create Topic", 8, 72, 195, 25) $btnSelectAll = GUICtrlCreateButton("Select All", 8, 104, 195, 25) ;CREATE GRUP FOLDER PROGRESSIVE $grpFolderProgressive = GUICtrlCreateGroup("Folder Progressive", 8, 136, 193, 209) $txtPrefixFolderProgressive = GUICtrlCreateInput("", 16, 272, 49, 21) $btnIncreaseFolderProgressiveCounter = GUICtrlCreateButton("+", 16, 176, 43, 25) $txtPostfixFolderProgressive = GUICtrlCreateInput("", 144, 272, 49, 21) $btnDecreaseFolderProgressiveCounter = GUICtrlCreateButton("-", 64, 176, 43, 25) $txtCounterFolderProgressive = GUICtrlCreateInput("0", 80, 272, 49, 21) $btnResetFolderProgressiveCounter = GUICtrlCreateButton("Reset", 112, 176, 75, 25) $chkEnableFolderProgressive = GUICtrlCreateCheckbox("Enable Folder Progressive", 16, 152, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoIncrementFolderProgressiveCounter = GUICtrlCreateCheckbox("Autoincrement", 16, 208, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) $lblPrefixFolderProgressive = GUICtrlCreateLabel("Prefix", 16, 248, 30, 17) $lblCounterFolderProgressive = GUICtrlCreateLabel("Counter", 80, 248, 41, 17) $lblPostfixCounterprogressive = GUICtrlCreateLabel("Postfix", 144, 248, 35, 17) $lblFolderProgressiveSeparator = GUICtrlCreateLabel("Separator", 128, 208, 50, 17) $txtFolderProgressiveSeparator = GUICtrlCreateInput(" ", 128, 224, 57, 21) $txtReplaceTextInTopicName = GUICtrlCreateInput("", 16, 312, 177, 21) $lblReplaceTextInTopicName = GUICtrlCreateLabel("Text to replace in topic name", 16, 296, 141, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) ;CREATE GROUP FILE PROGRESSIVE $grpFileProgressive = GUICtrlCreateGroup("File Progressive", 8, 352, 193, 193) $txtPrefixFileProgressive = GUICtrlCreateInput("", 16, 488, 49, 21) $btnIncreaseFileProgressiveCounter = GUICtrlCreateButton("+", 16, 392, 43, 25) $txtPostfixFileProgressive = GUICtrlCreateInput("", 144, 488, 49, 21) $btnDecreaseFileProgressiveCounter = GUICtrlCreateButton("-", 64, 392, 43, 25) $txtCounterFileProgressive = GUICtrlCreateInput("1", 80, 488, 49, 21) $btnResetFileProgressiveCounter = GUICtrlCreateButton("Reset", 112, 392, 75, 25) $chkEnableFileProgressive = GUICtrlCreateCheckbox("Enable File Progressive", 16, 368, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoIncrementFileProgressiveCounter = GUICtrlCreateCheckbox("Autoincrement", 16, 424, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $lblPrefixFileProgressive = GUICtrlCreateLabel("Prefix", 16, 464, 30, 17) $lblCounterFileProgressive = GUICtrlCreateLabel("Counter", 80, 464, 41, 17) $lblPostfixFileProgressive = GUICtrlCreateLabel("Postfix", 144, 464, 35, 17) $txtFileProgressiveSeparator = GUICtrlCreateInput(" ", 128, 440, 57, 21) $lblFileProgressiveSeparator = GUICtrlCreateLabel("Separator", 128, 424, 50, 17) $chkResetFileProgressiveCounterOnReopenFolderOrdFile = GUICtrlCreateCheckbox("Reset count after file/folder open", 16, 520, 177, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) ;CREATE BOTTOM BUTTONS $chkRefocusFormAfterTopicCreation = GUICtrlCreateCheckbox("Refocus form after creating topic", 16, 555, 177, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoLoadFilesAfterTopic = GUICtrlCreateCheckbox("Autoload files after topic creation", 16, 577, 185, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAskEveryFile = GUICtrlCreateCheckbox("Ask confirmation for every file", 16, 619, 185, 17) $chkElaborateAllFolders = GUICtrlCreateCheckbox("Elaborate all folders automatically", 16, 598, 177, 17) $btnProcessFiles = GUICtrlCreateButton("Process selected files", 8, 640, 195, 25) GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) ;CREATE UPPER LISTVIEW LABELS $lblCurrentFolderDesc = GUICtrlCreateLabel("Current folder", 208, 8, 67, 17) $lblNextFolderDesc = GUICtrlCreateLabel("Next folder", 456, 8, 55, 17) $txtCurrentFolder = GUICtrlCreateInput("-", 280, 5, 169, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $txtNextFolder = GUICtrlCreateInput("-", 512, 5, 185, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) ;CREATE LOWER LISTVIEW BUTTONS/LABELS $chkNextFolderAutoSwap = GUICtrlCreateCheckbox("Auto swap next folder", 224, 616, 121, 17) $btnOpenFolder = GUICtrlCreateButton("Open Folder", 352, 612, 139, 25) $btnSwapNextFolder = GUICtrlCreateButton("Next Folder", 504, 612, 195, 25) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $actionsdelay = 2200 Global $actionsdelay_short = 700 Global $actionsdelay_very_short = 400 Global $lastButtonClicked = "" Global $folder = "" Global $nextFolder = "" GUICtrlSetOnEvent($btnSelectFolder, "SelectFolder") GUICtrlSetOnEvent($btnSelectFile, "SelectFile") GUICtrlSetOnEvent($btnCreateTopic, "CreateTopic") GUICtrlSetOnEvent($btnIncreaseFolderProgressiveCounter, "IncreaseFolderProgressiveCounter") GUICtrlSetOnEvent($btnDecreaseFolderProgressiveCounter, "DecreaseFolderProgressiveCounter") GUICtrlSetOnEvent($btnResetFolderProgressiveCounter, "ResetFolderProgressiveCounter") GUICtrlSetOnEvent($btnIncreaseFileProgressiveCounter, "IncreaseFileProgressiveCounter") GUICtrlSetOnEvent($btnDecreaseFileProgressiveCounter, "DecreaseFileProgressiveCounter") GUICtrlSetOnEvent($btnResetFileProgressiveCounter, "ResetFileProgressiveCounter") GUICtrlSetOnEvent($btnProcessFiles, "ProcessFiles") GUICtrlSetOnEvent($btnSelectAll, "SelectAll") GUICtrlSetOnEvent($btnSwapNextFolder, "SwapNextFolder") GUICtrlSetOnEvent($chkNextFolderAutoSwap, "_chkNextFolderAutoSwap") GUICtrlSetOnEvent($chkAutoLoadFilesAfterTopic, "_chkAutoLoadFilesAfterTopic") While 1 Sleep(100) WEnd Func SelectFolder() $folder = FileSelectFolder("Select a folder", "") If @error Then MsgBox($MB_OK, "Error", "No folder selected.") Return EndIf $files = _FileListToArray($folder, "*", 1) If @error Then MsgBox($MB_OK, "Error", "No files found in the selected folder.") Return EndIf UpdateFileList($files) $lastButtonClicked = "SelectFolder" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() SelectAll() EndFunc Func SelectFile() $selectedFile = FileOpenDialog("Select a file", @WorkingDir, "All files (.)", 1) If @error Then MsgBox($MB_OK, "Error", "No file selected.") Return EndIf $files = StringSplit($selectedFile, "|", 1) UpdateFileList($files) $lastButtonClicked = "SelectFile" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() EndFunc Func UpdateFileList($files) _GUICtrlListView_DeleteAllItems($ListView1) For $i = 1 To UBound($files) - 1 If Not StringIsDigit($files[$i]) Then _GUICtrlListView_AddItem($ListView1, $files[$i]) EndIf Next EndFunc Func IncreaseFolderProgressiveCounter() $folderCounter = Int(GUICtrlRead($txtCounterFolderProgressive)) + 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndFunc Func DecreaseFolderProgressiveCounter() $folderCounter = Int(GUICtrlRead($txtCounterFolderProgressive)) If $folderCounter > 0 Then $folderCounter -= 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndIf EndFunc Func ResetFolderProgressiveCounter() GUICtrlSetData($txtCounterFolderProgressive, 0) EndFunc Func IncreaseFileProgressiveCounter() $fileCounter = Int(GUICtrlRead($txtCounterFileProgressive)) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndFunc Func DecreaseFileProgressiveCounter() $fileCounter = Int(GUICtrlRead($txtCounterFileProgressive)) If $fileCounter > 0 Then $fileCounter -= 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf EndFunc Func ResetFileProgressiveCounter() GUICtrlSetData($txtCounterFileProgressive, 1) EndFunc Func ProcessFiles() Local $selectedFiles[0] For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1 If _GUICtrlListView_GetItemChecked($ListView1, $i) Then _ArrayAdd($selectedFiles, _GUICtrlListView_GetItemText($ListView1, $i)) EndIf Next If UBound($selectedFiles) = 0 Then MsgBox($MB_OK, "Error", "No files selected.") Return EndIf $askConfirmation = (GUICtrlRead($chkAskEveryFile) = $GUI_CHECKED) For $i = 0 To UBound($selectedFiles) - 1 $filePath = $selectedFiles[$i] If $askConfirmation Then $confirmResult = MsgBox($MB_OKCANCEL, "Confirmation", "Process file:" & @CRLF & $filePath) If $confirmResult = $IDCANCEL Then Return ; Abort the whole process EndIf EndIf If $lastButtonClicked = "SelectFolder" Then ProcessFolderFile($filePath) ElseIf $lastButtonClicked = "SelectFile" Then ProcessSingleFile($filePath) EndIf Next If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then SwapNextFolder() WinActivate($TgUpperForm) EndIf EndFunc Func ProcessFolderFile($filePath) $folderName = GetFolderName($folder) $fileName = GetFileName($filePath) $fileFullPath = $folder & "\" & $filePath $filePrefix = GUICtrlRead($txtPrefixFileProgressive) $fileCounter = GUICtrlRead($txtCounterFileProgressive) $filePostfix = GUICtrlRead($txtPostfixFileProgressive) $fileSeparator = GuiCtrlRead($txtFileProgressiveSeparator) If GUICtrlRead($chkEnableFileProgressive) = $GUI_CHECKED Then $finalFileName = $filePrefix & $fileCounter & $filePostfix & $fileSeparator & $fileName Else $finalFileName = $fileName EndIf If GUICtrlRead($chkAutoIncrementFileProgressiveCounter) = $GUI_CHECKED Then $fileCounter = Int($fileCounter) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf UploadFile($fileFullPath, $finalFileName) EndFunc Func ProcessSingleFile($filePath) $folderName = GetFolderName($folder) $fileName = GetFileName($filePath) $fileFullPath = $folder & "" & $filePath $filePrefix = GUICtrlRead($txtPrefixFileProgressive) $fileCounter = GUICtrlRead($txtCounterFileProgressive) $filePostfix = GUICtrlRead($txtPostfixFileProgressive) If GUICtrlRead($chkEnableFileProgressive) = $GUI_CHECKED Then $finalFileName = $filePrefix & $fileCounter & $filePostfix & " - " & $fileName Else $finalFileName = $fileName EndIf $folderPrefix = GUICtrlRead($txtPrefixFolderProgressive) $folderCounter = GUICtrlRead($txtCounterFolderProgressive) $folderPostfix = GUICtrlRead($txtPostfixFolderProgressive) If GUICtrlRead($chkEnableFolderProgressive) = $GUI_CHECKED Then $finalFolderName = $folderPrefix & $folderCounter & $folderPostfix & " - " & $folderName Else $finalFolderName = $folderName EndIf MsgBox($MB_OK, "Processing Single File", "Folder Name: " & $finalFolderName & @CRLF & "File Full Path: " & $fileFullPath & @CRLF & "File Name: " & $finalFileName) If GUICtrlRead($chkAutoIncrementFileProgressiveCounter) = $GUI_CHECKED Then $fileCounter = Int($fileCounter) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf EndFunc Func GetFolderNameFromPath($path) Return StringRegExpReplace($path, "^.*\\", "") EndFunc Func GetFolderName($folderPath) Local $folderName = StringRegExpReplace($folderPath, "^.*\", "") Return $folderName EndFunc Func GetFileName($filePath) Local $fileName = StringRegExpReplace($filePath, "^.*\", "") Return $fileName EndFunc Func SelectAll() For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1 _GUICtrlListView_SetItemChecked($ListView1, $i) Next EndFunc Func _Exit() Exit EndFunc Func CreateTopic() If _GUICtrlListView_GetItemCount($ListView1) < 1 Then MsgBox($MB_OK, "Error", "No files selected.") Return EndIf $TopicName = GetFolderName($folder) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($folder, $sDrive, $sDir, $sFileName, $sExtension) $folderPrefix = GUICtrlRead($txtPrefixFolderProgressive) $folderCounter = GUICtrlRead($txtCounterFolderProgressive) $folderPostfix = GUICtrlRead($txtPostfixFolderProgressive) $folderSeparator = GuiCtrlRead($txtFolderProgressiveSeparator) $folderName = $aPathSplit[3] If GUICtrlRead($chkEnableFolderProgressive) = $GUI_CHECKED Then $topicName = $folderPrefix & $folderCounter & $folderPostfix & $folderSeparator & $folderName Else $topicName = $folderName EndIf If GUICtrlRead($chkAutoIncrementFolderProgressiveCounter) = $GUI_CHECKED Then $folderCounter = Int($folderCounter) + 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndIf $replaceText = GUICtrlRead($txtReplaceTextInTopicName) If $replaceText <> "" Then $topicName = StringReplace($topicName, $replaceText, "") $topicName = StringStripWS($topicName, 3) EndIf ;click on 3 dots MouseClick("left", 310, 50, 1, $actionsdelay) ;click on Create Topic MouseClick("left", 230, 85, 1, $actionsdelay) ;click on Create Topic MouseClick("left", 890, 360, 1, $actionsdelay) Send($TopicName, 1) ;click on Create Topic MouseClick("left", 1080, 755, 1, $actionsdelay) $filesList = _FileListToArray($folder, "*", 1) $fileListMessage = $topicName & @LF & "Files: " & _ArrayToString($filesList, @LF) WriteMessage($fileListMessage) If GUICtrlRead($chkRefocusFormAfterTopicCreation) = $GUI_CHECKED Then Sleep($actionsdelay_very_short) WinActivate($TgUpperForm) EndIf If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then ProcessFiles() EndIf ElaborateAllFolders() ; Call the new function EndFunc Func UploadFile($Path, $Filename) $chooseFilesWindowTitle = "Choose Files" ;click on clip icon to open file upload MouseClick("left", 355, 1010, 1, $actionsdelay_short) WinWait($chooseFilesWindowTitle) Sleep($actionsdelay) ;click on path textbox of upload file window ControlClick($chooseFilesWindowTitle, "", 1148) Sleep($actionsdelay_short) ;Inputs file path on the textbox Send($Path, 1) Sleep($actionsdelay_short) ;Click open to start uploading file on telegram ControlClick($chooseFilesWindowTitle, "", 1) ;Longer wait for telegram file upload window Sleep($actionsdelay) ;click on textbox for telegram file ;if Mp4 preview moves buttons down $extension = StringUpper(StringRight($Filename, 4)) If $extension = ".MP4" Then MouseClick("left", 865, 630, 1) ElseIf $extension = ".JPG" Or $extension = ".PNG" Or StringUpper(StringRight($Filename, 5)) = ".JPEG" Or StringUpper(StringRight($Filename, 5)) = ".JFIF" Then MouseClick("left", 865, 700, 1) Else MouseClick("left", 865, 560, 1) EndIf Sleep($actionsdelay_short) ;Write file name Send($Filename, 1) Sleep($actionsdelay_short) ;Clicks Send If $extension = ".mp4" Then MouseClick("left", 1100, 675, 1) ElseIf $extension = ".JPG" Or $extension = ".PNG" Or StringUpper(StringRight($Filename, 5)) = ".JPEG" Or StringUpper(StringRight($Filename, 5)) = ".JFIF" Then MouseClick("left", 1100, 745, 1) Sleep($actionsdelay_short) ;temp fix for smaller/different resolution images that move up the Send button ;Will be solved with pixelchecksum method While PixelGetColor(785,320) = 16777215 Sleep($actionsdelay_short) MouseClick("left",1100,720,1) WEnd Else MouseClick("left", 1100, 610, 1) EndIf EndFunc Func UpdateCurrentFolderDisplay() GUICtrlSetData($txtCurrentFolder, GetFolderName($folder)) EndFunc Func UpdateNextFolderDisplay() $nextFolder = GetNextFolderInAlphabeticalOrder($folder) GUICtrlSetData($txtNextFolder, GetFolderName($nextFolder)) EndFunc Func GetNextFolderInAlphabeticalOrder($currentFolder) Local $folderList = _FileListToArray($currentFolder & "\..", "*", 2) If @error Then Return "" EndIf Local $currentFolderName = GetFolderNameFromPath($currentFolder) Local $currentFolderIndex = _ArraySearch($folderList, $currentFolderName, 1) ; If folder is the last one then no next folder If $currentFolderIndex = UBound($folderList) - 1 Then Return "END-FOLDERS" EndIf Return _PathFull($currentFolder & "\..") & "\" & $folderList[$currentFolderIndex + 1] EndFunc Func SwapNextFolder() If $nextFolder = "" Or $nextFolder = "END-FOLDERS" Then MsgBox($MB_OK, "Info", "This was the last folder to process. No more folders to open.") Return EndIf $folder = $nextFolder $files = _FileListToArray($folder, "*", 1) If @error Then MsgBox($MB_OK, "Error", "No files found in the selected folder.") Return EndIf UpdateFileList($files) $lastButtonClicked = "SelectFolder" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() SelectAll() EndFunc Func _chkNextFolderAutoSwap() If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then GUICtrlSetState($btnSwapNextFolder, $GUI_DISABLE) Else GUICtrlSetState($btnSwapNextFolder, $GUI_ENABLE) EndIf EndFunc Func _chkAutoLoadFilesAfterTopic() If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) Else GUICtrlSetState($btnProcessFiles, $GUI_ENABLE) EndIf EndFunc Func UpdateSwapNextFolderButton() If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then GUICtrlSetState($btnSwapNextFolder, $GUI_DISABLE) Else GUICtrlSetState($btnSwapNextFolder, $GUI_ENABLE) EndIf EndFunc Func UpdateProcessFilesButton() If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) Else GUICtrlSetState($btnProcessFiles, $GUI_ENABLE) EndIf EndFunc ;NOTE: @CRLF will result in telegram sending the message ;To write multiline message you got to use @LF and then manually send {ENTER} Func WriteMessage($message) Sleep($actionsdelay_short) MouseClick("left", 400, 1010, 1) Send($message, 1) Send("{ENTER}") EndFunc Func ElaborateAllFolders() If GUICtrlRead($chkElaborateAllFolders) = $GUI_CHECKED Then While True CreateTopic() ProcessFiles() If GUICtrlRead($txtNextFolder) = "END-FOLDERS" Then ExitLoop EndIf SwapNextFolder() WinActivate($TgUpperForm) WEnd EndIf EndFunc Edited April 11 by Newb SOLVE-SMART and ioa747 2 I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 11 Share Posted April 11 1 hour ago, Newb said: BIG WARNING: I put up the fastest and ugliest code to make the thing work because I needed to upload a lot of stuff. [...] That said, I also need to tell you that it needs a lot of polishing and testing. [...] If you wish I can post more as I progress into developing it, but I do it in my free time and it will take some time to add missing features and refactor the code in a more ordered and organized way. Totally fine and understandable for me @Newb 🤝 , thanks. Don't worry about it. Post if you want to and no hurry on this. Best regards Sven Newb 1 Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now