diff --git a/bot.lua b/bot.lua
index 77682a5..266a777 100644
--- a/bot.lua
+++ b/bot.lua
@@ -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...')
diff --git a/config.lua.default b/config.lua.default
index 98234b8..0dd2c14 100644
--- a/config.lua.default
+++ b/config.lua.default
@@ -8,9 +8,7 @@ return {
admins = {
0
},
- blaclist = {
- 0
- },
+ blacklist = load_data('blacklist.json'),
plugins = {
'about.lua',
'help.lua',
diff --git a/plugins/blacklist.lua b/plugins/blacklist.lua
new file mode 100644
index 0000000..bd898aa
--- /dev/null
+++ b/plugins/blacklist.lua
@@ -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
+}
diff --git a/plugins/calc.lua b/plugins/calc.lua
index c94033d..2f4adb1 100644
--- a/plugins/calc.lua
+++ b/plugins/calc.lua
@@ -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)
diff --git a/plugins/chatter.lua b/plugins/chatter.lua
index 952f71c..d4bcbc2 100644
--- a/plugins/chatter.lua
+++ b/plugins/chatter.lua
@@ -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
diff --git a/plugins/currency.lua b/plugins/currency.lua
index 73839af..2efba7c 100644
--- a/plugins/currency.lua
+++ b/plugins/currency.lua
@@ -36,10 +36,9 @@ local action = function(msg)
return send_msg(msg, config.locale.errors.connection)
end
- local str = str:match('.*')
+ local str = str:match('(.*) %u+')
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
diff --git a/plugins/moderation.lua b/plugins/moderation.lua
index b02df28..1d5c6ad 100644
--- a/plugins/moderation.lua
+++ b/plugins/moderation.lua
@@ -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
diff --git a/plugins/weather.lua b/plugins/weather.lua
index c503ae3..5bf0829 100644
--- a/plugins/weather.lua
+++ b/plugins/weather.lua
@@ -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