Version 3.8
Relicense to AGPLv3, with consent of contributors. bindings.lua completely rewritten. Shift to multipart-post. Updated readme. New plugins: bing.lua, channel.lua. Removed plugins: floodcontrol.lua, librefm.lua. luarun.lua: Will now serialize returned tables. Aliased "/return" to "/lua return".
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
local about = {}
|
||||
|
||||
local bot = require('bot')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
about.command = 'about'
|
||||
about.doc = '`Returns information about the bot.`'
|
||||
@ -16,13 +16,13 @@ function about:action(msg)
|
||||
-- other plugins.
|
||||
if msg.forward_from then return end
|
||||
|
||||
local output = self.config.about_text .. '\nBased on @otouto v'..bot.version..' by topkecleon.'
|
||||
local output = self.config.about_text .. '\nBased on otouto v'..bot.version..' by topkecleon.'
|
||||
|
||||
if (msg.new_chat_participant and msg.new_chat_participant.id == self.info.id)
|
||||
or msg.text_lower:match('^/about')
|
||||
or msg.text_lower:match('^/about@'..self.info.username:lower())
|
||||
or msg.text_lower:match('^/start') then
|
||||
bindings.sendMessage(self, msg.chat.id, output, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
autokick_timer = 0
|
||||
groups[*].flags[6] = false
|
||||
groups[*].autoban = 3
|
||||
groups[*].autokicks = {}
|
||||
groups[*].autokicks = {}b
|
||||
|
||||
1.9.1 - Returned to non-toggled promotions/bans (too many complaints!).
|
||||
|
||||
@ -104,7 +104,7 @@ administration.flags = {
|
||||
},
|
||||
[6] = {
|
||||
name = 'antihammer',
|
||||
desc = 'Removes the ban on globally-banned users. Note that users hammered in this group will also be banned locally.',
|
||||
desc = 'Allows globally banned users to enter this group. Note that users hammered in this group will also be banned locally.',
|
||||
short = 'This group does not acknowledge global bans.',
|
||||
enabled = 'This group will no longer remove users for being globally banned.',
|
||||
disabled = 'This group will now remove users for being globally banned.'
|
||||
@ -412,10 +412,10 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if new_user ~= user and new_user.do_kick then
|
||||
administration.kick_user(self, msg.chat.id, msg.new_chat_participant.id, new_user.reason)
|
||||
if new_user.output then
|
||||
bindings.sendMessage(self, msg.new_chat_participant.id, new_user.output)
|
||||
utilities.send_message(self, msg.new_chat_participant.id, new_user.output)
|
||||
end
|
||||
if not new_user.dont_unban and msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } )
|
||||
end
|
||||
end
|
||||
|
||||
@ -437,16 +437,16 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if user.do_kick then
|
||||
administration.kick_user(self, msg.chat.id, msg.from.id, user.reason)
|
||||
if user.output then
|
||||
bindings.sendMessage(self, msg.from.id, user.output)
|
||||
utilities.send_message(self, msg.from.id, user.output)
|
||||
end
|
||||
if not user.dont_unban and msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } )
|
||||
end
|
||||
end
|
||||
|
||||
if msg.new_chat_participant and not new_user.do_kick then
|
||||
local output = administration.get_desc(self, msg.chat.id)
|
||||
bindings.sendMessage(self, msg.new_chat_participant.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.new_chat_participant.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
-- Last active time for group listing.
|
||||
@ -489,7 +489,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
else
|
||||
output = '*Groups:*\n' .. output
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -515,10 +515,10 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
end
|
||||
if doc then
|
||||
local output = '*Help for* _' .. input .. '_ :\n```\n' .. doc .. '\n```'
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
else
|
||||
local output = 'Sorry, there is no help for that command.\n/ahelp@'..self.info.username
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
end
|
||||
else
|
||||
local output = '*Commands for ' .. administration.ranks[rank] .. ':*\n'
|
||||
@ -528,12 +528,12 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
end
|
||||
end
|
||||
output = output .. 'Arguments: <required> \\[optional]'
|
||||
if bindings.sendMessage(self, msg.from.id, output, true, nil, true) then
|
||||
if utilities.send_message(self, msg.from.id, output, true, nil, true) then
|
||||
if msg.from.id ~= msg.chat.id then
|
||||
bindings.sendReply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
end
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -564,7 +564,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if output == '\n\n' then
|
||||
output = 'There are currently no moderators for this group.'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
},
|
||||
@ -579,12 +579,12 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
|
||||
action = function(self, msg)
|
||||
local output = administration.get_desc(self, msg.chat.id)
|
||||
if bindings.sendMessage(self, msg.from.id, output, true, nil, true) then
|
||||
if utilities.send_message(self, msg.from.id, output, true, nil, true) then
|
||||
if msg.from.id ~= msg.chat.id then
|
||||
bindings.sendReply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
end
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -613,7 +613,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
else
|
||||
output = 'No rules have been set for ' .. msg.chat.title .. '.'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -630,7 +630,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if group.motd then
|
||||
output = '*MOTD for ' .. msg.chat.title .. ':*\n' .. group.motd
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -647,7 +647,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if group.link then
|
||||
output = '[' .. msg.chat.title .. '](' .. group.link .. ')'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -661,11 +661,11 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
|
||||
action = function(self, msg)
|
||||
if administration.get_rank(self, msg.from.id) == 5 then
|
||||
bindings.sendReply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.')
|
||||
utilities.send_reply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.')
|
||||
else
|
||||
administration.kick_user(self, msg.chat.id, msg.from.id, 'kickme')
|
||||
if msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -682,14 +682,14 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank > 1 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is too privileged to be kicked.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is too privileged to be kicked.')
|
||||
else
|
||||
administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. msg.from.name)
|
||||
bindings.sendMessage(self, msg.chat.id, target.name .. ' has been kicked.')
|
||||
utilities.send_message(self, msg.chat.id, target.name .. ' has been kicked.')
|
||||
if msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, msg.chat.id, target.id)
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = target.id } )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -706,14 +706,14 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank > 1 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is too privileged to be banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is too privileged to be banned.')
|
||||
elseif group.bans[target.id_str] then
|
||||
bindings.sendReply(self, msg, target.name .. ' is already banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is already banned.')
|
||||
else
|
||||
administration.kick_user(self, msg.chat.id, target.id, ' banned by '..msg.from.name)
|
||||
bindings.sendReply(self, msg, target.name .. ' has been banned.')
|
||||
administration.kick_user(self, msg.chat.id, target.id, 'banned by '..msg.from.name)
|
||||
utilities.send_reply(self, msg, target.name .. ' has been banned.')
|
||||
group.bans[target.id_str] = true
|
||||
end
|
||||
end
|
||||
@ -730,16 +730,16 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
else
|
||||
if not group.bans[target.id_str] then
|
||||
bindings.sendReply(self, msg, target.name .. ' is not banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is not banned.')
|
||||
else
|
||||
group.bans[target.id_str] = nil
|
||||
bindings.sendReply(self, msg, target.name .. ' has been unbanned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' has been unbanned.')
|
||||
end
|
||||
if msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, msg.chat.id, target.id)
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = target.id } )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -757,7 +757,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
local input = msg.text:match('^/setrules[@'..self.info.username..']*(.+)')
|
||||
if input == ' --' or input == ' ' .. utilities.char.em_dash then
|
||||
group.rules = {}
|
||||
bindings.sendReply(self, msg, 'The rules have been cleared.')
|
||||
utilities.send_reply(self, msg, 'The rules have been cleared.')
|
||||
elseif input then
|
||||
group.rules = {}
|
||||
input = utilities.trim(input) .. '\n'
|
||||
@ -768,9 +768,9 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
i = i + 1
|
||||
table.insert(group.rules, utilities.trim(l))
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
else
|
||||
bindings.sendReply(self, msg, 'Please specify the new rules.')
|
||||
utilities.send_reply(self, msg, 'Please specify the new rules.')
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -808,7 +808,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
output = '*' .. rule_num .. '*. ' .. new_rule
|
||||
end
|
||||
end
|
||||
bindings.sendReply(self, msg, output, true)
|
||||
utilities.send_reply(self, msg, output, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -828,18 +828,18 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
if input then
|
||||
if input == '--' or input == utilities.char.em_dash then
|
||||
group.motd = nil
|
||||
bindings.sendReply(self, msg, 'The MOTD has been cleared.')
|
||||
utilities.send_reply(self, msg, 'The MOTD has been cleared.')
|
||||
else
|
||||
input = utilities.trim(input)
|
||||
group.motd = input
|
||||
local output = '*MOTD for ' .. msg.chat.title .. ':*\n' .. input
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
administration.update_desc(self, msg.chat.id)
|
||||
end
|
||||
else
|
||||
bindings.sendReply(self, msg, 'Please specify the new message of the day.')
|
||||
utilities.send_reply(self, msg, 'Please specify the new message of the day.')
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -856,13 +856,13 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
local input = utilities.input(msg.text)
|
||||
if input == '--' or input == utilities.char.em_dash then
|
||||
group.link = drua.export_link(msg.chat.id)
|
||||
bindings.sendReply(self, msg, 'The link has been regenerated.')
|
||||
utilities.send_reply(self, msg, 'The link has been regenerated.')
|
||||
elseif input then
|
||||
group.link = input
|
||||
local output = '[' .. msg.chat.title .. '](' .. input .. ')'
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
else
|
||||
bindings.sendReply(self, msg, 'Please specify the new link.')
|
||||
utilities.send_reply(self, msg, 'Please specify the new link.')
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -881,7 +881,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
for id,_ in pairs(self.database.administration.admins) do
|
||||
output = output .. administration.mod_format(self, id)
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -906,13 +906,13 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
local status = group.flags[i] or false
|
||||
output = output .. '`[' .. i .. ']` *' .. v.name .. '*` = ' .. tostring(status) .. '`\n• ' .. v.desc .. '\n'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
elseif group.flags[input] == true then
|
||||
group.flags[input] = false
|
||||
bindings.sendReply(self, msg, administration.flags[input].disabled)
|
||||
utilities.send_reply(self, msg, administration.flags[input].disabled)
|
||||
else
|
||||
group.flags[input] = true
|
||||
bindings.sendReply(self, msg, administration.flags[input].enabled)
|
||||
utilities.send_reply(self, msg, administration.flags[input].enabled)
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -927,7 +927,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
|
||||
action = function(self, msg, group)
|
||||
if not group.flags[5] then
|
||||
bindings.sendMessage(self, msg.chat.id, 'antiflood is not enabled. Use `/flag 5` to enable it.', true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, 'antiflood is not enabled. Use `/flag 5` to enable it.', true, nil, true)
|
||||
else
|
||||
if not group.antiflood then
|
||||
group.antiflood = JSON.decode(JSON.encode(administration.antiflood))
|
||||
@ -952,7 +952,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
end
|
||||
output = output .. 'Users will be banned automatically after *' .. group.autoban .. '* autokicks. Configure this with the *autoban* keyword.'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -968,14 +968,14 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
else
|
||||
if target.rank > 1 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is already a moderator or greater.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is already a moderator or greater.')
|
||||
else
|
||||
group.bans[target.id_str] = nil
|
||||
group.mods[target.id_str] = true
|
||||
bindings.sendReply(self, msg, target.name .. ' is now a moderator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is now a moderator.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 2)
|
||||
@ -995,13 +995,13 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
else
|
||||
if not group.mods[target.id_str] then
|
||||
bindings.sendReply(self, msg, target.name .. ' is not a moderator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is not a moderator.')
|
||||
else
|
||||
group.mods[target.id_str] = nil
|
||||
bindings.sendReply(self, msg, target.name .. ' is no longer a moderator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is no longer a moderator.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
||||
@ -1021,15 +1021,15 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
else
|
||||
if group.governor == target.id then
|
||||
bindings.sendReply(self, msg, target.name .. ' is already the governor.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is already the governor.')
|
||||
else
|
||||
group.bans[target.id_str] = nil
|
||||
group.mods[target.id_str] = nil
|
||||
group.governor = target.id
|
||||
bindings.sendReply(self, msg, target.name .. ' is the new governor.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is the new governor.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 2)
|
||||
@ -1050,13 +1050,13 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
else
|
||||
if group.governor ~= target.id then
|
||||
bindings.sendReply(self, msg, target.name .. ' is not the governor.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is not the governor.')
|
||||
else
|
||||
group.governor = msg.from.id
|
||||
bindings.sendReply(self, msg, target.name .. ' is no longer the governor.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is no longer the governor.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
||||
@ -1077,11 +1077,11 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank > 3 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is too privileged to be globally banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is too privileged to be globally banned.')
|
||||
elseif self.database.blacklist[target.id_str] then
|
||||
bindings.sendReply(self, msg, target.name .. ' is already globally banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is already globally banned.')
|
||||
else
|
||||
administration.kick_user(self, msg.chat.id, target.id, 'hammered by '..msg.from.name)
|
||||
self.database.blacklist[target.id_str] = true
|
||||
@ -1097,7 +1097,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
group.bans[target.id_str] = true
|
||||
output = target.name .. ' has been globally and locally banned.'
|
||||
end
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -1110,15 +1110,18 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
interior = false,
|
||||
doc = 'Removes a global ban. The target may be specified via reply, username, or ID.',
|
||||
|
||||
action = function(self, msg, group)
|
||||
action = function(self, msg)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif not self.database.blacklist[target.id_str] then
|
||||
bindings.sendReply(self, msg, target.name .. ' is not globally banned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is not globally banned.')
|
||||
else
|
||||
self.database.blacklist[target.id_str] = nil
|
||||
bindings.sendReply(self, msg, target.name .. ' has been globally unbanned.')
|
||||
utilities.send_reply(self, msg, target.name .. ' has been globally unbanned.')
|
||||
end
|
||||
if msg.chat.type == 'supergroup' then
|
||||
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = target.id } )
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -1131,18 +1134,18 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
interior = false,
|
||||
doc = 'Promotes a user to an administrator. The target may be specified via reply, username, or ID.',
|
||||
|
||||
action = function(self, msg)
|
||||
action = function(self, msg, group)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank >= 4 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is already an administrator or greater.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is already an administrator or greater.')
|
||||
else
|
||||
for _,group in pairs(self.database.administration.groups) do
|
||||
group.mods[target.id_str] = nil
|
||||
for _,g in pairs(self.database.administration.groups) do
|
||||
g.mods[target.id_str] = nil
|
||||
end
|
||||
self.database.administration.admins[target.id_str] = true
|
||||
bindings.sendReply(self, msg, target.name .. ' is now an administrator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is now an administrator.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 2)
|
||||
@ -1161,12 +1164,12 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank ~= 4 then
|
||||
bindings.sendReply(self, msg, target.name .. ' is not an administrator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is not an administrator.')
|
||||
else
|
||||
self.database.administration.admins[target.id_str] = nil
|
||||
bindings.sendReply(self, msg, target.name .. ' is no longer an administrator.')
|
||||
utilities.send_reply(self, msg, target.name .. ' is no longer an administrator.')
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -1181,7 +1184,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
|
||||
action = function(self, msg)
|
||||
if self.database.administration.groups[msg.chat.id_str] then
|
||||
bindings.sendReply(self, msg, 'I am already administrating this group.')
|
||||
utilities.send_reply(self, msg, 'I am already administrating this group.')
|
||||
else
|
||||
self.database.administration.groups[msg.chat.id_str] = {
|
||||
mods = {},
|
||||
@ -1202,7 +1205,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
self.database.administration.groups[msg.chat.id_str].flags[i] = false
|
||||
end
|
||||
table.insert(self.database.administration.activity, msg.chat.id_str)
|
||||
bindings.sendReply(self, msg, 'I am now administrating this group.')
|
||||
utilities.send_reply(self, msg, 'I am now administrating this group.')
|
||||
drua.channel_set_admin(msg.chat.id, self.info.id, 2)
|
||||
end
|
||||
end
|
||||
@ -1235,7 +1238,7 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
output = 'I do not administrate that group.'
|
||||
end
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -1260,9 +1263,9 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
else
|
||||
output = 'There are no groups.'
|
||||
end
|
||||
if bindings.sendMessage(self, msg.from.id, output, true, nil, true) then
|
||||
if utilities.send_message(self, msg.from.id, output, true, nil, true) then
|
||||
if msg.from.id ~= msg.chat.id then
|
||||
bindings.sendReply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1279,11 +1282,11 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
action = function(self, msg)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
bindings.sendReply(self, msg, 'Give me something to broadcast.')
|
||||
utilities.send_reply(self, msg, 'Give me something to broadcast.')
|
||||
else
|
||||
input = '*Admin Broadcast:*\n' .. input
|
||||
for id,_ in pairs(self.database.administration.groups) do
|
||||
bindings.sendMessage(self, id, input, true, nil, true)
|
||||
utilities.send_message(self, id, input, true, nil, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
-- Credit to Heitor (tg:Wololo666; gh:heitorPB) for this plugin.
|
||||
|
||||
local apod = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
local JSON = require('dkjson')
|
||||
local URL = require('socket.url')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
apod.command = 'apod [date]'
|
||||
@ -40,7 +41,7 @@ function apod:action(msg)
|
||||
url = url .. '&date=' .. URL.escape(input)
|
||||
date = date .. input
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, apod.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, apod.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
else
|
||||
@ -51,14 +52,14 @@ function apod:action(msg)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
if jdat.error then
|
||||
bindings.sendReply(msg, self.config.errors.results)
|
||||
utilities.send_reply(msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -79,7 +80,7 @@ function apod:action(msg)
|
||||
output = output .. '\nCopyright: ' .. jdat.copyright
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, disable_page_preview, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, disable_page_preview, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local bandersnatch = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
bandersnatch.command = 'bandersnatch'
|
||||
@ -29,7 +28,7 @@ function bandersnatch:action(msg)
|
||||
output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, '_'..output..'_', true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, '_'..output..'_', true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,6 @@ local bible = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function bible:init()
|
||||
@ -26,7 +25,7 @@ function bible:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, bible.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, bible.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -47,7 +46,7 @@ function bible:action(msg)
|
||||
output = 'The text is too long to post here. Try being more specific.'
|
||||
end
|
||||
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
|
||||
end
|
||||
|
||||
|
70
plugins/bing.lua
Normal file
70
plugins/bing.lua
Normal file
@ -0,0 +1,70 @@
|
||||
-- Credit to Juan (tg:JuanPotato; gh:JuanPotato) for this plugin.
|
||||
-- Or rather, the seven lines that actually mean anything.
|
||||
|
||||
local bing = {}
|
||||
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local mime = require('mime')
|
||||
local https = require('ssl.https')
|
||||
local ltn12 = require('ltn12')
|
||||
local utilities = require('utilities')
|
||||
|
||||
bing.command = 'bing <query>'
|
||||
bing.doc = [[```
|
||||
/bing <query>
|
||||
Returns the top web search results from Bing.
|
||||
Aliases: /g, /google
|
||||
```]]
|
||||
|
||||
bing.search_url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query=\'%s\'&$format=json'
|
||||
|
||||
function bing:init()
|
||||
if not self.config.bing_api_key then
|
||||
print('Missing config value: bing_api_key.')
|
||||
print('bing.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
bing.triggers = utilities.triggers(self.info.username):t('bing', true):t('g', true):t('google', true).table
|
||||
end
|
||||
|
||||
function bing:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
if msg.reply_to_message and msg.reply_to_message.text ~= '' then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
utilities.send_reply(self, msg, bing.doc, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
local url = bing.search_url:format(URL.escape(input))
|
||||
local resbody = {}
|
||||
local _,b,_ = https.request{
|
||||
url = url,
|
||||
headers = { ["Authorization"] = "Basic " .. mime.b64(":" .. self.config.bing_api_key) },
|
||||
sink = ltn12.sink.table(resbody),
|
||||
}
|
||||
if b ~= 200 then
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
local dat = JSON.decode(table.concat(resbody))
|
||||
local limit = 4
|
||||
if msg.chat.type == 'private' then
|
||||
limit = 8
|
||||
end
|
||||
if limit > #dat.d.results then
|
||||
limit = #dat.d.results
|
||||
end
|
||||
local reslist = {}
|
||||
for i = 1, limit do
|
||||
local result = dat.d.results[i]
|
||||
local s = '• [' .. result.Title:gsub('%]', '\\]') .. '](' .. result.Url:gsub('%)', '\\)') .. ')'
|
||||
table.insert(reslist, s)
|
||||
end
|
||||
local output = '*Search results for* _' .. utilities.md_escape(input) .. '_ *:*\n' .. table.concat(reslist, '\n')
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
return bing
|
@ -3,7 +3,6 @@
|
||||
|
||||
local blacklist = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function blacklist:init()
|
||||
@ -25,7 +24,7 @@ function blacklist:action(msg)
|
||||
|
||||
local target = utilities.user_from_message(self, msg)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
return
|
||||
end
|
||||
|
||||
@ -35,10 +34,10 @@ function blacklist:action(msg)
|
||||
|
||||
if self.database.blacklist[tostring(target.id)] then
|
||||
self.database.blacklist[tostring(target.id)] = nil
|
||||
bindings.sendReply(self, msg, target.name .. ' has been removed from the blacklist.')
|
||||
utilities.send_reply(self, msg, target.name .. ' has been removed from the blacklist.')
|
||||
else
|
||||
self.database.blacklist[tostring(target.id)] = true
|
||||
bindings.sendReply(self, msg, target.name .. ' has been added to the blacklist.')
|
||||
utilities.send_reply(self, msg, target.name .. ' has been added to the blacklist.')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,7 +2,6 @@ local calc = {}
|
||||
|
||||
local URL = require('socket.url')
|
||||
local HTTPS = require('ssl.https')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
calc.command = 'calc <expression>'
|
||||
@ -22,7 +21,7 @@ function calc:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, calc.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, calc.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -31,13 +30,13 @@ function calc:action(msg)
|
||||
|
||||
local output = HTTPS.request(url)
|
||||
if not output then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
output = '`' .. output .. '`'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
local cats = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function cats:init()
|
||||
@ -25,14 +24,14 @@ function cats:action(msg)
|
||||
|
||||
local str, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(msg, self.config.errors.connection)
|
||||
utilities.send_reply(msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
str = str:match('<img src="(.-)">')
|
||||
local output = '[Cat!]('..str..')'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
65
plugins/channel.lua
Normal file
65
plugins/channel.lua
Normal file
@ -0,0 +1,65 @@
|
||||
local channel = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
--channel.command = 'ch <channel> \\n <message>'
|
||||
channel.doc = [[```
|
||||
/ch <channel>
|
||||
<message>
|
||||
|
||||
Sends a message to a channel. Channel may be specified via ID or username. Messages are markdown-enabled. Users may only send messages to channels for which they are the owner or an administrator.
|
||||
|
||||
The following markdown syntax is supported:
|
||||
*bold text*
|
||||
_italic text_
|
||||
[text](URL)
|
||||
`inline fixed-width code`
|
||||
```pre-formatted fixed-width code block```
|
||||
|
||||
Due to the frequent dysfunction and incompletion of the API method used to determine the administrators of a channel, this command may not work for the owners of some channels.
|
||||
```]]
|
||||
|
||||
function channel:init()
|
||||
channel.triggers = utilities.triggers(self.info.username):t('ch', true).table
|
||||
end
|
||||
|
||||
function channel:action(msg)
|
||||
-- An exercise in using zero early returns. :)
|
||||
local input = utilities.input(msg.text)
|
||||
local output
|
||||
if input then
|
||||
local chat_id = utilities.get_word(input, 1)
|
||||
local admin_list, t = bindings.getChatAdministrators(self, { chat_id = chat_id } )
|
||||
if admin_list then
|
||||
local is_admin = false
|
||||
for _, admin in ipairs(admin_list.result) do
|
||||
if admin.user.id == msg.from.id then
|
||||
is_admin = true
|
||||
end
|
||||
end
|
||||
if is_admin then
|
||||
local text = input:match('\n(.+)')
|
||||
if text then
|
||||
local success, result = utilities.send_message(self, chat_id, text, true, nil, true)
|
||||
if success then
|
||||
output = 'Your message has been sent!'
|
||||
else
|
||||
output = 'Sorry, I was unable to send your message.\n`' .. result.description .. '`'
|
||||
end
|
||||
else
|
||||
output = 'Please enter a message to be sent. Markdown is supported.'
|
||||
end
|
||||
else
|
||||
output = 'Sorry, you do not appear to be an administrator for that channel.\nThere is currently a known bug in the getChatAdministrators method, where administrator lists will often not show a channel\'s owner.'
|
||||
end
|
||||
else
|
||||
output = 'Sorry, I was unable to retrieve a list of administrators for that channel.\n`' .. t.description .. '`'
|
||||
end
|
||||
else
|
||||
output = channel.doc
|
||||
end
|
||||
utilities.send_reply(self, msg, output, true)
|
||||
end
|
||||
|
||||
return channel
|
@ -6,6 +6,7 @@ local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function chatter:init()
|
||||
if not self.config.simsimi_key then
|
||||
@ -37,7 +38,7 @@ function chatter:action(msg)
|
||||
return true
|
||||
end
|
||||
|
||||
bindings.sendChatAction(self, msg.chat.id, 'typing')
|
||||
bindings.sendChatAction(self, { action = 'typing' } )
|
||||
|
||||
local input = msg.text_lower
|
||||
input = input:gsub(self.info.first_name, 'simsimi')
|
||||
@ -54,13 +55,13 @@ function chatter:action(msg)
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendMessage(self, msg.chat.id, self.config.errors.chatter_connection)
|
||||
utilities.send_message(self, msg.chat.id, self.config.errors.chatter_connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if not jdat.response then
|
||||
bindings.sendMessage(self, msg.chat.id, self.config.errors.chatter_response)
|
||||
utilities.send_message(self, msg.chat.id, self.config.errors.chatter_response)
|
||||
return
|
||||
end
|
||||
local output = jdat.response
|
||||
@ -85,7 +86,7 @@ function chatter:action(msg)
|
||||
output = output .. '.'
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
local commit = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
commit.command = 'commit'
|
||||
@ -424,7 +423,7 @@ local commits = {
|
||||
function commit:action(msg)
|
||||
|
||||
local output = '`'..commits[math.random(#commits)]..'`'
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
local control = {}
|
||||
|
||||
local bot = require('bot')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function control:init()
|
||||
@ -27,14 +26,14 @@ function control:action(msg)
|
||||
package.loaded['config'] = nil
|
||||
end
|
||||
bot.init(self)
|
||||
bindings.sendReply(self, msg, 'Bot reloaded!')
|
||||
utilities.send_reply(self, msg, 'Bot reloaded!')
|
||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
||||
self.is_started = false
|
||||
bindings.sendReply(self, msg, 'Stopping bot!')
|
||||
utilities.send_reply(self, msg, 'Stopping bot!')
|
||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'script') then
|
||||
local input = msg.text:match('^'..utilities.INVOCATION_PATTERN..'script\n(.+)')
|
||||
if not input then
|
||||
bindings.sendReply(self, msg, 'usage: ```\n/script\n/command <arg>\n...\n```', true)
|
||||
utilities.send_reply(self, msg, 'usage: ```\n/script\n/command <arg>\n...\n```', true)
|
||||
return
|
||||
end
|
||||
input = input .. '\n'
|
||||
|
@ -1,7 +1,6 @@
|
||||
local currency = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
currency.command = 'cash [amount] <from> to <to>'
|
||||
@ -20,7 +19,7 @@ function currency:action(msg)
|
||||
|
||||
local input = msg.text:upper()
|
||||
if not input:match('%a%a%a TO %a%a%a') then
|
||||
bindings.sendMessage(self, msg.chat.id, currency.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, currency.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -37,13 +36,13 @@ function currency:action(msg)
|
||||
url = url .. '?from=' .. from .. '&to=' .. to .. '&a=' .. amount
|
||||
local str, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
str = str:match('<span class=bld>(.*) %u+</span>')
|
||||
if not str then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -55,7 +54,7 @@ function currency:action(msg)
|
||||
output = output .. os.date('!%F %T UTC') .. '\nSource: Google Finance`'
|
||||
output = '```\n' .. output .. '\n```'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local dice = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
dice.command = 'roll <nDr>'
|
||||
@ -17,7 +16,7 @@ function dice:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text_lower)
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, dice.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, dice.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -28,7 +27,7 @@ function dice:action(msg)
|
||||
count = 1
|
||||
range = input:match('^d?([%d]+)$')
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, dice.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, dice.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -36,11 +35,11 @@ function dice:action(msg)
|
||||
range = tonumber(range)
|
||||
|
||||
if range < 2 then
|
||||
bindings.sendReply(self, msg, 'The minimum range is 2.')
|
||||
utilities.send_reply(self, msg, 'The minimum range is 2.')
|
||||
return
|
||||
end
|
||||
if range > 1000 or count > 1000 then
|
||||
bindings.sendReply(self, msg, 'The maximum range and count are 1000.')
|
||||
utilities.send_reply(self, msg, 'The maximum range and count are 1000.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -50,7 +49,7 @@ function dice:action(msg)
|
||||
end
|
||||
output = output .. '`'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ end
|
||||
|
||||
function dilbert:action(msg)
|
||||
|
||||
bindings.sendChatAction(self, msg.chat.id, 'upload_photo')
|
||||
bindings.sendChatAction(self, { chat_id = msg.chat.id, action = 'upload_photo' } )
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then input = os.date('%F') end
|
||||
@ -28,7 +28,7 @@ function dilbert:action(msg)
|
||||
local url = 'http://dilbert.com/strip/' .. URL.escape(input)
|
||||
local str, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -44,7 +44,7 @@ function dilbert:action(msg)
|
||||
|
||||
local strip_title = str:match('<meta property="article:publish_date" content="(.-)"/>')
|
||||
|
||||
bindings.sendPhoto(self, msg.chat.id, strip_file, strip_title)
|
||||
bindings.sendPhoto(self, { chat_id = msg.chat.id, caption = strip_title }, { photo = strip_file } )
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local echo = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
echo.command = 'echo <text>'
|
||||
@ -18,7 +17,7 @@ function echo:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, echo.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, echo.doc, true, msg.message_id, true)
|
||||
else
|
||||
local output
|
||||
if msg.chat.type == 'supergroup' then
|
||||
@ -26,7 +25,7 @@ function echo:action(msg)
|
||||
else
|
||||
output = utilities.md_escape(utilities.char.zwnj..input)
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local eightball = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
eightball.command = '8ball'
|
||||
@ -51,7 +50,7 @@ function eightball:action(msg)
|
||||
output = ball_answers[math.random(#ball_answers)]
|
||||
end
|
||||
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
-- Liberbot-compliant floodcontrol.
|
||||
-- Put this after moderation.lua or blacklist.lua.
|
||||
|
||||
local floodcontrol = {}
|
||||
|
||||
local JSON = require('dkjson')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function floodcontrol:init()
|
||||
self.floodcontrol = self.floodcontrol or {}
|
||||
end
|
||||
|
||||
floodcontrol.triggers = {
|
||||
''
|
||||
}
|
||||
|
||||
function floodcontrol:action(msg)
|
||||
|
||||
if self.floodcontrol[-msg.chat.id] then
|
||||
return
|
||||
end
|
||||
|
||||
local input = msg.text_lower:match('^/floodcontrol (.+)') or msg.text_lower:match('^/floodcontrol@'..self.info.username..' (.+)')
|
||||
if not input then return true end
|
||||
|
||||
if msg.from.id ~= 100547061 and msg.from.id ~= self.config.admin then
|
||||
return -- Only run for Liberbot or the admin.
|
||||
end
|
||||
|
||||
input = JSON.decode(input)
|
||||
|
||||
if not input.groupid then
|
||||
return
|
||||
end
|
||||
if not input.duration then
|
||||
input.duration = 600
|
||||
end
|
||||
|
||||
self.floodcontrol[input.groupid] = os.time() + input.duration
|
||||
|
||||
local output = input.groupid .. ' silenced for ' .. input.duration .. ' seconds.'
|
||||
utilities.handle_exception(self, 'floodcontrol.lua', output)
|
||||
|
||||
end
|
||||
|
||||
function floodcontrol:cron()
|
||||
|
||||
for k,v in pairs(self.floodcontrol) do
|
||||
if os.time() > v then
|
||||
self.floodcontrol[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return floodcontrol
|
@ -2,7 +2,6 @@
|
||||
|
||||
local fortune = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function fortune:init()
|
||||
@ -24,7 +23,7 @@ function fortune:action(msg)
|
||||
local fortunef = io.popen('fortune')
|
||||
local output = fortunef:read('*all')
|
||||
output = '```\n' .. output .. '\n```'
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
fortunef:close()
|
||||
|
||||
end
|
||||
|
@ -6,7 +6,6 @@ local gImages = {}
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function gImages:init()
|
||||
@ -37,7 +36,7 @@ function gImages:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, gImages.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, gImages.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -52,13 +51,13 @@ function gImages:action(msg)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.searchInformation.totalResults == '0' then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -69,9 +68,9 @@ function gImages:action(msg)
|
||||
|
||||
|
||||
if msg.text:match('nsfw') then
|
||||
bindings.sendReply(self, '*NSFW*\n'..msg, output)
|
||||
utilities.send_reply(self, '*NSFW*\n'..msg, output)
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,18 +21,23 @@ function gMaps:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, gMaps.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, gMaps.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local coords = utilities.get_coords(self, input)
|
||||
if type(coords) == 'string' then
|
||||
bindings.sendReply(self, msg, coords)
|
||||
utilities.send_reply(self, msg, coords)
|
||||
return
|
||||
end
|
||||
|
||||
bindings.sendLocation(self, msg.chat.id, coords.lat, coords.lon, msg.message_id)
|
||||
bindings.sendLocation(self, {
|
||||
chat_id = msg.chat.id,
|
||||
latitude = coords.lat,
|
||||
longitude = coords.lon,
|
||||
reply_to_message_id = msg.message_id
|
||||
} )
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@ local gSearch = {}
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
gSearch.command = 'google <query>'
|
||||
@ -24,7 +23,7 @@ function gSearch:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, gSearch.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, gSearch.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -45,17 +44,17 @@ function gSearch:action(msg)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if not jdat.responseData then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
if not jdat.responseData.results[1] then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -67,15 +66,15 @@ function gSearch:action(msg)
|
||||
title = title:sub(1, 45) .. '...'
|
||||
end
|
||||
]]--
|
||||
local url = jdat.responseData.results[i].unescapedUrl
|
||||
if url:find('%)') then
|
||||
output = output .. '• ' .. title .. '\n' .. url:gsub('_', '\\_') .. '\n'
|
||||
local u = jdat.responseData.results[i].unescapedUrl
|
||||
if u:find('%)') then
|
||||
output = output .. '• ' .. title .. '\n' .. u:gsub('_', '\\_') .. '\n'
|
||||
else
|
||||
output = output .. '• [' .. title .. '](' .. url .. ')\n'
|
||||
output = output .. '• [' .. title .. '](' .. u .. ')\n'
|
||||
end
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
local greetings = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function greetings:init()
|
||||
@ -49,7 +48,7 @@ function greetings:action(msg)
|
||||
for trigger,responses in pairs(self.config.greetings) do
|
||||
for _,response in pairs(responses) do
|
||||
if msg.text_lower:match(response..',? '..self.info.first_name:lower()) then
|
||||
bindings.sendMessage(self, msg.chat.id, utilities.latcyr(trigger:gsub('#NAME', nick)))
|
||||
utilities.send_message(self, msg.chat.id, utilities.latcyr(trigger:gsub('#NAME', nick)))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -17,11 +17,11 @@ end
|
||||
|
||||
function hackernews:action(msg)
|
||||
|
||||
bindings.sendChatAction(self, msg.chat.id, 'typing')
|
||||
bindings.sendChatAction(self, { chat_id = msg.chat.id, action = 'typing' } )
|
||||
|
||||
local jstr, res = HTTPS.request('https://hacker-news.firebaseio.com/v0/topstories.json')
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -37,7 +37,7 @@ function hackernews:action(msg)
|
||||
local res_url = 'https://hacker-news.firebaseio.com/v0/item/' .. jdat[i] .. '.json'
|
||||
jstr, res = HTTPS.request(res_url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
local res_jdat = JSON.decode(jstr)
|
||||
@ -47,7 +47,7 @@ function hackernews:action(msg)
|
||||
end
|
||||
local url = res_jdat.url
|
||||
if not url then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
if url:find('%(') then
|
||||
@ -58,7 +58,7 @@ function hackernews:action(msg)
|
||||
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
local hearthstone = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
--local HTTPS = require('ssl.https')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function hearthstone:init()
|
||||
@ -79,7 +78,7 @@ local function format_card(card)
|
||||
end
|
||||
|
||||
-- unused?
|
||||
local info = ''
|
||||
local info
|
||||
if card.text then
|
||||
info = card.text:gsub('</?.->',''):gsub('%$','')
|
||||
if card.flavor then
|
||||
@ -107,7 +106,7 @@ function hearthstone:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text_lower)
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, hearthstone.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, hearthstone.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -120,11 +119,11 @@ function hearthstone:action(msg)
|
||||
|
||||
output = utilities.trim(output)
|
||||
if output:len() == 0 then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
local help = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
local help_text
|
||||
@ -38,11 +37,11 @@ function help:action(msg)
|
||||
-- Attempts to send the help message via PM.
|
||||
-- If msg is from a group, it tells the group whether the PM was successful.
|
||||
if not input then
|
||||
local res = bindings.sendMessage(self, msg.from.id, help_text, true, nil, true)
|
||||
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
|
||||
if not res then
|
||||
bindings.sendReply(self, msg, 'Please message me privately for a list of commands.')
|
||||
utilities.send_reply(self, msg, 'Please message me privately for a list of commands.')
|
||||
elseif msg.chat.type ~= 'private' then
|
||||
bindings.sendReply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -50,12 +49,12 @@ function help:action(msg)
|
||||
for _,plugin in ipairs(self.plugins) do
|
||||
if plugin.command and utilities.get_word(plugin.command, 1) == input and plugin.doc then
|
||||
local output = '*Help for* _' .. utilities.get_word(plugin.command, 1) .. '_ *:*\n' .. plugin.doc
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
bindings.sendReply(self, msg, 'Sorry, there is no help for that command.')
|
||||
utilities.send_reply(self, msg, 'Sorry, there is no help for that command.')
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@ local imdb = {}
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
imdb.command = 'imdb <query>'
|
||||
@ -23,7 +22,7 @@ function imdb:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, imdb.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, imdb.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -32,14 +31,14 @@ function imdb:action(msg)
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
if jdat.Response ~= 'True' then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -48,7 +47,7 @@ function imdb:action(msg)
|
||||
output = output .. '_' .. jdat.Plot .. '_\n'
|
||||
output = output .. '[Read more.](http://imdb.com/title/' .. jdat.imdbID .. ')'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
-- TODO: Add support for librefm API.
|
||||
-- Just kidding, nobody actually uses that.
|
||||
|
||||
local lastfm = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function lastfm:init()
|
||||
@ -30,17 +32,17 @@ function lastfm:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if string.match(msg.text, '^/lastfm') then
|
||||
bindings.sendMessage(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
return
|
||||
elseif string.match(msg.text, '^/fmset') then
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
elseif input == '--' or input == utilities.char.em_dash then
|
||||
self.database.users[msg.from.id_str].lastfm = nil
|
||||
bindings.sendReply(self, msg, 'Your last.fm username has been forgotten.')
|
||||
utilities.send_reply(self, msg, 'Your last.fm username has been forgotten.')
|
||||
else
|
||||
self.database.users[msg.from.id_str].lastfm = input
|
||||
bindings.sendReply(self, msg, 'Your last.fm username has been set to "' .. input .. '".')
|
||||
utilities.send_reply(self, msg, 'Your last.fm username has been set to "' .. input .. '".')
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -58,7 +60,7 @@ function lastfm:action(msg)
|
||||
alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /fmset <username>.'
|
||||
self.database.users[msg.from.id_str].lastfm = username
|
||||
else
|
||||
bindings.sendReply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
||||
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -70,19 +72,19 @@ function lastfm:action(msg)
|
||||
jstr, res = HTTP.request(url)
|
||||
end)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.error then
|
||||
bindings.sendReply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
||||
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
||||
return
|
||||
end
|
||||
|
||||
jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
|
||||
if not jdat then
|
||||
bindings.sendReply(self, msg, 'No history for this user.' .. alert)
|
||||
utilities.send_reply(self, msg, 'No history for this user.' .. alert)
|
||||
return
|
||||
end
|
||||
|
||||
@ -102,7 +104,7 @@ function lastfm:action(msg)
|
||||
end
|
||||
|
||||
output = output .. title .. ' - ' .. artist .. alert
|
||||
bindings.sendMessage(self, msg.chat.id, output)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,103 +0,0 @@
|
||||
local librefm = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function librefm:init()
|
||||
if not self.database.librefm then
|
||||
self.database.librefm = {}
|
||||
end
|
||||
|
||||
librefm.triggers = utilities.triggers(self.info.username):t('librefm', true):t('lnp', true):t('lfmset', true)
|
||||
end
|
||||
|
||||
librefm.command = 'librefm'
|
||||
librefm.doc = [[```
|
||||
/lnp [username]
|
||||
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
|
||||
|
||||
/lfmset <username>
|
||||
Sets your libre.fm username. Otherwise, /np will use your Telegram username. Use "/fmset -" to delete it.
|
||||
```]]
|
||||
|
||||
function librefm:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if string.match(msg.text, '^/librefm') then
|
||||
bindings.sendMessage(self, msg.chat.id, librefm.doc, true, msg.message_id, true)
|
||||
return
|
||||
elseif string.match(msg.text, '^/lfmset') then
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, librefm.doc, true, msg.message_id, true)
|
||||
elseif input == '-' then
|
||||
self.database.librefm[msg.from.id_str] = nil
|
||||
bindings.sendReply(self, msg, 'Your libre.fm username has been forgotten.')
|
||||
else
|
||||
self.database.librefm[msg.from.id_str] = input
|
||||
bindings.sendReply(self, msg, 'Your libre.fm username has been set to "' .. input .. '".')
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local url = 'http://alpha.libre.fm/2.0/?method=user.getrecenttracks&format=json&limit=1&api_key=0&user='
|
||||
|
||||
local username
|
||||
local alert = ''
|
||||
if input then
|
||||
username = input
|
||||
elseif self.database.librefm[msg.from.id_str] then
|
||||
username = self.database.librefm[msg.from.id_str]
|
||||
elseif msg.from.username then
|
||||
username = msg.from.username
|
||||
alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /lfmset <username>.'
|
||||
self.database.librefm[msg.from.id_str] = username
|
||||
else
|
||||
bindings.sendReply(self, msg, 'Please specify your libre.fm username or set it with /lfmset.')
|
||||
return
|
||||
end
|
||||
|
||||
url = url .. URL.escape(username)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.error then
|
||||
bindings.sendReply(self, msg, 'Please specify your libre.fm username or set it with /lfmset.')
|
||||
return
|
||||
end
|
||||
|
||||
jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
|
||||
if not jdat then
|
||||
bindings.sendReply(self, msg, 'No history for this user.' .. alert)
|
||||
return
|
||||
end
|
||||
|
||||
local output = input or msg.from.first_name
|
||||
output = '🎵 ' .. output
|
||||
|
||||
if jdat['@attr'] and jdat['@attr'].nowplaying then
|
||||
output = output .. ' is currently listening to:\n'
|
||||
else
|
||||
output = output .. ' last listened to:\n'
|
||||
end
|
||||
|
||||
local title = jdat.name or 'Unknown'
|
||||
local artist = 'Unknown'
|
||||
if jdat.artist then
|
||||
artist = jdat.artist['#text']
|
||||
end
|
||||
|
||||
output = output .. title .. ' - ' .. artist .. alert
|
||||
bindings.sendMessage(self, msg.chat.id, output)
|
||||
|
||||
end
|
||||
|
||||
return librefm
|
@ -1,25 +1,31 @@
|
||||
local luarun = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
|
||||
function luarun:init()
|
||||
luarun.triggers = utilities.triggers(self.info.username):t('lua', true).table
|
||||
luarun.triggers = utilities.triggers(self.info.username):t('lua', true):t('return', true).table
|
||||
end
|
||||
|
||||
function luarun:action(msg)
|
||||
|
||||
if msg.from.id ~= self.config.admin then
|
||||
return
|
||||
return true
|
||||
end
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
bindings.sendReply(self, msg, 'Please enter a string to load.')
|
||||
utilities.send_reply(self, msg, 'Please enter a string to load.')
|
||||
return
|
||||
end
|
||||
|
||||
if msg.text_lower:match('^/return') then
|
||||
input = 'return ' .. input
|
||||
end
|
||||
|
||||
local output = loadstring( [[
|
||||
local bot = require('bot')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
local JSON = require('dkjson')
|
||||
@ -31,9 +37,15 @@ function luarun:action(msg)
|
||||
if output == nil then
|
||||
output = 'Done!'
|
||||
else
|
||||
if type(output) == 'table' then
|
||||
local s = JSON.encode(output, {indent=true})
|
||||
if URL.escape(s):len() < 4000 then
|
||||
output = s
|
||||
end
|
||||
end
|
||||
output = '```\n' .. tostring(output) .. '\n```'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local me = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function me:init()
|
||||
@ -14,7 +13,7 @@ function me:action(msg)
|
||||
if msg.from.id == self.config.admin and (msg.reply_to_message or utilities.input(msg.text)) then
|
||||
target = utilities.user_from_message(self, msg, true)
|
||||
if target.err then
|
||||
bindings.sendReply(self, msg, target.err)
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -23,7 +22,7 @@ function me:action(msg)
|
||||
for k,v in pairs(target) do
|
||||
output = output .. '*' .. k .. ':* `' .. tostring(v) .. '`\n'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local nick = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
nick.command = 'nick <nickname>'
|
||||
@ -45,7 +44,7 @@ function nick:action(msg)
|
||||
output = target.name .. '\'s nickname has been set to "' .. input .. '".'
|
||||
end
|
||||
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
local patterns = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
patterns.triggers = {
|
||||
'^/?s/.-/.-/?$'
|
||||
@ -19,11 +19,11 @@ function patterns:action(msg)
|
||||
)
|
||||
if res == false then
|
||||
output = 'Malformed pattern!'
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
return
|
||||
end
|
||||
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"'
|
||||
bindings.sendReply(self, msg.reply_to_message, output)
|
||||
utilities.send_reply(self, msg.reply_to_message, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
local ping = {}
|
||||
|
||||
local utilities = require('utilities')
|
||||
local bindings = require('bindings')
|
||||
|
||||
function ping:init()
|
||||
ping.triggers = utilities.triggers(self.info.username):t('ping'):t('annyong').table
|
||||
@ -11,7 +10,7 @@ end
|
||||
|
||||
function ping:action(msg)
|
||||
local output = msg.text_lower:match('^/ping') and 'Pong!' or 'Annyong.'
|
||||
bindings.sendMessage(self, msg.chat.id, output)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
end
|
||||
|
||||
return ping
|
||||
|
@ -18,12 +18,14 @@ end
|
||||
|
||||
function pokedex:action(msg)
|
||||
|
||||
bindings.sendChatAction(self, { chat_id = msg.chat.id, action = 'typing' } )
|
||||
|
||||
local input = utilities.input(msg.text_lower)
|
||||
if not input then
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, pokedex.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, pokedex.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -33,7 +35,7 @@ function pokedex:action(msg)
|
||||
local dex_url = url .. '/api/v1/pokemon/' .. input
|
||||
local dex_jstr, res = HTTP.request(dex_url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -42,7 +44,7 @@ function pokedex:action(msg)
|
||||
local desc_url = url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri
|
||||
local desc_jstr, _ = HTTP.request(desc_url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -62,7 +64,7 @@ function pokedex:action(msg)
|
||||
local output = '*' .. dex_jdat.name .. '*\n#' .. dex_jdat.national_id .. ' | ' .. poke_type .. '\n_' .. desc_jdat.description:gsub('POKMON', 'Pokémon'):gsub('Pokmon', 'Pokémon') .. '_'
|
||||
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
local preview = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
preview.command = 'preview <link>'
|
||||
@ -19,7 +18,7 @@ function preview:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, preview.doc, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, preview.doc, true, nil, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -30,18 +29,18 @@ function preview:action(msg)
|
||||
|
||||
local res = HTTP.request(input)
|
||||
if not res then
|
||||
bindings.sendReply(self, msg, 'Please provide a valid link.')
|
||||
utilities.send_reply(self, msg, 'Please provide a valid link.')
|
||||
return
|
||||
end
|
||||
|
||||
if res:len() == 0 then
|
||||
bindings.sendReply(self, msg, 'Sorry, the link you provided is not letting us make a preview.')
|
||||
utilities.send_reply(self, msg, 'Sorry, the link you provided is not letting us make a preview.')
|
||||
return
|
||||
end
|
||||
|
||||
-- Invisible zero-width, non-joiner.
|
||||
local output = '[](' .. input .. ')'
|
||||
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local pun = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
pun.command = 'pun'
|
||||
@ -138,7 +137,7 @@ local puns = {
|
||||
|
||||
function pun:action(msg)
|
||||
|
||||
bindings.sendReply(self, msg, puns[math.random(#puns)])
|
||||
utilities.send_reply(self, msg, puns[math.random(#puns)])
|
||||
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
local reactions = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
reactions.command = 'reactions'
|
||||
@ -39,12 +38,12 @@ end
|
||||
|
||||
function reactions:action(msg)
|
||||
if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..'reactions') then
|
||||
bindings.sendMessage(self, msg.chat.id, help)
|
||||
utilities.send_message(self, msg.chat.id, help)
|
||||
return
|
||||
end
|
||||
for trigger,reaction in pairs(mapping) do
|
||||
if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..trigger) then
|
||||
bindings.sendMessage(self, msg.chat.id, reaction)
|
||||
utilities.send_message(self, msg.chat.id, reaction)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,6 @@ local reddit = {}
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
reddit.command = 'reddit [r/subreddit | query]'
|
||||
@ -70,15 +69,15 @@ function reddit:action(msg)
|
||||
end
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
else
|
||||
local jdat = JSON.decode(jstr)
|
||||
if #jdat.data.children == 0 then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
else
|
||||
local output = format_results(jdat.data.children)
|
||||
output = source .. output
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,5 @@
|
||||
local remind = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
remind.command = 'remind <duration> <message>'
|
||||
@ -19,13 +18,13 @@ function remind:action(msg)
|
||||
-- Ensure there are arguments. If not, send doc.
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Ensure first arg is a number. If not, send doc.
|
||||
local duration = utilities.get_word(input, 1)
|
||||
if not tonumber(duration) then
|
||||
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Duration must be between one minute and one year (approximately).
|
||||
@ -38,17 +37,17 @@ function remind:action(msg)
|
||||
-- Ensure there is a second arg.
|
||||
local message = utilities.input(input)
|
||||
if not message then
|
||||
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Make a database entry for the group/user if one does not exist.
|
||||
self.database.reminders[msg.chat.id_str] = self.database.reminders[msg.chat.id_str] or {}
|
||||
-- Limit group reminders to 10 and private reminders to 50.
|
||||
if msg.chat.type ~= 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 9 then
|
||||
bindings.sendReply(self, msg, 'Sorry, this group already has ten reminders.')
|
||||
utilities.send_reply(self, msg, 'Sorry, this group already has ten reminders.')
|
||||
return
|
||||
elseif msg.chat.type == 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 49 then
|
||||
bindings.sendReply(msg, 'Sorry, you already have fifty reminders.')
|
||||
utilities.send_reply(msg, 'Sorry, you already have fifty reminders.')
|
||||
return
|
||||
end
|
||||
-- Put together the reminder with the expiration, message, and message to reply to.
|
||||
@ -63,7 +62,7 @@ function remind:action(msg)
|
||||
else
|
||||
output = output .. ' minutes!'
|
||||
end
|
||||
bindings.sendReply(self, msg, output)
|
||||
utilities.send_reply(self, msg, output)
|
||||
end
|
||||
|
||||
function remind:cron()
|
||||
@ -77,7 +76,7 @@ function remind:cron()
|
||||
-- Otherwise, add it to the replacement table.
|
||||
if time > reminder.time then
|
||||
local output = '*Reminder:*\n"' .. utilities.md_escape(reminder.message) .. '"'
|
||||
local res = bindings.sendMessage(self, chat_id, output, true, nil, true)
|
||||
local res = utilities.send_message(self, chat_id, output, true, nil, true)
|
||||
-- If the message fails to send, save it for later.
|
||||
if not res then
|
||||
table.insert(new_group, reminder)
|
||||
|
@ -1,6 +1,5 @@
|
||||
local setandget = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function setandget:init()
|
||||
@ -25,7 +24,7 @@ function setandget:action(msg)
|
||||
if msg.text_lower:match('^/set') then
|
||||
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, setandget.doc, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -33,13 +32,13 @@ function setandget:action(msg)
|
||||
local value = utilities.input(input)
|
||||
|
||||
if not name or not value then
|
||||
bindings.sendMessage(self, msg.chat.id, setandget.doc, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
||||
elseif value == '--' or value == '—' then
|
||||
self.database.setandget[msg.chat.id_str][name] = nil
|
||||
bindings.sendMessage(self, msg.chat.id, 'That value has been deleted.')
|
||||
utilities.send_message(self, msg.chat.id, 'That value has been deleted.')
|
||||
else
|
||||
self.database.setandget[msg.chat.id_str][name] = value
|
||||
bindings.sendMessage(self, msg.chat.id, '"' .. name .. '" has been set to "' .. value .. '".', true)
|
||||
utilities.send_message(self, msg.chat.id, '"' .. name .. '" has been set to "' .. value .. '".', true)
|
||||
end
|
||||
|
||||
elseif msg.text_lower:match('^/get') then
|
||||
@ -54,7 +53,7 @@ function setandget:action(msg)
|
||||
output = output .. '• ' .. k .. ': `' .. v .. '`\n'
|
||||
end
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -65,7 +64,7 @@ function setandget:action(msg)
|
||||
output = 'There is no value stored by that name.'
|
||||
end
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local shell = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function shell:init()
|
||||
@ -15,9 +14,9 @@ function shell:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
input = input:gsub('—', '--')
|
||||
|
||||
|
||||
if not input then
|
||||
bindings.sendReply(self, msg, 'Please specify a command to run.')
|
||||
utilities.send_reply(self, msg, 'Please specify a command to run.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -27,7 +26,7 @@ function shell:action(msg)
|
||||
else
|
||||
output = '```\n' .. output .. '\n```'
|
||||
end
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local shout = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
shout.command = 'shout <text>'
|
||||
@ -18,7 +17,7 @@ function shout:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if not input then
|
||||
bindings.sendMessage(self, msg.chat.id, shout.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, shout.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
input = utilities.trim(input)
|
||||
@ -43,7 +42,7 @@ function shout:action(msg)
|
||||
output = output .. match .. ' ' .. spacing .. match .. '\n'
|
||||
end
|
||||
output = '```\n' .. utilities.trim(output) .. '\n```'
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, false, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, false, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local slap = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
slap.command = 'slap [target]'
|
||||
@ -124,7 +123,7 @@ function slap:action(msg)
|
||||
output = output:gsub('VICTOR', victor_name)
|
||||
output = utilities.char.zwnj .. output
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,6 @@ local time = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
time.command = 'time <location>'
|
||||
@ -22,14 +21,14 @@ function time:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, time.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, time.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local coords = utilities.get_coords(self, input)
|
||||
if type(coords) == 'string' then
|
||||
bindings.sendReply(self, msg, coords)
|
||||
utilities.send_reply(self, msg, coords)
|
||||
return
|
||||
end
|
||||
|
||||
@ -40,7 +39,7 @@ function time:action(msg)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -56,7 +55,7 @@ function time:action(msg)
|
||||
local output = os.date('!%I:%M %p\n', timestamp) .. os.date('!%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')'
|
||||
output = '```\n' .. output .. '\n```'
|
||||
|
||||
bindings.sendReply(self, msg, output, true)
|
||||
utilities.send_reply(self, msg, output, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@ local translate = {}
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
translate.command = 'translate [text]'
|
||||
@ -23,7 +22,7 @@ function translate:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, translate.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, translate.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -32,20 +31,20 @@ function translate:action(msg)
|
||||
|
||||
local str, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(str)
|
||||
if jdat.code ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local output = jdat.text[1]
|
||||
output = '*Translation:*\n"' .. utilities.md_escape(output) .. '"'
|
||||
|
||||
bindings.sendReply(self, msg.reply_to_message or msg, output, true)
|
||||
utilities.send_reply(self, msg.reply_to_message or msg, output, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@ local urbandictionary = {}
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
urbandictionary.command = 'urbandictionary <query>'
|
||||
@ -24,7 +23,7 @@ function urbandictionary:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, urbandictionary.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, urbandictionary.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -33,13 +32,13 @@ function urbandictionary:action(msg)
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.result_type == "no_results" then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -50,7 +49,7 @@ function urbandictionary:action(msg)
|
||||
|
||||
output = output:gsub('%[', ''):gsub('%]', '')
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,6 @@ local weather = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function weather:init()
|
||||
@ -28,14 +27,14 @@ function weather:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, weather.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, weather.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local coords = utilities.get_coords(self, input)
|
||||
if type(coords) == 'string' then
|
||||
bindings.sendReply(self, msg, coords)
|
||||
utilities.send_reply(self, msg, coords)
|
||||
return
|
||||
end
|
||||
|
||||
@ -43,13 +42,13 @@ function weather:action(msg)
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.cod ~= 200 then
|
||||
bindings.sendReply(self, msg, 'Error: City not found.')
|
||||
utilities.send_reply(self, msg, 'Error: City not found.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -57,7 +56,7 @@ function weather:action(msg)
|
||||
local fahrenheit = string.format('%.2f', celsius * (9/5) + 32)
|
||||
local output = '`' .. celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.`'
|
||||
|
||||
bindings.sendReply(self, msg, output, true)
|
||||
utilities.send_reply(self, msg, output, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local whoami = {}
|
||||
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
whoami.command = 'whoami'
|
||||
@ -45,7 +44,7 @@ function whoami:action(msg)
|
||||
|
||||
local output = user .. ', and you are messaging ' .. group
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,6 @@ local wikipedia = {}
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
wikipedia.command = 'wikipedia <query>'
|
||||
@ -18,7 +17,7 @@ function wikipedia:init()
|
||||
end
|
||||
|
||||
local get_title = function(search)
|
||||
for i,v in ipairs(search) do
|
||||
for _,v in ipairs(search) do
|
||||
if not v.snippet:match('may refer to:') then
|
||||
return v.title
|
||||
end
|
||||
@ -35,7 +34,7 @@ function wikipedia:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, wikipedia.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, wikipedia.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -51,19 +50,19 @@ function wikipedia:action(msg)
|
||||
|
||||
jstr, res = HTTPS.request(search_url .. URL.escape(input))
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
jdat = JSON.decode(jstr)
|
||||
if jdat.query.searchinfo.totalhits == 0 then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
local title = get_title(jdat.query.search)
|
||||
if not title then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -71,7 +70,7 @@ function wikipedia:action(msg)
|
||||
|
||||
jstr, res = HTTPS.request(res_url .. URL.escape(title))
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
@ -79,7 +78,7 @@ function wikipedia:action(msg)
|
||||
local text = JSON.decode(jstr).query.pages
|
||||
_, text = next(text)
|
||||
if not text then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
else
|
||||
text = text.extract
|
||||
@ -108,7 +107,7 @@ function wikipedia:action(msg)
|
||||
end
|
||||
output = output .. '\n[Read more.](' .. url:gsub('%)', '\\)') .. ')'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
local xkcd = {}
|
||||
|
||||
local HTTP = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
xkcd.command = 'xkcd [i]'
|
||||
@ -20,7 +18,7 @@ function xkcd:action(msg)
|
||||
|
||||
local jstr, res = HTTP.request('http://xkcd.com/info.0.json')
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
local latest = JSON.decode(jstr).num
|
||||
@ -29,7 +27,7 @@ function xkcd:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
if input then
|
||||
if input == '404' then
|
||||
bindings.sendMessage(self, msg.chat.id, '*404*\nNot found.', false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, '*404*\nNot found.', false, nil, true)
|
||||
return
|
||||
elseif tonumber(input) then
|
||||
if tonumber(input) > latest then
|
||||
@ -46,14 +44,14 @@ function xkcd:action(msg)
|
||||
|
||||
jstr, res = HTTP.request(res_url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
local output = '*' .. jdat.safe_title .. '* ([' .. jdat.num .. '](' .. jdat.img .. '))\n' .. jdat.alt
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,6 @@ local youtube = {}
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local JSON = require('dkjson')
|
||||
local bindings = require('bindings')
|
||||
local utilities = require('utilities')
|
||||
|
||||
function youtube:init()
|
||||
@ -32,7 +31,7 @@ function youtube:action(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
bindings.sendMessage(self, msg.chat.id, youtube.doc, true, msg.message_id, true)
|
||||
utilities.send_message(self, msg.chat.id, youtube.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -41,13 +40,13 @@ function youtube:action(msg)
|
||||
|
||||
local jstr, res = HTTPS.request(url)
|
||||
if res ~= 200 then
|
||||
bindings.sendReply(self, msg, self.config.errors.connection)
|
||||
utilities.send_reply(self, msg, self.config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if jdat.pageInfo.totalResults == 0 then
|
||||
bindings.sendReply(self, msg, self.config.errors.results)
|
||||
utilities.send_reply(self, msg, self.config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
@ -56,7 +55,7 @@ function youtube:action(msg)
|
||||
vid_title = vid_title:gsub('%(.+%)',''):gsub('%[.+%]','')
|
||||
local output = '[' .. vid_title .. '](' .. vid_url .. ')'
|
||||
|
||||
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user