acc7046d64
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.
51 lines
1.6 KiB
Lua
51 lines
1.6 KiB
Lua
local urbandictionary = {}
|
|
|
|
local HTTP = require('socket.http')
|
|
local URL = require('socket.url')
|
|
local JSON = require('dkjson')
|
|
local utilities = require('otouto.utilities')
|
|
|
|
urbandictionary.command = 'urbandictionary <query>'
|
|
urbandictionary.base_url = 'http://api.urbandictionary.com/v0/define?term='
|
|
|
|
function urbandictionary:init(config)
|
|
urbandictionary.triggers = utilities.triggers(self.info.username, config.cmd_pat)
|
|
:t('urbandictionary', true):t('ud', true):t('urban', true).table
|
|
urbandictionary.doc = [[
|
|
/urbandictionary <query>
|
|
Returns a definition from Urban Dictionary.
|
|
Aliases: /ud, /urban
|
|
]]
|
|
urbandictionary.doc = urbandictionary.doc:gsub('/', config.cmd_pat)
|
|
end
|
|
|
|
function urbandictionary:action(msg, config)
|
|
local input = utilities.input_from_msg(msg)
|
|
if not input then
|
|
utilities.send_reply(msg, urbandictionary.doc, true)
|
|
return
|
|
end
|
|
|
|
local url = urbandictionary.base_url .. URL.escape(input)
|
|
local jstr, code = HTTP.request(url)
|
|
if code ~= 200 then
|
|
utilities.send_reply(msg, config.errors.connection)
|
|
return
|
|
end
|
|
|
|
local data = JSON.decode(jstr)
|
|
local output
|
|
if data.result_type == 'no_results' then
|
|
output = config.errors.results
|
|
else
|
|
output = string.format('*%s*\n\n%s\n\n_%s_',
|
|
data.list[1].word:gsub('*', '*\\**'),
|
|
utilities.trim(utilities.md_escape(data.list[1].definition)),
|
|
utilities.trim((data.list[1].example or '')):gsub('_', '_\\__')
|
|
)
|
|
end
|
|
utilities.send_reply(msg, output, true)
|
|
end
|
|
|
|
return urbandictionary
|