2016-04-11 06:04:47 +02:00
|
|
|
local whoami = {}
|
|
|
|
|
|
|
|
local utilities = require('utilities')
|
|
|
|
|
|
|
|
whoami.command = 'whoami'
|
2016-05-27 05:28:44 +02:00
|
|
|
|
|
|
|
function whoami:init(config)
|
|
|
|
whoami.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('who', true):t('whoami').table
|
|
|
|
whoami.doc = [[```
|
2016-01-08 14:44:37 +01:00
|
|
|
Returns user and chat info for you or the replied-to message.
|
2016-05-27 05:28:44 +02:00
|
|
|
Alias: ]]..config.cmd_pat..[[who
|
2016-01-08 14:44:37 +01:00
|
|
|
```]]
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
function whoami:action(msg)
|
2015-07-11 02:46:51 +02:00
|
|
|
|
|
|
|
if msg.reply_to_message then
|
|
|
|
msg = msg.reply_to_message
|
2016-04-14 05:48:20 +02:00
|
|
|
msg.from.name = utilities.build_name(msg.from.first_name, msg.from.last_name)
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
2015-07-08 09:38:04 +02:00
|
|
|
|
2016-03-27 14:30:41 +02:00
|
|
|
local chat_id = math.abs(msg.chat.id)
|
|
|
|
if chat_id > 1000000000000 then
|
|
|
|
chat_id = chat_id - 1000000000000
|
|
|
|
end
|
|
|
|
|
2016-03-28 08:15:46 +02:00
|
|
|
local user = 'You are @%s, also known as *%s* `[%s]`'
|
|
|
|
if msg.from.username then
|
2016-04-11 06:04:47 +02:00
|
|
|
user = user:format(utilities.markdown_escape(msg.from.username), msg.from.name, msg.from.id)
|
2016-03-28 08:15:46 +02:00
|
|
|
else
|
|
|
|
user = 'You are *%s* `[%s]`,'
|
|
|
|
user = user:format(msg.from.name, msg.from.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
local group = '@%s, also known as *%s* `[%s]`.'
|
|
|
|
if msg.chat.type == 'private' then
|
2016-04-11 06:04:47 +02:00
|
|
|
group = group:format(utilities.markdown_escape(self.info.username), self.info.first_name, self.info.id)
|
2016-03-28 08:15:46 +02:00
|
|
|
elseif msg.chat.username then
|
2016-04-11 06:04:47 +02:00
|
|
|
group = group:format(utilities.markdown_escape(msg.chat.username), msg.chat.title, chat_id)
|
2015-11-25 03:22:04 +01:00
|
|
|
else
|
2016-03-28 08:15:46 +02:00
|
|
|
group = '*%s* `[%s]`.'
|
|
|
|
group = group:format(msg.chat.title, chat_id)
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
|
2016-03-28 08:15:46 +02:00
|
|
|
local output = user .. ', and you are messaging ' .. group
|
2015-07-08 09:38:04 +02:00
|
|
|
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
2015-07-03 00:15:52 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return whoami
|