split admin.lua into multiple plugins to make way for the future

added shout.lua
This commit is contained in:
topkecleon 2015-12-13 09:25:49 -05:00
parent c8a90c5c7f
commit a0bbdba135
8 changed files with 123 additions and 75 deletions

View File

@ -1,75 +0,0 @@
local triggers = {
'^/admin[@'..bot.username..']*'
}
local commands = {
['run'] = function(cmd)
local cmd = cmd:input()
if not cmd then
return 'Please enter a command to run.'
end
return io.popen(cmd):read('*all')
end,
['lua'] = function(cmd)
local cmd = cmd:input()
if not cmd then
return 'Please enter a command to run.'
end
local a = loadstring(cmd)()
if a then
return a
else
return 'Done!'
end
end,
['reload'] = function(cmd)
bot_init()
return 'Bot reloaded!'
end,
['halt'] = function(cmd)
is_started = false
return 'Stopping bot!'
end,
['error'] = function(cmd)
error('Intentional test error.')
end
}
local action = function(msg)
if msg.from.id ~= config.admin then
return
end
local input = msg.text:input()
if not input then
local list = 'Specify a command: '
for k,v in pairs(commands) do
list = list .. k .. ', '
end
list = list:gsub(', $', '.')
sendReply(msg, list)
return
end
for k,v in pairs(commands) do
if string.match(get_word(input, 1), k) then
sendReply(msg, v(input))
return
end
end
sendReply(msg, 'Specify a command: run, reload, halt.')
end
return {
action = action,
triggers = triggers
}

View File

@ -1,3 +1,4 @@
-- An extension to moderation.lua. This plugin is useless without it.
-- Put this at the very top of your plugin list, even before blacklist.lua. -- Put this at the very top of your plugin list, even before blacklist.lua.
-- Developed by the incredible JuanPotato, creator of the Python CLI bot Botato. -- Developed by the incredible JuanPotato, creator of the Python CLI bot Botato.

26
plugins/control.lua Normal file
View File

@ -0,0 +1,26 @@
local triggers = {
'^/reload[@'..bot.username..']*',
'^/halt[@'..bot.username..']*'
}
local action = function(msg)
if msg.from.id ~= config.admin then
return
end
if msg.text:match('^/reload') then
bot_init()
sendReply(msg, 'Bot reloaded!')
elseif msg.text:match('^/halt') then
is_started = false
sendReply(msg, 'Stopping bot!')
end
end
return {
action = action,
triggers = triggers
}

0
plugins/hearthstone.lua Normal file → Executable file
View File

27
plugins/luarun.lua Normal file
View File

@ -0,0 +1,27 @@
local triggers = {
'^/lua[@'..bot.username..']*'
}
local action = function(msg)
if msg.from.id ~= config.admin then
return
end
local input = msg.text:input()
if not input then
sendReply(msg, 'Please enter a string to load.')
return
end
local output = loadstring(input)()
if not output then output = 'Done!' end
sendReply(msg, output)
end
return {
action = action,
triggers = triggers
}

0
plugins/ping.lua Normal file → Executable file
View File

26
plugins/shell.lua Normal file
View File

@ -0,0 +1,26 @@
local triggers = {
'^/run[@'..bot.username..']*'
}
local action = function(msg)
if msg.from.id ~= config.admin then
return
end
local input = msg.text:input()
if not input then
sendReply(msg, 'Please specify a command to run.')
return
end
local output = io.popen(input):read('*all')
if output:len() == 0 then output = 'Done!' end
sendReply(msg, output)
end
return {
action = action,
triggers = triggers
}

43
plugins/shout.lua Normal file
View File

@ -0,0 +1,43 @@
local doc = [[
/shout <term>
Shout something!
]]
local triggers = {
'^/shout[@'..bot.username..']*'
}
local action = function(msg)
local input = msg.text:input()
if not input then
sendReply(msg, doc)
return
end
input = input:upper()
local output = ''
local inc = 0
for match in input:gmatch('.') do
output = output .. match .. ' '
end
output = output .. '\n'
for match in input:sub(2):gmatch('.') do
local spacing = ''
for i = 1, inc do
spacing = spacing .. ' '
end
inc = inc + 1
output = output .. match .. ' ' .. spacing .. match .. '\n'
end
output = '```\n' .. output:trim() .. '\n```'
sendMessage(msg.chat.id, output, true, false, true)
end
return {
action = action,
triggers = triggers,
doc = doc
}