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.
128 lines
4.1 KiB
Plaintext
128 lines
4.1 KiB
Plaintext
1 year ago
|
; -------------------------------Discord-------------------------------
|
||
|
PostToDiscord:
|
||
|
CurrentSite := "Discord"
|
||
|
|
||
|
; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
|
||
|
Message = Posting Through API
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||
|
|
||
|
if(DiscordParlerWebhookURL = ""){
|
||
|
Message = Webhook Link not found. Please set "DiscordParlerWebhookURL" in %SettingsIniFilepath%.
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||
|
Return
|
||
|
}
|
||
|
|
||
|
|
||
|
if(BoldTitleWAPI){
|
||
|
if(NewLineBetweenTitle)
|
||
|
Message = **%PostTitle%**`n`n%PostBody%
|
||
|
else,
|
||
|
Message = **%PostTitle%**`n%PostBody%
|
||
|
}
|
||
|
else, { ; NOT bold title
|
||
|
if(NewLineBetweenTitle)
|
||
|
Message = %PostTitle%`n`n%PostBody%
|
||
|
else,
|
||
|
Message = %PostTitle%`n%PostBody%
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
if(ImageAttachmentFilepath != ""){
|
||
|
SingleQuotationMark = "
|
||
|
; remove any single quotes from filepath
|
||
|
ImageAttachmentFilepath := StrReplace(ImageAttachmentFilepath, SingleQuotationMark, "")
|
||
|
|
||
|
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
|
||
|
loop % StrLen(Message) {
|
||
|
|
||
|
if(A_index < 1900)
|
||
|
Continue
|
||
|
|
||
|
SplitCharNumber := A_index
|
||
|
; IndexMinusOne := A_index - 1
|
||
|
|
||
|
SplitLocationText := SubStr(Message, SplitCharNumber, 1)
|
||
|
if(SplitLocationText = " "){
|
||
|
Break
|
||
|
; Msgbox % "SplitLocation: " SplitLocation
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
|
||
|
SplitCharNumber := SplitCharNumber + 1
|
||
|
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
|
||
|
; Msgbox % "DiscordMessagePartOne: " DiscordMessagePartOne
|
||
|
; Msgbox % "DiscordMessagePartTwo: " DiscordMessagePartTwo
|
||
|
|
||
|
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
|
||
|
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
|
||
|
Status := UploadImageToDiscord(DiscordParlerWebhookURL, "", ImageAttachmentFilepath)
|
||
|
|
||
|
; Msgbox % "StatusOne: " StatusOne
|
||
|
; Msgbox % "StatusTwo: " StatusTwo
|
||
|
|
||
|
/* if(!InStr(StatusOne, "id")){ ; if error for each of the messages, post its
|
||
|
parsed := JSON.Load(StatusOne)
|
||
|
StatusOneFailure := parsed.content[1]
|
||
|
|
||
|
parsed := JSON.Load(StatusTwo)
|
||
|
StatusTwoFailure := parsed.content[1]
|
||
|
|
||
|
Message = Partial Failure for the following reason: %StatusOneFailure% OR %StatusTwoFailure%
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||
|
}
|
||
|
*/
|
||
|
} ; end of strlen > 1999
|
||
|
else, {
|
||
|
Status := UploadImageToDiscord(DiscordParlerWebhookURL, Message, ImageAttachmentFilepath)
|
||
|
SaveOrPostProgress(Message:="Status",PostType:="ErrorLoggingTextFile")
|
||
|
|
||
|
if(!InStr(Status, "id")){
|
||
|
parsed := JSON.Load(Status)
|
||
|
Error := parsed.content[1]
|
||
|
; Msgbox % "error: " error
|
||
|
Message = Discord Post Failed due to API Issue. Error was saved to errorlog; please forward to Yuriy
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||
|
Return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
|
||
|
loop % StrLen(Message) {
|
||
|
|
||
|
if(A_index < 1900)
|
||
|
Continue
|
||
|
|
||
|
SplitCharNumber := A_index
|
||
|
|
||
|
SplitLocationText := SubStr(Message, SplitCharNumber, 1)
|
||
|
if(SplitLocationText = " "){
|
||
|
Break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
|
||
|
SplitCharNumber := SplitCharNumber + 1
|
||
|
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
|
||
|
|
||
|
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
|
||
|
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
|
||
|
}
|
||
|
else,
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordParler")
|
||
|
}
|
||
|
|
||
|
IniWrite, Successful, %StatusFileFilePath%, Status, Discord
|
||
|
AddToTotalPostsPostedCount()
|
||
|
|
||
|
Message = Post Publish Successful
|
||
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||
|
|
||
|
|
||
|
Return
|
||
|
; -------------------------------/Discord-------------------------------
|