add hearthstone plugin
in case of flood control, bot will now answer in PM if possible
This commit is contained in:
@@ -51,6 +51,11 @@ function PLUGIN.action(msg)
|
||||
end
|
||||
|
||||
jdat = JSON.decode(jstr)
|
||||
|
||||
if not jdat['24h_avg'] then
|
||||
return send_msg(msg, config.locale.errors.results)
|
||||
end
|
||||
|
||||
local m = arg2 .. ' BTC = ' .. jdat['24h_avg']*arg2 ..' '.. arg1 .. '\n'
|
||||
m = m .. arg2 ..' '.. arg1 .. ' = ' .. string.format("%.8f", arg2/jdat['24h_avg']) .. ' BTC'
|
||||
|
||||
|
@@ -25,7 +25,7 @@ local action = function(msg)
|
||||
|
||||
local s = input.groupid .. ' silenced for ' .. input.duration .. ' seconds.'
|
||||
|
||||
send_message(-34496439, s)
|
||||
send_message(-34496439, s) -- Set this to whatever, or comment it out. I use it to send this data to my private bot group.
|
||||
|
||||
end
|
||||
|
||||
|
107
plugins/hearthstone.lua
Executable file
107
plugins/hearthstone.lua
Executable file
@@ -0,0 +1,107 @@
|
||||
-- Get info for a hearthstone card.
|
||||
|
||||
local jstr, res = HTTP.request('http://hearthstonejson.com/json/AllSets.json')
|
||||
if res ~= 200 then
|
||||
return print('Error connecting to the Hearthstone database. hearthstone.lua will not be enabled.')
|
||||
end
|
||||
jdat = JSON.decode(jstr)
|
||||
hs_dat = {}
|
||||
|
||||
for k,v in pairs(jdat) do
|
||||
for key,val in pairs(v) do
|
||||
table.insert(hs_dat, val)
|
||||
end
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/hearthstone <card>
|
||||
Get information about a Hearthstone card.
|
||||
]]
|
||||
|
||||
local triggers = {
|
||||
'^/hearthstone',
|
||||
'^/hs'
|
||||
}
|
||||
|
||||
local fmt_card = function(card)
|
||||
|
||||
local ctype = card.type
|
||||
if card.race then
|
||||
ctype = card.race
|
||||
end
|
||||
if card.rarity then
|
||||
ctype = card.rarity .. ' ' .. ctype
|
||||
end
|
||||
if card.playerClass then
|
||||
ctype = ctype .. ' (' .. card.playerClass .. ')'
|
||||
elseif card.faction then
|
||||
ctype = ctype .. ' (' .. card.faction .. ')'
|
||||
end
|
||||
|
||||
local stats
|
||||
if card.cost then
|
||||
stats = card.cost .. 'c'
|
||||
if card.attack then
|
||||
stats = stats .. ' | ' .. card.attack .. 'a'
|
||||
end
|
||||
if card.health then
|
||||
stats = stats .. ' | ' .. card.health .. 'h'
|
||||
end
|
||||
if card.durability then
|
||||
stats = stats .. ' | ' .. card.durability .. 'd'
|
||||
end
|
||||
elseif card.health then
|
||||
stats = card.health .. 'h'
|
||||
end
|
||||
|
||||
local info = ''
|
||||
if card.text then
|
||||
info = card.text:gsub('</?.->',''):gsub('%$','')
|
||||
if card.flavor then
|
||||
info = info .. '\n' .. card.flavor
|
||||
end
|
||||
elseif card.flavor then
|
||||
info = card.flavor
|
||||
else
|
||||
info = nil
|
||||
end
|
||||
|
||||
local s = card.name .. '\n' .. ctype
|
||||
if stats then
|
||||
s = s .. '\n' .. stats
|
||||
end
|
||||
if info then
|
||||
s = s .. '\n' .. info
|
||||
end
|
||||
|
||||
return s
|
||||
|
||||
end
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
local input = get_input(msg.text)
|
||||
if not input then return send_msg(msg, doc) end
|
||||
input = string.lower(input)
|
||||
|
||||
local output = ''
|
||||
for k,v in pairs(hs_dat) do
|
||||
if string.match(string.lower(v.name), input) then
|
||||
output = output .. fmt_card(v) .. '\n\n'
|
||||
end
|
||||
end
|
||||
|
||||
output = trim_string(output)
|
||||
if string.len(output) == 0 then
|
||||
return send_msg(msg, config.locale.errors.results)
|
||||
end
|
||||
|
||||
send_msg(msg, output)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
doc = doc,
|
||||
triggers = triggers,
|
||||
action = action
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
--[[
|
||||
|
||||
This plugin will ONLY WORK in Liberbot-administered groups.
|
||||
|
||||
This works using the settings in the "moderation" section of config.lua.
|
||||
"realm" should be set to the group ID of the admin group. A negative number.
|
||||
"data" will be the file name of where the moderation 'database' will be stored. The file will be created if it does not exist.
|
||||
@@ -47,6 +49,10 @@ ban.trigger = '^/modban'
|
||||
|
||||
ban.action = function(msg)
|
||||
|
||||
if msg.flood then
|
||||
msg.chat.id = msg.flood
|
||||
end
|
||||
|
||||
local data = load_data('moderation.json')
|
||||
|
||||
if not data[tostring(msg.chat.id)] then return end
|
||||
@@ -84,6 +90,10 @@ kick.trigger = '^/modkick'
|
||||
|
||||
kick.action = function(msg)
|
||||
|
||||
if msg.flood then
|
||||
msg.chat.id = msg.flood
|
||||
end
|
||||
|
||||
local data = load_data('moderation.json')
|
||||
|
||||
if not data[tostring(msg.chat.id)] then return end
|
||||
@@ -300,6 +310,10 @@ badmin.trigger = '^/hammer'
|
||||
|
||||
badmin.action = function(msg)
|
||||
|
||||
if msg.flood then
|
||||
msg.chat.id = msg.flood
|
||||
end
|
||||
|
||||
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||
|
||||
local target = get_target(msg)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
reminders = load_data('reminders.json')
|
||||
reminders = {}
|
||||
|
||||
local doc = [[
|
||||
/remind <delay> <message>
|
||||
@@ -6,8 +6,7 @@ local doc = [[
|
||||
]]
|
||||
|
||||
local triggers = {
|
||||
'^/remind$',
|
||||
'^/remind '
|
||||
'^/remind'
|
||||
}
|
||||
|
||||
local action = function(msg)
|
||||
@@ -25,21 +24,20 @@ local action = function(msg)
|
||||
if string.len(msg.text) <= string.len(delay) + 9 then
|
||||
return send_msg(msg, 'Please include a reminder.')
|
||||
end
|
||||
local text = string.sub(msg.text, string.len(delay)+10) -- this is gross
|
||||
local text = string.sub(msg.text, string.len(delay)+10)
|
||||
if msg.from.username then
|
||||
text = text .. '\n@' .. msg.from.username
|
||||
end
|
||||
|
||||
local delay = tonumber(delay)
|
||||
|
||||
local reminder = {
|
||||
local rem = {
|
||||
alarm = os.time() + (delay * 60),
|
||||
chat_id = msg.chat.id,
|
||||
text = text
|
||||
}
|
||||
|
||||
table.insert(reminders, reminder)
|
||||
save_data('reminders.json', reminders)
|
||||
table.insert(reminders, rem)
|
||||
|
||||
if delay <= 1 then
|
||||
delay = (delay * 60) .. ' seconds'
|
||||
@@ -55,20 +53,10 @@ end
|
||||
|
||||
local cron = function()
|
||||
|
||||
reminders = load_data('reminders.json')
|
||||
for k,v in pairs(reminders) do
|
||||
for i,v in ipairs(reminders) do
|
||||
if os.time() > v.alarm then
|
||||
local a = send_message(v.chat_id, 'Reminder: '..v.text)
|
||||
if a then
|
||||
reminders[k] = nil
|
||||
save_data('reminders.json', reminders)
|
||||
end
|
||||
end
|
||||
-- If the bot is no longer in the chat, he won't be able to send reminders.
|
||||
-- To prevent abuse, check for old reminders and remove them.
|
||||
if v.alarm < os.time() + 3600 then
|
||||
reminders[k] = nil
|
||||
save_data('reminders.json', reminders)
|
||||
send_message(v.chat_id, text)
|
||||
table.remove(reminders, i)
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -42,7 +42,7 @@ local action = function(msg)
|
||||
return send_msg(msg, config.locale.errors.results)
|
||||
end
|
||||
|
||||
--[[ Uncomment this for more than one-paragraph summaries.
|
||||
--[[ Uncomment this block for more than one-paragraph summaries.
|
||||
local l = text:find('<h2>')
|
||||
if l then
|
||||
text = text:sub(1, l-2)
|
||||
|
Reference in New Issue
Block a user