hearthstone.lua: Temporary fix. API does not play well with lua-sec, so using curl for now.
bindings.lua: Added support for kickChatMember and unbanChatMember methods. utilties.lua: enrich_message() will rename the new_chat_member and left_chat_member values to the names expected by plugins: new_chat_participant and left_chat_participant. bot.lua: Removed migration code. Rewrite soon. eightball.lua: Bugfix.
This commit is contained in:
parent
550d0743b7
commit
38b4b68ba2
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,7 @@
|
||||
plugins/mokubot*
|
||||
plugins/qtbot*
|
||||
plugins/mjolnir*
|
||||
plugins/antisquigbot*
|
||||
*.db
|
||||
lua-tg
|
||||
drua-tg
|
||||
|
14
bindings.lua
14
bindings.lua
@ -16,10 +16,6 @@ sendRequest = function(url)
|
||||
|
||||
local dat, res = HTTPS.request(url)
|
||||
|
||||
if res ~= 200 then
|
||||
return false, res
|
||||
end
|
||||
|
||||
local tab = JSON.decode(dat)
|
||||
|
||||
if not tab.ok then
|
||||
@ -118,6 +114,16 @@ forwardMessage = function(chat_id, from_chat_id, message_id, disable_notificatio
|
||||
|
||||
end
|
||||
|
||||
kickChatMember = function(chat_id, user_id)
|
||||
local url = BASE_URL .. '/kickChatMember?chat_id=' .. chat_id .. '&user_id=' .. user_id
|
||||
return sendRequest(url)
|
||||
end
|
||||
|
||||
unbanChatMember = function(chat_id, user_id)
|
||||
local url = BASE_URL .. '/unbanChatMember?chat_id=' .. chat_id .. '&user_id=' .. user_id
|
||||
return sendRequest(url)
|
||||
end
|
||||
|
||||
-- TODO: More of this.
|
||||
|
||||
sendPhotoID = function(chat_id, file_id, caption, reply_to_message_id, disable_notification)
|
||||
|
30
bot.lua
30
bot.lua
@ -3,7 +3,7 @@ HTTPS = require('ssl.https')
|
||||
URL = require('socket.url')
|
||||
JSON = require('cjson')
|
||||
|
||||
version = '3.5'
|
||||
version = '3.6'
|
||||
|
||||
bot_init = function() -- The function run when the bot is started or reloaded.
|
||||
|
||||
@ -38,22 +38,6 @@ bot_init = function() -- The function run when the bot is started or reloaded.
|
||||
database.users = database.users or {} -- Table to cache userdata.
|
||||
database.users[tostring(bot.id)] = bot
|
||||
|
||||
-- Migration code. Remove in 3.6.
|
||||
if database.lastfm then
|
||||
for k,v in pairs(database.lastfm) do
|
||||
if not database.users[k] then database.users[k] = {} end
|
||||
database.users[k].lastfm = v
|
||||
end
|
||||
end
|
||||
|
||||
-- Migration code. Remove in 3.6.
|
||||
if database.nicknames then
|
||||
for k,v in pairs(database.nicknames) do
|
||||
if not database.users[k] then database.users[k] = {} end
|
||||
database.users[k].nickname = v
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
on_msg_receive = function(msg) -- The fn run whenever a message is received.
|
||||
@ -71,25 +55,17 @@ on_msg_receive = function(msg) -- The fn run whenever a message is received.
|
||||
end
|
||||
|
||||
if msg.date < os.time() - 5 then return end -- Do not process old messages.
|
||||
if not msg.text then msg.text = msg.caption or '' end
|
||||
|
||||
if msg.reply_to_message and msg.reply_to_message.caption then
|
||||
msg.reply_to_message.text = msg.reply_to_message.caption
|
||||
end -- If the replied-to message has a caption, make that its text.
|
||||
msg = enrich_message(msg)
|
||||
|
||||
if msg.text:match('^/start .+') then
|
||||
msg.text = '/' .. msg.text:input()
|
||||
msg.text_lower = msg.text:lower()
|
||||
end
|
||||
|
||||
for i,v in ipairs(plugins) do
|
||||
for k,w in pairs(v.triggers) do
|
||||
if string.match(msg.text:lower(), w) then
|
||||
-- a few shortcuts
|
||||
msg.chat.id_str = tostring(msg.chat.id)
|
||||
msg.from.id_str = tostring(msg.from.id)
|
||||
msg.text_lower = msg.text:lower()
|
||||
msg.from.name = build_name(msg.from.first_name, msg.from.last_name)
|
||||
|
||||
local success, result = pcall(function()
|
||||
return v.action(msg)
|
||||
end)
|
||||
|
@ -2,12 +2,12 @@ return {
|
||||
|
||||
-- Your authorization token from the botfather.
|
||||
bot_api_key = '',
|
||||
-- Your Telegram ID.
|
||||
admin = 00000000,
|
||||
-- Differences, in seconds, between your time and UTC.
|
||||
time_offset = 0,
|
||||
-- Two-letter language code.
|
||||
lang = 'en',
|
||||
-- Your Telegram ID.
|
||||
admin = 00000000,
|
||||
-- The channel, group, or user to send error reports to.
|
||||
-- If this is not set, errors will be printed to the console.
|
||||
log_chat = nil,
|
||||
|
@ -1059,6 +1059,7 @@ local commands = {
|
||||
photo = drua.get_photo(msg.chat.id),
|
||||
founded = os.time()
|
||||
}
|
||||
update_desc(msg.chat.id)
|
||||
for i = 1, #flags do
|
||||
database.administration.groups[msg.chat.id_str].flags[i] = false
|
||||
end
|
||||
|
@ -39,10 +39,6 @@ local yesno_answers = {
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
if msg.reply_to_message then
|
||||
msg = msg.reply_to_message
|
||||
end
|
||||
|
||||
local message
|
||||
|
||||
if msg.text_lower:match('y/n%p?$') then
|
||||
|
@ -4,23 +4,26 @@ if not database.hearthstone or os.time() > database.hearthstone.expiration then
|
||||
|
||||
print('Downloading Hearthstone database...')
|
||||
|
||||
database.hearthstone = {
|
||||
expiration = os.time() + 600000
|
||||
}
|
||||
-- This stuff doesn't play well with lua-sec. Disable it for now; hack in curl.
|
||||
--local jstr, res = HTTPS.request('https://api.hearthstonejson.com/v1/latest/enUS/cards.json')
|
||||
--if res ~= 200 then
|
||||
--print('Error connecting to hearthstonejson.com.')
|
||||
--print('hearthstone.lua will not be enabled.')
|
||||
--return
|
||||
--end
|
||||
--local jdat = JSON.decode(jstr)
|
||||
|
||||
local jstr, res = HTTPS.request('http://hearthstonejson.com/json/AllSets.json')
|
||||
if res ~= 200 then
|
||||
local s = io.popen('curl -s https://api.hearthstonejson.com/v1/latest/enUS/cards.json'):read('*all')
|
||||
local d = JSON.decode(s)
|
||||
|
||||
if not d then
|
||||
print('Error connecting to hearthstonejson.com.')
|
||||
print('hearthstone.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
for k,v in pairs(jdat) do
|
||||
for key,val in pairs(v) do
|
||||
table.insert(database.hearthstone, val)
|
||||
end
|
||||
end
|
||||
database.hearthstone = d
|
||||
database.hearthstone.expiration = os.time() + 600000
|
||||
|
||||
print('Download complete! It will be stored for a week.')
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
-- utilities.lua
|
||||
-- Functions shared among plugins.
|
||||
|
||||
-- you're welcome, brayden :^)
|
||||
HTTP = HTTP or require('socket.http')
|
||||
HTTPS = HTTPS or require('ssl.https')
|
||||
JSON = JSON or require('cjson')
|
||||
@ -25,7 +24,7 @@ end
|
||||
-- Returns the actual index.
|
||||
function string:index()
|
||||
local t = {}
|
||||
for w in s:gmatch('%g+') do
|
||||
for w in self:gmatch('%g+') do
|
||||
table.insert(t, w)
|
||||
end
|
||||
return t
|
||||
@ -167,7 +166,7 @@ user_from_message = function(msg)
|
||||
if msg.reply_to_message then
|
||||
target = msg.reply_to_message.from
|
||||
elseif input and tonumber(input) then
|
||||
target.id = input
|
||||
target.id = tonumber(input)
|
||||
if database.users[input] then
|
||||
for k,v in pairs(database.users[input]) do
|
||||
target[k] = v
|
||||
@ -270,3 +269,34 @@ function string:md_escape()
|
||||
text = text:gsub('`', '\\`')
|
||||
return text
|
||||
end
|
||||
|
||||
enrich_user = function(user)
|
||||
user.id_str = tostring(user.id)
|
||||
user.name = build_name(user.first_name, user.last_name)
|
||||
return user
|
||||
end
|
||||
|
||||
enrich_message = function(msg)
|
||||
if not msg.text then msg.text = msg.caption or '' end
|
||||
msg.text_lower = msg.text:lower()
|
||||
msg.from = enrich_user(msg.from)
|
||||
msg.chat.id_str = tostring(msg.chat.id)
|
||||
if msg.reply_to_message then
|
||||
if not msg.reply_to_message.text then
|
||||
msg.reply_to_message.text = msg.reply_to_message.caption or ''
|
||||
end
|
||||
msg.reply_to_message.text_lower = msg.reply_to_message.text:lower()
|
||||
msg.reply_to_message.from = enrich_user(msg.reply_to_message.from)
|
||||
msg.reply_to_message.chat.id_str = tostring(msg.reply_to_message.chat.id)
|
||||
end
|
||||
if msg.forward_from then
|
||||
msg.forward_from = enrich_user(msg.forward_from)
|
||||
end
|
||||
if msg.new_chat_participant then
|
||||
msg.new_chat_participant = enrich_user(msg.new_chat_participant)
|
||||
end
|
||||
if msg.left_chat_participant then
|
||||
msg.left_chat_participant = enrich_user(msg.left_chat_participant)
|
||||
end
|
||||
return msg
|
||||
end
|
||||
|
Reference in New Issue
Block a user