d3k/old_versions/T_Msg.ahk

145 lines
2.8 KiB
AutoHotkey
Raw Normal View History

; Sauce: https://www.autohotkey.com/boards/viewtopic.php?t=24919
T_SendMsg(Option,EmojiPosition,Text)
{
ini = %A_MyDocuments%\D3Ksettings.ini ; Where the ini is
IniRead, TelegramBotToken, %ini%, Info, TBToken, 0
IniRead, TelegramBotChatID, %ini%, Info, TBChatID, 0
if !(TelegramBotToken)
{
Return
}
if (Option = "hand")
{
TelegramIconString := "%E2%9D%8C"
}
if (Option = "question")
{
TelegramIconString := "%E2%9D%94"
}
if (Option = "alert")
{
TelegramIconString := "%E2%9A%A0%EF%B8%8F"
}
if (Option = "info")
{
TelegramIconString := "%E2%84%B9%EF%B8%8F"
}
IfInString, Option, `%
TelegramIconString := Option
Text := StrReplace(Text, "`n", "%0A")
If (EmojiPosition = 1)
{
Text = %TelegramIconString% %Text%
}
If (EmojiPosition = 2)
{
Text = %Text% %TelegramIconString%
}
If (EmojiPosition = 3)
{
Text = %TelegramIconString% %Text% %TelegramIconString%
}
loop 3
{
UrlDownloadToFile https://api.telegram.org/bot%TelegramBotToken%/sendmessage?chat_id=%TelegramBotChatID%&parse_mode=HTML&text=%Text%, %A_ScriptDir%\Tlog
sleep 1000
ifexist %A_ScriptDir%\Tlog
{
break
}
if A_index = 3
{
MsgBox, 16,, Something went wrong with sending the Telegram message.
}
}
}
T_Edit(Option,EmojiPosition,Text)
{
ini = %A_MyDocuments%\D3Ksettings.ini ; Where the ini is
IniRead, TelegramBotToken, %ini%, Info, TBToken, 0
IniRead, TelegramBotChatID, %ini%, Info, TBChatID, 0
if !(TelegramBotToken)
{
Return
}
if (Option = "hand")
{
TelegramIconString := "%E2%9D%8C"
}
if (Option = "question")
{
TelegramIconString := "%E2%9D%94"
}
if (Option = "alert")
{
TelegramIconString := "%E2%9A%A0%EF%B8%8F"
}
if (Option = "info")
{
TelegramIconString := "%E2%84%B9%EF%B8%8F"
}
IfInString, Option, `%
TelegramIconString := Option
Text := StrReplace(Text, "`n", "%0A")
If (EmojiPosition = 1)
{
Text = %TelegramIconString% %Text%
}
If (EmojiPosition = 2)
{
Text = %Text% %TelegramIconString%
}
If (EmojiPosition = 3)
{
Text = %TelegramIconString% %Text% %TelegramIconString%
}
FileRead, Tlog, %A_ScriptDir%/Tlog
RegExMatch(Tlog, "(?<=""ok"":).", success)
If (success = "t") ; Check to see if message editing succeeded
{
RegExMatch(Tlog, "(?<=""message_id"":)...", message_id)
}
If (success = "f") ; Check to see if message editing succeeded
{
RegExMatch(Tlog, "(?<=""description"":"").+(?="")", error_msg)
MsgBox, %error_msg%
Return
}
loop 3
{
UrlDownloadToFile https://api.telegram.org/bot%TelegramBotToken%/editMessageText?chat_id=%TelegramBotChatID%&message_id=%message_id%&parse_mode=HTML&text=%Text%, %A_ScriptDir%\Tlog
sleep 1000
ifexist %A_ScriptDir%\Tlog
{
break
}
if A_index = 3
{
MsgBox, 16,, Something went wrong with updating the Telegram message.
}
}
}