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/channel.lua
topkecleon acc7046d64 administration 1.13.1
Added optional target for kick/ban logs. Added flag 7 to use default log
 per group. This way, a realm can have a public kick/ban log but governors
 are able to opt out. Added flag 8, antilink. Kicks for Telegram join links
 which do not refer to groups within the realm. Added flag 9, modrights, to
 give moderators access to changing the group photo, title, link, and motd
 (config option is deprecated. RIP). /unban will reset the target's autokick
 counter. Added configuration for default flag settings.

Revision to bindings.lua.
BASE_URL has been moved to bindings. There is no real reason for it to remain
in instance. Token is passed to bindings.init at load. All plugins have been
updated accordingly.
2016-08-23 00:16:32 -04:00

61 lines
2.2 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local channel = {}
local bindings = require('otouto.bindings')
local utilities = require('otouto.utilities')
function channel:init(config)
channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table
channel.command = 'ch <channel> \\n <message>'
channel.doc = config.cmd_pat .. [[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```]]
end
function channel:action(msg, config)
-- 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{ 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(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.'
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(msg, output, true)
end
return channel