From 76e392c3b5311b93d406443fc3336ea4474c34df Mon Sep 17 00:00:00 2001 From: imandaneshi Date: Fri, 8 Apr 2016 19:17:36 +0100 Subject: [PATCH] Jack version 1 ! --- README.md | 21 ++++++++++++------- jackbot.moon | 42 +++++++++++++++++++++++++++++++++++++- plugins/admin.moon | 51 +++++++++++++++++++++++++++++++++++++++++++++- run.sh | 50 +++++++++++++++++++++++++++++++++++++++++---- utilities.moon | 21 ++++++++++++++++++- 5 files changed, 171 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 961bcca..52c0878 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Jack +# Jack Multi purpose telegram bot written in MoonScript/lua and licenced under the GNU General Public License. @@ -9,6 +9,7 @@ Multi purpose telegram bot written in MoonScript/lua and licenced under the GNU Table of Contents * [Setup](#setup) +* [Ranks](#ranks) * [Telegram Cli](#telegram-cli) * [Database](#database) * [Plugins](#plugins) @@ -17,7 +18,7 @@ Table of Contents * [Collaborators](#collaborators) * [Other projects](#other-projects) -#Setup +# Setup Clone Jack ! @@ -58,13 +59,17 @@ chmod +x run.sh ### options -*1 - No output* +Use `./run.sh --help` for available options -`--no-output` ->./run.sh --no-output +# Ranks -Bot wont print msgs in this mod + Ranks | Permissions | +------ | ---------------- | + Admin | Has access to everything + premium | Has access to premium feature + normal user | Has access to public feature + blacklisted | Bot will ignore blacklisted users # Telegram cli @@ -103,7 +108,7 @@ Few examples [Telegram CLI Commands](https://github.com/vysheng/tg/wiki/Telegram-CLI-Commands) -#Database +# Database Jack uses redis as database @@ -917,6 +922,8 @@ Join our development group by sending /join 1047524697 to [@TeleSeed](https://te [Yago](https://github.com/yagop) +[Flippylosaurus](https://telegram.me/Flippylosaurus) + # Collaborators diff --git a/jackbot.moon b/jackbot.moon index 696a8ca..ba74a46 100644 --- a/jackbot.moon +++ b/jackbot.moon @@ -8,6 +8,8 @@ export socket = require "socket" export JSON = require "cjson" export colors = require 'ansicolors' export config = moonscript.loadfile "config.moon" +http.TIMEOUT = 5 +https.TIMEOUT = 5 utilities = moonscript.loadfile "utilities.moon",implicitly_return_root:true utilities! export redis = (Redis @).client @@ -80,6 +82,42 @@ export msg_processor = (msg) -> if msg.text if msg.text\match '^[/]' msg.text = msg.text\gsub "@#{bot_username}",""--Remove username + --Msg filter + if admin_only! + unless is_admin(msg) + return + msg.text = "###photo" if msg.photo + + msg.text = "###audio" if msg.audio + + msg.text = "###document" if msg.document + + msg.text = "###sticker" if msg.sticker + + msg.text = "###video" if msg.video + + msg.text = "###voice" if msg.voice + + msg.text = "###contact" if msg.contact + + msg.text = "###location" if msg.location + + msg.text = "###new_chat_participant" if msg.new_chat_participant + + msg.text = "###left_chat_participant" if msg.left_chat_participant + + msg.text = "###new_chat_title" if msg.new_chat_title + + msg.text = "###new_chat_photo" if msg.new_chat_photo + + msg.text = "###delete_chat_photo" if msg.delete_chat_photo + + msg.text = "###group_chat_created" if msg.group_chat_created + + msg.text = "###supergroup_chat_created" if msg.supergroup_chat_created + + msg.text = "###migrate" if msg.migrate_to_chat_id + msg_text = msg.text or "" --User changed chat name msg_text = "changed group name to > #{msg.new_chat_title}" if msg.new_chat_title @@ -249,10 +287,12 @@ export inline_query_received = (inline) -> bot_run!--Load the bot -print colors("%{red}\nNo output mode enabled . I wont print messages\n%{reset}") if no_output! +print colors("%{red}\nNo output mode enabled. I wont print messages\n%{reset}") if no_output! +print colors("%{red}\nAdmin mode enabled.\n%{reset}") if admin_only! while is_running--A loop for getting messages if last_cron < os.time() - 10--cron thing + export last_cron = os.time() for i,v in pairs plugins if (v @) if (v @).cron diff --git a/plugins/admin.moon b/plugins/admin.moon index 429a74f..e9583bb 100644 --- a/plugins/admin.moon +++ b/plugins/admin.moon @@ -1,3 +1,33 @@ +obtain_user_info = (user_id) -> + first_name = false + last_name = false + username = false + info = redis\hgetall "bot:users:#{user_id}" + if info + if info.first_name + first_name = info.first_name + if info.last_name + last_name = info.last_name + if info.username + username = info.username + text = "" + if first_name + text ..= "#{first_name} " + if last_name + text ..= "#{last_name} " + text ..= "#{user_id} " + if username + text ..= "@#{username}" + text ..= "\n" + return text + +premium_list = (msg) -> + text = "" + users = redis\smembers "bot:premium:users" + for k,v in pairs(users) + text ..= "#{obtain_user_info v}" + return text + spairs = (t, order) -> -- collect the keys keys = {} @@ -98,7 +128,23 @@ run = (msg,matches) -> elseif matches[4] == "true" then redis\set "bot:plugin_disabled_on_chat:#{matches[2]}:#{matches[3]}", true return "*Plugin* `#{matches[2]} `disabled on `#{matches[3]}`" - return + if matches[1] == "premium" + if matches[2] + if matches[2] == "list" + return premium_list! + user_id = "" + if msg.reply_to_message + user_id = msg.reply_to_message.from.id + elseif matches[2] + user_id = matches[2] + + is_premium = redis\sismember("bot:premium:users", user_id) + if is_premium + redis\srem("bot:premium:users", user_id) + return "`User #{user_id} removed from premium list`" + else + redis\sadd("bot:premium:users", user_id) + return "`User #{user_id} Added to premium list`" @@ -107,7 +153,10 @@ patterns = { "^[!#/](plugins) ([^%s]+) (.+) (true)$" "^[!#/](plugins) ([^%s]+) (.+) (false)$" "^[!#/](blacklist) (%d+)$" + "^[!#/](premium) (%d+)$" + "^[!#/](premium) (list)$" "^[!#/](blacklist)$" + "^[!#/](premium)$" "^[!#/](bc) ([^%s]+) (.*)$" "^[!#/](broadcast) +(.+)$" "^[!#/](bot)$" diff --git a/run.sh b/run.sh index d43213f..a2fdf93 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,46 @@ -while true; do - moon jackbot.moon "${@}" - sleep 10s -done +ver="1.0" +if [ "$1" = "--help" ]; then + echo -e " + \033[31;47mJack Telegram Bot\033[0m + + \033[5mV $ver\033[0m + + + +--no-outpot Bot won't print incoming msgs +--admin-mode Only listen to admins ! +--update Sync bot with master repo +--about About bot +--help Prints this msg +" + +elif [ "$1" = "--about" ]; then + echo -e " + + \033[31;47mJack Telegram Bot\033[0m + + By Iman Daneshi + + \033[5mV $ver\033[0m + +A multi purpose Telegram bot written in MoonScript ! + +Website: jack.seedteam.org + +" +elif [ "$1" = "--Update" ]; then + git pull +else + echo -e " + + \033[31;47mJack Telegram Bot\033[0m + + By Iman Daneshi + + \033[5mV $ver\033[0m +" + while true; do + moon jackbot.moon "${@}" + sleep 10s + done +fi diff --git a/utilities.moon b/utilities.moon index db124cb..01ec0ff 100644 --- a/utilities.moon +++ b/utilities.moon @@ -419,6 +419,25 @@ export up_the_first = (word) -> export no_output = -> if #arg >= 1 for k,v in pairs arg - if v == "--no-output" + if v\lower! == "--no-output" return true return false + +export admin_only = -> + if #arg >= 1 + for k,v in pairs arg + if v\lower! == "--admin-mode" + return true + return false + +export is_premium = (msg) -> + if is_admin(msg) + return true + redis = (Redis @).client + users = redis\smembers "bot:premium:users" + for k,v in pairs(users) + if msg.from.id == tonumber(v) + return true + if msg.chat.id == tonumber(v) + return true + return false