diff --git a/README.md b/README.md index 3ab4cdc..b7bc5f4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ # 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. \ No newline at end of file diff --git a/config.json b/config.json index 317cd6f..1c92632 100644 --- a/config.json +++ b/config.json @@ -1,9 +1,11 @@ { "BOT_API_KEY": "", - "ADMIN_ID": 0, "BIBLIA_API_KEY": "", "GIPHY_API_KEY": "", "TIME_OFFSET": 0, + "admins": [ + 0 + ], "plugins": [ "8ball.lua", "admin.lua", @@ -27,6 +29,7 @@ "imdb.lua", "personality.lua", "pokedex.lua", + "pun.lua", "reddit.lua", "remind.lua", "shrug.lua", @@ -36,6 +39,9 @@ "weather.lua", "whoami.lua", "xkcd.lua" - ] + ], + "people": { + "0": "nickname", + } } diff --git a/plugin.lua b/plugin.lua deleted file mode 100644 index 9eef8aa..0000000 --- a/plugin.lua +++ /dev/null @@ -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 diff --git a/plugins/admin.lua b/plugins/admin.lua index 2d1370d..7cbc2b4 100644 --- a/plugins/admin.lua +++ b/plugins/admin.lua @@ -10,7 +10,14 @@ function PLUGIN.action(msg) 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.' elseif string.lower(first_word(input)) == 'run' then diff --git a/plugins/chatter.lua b/plugins/chatter.lua index fafdc3c..0189f98 100644 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -25,14 +25,24 @@ function PLUGIN.action(msg) jdat.res = "I don't know what to say to that." end + local message = jdat.res + -- Let's clean up the response a little. Capitalization & punctuation. - local message = jdat.res:gsub('simsimi', 'clive') - local message = message:gsub("^%l", string.upper) + filter = { + ['%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 message = message .. '.' end - send_message(msg.chat.id, jdat.res) + send_message(msg.chat.id, message) end diff --git a/plugins/help.lua b/plugins/help.lua index 3209bd0..1c6e587 100644 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -13,6 +13,8 @@ PLUGIN.triggers = { 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) if input then @@ -29,6 +31,7 @@ function PLUGIN.action(msg) *Arguments: [optional] Use "!help " for specific information. otouto v]] .. VERSION .. [[ by @topkecleon. + Fork me on github! github.com/topkecleon/otouto ]] if msg.from.id ~= msg.chat.id then diff --git a/plugins/personality.lua b/plugins/personality.lua index ddb917c..70b3056 100644 --- a/plugins/personality.lua +++ b/plugins/personality.lua @@ -1,7 +1,12 @@ + -- config.people is a table of IDs/nicknames the bot can address more familiarly + -- like so: + -- 13227902: "Drew" + + local PLUGIN = {} PLUGIN.triggers = { - 'otouto%p?$', + bot.first_name .. '%p?$', '^tadaima%p?$', '^i\'m home%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) + 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 if string.match(input, PLUGIN.triggers[i]) then return send_message(msg.chat.id, 'Welcome back, ' .. msg.from.first_name .. '!') 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 .. '!') 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 .. '!') 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, '; _ ;') 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') end diff --git a/plugins/slap.lua b/plugins/slap.lua index 9e9a0b8..7938739 100644 --- a/plugins/slap.lua +++ b/plugins/slap.lua @@ -105,7 +105,7 @@ function PLUGIN.action(msg) slapper = msg.from.first_name else victim = msg.from.first_name - slapper = bot.username + slapper = bot.first_name end local message = PLUGIN.getSlap(slapper, victim) diff --git a/plugins/time.lua b/plugins/time.lua index 524ce18..9c4a910 100644 --- a/plugins/time.lua +++ b/plugins/time.lua @@ -1,3 +1,5 @@ + -- TIME_OFFSET is the number of seconds necessary to correct your system clock to UTC. + local PLUGIN = {} PLUGIN.doc = [[