This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/me.lua

69 lines
1.6 KiB
Lua
Raw Normal View History

local me = {}
2016-06-07 06:31:34 +02:00
local utilities = require('otouto.utilities')
function me:init(config)
me.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('me', true).table
me.command = 'me'
me.doc = 'Returns userdata stored by the bot.'
end
2016-05-27 02:26:30 +02:00
function me:action(msg, config)
2016-08-14 04:26:44 +02:00
local user
if msg.from.id == config.admin then
if msg.reply_to_message then
2016-08-14 04:26:44 +02:00
user = msg.reply_to_message.from
else
local input = utilities.input(msg.text)
if input then
2016-08-14 04:26:44 +02:00
if tonumber(input) then
user = self.database.users[input]
if not user then
utilities.send_reply(self, msg, 'Unrecognized ID.')
return
end
elseif input:match('^@') then
user = utilities.resolve_username(self, input)
if not user then
utilities.send_reply(self, msg, 'Unrecognized username.')
return
end
else
utilities.send_reply(self, msg, 'Invalid username or ID.')
return
end
end
end
end
2016-08-14 04:26:44 +02:00
user = user or msg.from
local userdata = self.database.userdata[tostring(user.id)] or {}
2016-08-14 04:26:44 +02:00
local data = {}
for k,v in pairs(userdata) do
2016-08-14 04:26:44 +02:00
table.insert(data, string.format(
'<b>%s</b> <code>%s</code>\n',
utilities.html_escape(k),
utilities.html_escape(v)
))
end
2016-08-14 04:26:44 +02:00
local output
if #data == 0 then
output = 'There is no data stored for this user.'
2016-08-14 04:26:44 +02:00
else
output = string.format(
'<b>%s</b> <code>[%s]</code><b>:</b>\n',
utilities.html_escape(utilities.build_name(
user.first_name,
user.last_name
)),
user.id
) .. table.concat(data)
end
2016-08-14 04:26:44 +02:00
utilities.send_message(self, msg.chat.id, output, true, nil, 'html')
end
return me