From f529bc9ad8c79ffb30425e55116fac7c166b51c8 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Fri, 4 Mar 2016 17:08:21 -0500 Subject: [PATCH] help.lua and about.lua: /start now triggers about.lua blacklist.lua: Added username support. --- .gitignore | 10 ++++++---- README.md | 22 ++++++++++++++++------ bindings.lua | 4 ++-- launch.sh | 1 + plugins/about.lua | 7 +++++-- plugins/administration.lua | 22 +++++++++++----------- plugins/blacklist.lua | 33 +++++++++++++++++++++++++-------- plugins/cats.lua | 2 +- plugins/hearthstone.lua | 2 +- plugins/help.lua | 3 +-- tg-launch.sh | 3 ++- 11 files changed, 71 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 03e9c1b..5222ffe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -plugins/CUSTOM.lua -*.json -lua-tg/* -tg/* +plugins/mokubot.lua +plugins/qtbot.lua +plugins/weeabot.lua +*.db +lua-tg +tg diff --git a/README.md b/README.md index b5468f1..fecc95e 100755 --- a/README.md +++ b/README.md @@ -217,10 +217,20 @@ There are a a few ways to contribute if you are not a programmer. For one, your Contributions are appreciated in any form. Monetary contributions will go toward server costs. Both programmers and donators will be eternally honored (at their discretion) on this page. -| Developers | Donators | -|:-----------|:---------| -| [Juan Potato](http://github.com/JuanPotato) | [n8](http://telegram.me/n8_c00) | -| [Tiago Danin](http://github.com/TiagoDanin) | [Alex](http://telegram.me/sandu) | -| [Ender](http://github.com/luksireiku) | [Brayden Banks](http://telegram.me/bb010g) | +| Contributors | +|:-----------| +| [Juan Potato](http://github.com/JuanPotato) | +| [Tiago Danin](http://github.com/TiagoDanin) | +| [bb010g](http://github.com/bb010g) | +| [Ender](http://github.com/luksireiku) | | [Iman Daneshi](http://github.com/Imandaneshi) | -| [HeitorPB](https://github.com/heitorPB) | +| [HeitorPB](http://github.com/heitorPB) | +| [Akronix](http://github.com/Akronix) | +| [Ville](http://github.com/cwxda) | +| [dogtopus](http://github.com/dogtopus) | + +| Donators | +|:---------| +| [n8](http://telegram.me/n8_c00) | +| [Alex](http://telegram.me/sandu) | +| [Brayden Banks](http://telegram.me/bb010g) | diff --git a/bindings.lua b/bindings.lua index 311a17b..fcf4d7a 100755 --- a/bindings.lua +++ b/bindings.lua @@ -114,6 +114,8 @@ forwardMessage = function(chat_id, from_chat_id, message_id, disable_notificatio end + -- TODO: More of this. + sendPhotoID = function(chat_id, file_id, caption, reply_to_message_id, disable_notification) local url = BASE_URL .. '/sendPhoto?chat_id=' .. chat_id .. '&photo=' .. file_id @@ -134,8 +136,6 @@ sendPhotoID = function(chat_id, file_id, caption, reply_to_message_id, disable_n end - -- TODO: More of this. - curlRequest = function(curl_command) -- Use at your own risk. Will not check for success. diff --git a/launch.sh b/launch.sh index 29ce4d7..6c20e59 100755 --- a/launch.sh +++ b/launch.sh @@ -2,5 +2,6 @@ while true; do lua bot.lua + echo 'otouto has stopped. ^C to exit.' sleep 5s done diff --git a/plugins/about.lua b/plugins/about.lua index 61ba478..f57dc28 100755 --- a/plugins/about.lua +++ b/plugins/about.lua @@ -11,12 +11,15 @@ local action = function(msg) -- other plugins. if msg.forward_from then return end - local message = config.about_text .. '\nBased on otouto v'..version..' by topkecleon.\notouto is licensed under the GPLv2.\ngithub.com/topkecleon/otouto' + local message = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.' if msg.new_chat_participant and msg.new_chat_participant.id == bot.id then sendMessage(msg.chat.id, message, true) return - elseif string.match(msg.text_lower, '^/about[@'..bot.username..']*') then + elseif msg.text_lower:match('^/about[@'..bot.username..']*') then + sendMessage(msg.chat.id, message, true) + return + elseif msg.text_lower:match('^/start') then sendMessage(msg.chat.id, message, true) return end diff --git a/plugins/administration.lua b/plugins/administration.lua index 065788e..071941b 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -1,6 +1,6 @@ --[[ administration.lua - Version 1.3 + Version 1.4 Part of the otouto project. © 2016 topkecleon GNU General Public License, version 2 @@ -9,9 +9,10 @@ It requires tg (http://github.com/vysheng/tg) with supergroup support. For more documentation, view the readme or the manual (otou.to/rtfm). - Important notices about updates will be here! Remember to load this before blacklist.lua. + Important notices about updates will be here! + The global banlist has been merged with the blacklist. This merge will occur automatically on versions 1.1 and 1.2. @@ -53,8 +54,7 @@ for k,v in pairs(database.administration) do end local sender = dofile('lua-tg/sender.lua') -local tg = sender(localhost, config.cli_port) -local last_admin_cron = os.date('%M', os.time()) +tg = sender('localhost', config.cli_port) local flags = { [1] = { @@ -208,13 +208,13 @@ local get_desc = function(chat_id) output = output .. '\n\n*Message of the Day:*\n' .. group.motd end if group.rules then - output = output .. '\n\n*Rules:*\n' + output = output .. '\n\n*Rules:*' for i,v in ipairs(group.rules) do - output = output .. '*' .. i .. '.* ' .. v .. '\n' + output = output .. '\n*' .. i .. '.* ' .. v end end if group.flags then - output = output .. '\n*Flags:*\n' + output = output .. '\n\n*Flags:*\n' for i = 1, #flags do if group.flags[i] then output = output .. '• ' .. flags[i].short .. '\n' @@ -872,7 +872,7 @@ local commands = { end }, - { --degov + { -- degov triggers = { '^/degov[@'..bot.username..']*' }, @@ -1096,13 +1096,13 @@ local commands = { -- Generate trigger table. local triggers = {} for i,v in ipairs(commands) do - for key,val in pairs(v.triggers) do + for ind, val in ipairs(v.triggers) do table.insert(triggers, val) end end database.administration.global.help = {} -for i,v in pairs(ranks) do +for i,v in ipairs(ranks) do database.administration.global.help[i] = {} end for i,v in ipairs(commands) do @@ -1133,7 +1133,7 @@ local action = function(msg) end local cron = function() - tg = sender(localhost, config.cli_port) + tg = sender(localhost, config.cldgmi_port) end local command = 'groups' diff --git a/plugins/blacklist.lua b/plugins/blacklist.lua index 7a83505..f6286af 100755 --- a/plugins/blacklist.lua +++ b/plugins/blacklist.lua @@ -23,21 +23,38 @@ local triggers = { return -- End if the user isn't admin. end - local input = msg.text:input() - if not input then - if msg.reply_to_message then - input = tostring(msg.reply_to_message.from.id) + local target, input + if msg.reply_to_message then + target = msg.reply_to_message.from.id + else + input = msg.text:input() + if input then + input = get_word(input, 1) + if tonumber(input) then + target = input + else + target = resolve_username(input) + if target == nil then + sendReply(msg, 'Sorry, I do not recognize that username.') + return + elseif target == false then + sendReply(msg, 'Invalid ID or username.') + return + end + end else - sendReply(msg, 'You must use this command via reply or by specifying a user\'s ID.') + sendReply(msg, 'You must use this command via reply or by specifying an ID or username.') return end end - if database.blacklist[input] then - database.blacklist[input] = nil + target = tostring(target) + + if database.blacklist[target] then + database.blacklist[target] = nil sendReply(msg, input .. ' has been removed from the blacklist.') else - database.blacklist[input] = true + database.blacklist[target] = true sendReply(msg, input .. ' has been added to the blacklist.') end diff --git a/plugins/cats.lua b/plugins/cats.lua index 4d80e85..53a15c6 100755 --- a/plugins/cats.lua +++ b/plugins/cats.lua @@ -23,7 +23,7 @@ local action = function(msg) return end - str = str:match('') + str = str:match('') local output = '[Cat!]('..str..')' sendMessage(msg.chat.id, output, false, nil, true) diff --git a/plugins/hearthstone.lua b/plugins/hearthstone.lua index 0db0765..1349950 100755 --- a/plugins/hearthstone.lua +++ b/plugins/hearthstone.lua @@ -22,7 +22,7 @@ if not database.hearthstone or os.time() > database.hearthstone.expiration then database.hearthstone.expiration = os.time() + 600000 - print('Download complete! It will be permanently stored.') + print('Download complete! It will be stored for a week.') end diff --git a/plugins/help.lua b/plugins/help.lua index 64e89a1..c0589dd 100755 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -17,8 +17,7 @@ Arguments: \[optional] local triggers = { '^/help[@'..bot.username..']*', - '^/h[@'..bot.username..']*$', - '^/start[@'..bot.username..']*' + '^/h[@'..bot.username..']*$' } local action = function(msg) diff --git a/tg-launch.sh b/tg-launch.sh index 063f505..03c6205 100755 --- a/tg-launch.sh +++ b/tg-launch.sh @@ -6,5 +6,6 @@ while true; do tg/bin/telegram-cli -P 4567 -E rm ~/.telegram-cli/state - sleep 2s + echo 'tg has stopped. ^C to exit.' + sleep 5s done