Merge Upstream
This commit is contained in:
@ -18,13 +18,14 @@ function about:action(msg, config)
|
||||
-- disabled to restore old behaviour
|
||||
-- if msg.forward_from then return end
|
||||
|
||||
local output = config.about_text .. '\nBrawlbot v2.0, basierend auf Otouto von topkecleon.'
|
||||
local output = config.about_text .. '\nBrawlbot v'..bot.version..', basierend auf Otouto von topkecleon.'
|
||||
|
||||
if
|
||||
(msg.new_chat_participant and msg.new_chat_participant.id == self.info.id)
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'about')
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'about@'..self.info.username:lower())
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'start')
|
||||
(msg.new_chat_member and msg.new_chat_member.id == self.info.id)
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'about$')
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'about@'..self.info.username:lower()..'$')
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'start$')
|
||||
or msg.text_lower:match('^'..config.cmd_pat..'start@'..self.info.username:lower()..'$')
|
||||
then
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
return
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,8 +17,8 @@ blacklist.triggers = {
|
||||
|
||||
function blacklist:action(msg, config)
|
||||
|
||||
if self.database.blacklist[msg.from.id_str] then return end
|
||||
if self.database.blacklist[msg.chat.id_str] then return end
|
||||
if self.database.blacklist[tostring(msg.from.id)] then return end
|
||||
if self.database.blacklist[tostring(msg.chat.id)] then return end
|
||||
if not msg.text:match('^'..config.cmd_pat..'blacklist') then return true end
|
||||
if msg.from.id ~= config.admin then return end
|
||||
|
||||
@ -35,9 +35,15 @@ function blacklist:action(msg, config)
|
||||
if self.database.blacklist[tostring(target.id)] then
|
||||
self.database.blacklist[tostring(target.id)] = nil
|
||||
utilities.send_reply(self, msg, target.name .. ' has been removed from the blacklist.')
|
||||
if config.drua_block_on_blacklist then
|
||||
require('drua-tg').unblock(target.id)
|
||||
end
|
||||
else
|
||||
self.database.blacklist[tostring(target.id)] = true
|
||||
utilities.send_reply(self, msg, target.name .. ' has been added to the blacklist.')
|
||||
if config.drua_block_on_blacklist then
|
||||
require('drua-tg').block(target.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ function control:action(msg, config)
|
||||
return
|
||||
end
|
||||
|
||||
if msg.date < os.time() - 1 then return end
|
||||
if msg.date < os.time() - 2 then return end
|
||||
|
||||
if msg.text_lower:match('^'..cmd_pat..'restart') then
|
||||
for pac, _ in pairs(package.loaded) do
|
||||
|
@ -41,12 +41,16 @@ end
|
||||
|
||||
function greetings:action(msg, config)
|
||||
|
||||
local nick = self.database.users[msg.from.id_str].nickname or msg.from.first_name
|
||||
local nick = utilities.build_name(msg.from.first_name, msg.from.last_name)
|
||||
if self.database.userdata[tostring(msg.from.id)] then
|
||||
nick = self.database.userdata[tostring(msg.from.id)].nickname or nick
|
||||
end
|
||||
|
||||
for trigger,responses in pairs(config.greetings) do
|
||||
for _,response in pairs(responses) do
|
||||
if msg.text_lower:match(response..',? '..self.info.first_name:lower()) then
|
||||
utilities.send_message(self, msg.chat.id, utilities.latcyr(trigger:gsub('#NAME', nick)))
|
||||
local output = utilities.char.zwnj .. trigger:gsub('#NAME', nick)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -30,6 +30,8 @@ lastfm.command = 'lastfm'
|
||||
function lastfm:action(msg, config)
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
local from_id_str = tostring(msg.from.id)
|
||||
self.database.userdata[from_id_str] = self.database.userdata[from_id_str] or {}
|
||||
|
||||
if string.match(msg.text, '^'..config.cmd_pat..'lastfm') then
|
||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
@ -38,10 +40,10 @@ function lastfm:action(msg, config)
|
||||
if not input then
|
||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||
elseif input == '--' or input == utilities.char.em_dash then
|
||||
self.database.users[msg.from.id_str].lastfm = nil
|
||||
self.database.userdata[from_id_str].lastfm = nil
|
||||
utilities.send_reply(self, msg, 'Your last.fm username has been forgotten.')
|
||||
else
|
||||
self.database.users[msg.from.id_str].lastfm = input
|
||||
self.database.userdata[from_id_str].lastfm = input
|
||||
utilities.send_reply(self, msg, 'Your last.fm username has been set to "' .. input .. '".')
|
||||
end
|
||||
return
|
||||
@ -53,12 +55,12 @@ function lastfm:action(msg, config)
|
||||
local alert = ''
|
||||
if input then
|
||||
username = input
|
||||
elseif self.database.users[msg.from.id_str].lastfm then
|
||||
username = self.database.users[msg.from.id_str].lastfm
|
||||
elseif self.database.userdata[from_id_str].lastfm then
|
||||
username = self.database.userdata[from_id_str].lastfm
|
||||
elseif msg.from.username then
|
||||
username = msg.from.username
|
||||
alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use '..config.cmd_pat..'fmset <username>.'
|
||||
self.database.users[msg.from.id_str].lastfm = username
|
||||
self.database.userdata[from_id_str].lastfm = username
|
||||
else
|
||||
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with '..config.cmd_pat..'fmset.')
|
||||
return
|
||||
|
@ -4,24 +4,37 @@ 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
|
||||
|
||||
function me:action(msg, config)
|
||||
|
||||
local target = self.database.users[msg.from.id_str]
|
||||
local userdata = self.database.userdata[tostring(msg.from.id)] or {}
|
||||
|
||||
if msg.from.id == config.admin and (msg.reply_to_message or utilities.input(msg.text)) then
|
||||
target = utilities.user_from_message(self, msg, true)
|
||||
if target.err then
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
return
|
||||
if msg.from.id == config.admin then
|
||||
if msg.reply_to_message then
|
||||
userdata = self.database.userdata[tostring(msg.reply_to_message.from.id)]
|
||||
else
|
||||
local input = utilities.input(msg.text)
|
||||
if input then
|
||||
local user_id = utilities.id_from_username(self, input)
|
||||
if user_id then
|
||||
userdata = self.database.userdata[tostring(user_id)] or {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local output = ''
|
||||
for k,v in pairs(target) do
|
||||
for k,v in pairs(userdata) do
|
||||
output = output .. '*' .. k .. ':* `' .. tostring(v) .. '`\n'
|
||||
end
|
||||
|
||||
if output == '' then
|
||||
output = 'There is no data stored for this user.'
|
||||
end
|
||||
|
||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
@ -14,34 +14,35 @@ end
|
||||
|
||||
function nick:action(msg, config)
|
||||
|
||||
local target = msg.from
|
||||
local id_str, name
|
||||
|
||||
if msg.from.id == config.admin and msg.reply_to_message then
|
||||
target = msg.reply_to_message.from
|
||||
target.id_str = tostring(target.id)
|
||||
target.name = target.first_name
|
||||
if target.last_name then
|
||||
target.name = target.first_name .. ' ' .. target.last_name
|
||||
end
|
||||
id_str = tostring(msg.reply_to_message.from.id)
|
||||
name = utilities.build_name(msg.reply_to_message.from.first_name, msg.reply_to_message.from.last_name)
|
||||
else
|
||||
id_str = tostring(msg.from.id)
|
||||
name = utilities.build_name(msg.from.first_name, msg.from.last_name)
|
||||
end
|
||||
|
||||
self.database.userdata[id_str] = self.database.userdata[id_str] or {}
|
||||
|
||||
local output
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
if self.database.users[target.id_str].nickname then
|
||||
output = target.name .. '\'s nickname is "' .. self.database.users[target.id_str].nickname .. '".'
|
||||
if self.database.userdata[id_str].nickname then
|
||||
output = name .. '\'s nickname is "' .. self.database.userdata[id_str].nickname .. '".'
|
||||
else
|
||||
output = target.name .. ' currently has no nickname.'
|
||||
output = name .. ' currently has no nickname.'
|
||||
end
|
||||
elseif utilities.utf8_len(input) > 32 then
|
||||
output = 'The character limit for nicknames is 32.'
|
||||
elseif input == '--' or input == utilities.char.em_dash then
|
||||
self.database.users[target.id_str].nickname = nil
|
||||
output = target.name .. '\'s nickname has been deleted.'
|
||||
self.database.userdata[id_str].nickname = nil
|
||||
output = name .. '\'s nickname has been deleted.'
|
||||
else
|
||||
input = input:gsub('\n', ' ')
|
||||
self.database.users[target.id_str].nickname = input
|
||||
output = target.name .. '\'s nickname has been set to "' .. input .. '".'
|
||||
self.database.userdata[id_str].nickname = input
|
||||
output = name .. '\'s nickname has been set to "' .. input .. '".'
|
||||
end
|
||||
|
||||
utilities.send_reply(self, msg, output)
|
||||
|
@ -92,4 +92,4 @@ function remind:cron()
|
||||
end
|
||||
end
|
||||
|
||||
return remind
|
||||
return remind
|
@ -61,7 +61,7 @@ local slaps = {
|
||||
'VICTIM died. I blame VICTOR.',
|
||||
'VICTIM was axe-murdered by VICTOR.',
|
||||
'VICTIM\'s melon was split by VICTOR.',
|
||||
'VICTIM was slice and diced by VICTOR.',
|
||||
'VICTIM was sliced and diced by VICTOR.',
|
||||
'VICTIM was split from crotch to sternum by VICTOR.',
|
||||
'VICTIM\'s death put another notch in VICTOR\'s axe.',
|
||||
'VICTIM died impossibly!',
|
||||
@ -102,29 +102,52 @@ local slaps = {
|
||||
'VICTIM was impeached.',
|
||||
'VICTIM was one-hit KO\'d by VICTOR.',
|
||||
'VICTOR sent VICTIM to /dev/null.',
|
||||
'VICTOR sent VICTIM down the memory hole.'
|
||||
'VICTOR sent VICTIM down the memory hole.',
|
||||
'VICTIM was a mistake.',
|
||||
'"VICTIM was a mistake." - VICTOR',
|
||||
'VICTOR checkmated VICTIM in two moves.'
|
||||
}
|
||||
|
||||
-- optimize later
|
||||
function slap:action(msg)
|
||||
|
||||
local victor = self.database.users[msg.from.id_str]
|
||||
local victim = utilities.user_from_message(self, msg, true)
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
local victim_name = victim.nickname or victim.first_name or input
|
||||
local victor_name = victor.nickname or victor.first_name
|
||||
if not victim_name or victim_name == victor_name then
|
||||
victim_name = victor_name
|
||||
local victor_id = msg.from.id
|
||||
local victim_id = utilities.id_from_message(self, msg)
|
||||
-- IDs
|
||||
if victim_id then
|
||||
if victim_id == victor_id then
|
||||
victor_id = self.info.id
|
||||
end
|
||||
else
|
||||
if not input then
|
||||
victor_id = self.info.id
|
||||
victim_id = msg.from.id
|
||||
end
|
||||
end
|
||||
-- Names
|
||||
local victor_name, victim_name
|
||||
if input and not victim_id then
|
||||
victim_name = input
|
||||
else
|
||||
local victim_id_str = tostring(victim_id)
|
||||
if self.database.userdata[victim_id_str] and self.database.userdata[victim_id_str].nickname then
|
||||
victim_name = self.database.userdata[victim_id_str].nickname
|
||||
elseif self.database.users[victim_id_str] then
|
||||
victim_name = utilities.build_name(self.database.users[victim_id_str].first_name, self.database.users[victim_id_str].last_name)
|
||||
else
|
||||
victim_name = victim_id_str
|
||||
end
|
||||
end
|
||||
local victor_id_str = tostring(victor_id)
|
||||
if self.database.userdata[victor_id_str] and self.database.userdata[victor_id_str].nickname then
|
||||
victor_name = self.database.userdata[victor_id_str].nickname
|
||||
elseif self.database.users[victor_id_str] then
|
||||
victor_name = utilities.build_name(self.database.users[victor_id_str].first_name, self.database.users[victor_id_str].last_name)
|
||||
else
|
||||
victor_name = self.info.first_name
|
||||
end
|
||||
|
||||
local output = slaps[math.random(#slaps)]
|
||||
output = output:gsub('VICTIM', victim_name)
|
||||
output = output:gsub('VICTOR', victor_name)
|
||||
output = utilities.char.zwnj .. output
|
||||
|
||||
local output = utilities.char.zwnj .. slaps[math.random(#slaps)]:gsub('VICTIM', victim_name):gsub('VICTOR', victor_name)
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
|
||||
end
|
||||
|
||||
return slap
|
||||
|
@ -2,6 +2,7 @@ local weather = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
local URL = require('socket.url')
|
||||
local HTTP = require('socket.http')
|
||||
local JSON = require('dkjson')
|
||||
local utilities = require('otouto.utilities')
|
||||
local bindings = require('otouto.bindings')
|
||||
|
@ -16,9 +16,10 @@ function whoami:action(msg)
|
||||
|
||||
if msg.reply_to_message then
|
||||
msg = msg.reply_to_message
|
||||
msg.from.name = utilities.build_name(msg.from.first_name, msg.from.last_name)
|
||||
end
|
||||
|
||||
local from_name = utilities.build_name(msg.from.first_name, msg.from.last_name)
|
||||
|
||||
local chat_id = math.abs(msg.chat.id)
|
||||
if chat_id > 1000000000000 then
|
||||
chat_id = chat_id - 1000000000000
|
||||
@ -26,10 +27,10 @@ function whoami:action(msg)
|
||||
|
||||
local user = 'You are @%s, also known as *%s* `[%s]`'
|
||||
if msg.from.username then
|
||||
user = user:format(utilities.markdown_escape(msg.from.username), msg.from.name, msg.from.id)
|
||||
user = user:format(utilities.markdown_escape(msg.from.username), from_name, msg.from.id)
|
||||
else
|
||||
user = 'You are *%s* `[%s]`,'
|
||||
user = user:format(msg.from.name, msg.from.id)
|
||||
user = user:format(from_name, msg.from.id)
|
||||
end
|
||||
|
||||
local group = '@%s, also known as *%s* `[%s]`.'
|
||||
|
Reference in New Issue
Block a user