-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.lua
97 lines (82 loc) · 3.11 KB
/
script.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
me = 121913323
function vardump(value, depth, key)
local linePrefix = ""
local spaces = ""
if key ~= nil then
linePrefix = "["..key.."] = "
end
if depth == nil then
depth = 0
else
depth = depth + 1
for i=1, depth do spaces = spaces .. " " end
end
if type(value) == 'table' then
mTable = getmetatable(value)
if mTable == nil then
print(spaces ..linePrefix.."(table) ")
else
print(spaces .."(metatable) ")
value = mTable
end
for tableKey, tableValue in pairs(value) do
vardump(tableValue, depth, tableKey)
end
elseif type(value) == 'function' or
type(value) == 'thread' or
type(value) == 'userdata' or
value == nil
then
print(spaces..tostring(value))
else
print(spaces..linePrefix.."("..type(value)..") "..tostring(value))
end
end
local lgi = require ('lgi')
local notify = lgi.require('Notify')
local utf8 = require('utf8')
notify.init ("Telegram updates")
chats = {}
function do_notify (user, msg)
local n = notify.Notification.new(user, msg)
n:show ()
end
function strike (s)
--s = string.gsub(s, "[\192-\255][\128-\191]*", "%1" .. utf8.char(822))
s = string.gsub(s, "[\000-\127]","%1" .. utf8.char(822))
s = string.gsub(s,"[\192-\255][\128-\191]", "%1" .. utf8.char(822))
s = string.gsub(s,"~","")
return s
end
function dl_cb (arg, data)
end
function tdcli_update_callback (data)
if (data.ID == "UpdateNewMessage") then
local msg = data.message_
local d = data.disable_notification_
local chat = chats[msg.chat_id_]
if((data.message_.send_state_.ID == "MessageIsSuccessfullySent") and (data.message_.can_be_edited_ == true) and (data.message_.sender_user_id_ == me)) then
local editmsg = data.message_
_, _, textToStrike = string.find(editmsg.content_.text_,"(%b~~)")
if (textToStrike) then textStruckthru = strike(textToStrike)
editmsg.content_.text_ = string.gsub(editmsg.content_.text_,textToStrike,textStruckthru)
tdcli_function ({ID="EditMessageText", chat_id_=editmsg.chat_id_, message_id_=editmsg.id_, reply_markup_=nil, input_message_content_={ID="InputMessageText", text_=editmsg.content_.text_, disable_web_page_preview_=1, clear_draft_=0,entities_ = {}, parse_mode_=editmsg.parse_mode_}}, dl_cb, nil)
end
end
if ((not d) and chat) then
if msg.content_.ID == "MessageText" then
do_notify (chat.title_, msg.content_.text_)
else
do_notify (chat.title_, msg.content_.ID)
end
end
if msg.content_.ID == "MessageText" then
tdcli_function ({ID="SendMessage", chat_id_=me, reply_to_message_id_=msg.id_, disable_notification_=0, from_background_=1, reply_markup_=nil, input_message_content_={ID="InputMessageForwarded", from_chat_id_=msg.chat_id_, message_id_=msg.id_, in_game_share_=0 }}, dl_cb, nil)
end
elseif (data.ID == "UpdateChat") then
chat = data.chat_
chats[chat.id_] = chat
elseif (data.ID == "UpdateOption" and data.name_ == "my_id") then
tdcli_function ({ID="GetChats", offset_order_="9223372036854775807", offset_chat_id_=0, limit_=20}, dl_cb, nil)
end
end