You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.2 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, August 01, 2018, 10:47 PM -->
<!-- MuClient version 5.06-pre -->
<!-- Plugin "Notifier" generated by Plugin Wizard -->
<muclient>
<plugin name="Notifier" author="Crowley" id="f99bb4b89cfa8c90ac2d03d5" language="Lua" purpose="Uses Telegram API to notify of events." save_state="y" date_written="2018-08-01 22:46:31" requires="5.06" version="1.1">
</plugin>
<aliases>
<alias
name="onOffToggle"
match="^telegram (on|off)"
script="toggleConfig"
regexp="y"
ignore_case="y"
enabled="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
async_ok, async = pcall(require, "async")
socket = require 'socket'
url = require 'socket.url'
local triggerLines = {
{name = "regularDouble", match = "^For the next 15 minutes experience is doubled in honor of the new superhero.", message = "Double for 15 minutes!"},
{name = "blessingDouble", match = "^Double experience for 10 minutes courtesy of .* daily blessing\\.", message = "Double for 10 minutes!"},
{name = "donationDouble", match ="\\[ 10 minutes of double exp started courtesy of donations being open \\]", message = "Double for 10 minutes!"},
{name = "hourDouble", match = "^For the next 60 minutes all experience is doubled!!$", message = "Hour of double!"},
{name = "questAlert", match = "^QUEST: You may now quest again.", message = "Quest time!"},
{name = "gqAlert", match = "^Global Quest\\: Global quest \\# (.*?) has been declared(.*?)$", message = "GQ ALERT#"},
}
local triggerSetup = [[
<triggers>
<trigger match="%s" enabled="y" regexp="y" group="Notifier" keep_evaluating="y" sequence="100" name="%s" script="sendAlert">
</trigger>
</triggers>
]]
for _,v in ipairs(triggerLines) do
local triggerXML = string.format(triggerSetup, v.match, v.name)
ImportXML(triggerXML)
end
chatID = <your chat ID>
apiToken = "<your bot token>"
alertFormat = "https://api.telegram.org/bot" .. apiToken .. "/sendMessage?chat_id=" .. chatID .. "&text=%s"
function url_encode(str)
if str then
str = str:gsub("\n", "\r\n")
str = str:gsub("([^%w %-%_%.%~])", function(c)
return ("%%%02X"):format(string.byte(c))
end)
str = str:gsub(" ", "+")
end
return str
end
function pageRequest(req, protocol)
local req = string.format(alertFormat, req)
if async_ok then
async.doAsyncRemoteRequest(req, "", protocol)
else
ColourNote("white", "blue", "Async failed to load for some reason.")
end
end
function sendAlert(name, line, wildcards)
if name ~= "TestAlert" then
local wc = wildcards[1] or ""
for _,v in ipairs(triggerLines) do
if name == v.name then
msg = url.escape(v.message .. wc)
break
end
end
else
msg = "Test notification."
end
pageRequest(msg, "HTTPS")
end
function toggleConfig(name, line, wildcards)
EnableTriggerGroup("Notifier", (true and (wildcards[1] == "on")))
ColourNote("goldenrod", "navy", "Turning Telegram functionality " .. wildcards[1] .. "!")
end
]]>
</script>
</muclient>