blacklist now in json file

various bugfixes
This commit is contained in:
topkecleon 2015-08-08 20:53:46 -04:00
parent 566086c64d
commit 1a0b61814e
8 changed files with 64 additions and 18 deletions

View File

@ -6,11 +6,11 @@ HTTPS = require('ssl.https')
URL = require('socket.url')
JSON = require('dkjson')
VERSION = 2.6
VERSION = 2.7
function on_msg_receive(msg)
if config.blacklist[msg.from.id] then return end
if config.blacklist[tostring(msg.from.id)] then return end
msg = process_msg(msg)
@ -25,7 +25,7 @@ function on_msg_receive(msg)
if not v.no_typing then
send_chat_action(msg.chat.id, 'typing')
end
local a,b = pcall(function() -- Janky error handling, but it works.
local a,b = pcall(function() -- Janky error handling
v.action(msg)
end)
if not a then
@ -38,6 +38,7 @@ function on_msg_receive(msg)
end
function bot_init()
require('utilities')
print('\nLoading configuration...')
@ -46,7 +47,6 @@ function bot_init()
print(#config.plugins .. ' plugins enabled.')
require('bindings')
require('utilities')
print('\nFetching bot information...')

View File

@ -8,9 +8,7 @@ return {
admins = {
0
},
blaclist = {
0
},
blacklist = load_data('blacklist.json'),
plugins = {
'about.lua',
'help.lua',

41
plugins/blacklist.lua Normal file
View File

@ -0,0 +1,41 @@
-- Admins can blacklist a user from utilizing this bot. Use via reply or with an ID as an argument. Un-blacklist a user with the same command.
local triggers = {
'^/blacklist'
}
local action = function(msg)
if not config.admins[msg.from.id] then
return send_msg(msg, 'Permission denied.')
end
local input = get_input(msg.text)
if not input then
if msg.reply_to_message then
input = msg.reply_to_message.from.id
else
return send_msg(msg, 'Must be used via reply or by specifying a user\'s ID.')
end
end
local id = tostring(input)
if config.blacklist[id] then
config.blacklist[id] = nil
send_msg(msg, 'User has been removed from the blacklist.')
else
config.blacklist[id] = true
send_msg(msg, 'User has been blacklisted.')
end
save_data('blacklist.json', config.blacklist)
end
return {
doc = doc,
triggers = triggers,
action = action,
no_typing = true
}

View File

@ -20,7 +20,7 @@ function PLUGIN.action(msg)
local message, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, config.locale.errors.connection)
return send_msg(msg, config.locale.errors.syntax)
end
send_msg(msg, message)

View File

@ -21,7 +21,7 @@ function PLUGIN.action(msg)
local jdat = JSON.decode(jstr)
if string.match(jdat.res, '^I HAVE NO RESPONSE.') then
if string.match(jdat.res, '^I HAVE NO RESPONSE.') or not jdat then
jdat.res = "I don't know what to say to that."
end

View File

@ -36,10 +36,9 @@ local action = function(msg)
return send_msg(msg, config.locale.errors.connection)
end
local str = str:match('<span class=bld>.*</span>')
local str = str:match('<span class=bld>(.*) %u+</span>')
if not str then return send_msg(msg, config.locale.errors.results) end
local str = str:sub(str:find('>')+1)
result = str:sub(1, str:find(' ')-1)
result = string.format('%.2f', str)
end

View File

@ -198,18 +198,23 @@ demote.action = function(msg)
return send_message(msg.chat.id, 'Group is not added.')
end
if not msg.reply_to_message then
return send_message(msg.chat.id, 'Demotions must be done via reply.')
local input = get_input(msg.text)
if not input then
if msg.reply_to_message then
input = msg.reply_to_message.from.id
else
return send_msg('Demotions must be done by reply or by specifying a moderator\'s ID.')
end
end
if not data[tostring(msg.chat.id)][tostring(msg.reply_to_message.from.id)] then
return send_message(msg.chat.id, msg.reply_to_message.from.first_name..' is not a moderator.')
if not data[tostring(msg.chat.id)][tostring(input)] then
return send_message(msg.chat.id, input..' is not a moderator.')
end
data[tostring(msg.chat.id)][tostring(msg.reply_to_message.from.id)] = nil
data[tostring(msg.chat.id)][tostring(input)] = nil
save_data(config.moderation.data, data)
send_message(msg.chat.id, msg.reply_to_message.from.first_name..' has been demoted.')
send_message(msg.chat.id, input..' has been demoted.')
end

View File

@ -25,6 +25,9 @@ function PLUGIN.action(msg)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
if not jdat.query.results then
return send_msg(msg, config.locale.errors.results)
end
local data = jdat.query.results.channel.item.condition
local fahrenheit = data.temp