You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
post-scheduler/Freedomain Post Scheduler.ahk

249 lines
6.9 KiB
Plaintext

6 months ago
; ENVIRONMENT
;------------------------------------------------
#Requires AutoHotkey v1.0
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
;DetectHiddenWindows, On
#SingleInstance, Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;SetKeyDelay, 500
CoordMode, ToolTip, Screen
CoordMode, Mouse, Screen
; Tray Icon & Custom Tray Menu
; ------------------------------------------------
; Only Set tool tray icon if this is the source .ahk script.
; The .exe has the icon compiled into it
if(InStr(A_ScriptFullPath, ".ahk")){
try Menu, Tray, Icon, %A_ScriptDir%\Assets\Icon.ico
}
Menu, tray, NoStandard
Menu, Tray, Add, Exit, KillScript
; Menu, Tray, Add, Pause, PauseScript
Menu, Tray, Add, Restart, ReloadScript
Menu, Tray, Add, Pause, TogglePause
Menu, Tray, Add, Show Schedule, ShowSchedule
Menu, Tray, Default, Show Schedule
; Notes/Extra Info/#Includes
;------------------------------------------------
; @todo: Ask user if this program should startup automatically on boot
; @todo: check if SMP and VU files exist after reading filepath
; @todo: add settings to GUI - DiscordPing, DiscordLog,
; VARIABLES
;------------------------------------------------
global SettingsIniFilepath
global SchedulePostsDir
; Set filepaths for different files and folders
if(A_Username = "yuriy"){
SchedulePostsDir = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Video-Uploader\Scheduled-Posts\*.ini
SettingsIniFilepath = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Video-Uploader\Settings.ini
}
else, {
SchedulePostsDir = %A_ScriptDir%\Scheduled-Posts\*.ini
SettingsIniFilepath = %A_ScriptDir%\Settings.ini
}
global ScriptSettingsSection
ScriptSettingsSection := "Freedomain Post Scheduler"
global ScriptNameAcronym
ScriptNameAcronym := "FPS"
global ScriptName
global ScriptVersion
global FullScriptName
VersionIniFilepath = %A_ScriptDir%\Lib\Version-%ScriptNameAcronym%.ini
; Install the Version.ini file in lib folder (Used by .exe file)
FileInstall, Version.ini, %VersionIniFilepath%, 1
IniRead, ScriptVersion, %VersionIniFilepath%,%ScriptSettingsSection%, Version, 0.0
IniRead, ScriptName, %VersionIniFilepath%,%ScriptSettingsSection%, Name, %ScriptSettingsSection%
FullScriptName := ScriptName . " - " . ScriptVersion
; Write filepath to settings file so it can be read by FVU and FSMP
IniWrite, %A_ScriptFullPath%, %SettingsIniFilepath%, Filepaths, PostScheduler
IniWrite, %A_ScriptFullPath%, %SettingsIniFilepath%, Filepaths, PostScheduler
; MAIN SCRIPT
;------------------------------------------------
CheckDirectory:
Loop, {
; Msgbox % "SchedulePostsDir: " SchedulePostsDir
Loop, files, % SchedulePostsDir ; , DFR
{ ; D = Directories, F = Files, R = Recursive
SplitPath, A_LoopFileFullPath, FileNameWExt, FileDir, FileExt, FileNameNoExt
; Msgbox % "A_LoopFileFullPath: " A_LoopFileFullPath
IniRead, MinutesToUpload, %A_LoopFileFullPath%, Schedule-Info, TimeStamp, %A_Space%
; Clipboard := MinutesToUpload
; Clipboard := A_Now
TimeDifference := A_Now
; Msgbox % "TimeDifference: " TimeDifference
; Msgbox % "MinutesToUpload: " MinutesToUpload
EnvSub, MinutesToUpload,A_Now, Minutes ; [, TimeUnits]
; Msgbox % "MinutesToUpload: " MinutesToUpload
if(MinutesToUpload < 1){
IniRead, BodyTextFilePath, %A_LoopFileFullPath%, Schedule-Info, ProjectFilepath, %A_Space%
IniRead, PostType, %A_LoopFileFullPath%, Schedule-Info, PostType, %A_Space%
IniRead, Sites, %A_LoopFileFullPath%, Schedule-Info, Sites, %A_Space%
SitesForMsgbox := StrReplace(Sites, "|", ",")
IniRead, Title, %A_LoopFileFullPath%, Schedule-Info, Title, %A_Space%
; Msgbox % "Sites: " Sites
OnMessage(0x44, "OnMsgBoxScheduledPostConfirmation")
MsgBox 0x43, Scheduled Post Starting Soon, Starting the Following Scheduled Post in 1 Minute:`n`nTitle:`n%Title%`n`nTo Sites:`n%SitesForMsgbox%, 60
OnMessage(0x44, "")
IfMsgBox Yes, {
} Else IfMsgBox No, {
Pause, Toggle
} Else IfMsgBox Cancel, {
; msgbox, deleting file
FileDelete, %A_LoopFileFullPath%
Continue
if(ErrorLevel){
Message = Failed to delete Schedule Post File
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
} Else IfMsgBox Timeout, {
}
if(PostType = "Video"){
IniRead, UploaderFilepath, %SettingsIniFilepath%, Filepaths, VideoUploaderFilepath, %A_Space%
}
if(PostType = "Social"){
IniRead, UploaderFilepath, %SettingsIniFilepath%, Filepaths, SocialMediaPosterFilepath, %A_Space%
}
; launch the scheduled post
run, %UploaderFilepath% "%BodyTextFilePath%" "Scheduled" "%Sites%"
; delete the scheduled file
FileDelete, %A_LoopFileFullPath%
Message = Scheduled Post Started Title:`n%Title%`n`nTo Sites:`n%SitesForMsgbox%
; sleep, 5000
; Tooltip, hererer!
; msgbox, launched!
}
}
; MinutesToSleep := 5000
MinutesToSleep := 5 * 60000
sleep, %MinutesToSleep%
} ; /Loop
/*
*/
TogglePause:
Pause, Toggle
Return
ReloadScript:
Reload
ExitApp
ShowSchedule:
ShowGUI:
Gui, Font, s10
Loop, files, % SchedulePostsDir ; , DFR
{ ; D = Directories, F = Files, R = Recursive
; msgbox, yoo
SplitPath, A_LoopFileFullPath, FileNameWExt, FileDir, FileExt, FileNameNoExt
IniRead, PostType, %A_LoopFileFullPath%, Schedule-Info, PostType, %A_Space%
IniRead, MinutesToUpload, %A_LoopFileFullPath%, Schedule-Info, TimeStamp, %A_Space%
IniRead, Title, %A_LoopFileFullPath%, Schedule-Info, Title, %A_Space%
IniRead, ProjectFilepath, %A_LoopFileFullPath%, Schedule-Info, ProjectFilepath, %A_Space%
SplitPath, ProjectFilepath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
MinutesUntilUpload := MinutesToUpload
EnvSub, MinutesUntilUpload, A_Now, Minutes
FormatTime, TimeForUpload , %MinutesToUpload%, yyyy-MM-dd @ hh:mm tt
TimeForUpload = %TimeForUpload% (%MinutesUntilUpload% Minutes Left)
Gui, Add, Button , x10 w100 yp+10, Title
Gui, Add, Edit, x+10 w300, %Title%
Gui, Add, Button, x10 w100, Date
Gui, Add, Edit, x+10 w300, %TimeForUpload%
; Gui, Add, Button, x10 w100, Project
; Gui, Add, Edit, x+10 w300, %OutFileName%
Gui, Add, Button, x10 w100, Type
Gui, Add, Edit, x+10 w300, %PostType%
Gui, add, text, x15 w400 0x10 ;Horizontal Line > Etched Gray
Gui, Add, Text, yp+5,
}
Gui, Add, Button, gGuiClose w800,Close
gui, Show,, %FullScriptName%
goto, CheckDirectory
Return
GuiClose:
Gui, Destroy
goto, CheckDirectory
Return
KillScript:
ExitApp
; Functions
; ------------------------------------------------
OnMsgBoxScheduledPostConfirmation() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, OK
ControlSetText Button2, Pause
ControlSetText Button3, Delete
}
}