various improvements

This commit is contained in:
dupie 2015-07-07 22:24:12 -04:00
parent 21f8e10147
commit dfece989a0
9 changed files with 65 additions and 34 deletions

View File

@ -1,3 +1,19 @@
# otouto # otouto
A plugin-wielding Telegram bot using the new API.
The latest version runs on @mokubot. v1 runs on @otouto. The plugin-wielding, multi-purpose Telgram chat bot.
Public bot runs on [@mokubot](http://telegram.me/mokubot).
Requires lua-socket, lua-sec, and cjson or dkjson.
###Configuration
Most config.json entries are self-explanatory.
TIME_OFFSET is the time difference, in seconds, between your system clock. It is often necessary for accurate output of the time plugin.
"admins" table includes the ID numbers, as integers, of any privileged users. These will have access to the admin plugin and any addition privileged commands.
"people" table is for the personality plugin:
`"123456789": "foobar"`
ID number must be a string.

View File

@ -1,9 +1,11 @@
{ {
"BOT_API_KEY": "", "BOT_API_KEY": "",
"ADMIN_ID": 0,
"BIBLIA_API_KEY": "", "BIBLIA_API_KEY": "",
"GIPHY_API_KEY": "", "GIPHY_API_KEY": "",
"TIME_OFFSET": 0, "TIME_OFFSET": 0,
"admins": [
0
],
"plugins": [ "plugins": [
"8ball.lua", "8ball.lua",
"admin.lua", "admin.lua",
@ -27,6 +29,7 @@
"imdb.lua", "imdb.lua",
"personality.lua", "personality.lua",
"pokedex.lua", "pokedex.lua",
"pun.lua",
"reddit.lua", "reddit.lua",
"remind.lua", "remind.lua",
"shrug.lua", "shrug.lua",
@ -36,6 +39,9 @@
"weather.lua", "weather.lua",
"whoami.lua", "whoami.lua",
"xkcd.lua" "xkcd.lua"
] ],
"people": {
"0": "nickname",
}
} }

View File

@ -1,20 +0,0 @@
local PLUGIN = {}
PLUGIN.doc = [[
!example
Info about the command.
]]
PLUGIN.triggers = {
'^!example',
'^!e$'
}
function PLUGIN.action(msg)
local message = 'Example output.'
send_msg(msg, message)
end
return PLUGIN

View File

@ -10,7 +10,14 @@ function PLUGIN.action(msg)
local message = 'Command not found.' local message = 'Command not found.'
if msg.from.id ~= config.ADMIN_ID then local sudo = 0
for i,v in ipairs(config.admins) do
if msg.from.id == v then
sudo = v
end
end
if sudo == 0 then
message = 'Permission denied.' message = 'Permission denied.'
elseif string.lower(first_word(input)) == 'run' then elseif string.lower(first_word(input)) == 'run' then

View File

@ -25,14 +25,24 @@ function PLUGIN.action(msg)
jdat.res = "I don't know what to say to that." jdat.res = "I don't know what to say to that."
end end
local message = jdat.res
-- Let's clean up the response a little. Capitalization & punctuation. -- Let's clean up the response a little. Capitalization & punctuation.
local message = jdat.res:gsub('simsimi', 'clive') filter = {
local message = message:gsub("^%l", string.upper) ['%aim%aimi'] = bot.first_name,
['^%s*(.-)%s*$'] = '%1',
['^%l'] = string.upper
}
for k,v in pairs(filter) do
message = string.gsub(message, k, v)
end
if not string.match(message, '%p$') then if not string.match(message, '%p$') then
message = message .. '.' message = message .. '.'
end end
send_message(msg.chat.id, jdat.res) send_message(msg.chat.id, message)
end end

View File

@ -13,6 +13,8 @@ PLUGIN.triggers = {
function PLUGIN.action(msg) function PLUGIN.action(msg)
if string.find(msg.text, '@') and not string.match('help@'..bot.username) then return end
local input = get_input(msg.text) local input = get_input(msg.text)
if input then if input then
@ -29,6 +31,7 @@ function PLUGIN.action(msg)
*Arguments: <required> [optional] *Arguments: <required> [optional]
Use "!help <command>" for specific information. Use "!help <command>" for specific information.
otouto v]] .. VERSION .. [[ by @topkecleon. otouto v]] .. VERSION .. [[ by @topkecleon.
Fork me on github! github.com/topkecleon/otouto
]] ]]
if msg.from.id ~= msg.chat.id then if msg.from.id ~= msg.chat.id then

View File

@ -1,7 +1,12 @@
-- config.people is a table of IDs/nicknames the bot can address more familiarly
-- like so:
-- 13227902: "Drew"
local PLUGIN = {} local PLUGIN = {}
PLUGIN.triggers = { PLUGIN.triggers = {
'otouto%p?$', bot.first_name .. '%p?$',
'^tadaima%p?$', '^tadaima%p?$',
'^i\'m home%p?$', '^i\'m home%p?$',
'^i\'m back%p?$' '^i\'m back%p?$'
@ -11,25 +16,27 @@ function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT
local input = string.lower(msg.text) local input = string.lower(msg.text)
if config.people[tostring(msg.from.id)] then msg.from.first_name = config.people[tostring(msg.from.id)] end
for i = 2, #PLUGIN.triggers do for i = 2, #PLUGIN.triggers do
if string.match(input, PLUGIN.triggers[i]) then if string.match(input, PLUGIN.triggers[i]) then
return send_message(msg.chat.id, 'Welcome back, ' .. msg.from.first_name .. '!') return send_message(msg.chat.id, 'Welcome back, ' .. msg.from.first_name .. '!')
end end
end end
if input:match('thanks,? otouto') or input:match('thank you,? otouto') then if input:match('thanks,? '..bot.first_name) or input:match('thank you,? '..bot.first_name) then
return send_message(msg.chat.id, 'No problem, ' .. msg.from.first_name .. '!') return send_message(msg.chat.id, 'No problem, ' .. msg.from.first_name .. '!')
end end
if input:match('hello,? otouto') or input:match('hey,? otouto') or input:match('hi,? otouto') then if input:match('hello,? '..bot.first_name) or input:match('hey,? '..bot.first_name) or input:match('hi,? '..bot.first_name) then
return send_message(msg.chat.id, 'Hi, ' .. msg.from.first_name .. '!') return send_message(msg.chat.id, 'Hi, ' .. msg.from.first_name .. '!')
end end
if input:match('i hate you,? otouto') or input:match('screw you,? otouto') or input:match('fuck you,? otouto') then if input:match('i hate you,? '..bot.first_name) or input:match('screw you,? '..bot.first_name) or input:match('fuck you,? '..bot.first_name) then
return send_msg(msg, '; _ ;') return send_msg(msg, '; _ ;')
end end
if string.match(input, 'i love you,? otouto') then if string.match(input, 'i love you,? '..bot.first_name) then
return send_msg(msg, '<3') return send_msg(msg, '<3')
end end

View File

@ -105,7 +105,7 @@ function PLUGIN.action(msg)
slapper = msg.from.first_name slapper = msg.from.first_name
else else
victim = msg.from.first_name victim = msg.from.first_name
slapper = bot.username slapper = bot.first_name
end end
local message = PLUGIN.getSlap(slapper, victim) local message = PLUGIN.getSlap(slapper, victim)

View File

@ -1,3 +1,5 @@
-- TIME_OFFSET is the number of seconds necessary to correct your system clock to UTC.
local PLUGIN = {} local PLUGIN = {}
PLUGIN.doc = [[ PLUGIN.doc = [[