├── data ├── .gitkeep └── photos │ └── text ├── .gitignore ├── .gitmodules ├── etc └── telegram.conf ├── .travis.yml ├── plugins ├── links.lua ├── arabic.lua ├── version.lua ├── spam.lua ├── export_gban.lua ├── rules.lua ├── bot.lua ├── commands.lua ├── welcome.lua ├── plugins.lua ├── id.lua └── giverank.lua ├── config_fix.sh ├── libs ├── redis.lua └── mimetype.lua ├── bot ├── permissions.lua ├── bot.lua └── utils.lua ├── patches └── disable-python-and-libjansson.patch ├── launch.sh ├── start.sh ├── LICENSE ├── steady.sh ├── README.md └── lang ├── arabic_lang.lua ├── galician_lang.lua └── portuguese_lang.lua /data/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /data/photos/text: -------------------------------------------------------------------------------- 1 | text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | res/ 2 | data/ 3 | .luarocks -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tg"] 2 | path = tg 3 | url = https://github.com/Josepdal/tg.git 4 | -------------------------------------------------------------------------------- /etc/telegram.conf: -------------------------------------------------------------------------------- 1 | description "Telegram-bot upstart script" 2 | 3 | respawn 4 | respawn limit 15 5 5 | 6 | start on runlevel [2345] 7 | stop on shutdown 8 | 9 | setuid yourusername 10 | exec /bin/sh telegrambotpath/launch.sh 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: erlang 2 | 3 | before_install: 4 | - sudo apt-get update -qq 5 | - sudo apt-get install -qq libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git libjansson-dev python2.7-dev 6 | - ./launch.sh install 7 | 8 | script: 9 | - luac -p bot/*.lua 10 | - luac -p plugins/*.lua 11 | -------------------------------------------------------------------------------- /plugins/links.lua: -------------------------------------------------------------------------------- 1 | local function run(msg, matches) 2 | if not permissions(msg.from.id, msg.to.id, "settings") then 3 | local hash = 'links:'..msg.to.id 4 | if redis:get(hash) then 5 | delete_msg(msg.id, ok_cb, false) 6 | send_report(msg) 7 | end 8 | end 9 | end 10 | 11 | return { 12 | patterns = { 13 | -- Agrega mas links si es necesario 14 | "[Hh][Tt][Tt][Pp][Ss][:][/][/]", 15 | "[Hh][Tt][Tt][Pp][:][/][/]", 16 | "[Ww][Ww][Ww][.]", 17 | "[.][Cc][Oo][Mm]", 18 | "https?://[%w-_%.%?%.:/%+=&]+%" 19 | }, run = run} 20 | -------------------------------------------------------------------------------- /plugins/arabic.lua: -------------------------------------------------------------------------------- 1 | local function run(msg) 2 | local hash = 'arabic:'..msg.to.id 3 | if redis:get(hash) then 4 | delete_msg(msg.id, ok_cb, false) 5 | if msg.to.type == 'chat' then 6 | send_msg('chat#id'..msg.to.id, lang_text(msg.to.id, 'noArabicT'), ok_cb, true) 7 | chat_del_user('chat#id'..msg.to.id, 'user#id'..msg.from.id, ok_cb, true) 8 | elseif msg.to.type == 'channel' then 9 | send_msg('channel#id'..msg.to.id, lang_text(msg.to.id, 'noArabicL'), ok_cb, true) 10 | channel_kick_user('channel#id'..msg.to.id, 'user#id'..msg.from.id, ok_cb, true) 11 | end 12 | return 13 | end 14 | end 15 | 16 | return { 17 | patterns = { 18 | '([\216-\219][\128-\191])' 19 | }, 20 | run = run 21 | } -------------------------------------------------------------------------------- /plugins/version.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | do 15 | 16 | function run(msg, matches) 17 | return 'DBTeam Bot V1 Supergroups\nAn advanced Administration bot based on yagop/telegram-bot\n\nDevelopers: @MaSkAoS @Josepdal\nSupport: @skneos @iicc1 @Serx666\nChannels: @DBTeamEN @DBTeamES\n\nCheckout: https://github.com/Josepdal/DBTeam\nGNU GPL v2 license.' 18 | end 19 | 20 | return { 21 | patterns = { 22 | "^#version$" 23 | }, 24 | run = run 25 | } 26 | 27 | end 28 | -------------------------------------------------------------------------------- /config_fix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Script to fix config.lua By @iicc1 3 | #DBTeam 4 | 5 | CONF=data/config.lua 6 | CONF2=data/config2.lua 7 | 8 | cat $CONF | grep "enabled_lang" > /dev/null 9 | if [ $? == 0 ]; then 10 | echo -e "\e[33mPatching config.lua not needed.\e[36m" 11 | exit 0 12 | else 13 | 14 | echo -e "\e[33mPatching config.lua languages...\e[39m" 15 | sleep 1.5 16 | 17 | #config.lua backup 18 | cp $CONF ${CONF}.backup 19 | 20 | grep -v "_lang" $CONF > $CONF2 21 | 22 | awk '/sudo_users/{print " enabled_lang = {"}1' $CONF2 > $CONF 23 | sed 's/.*enabled_lang.*/&\n "arabic_lang",/' $CONF > $CONF2 24 | sed 's/.*arabic_lang.*/&\n "catalan_lang",/' $CONF2 > $CONF 25 | sed 's/.*catalan_lang.*/&\n "english_lang",/' $CONF > $CONF2 26 | sed 's/.*english_lang.*/&\n "galician_lang",/' $CONF2 > $CONF 27 | sed 's/.*galician_lang.*/&\n "italian_lang",/' $CONF > $CONF2 28 | sed 's/.*italian_lang.*/&\n "persian_lang",/' $CONF2 > $CONF 29 | sed 's/.*persian_lang.*/&\n "portuguese_lang",/' $CONF > $CONF2 30 | sed 's/.*portuguese_lang.*/&\n "spanish_lang"/' $CONF2 > $CONF 31 | sed 's/.*spanish_lang.*/&\n },/' $CONF > $CONF2 32 | mv $CONF2 $CONF 33 | echo -e "\e[96mDone!\e[36m" 34 | fi 35 | -------------------------------------------------------------------------------- /libs/redis.lua: -------------------------------------------------------------------------------- 1 | local Redis = require 'redis' 2 | local FakeRedis = require 'fakeredis' 3 | 4 | local params = { 5 | host = os.getenv('REDIS_HOST') or '127.0.0.1', 6 | port = tonumber(os.getenv('REDIS_PORT') or 6379) 7 | } 8 | 9 | local database = os.getenv('REDIS_DB') 10 | local password = os.getenv('REDIS_PASSWORD') 11 | 12 | -- Overwrite HGETALL 13 | Redis.commands.hgetall = Redis.command('hgetall', { 14 | response = function(reply, command, ...) 15 | local new_reply = { } 16 | for i = 1, #reply, 2 do new_reply[reply[i]] = reply[i + 1] end 17 | return new_reply 18 | end 19 | }) 20 | 21 | local redis = nil 22 | 23 | -- Won't launch an error if fails 24 | local ok = pcall(function() 25 | redis = Redis.connect(params) 26 | end) 27 | 28 | if not ok then 29 | 30 | local fake_func = function() 31 | print('\27[31mCan\'t connect with Redis, install/configure it!\27[39m') 32 | end 33 | fake_func() 34 | fake = FakeRedis.new() 35 | 36 | print('\27[31mRedis addr: '..params.host..'\27[39m') 37 | print('\27[31mRedis port: '..params.port..'\27[39m') 38 | 39 | redis = setmetatable({fakeredis=true}, { 40 | __index = function(a, b) 41 | if b ~= 'data' and fake[b] then 42 | fake_func(b) 43 | end 44 | return fake[b] or fake_func 45 | end }) 46 | 47 | else 48 | if password then 49 | redis:auth(password) 50 | end 51 | if database then 52 | redis:select(database) 53 | end 54 | end 55 | 56 | 57 | return redis 58 | -------------------------------------------------------------------------------- /bot/permissions.lua: -------------------------------------------------------------------------------- 1 | local sudos = { 2 | "plugins", 3 | "rank_admin", 4 | "bot", 5 | "lang_install", 6 | "set_lang", 7 | "tosupergroup", 8 | "gban_installer" 9 | } 10 | local admins = { 11 | "rank_mod", 12 | "gban", 13 | "ungban", 14 | "setrules", 15 | "setphoto", 16 | "creategroup", 17 | "setname", 18 | "addbots", 19 | "setlink", 20 | "rank_guest", 21 | "description", 22 | "export_gban" 23 | } 24 | local mods = { 25 | "whois", 26 | "kick", 27 | "add", 28 | "ban", 29 | "unban", 30 | "lockmember", 31 | "mute", 32 | "unmute", 33 | "admins", 34 | "members", 35 | "welcome", 36 | "mods", 37 | "flood", 38 | "commands", 39 | "lang", 40 | "settings", 41 | "mod_commands", 42 | "no_flood_ban", 43 | "muteall", 44 | "rules", 45 | "pre_process" 46 | } 47 | 48 | local function get_tag(plugin_tag) 49 | for v,tag in pairs(sudos) do 50 | if tag == plugin_tag then 51 | return 3 52 | end 53 | end 54 | for v,tag in pairs(admins) do 55 | if tag == plugin_tag then 56 | return 2 57 | end 58 | end 59 | for v,tag in pairs(mods) do 60 | if tag == plugin_tag then 61 | return 1 62 | end 63 | end 64 | return 0 65 | end 66 | 67 | local function user_num(user_id, chat_id) 68 | if new_is_sudo(user_id) then 69 | return 3 70 | elseif is_admin(user_id) then 71 | return 2 72 | elseif is_mod(chat_id, user_id) then 73 | return 1 74 | else 75 | return 0 76 | end 77 | end 78 | 79 | function permissions(user_id, chat_id, plugin_tag) 80 | local user_is = get_tag(plugin_tag) 81 | local user_n = user_num(user_id, chat_id) 82 | if user_n >= user_is then 83 | return true 84 | else 85 | return false 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /plugins/spam.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | local function kick_user(msg) 15 | local chat = 'chat#id'..msg.to.id 16 | local channel = 'channel#id'..msg.to.id 17 | local user = msg.from.id 18 | if msg.to.type == 'chat' then 19 | chat_del_user(chat, 'user#id'..user, ok_cb, true) 20 | elseif msg.to.type == 'channel' then 21 | channel_kick_user(channel, 'user#id'..user, ok_cb, true) 22 | end 23 | end 24 | 25 | local function run(msg, matches) 26 | if not permissions(msg.from.id, msg.to.id, "settings") then 27 | local hash = 'spam:'..msg.to.id 28 | if redis:get(hash) then 29 | kick_user(msg) 30 | delete_msg(msg.id, ok_cb, false) 31 | send_report(msg) 32 | end 33 | end 34 | end 35 | 36 | return { 37 | patterns = { 38 | -- You can add much as patterns you want to stop all spam traffic 39 | "[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm]%.[Mm][Ee]", 40 | "[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm]%.[Oo][Rr][Gg]", 41 | "[Aa][Dd][Ff]%.[Ll][Yy]", 42 | "[Bb][Ii][Tt]%.[Ll][Yy]", 43 | "[Gg][Oo][Oo]%.[Gg][Ll]" 44 | }, run = run} 45 | -------------------------------------------------------------------------------- /plugins/export_gban.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | local function run(msg, matches) 15 | if permissions(msg.from.id, msg.to.id, "export_gban") then 16 | if matches[1] == 'gbans' then 17 | local receiver = get_receiver(msg) 18 | if matches[2] == 'installer' then 19 | local text = 'local function run(msg)\nif permissions(msg.from.id, msg.to.id, "gban_installer") then\n' 20 | local count = 0 21 | for v,user in pairs(_gbans.gbans_users) do 22 | text = text..'gban_id('..user..')\n' 23 | count = count + 1 24 | end 25 | 26 | local text = text..[[ 27 | if msg.to.type == 'chat' then 28 | send_msg('chat#id'..msg.to.id, ']]..count..' '..lang_text(msg.to.id, 'accountsGban')..[[ ☠', ok_cb, false) 29 | elseif msg.to.type == 'channel' then 30 | send_msg('channel#id'..msg.to.id, ']]..count..' '..lang_text(msg.to.id, 'accountsGban')..[[ ☠', ok_cb, false) 31 | end 32 | else 33 | return '🚫 '..lang_text(msg.to.id, 'require_sudo') 34 | end 35 | end 36 | 37 | return { 38 | description = 'Add gbans into your bot. A gbanlist command.', 39 | usage = {}, 40 | patterns = { 41 | "^#(install) (gbans)$" 42 | }, 43 | run = run 44 | } 45 | ]] 46 | 47 | local file = io.open("./plugins/gban_installer.lua", "w") 48 | file:write(text) 49 | file:close() 50 | 51 | send_document(receiver, './plugins/gban_installer.lua', ok_cb, false) 52 | elseif matches[2] == 'list' then 53 | send_document(receiver, './data/gbans.lua', ok_cb, false) 54 | end 55 | end 56 | else 57 | return '🚫 '..lang_text(msg.to.id, 'require_admin') 58 | end 59 | end 60 | 61 | return { 62 | patterns = { 63 | "^#(gbans) (.*)$" 64 | }, 65 | run = run 66 | } 67 | -------------------------------------------------------------------------------- /plugins/rules.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -- Created by @Josepdal & @A7F -- 13 | -- -- 14 | -------------------------------------------------- 15 | 16 | local function set_rules_channel(msg, text) 17 | local rules = text 18 | local hash = 'channel:id:'..msg.to.id..':rules' 19 | redis:set(hash, rules) 20 | end 21 | 22 | local function del_rules_channel(chat_id) 23 | local hash = 'channel:id:'..chat_id..':rules' 24 | redis:del(hash) 25 | end 26 | 27 | local function init_def_rules(chat_id) 28 | local rules = 'ℹ️ Rules:\n' 29 | ..'1⃣ No Flood.\n' 30 | ..'2⃣ No Spam.\n' 31 | ..'3⃣ Try to stay on topic.\n' 32 | ..'4⃣ Forbidden any racist, sexual, homophobic or gore content.\n' 33 | ..'➡️ Repeated failure to comply with these rules will cause ban.' 34 | 35 | local hash='channel:id:'..chat_id..':rules' 36 | redis:set(hash, rules) 37 | end 38 | 39 | local function ret_rules_channel(msg) 40 | local chat_id = msg.to.id 41 | local hash = 'channel:id:'..msg.to.id..':rules' 42 | if redis:get(hash) then 43 | return redis:get(hash) 44 | else 45 | init_def_rules(chat_id) 46 | return redis:get(hash) 47 | end 48 | end 49 | 50 | 51 | local function run(msg, matches) 52 | 53 | if matches[1] == 'rules' then 54 | return ret_rules_channel(msg) 55 | elseif matches[1] == 'setrules' then 56 | if permissions(msg.from.id, msg.to.id, 'rules') then 57 | set_rules_channel(msg, matches[2]) 58 | return 'ℹ️ '..lang_text(msg.to.id, 'setRules') 59 | end 60 | elseif matches[1] == 'remrules' then 61 | if permissions(msg.from.id, msg.to.id, 'rules') then 62 | del_rules_channel(msg.to.id) 63 | return 'ℹ️ '..lang_text(msg.to.id, 'remRules') 64 | end 65 | end 66 | 67 | end 68 | 69 | return { 70 | patterns = { 71 | '^[!/#](rules)$', 72 | '^[!/#](setrules) (.+)$', 73 | '^[!/#](remrules)$' 74 | }, 75 | run = run 76 | } 77 | -------------------------------------------------------------------------------- /plugins/bot.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- @h3iran :D -- 12 | -------------------------------------------------- 13 | local function is_channel_disabled( receiver ) 14 | if not _config.disabled_channels then 15 | return false 16 | end 17 | 18 | if _config.disabled_channels[receiver] == nil then 19 | return false 20 | end 21 | 22 | return _config.disabled_channels[receiver] 23 | end 24 | 25 | local function enable_channel(receiver, to_id) 26 | if not _config.disabled_channels then 27 | _config.disabled_channels = {} 28 | end 29 | 30 | if _config.disabled_channels[receiver] == nil then 31 | return lang_text(to_id, 'botOn')..' 😏' 32 | end 33 | 34 | _config.disabled_channels[receiver] = false 35 | 36 | save_config() 37 | return lang_text(to_id, 'botOn')..' 😏' 38 | end 39 | 40 | local function disable_channel(receiver, to_id) 41 | if not _config.disabled_channels then 42 | _config.disabled_channels = {} 43 | end 44 | 45 | _config.disabled_channels[receiver] = true 46 | 47 | save_config() 48 | return lang_text(to_id, 'botOff')..' 🚀' 49 | end 50 | 51 | local function pre_process(msg) 52 | local receiver = get_receiver(msg) 53 | 54 | -- If sender is sudo then re-enable the channel 55 | if is_sudo(msg) then 56 | if msg.text == "#bot on" or msg.text == "!bot on" or msg.text == "/bot on" then 57 | enable_channel(receiver, msg.to.id) 58 | end 59 | end 60 | 61 | if is_channel_disabled(receiver) then 62 | msg.text = "" 63 | end 64 | 65 | return msg 66 | end 67 | 68 | local function run(msg, matches) 69 | if permissions(msg.from.id, msg.to.id, "bot") then 70 | local receiver = get_receiver(msg) 71 | -- Enable a channel 72 | if matches[1] == 'on' then 73 | return enable_channel(receiver, msg.to.id) 74 | end 75 | -- Disable a channel 76 | if matches[1] == 'off' then 77 | return disable_channel(receiver, msg.to.id) 78 | end 79 | else 80 | return '🚫 '..lang_text(msg.to.id, 'require_sudo') 81 | end 82 | end 83 | 84 | return { 85 | patterns = { 86 | "^[!/#]bot? (on)", 87 | "^[!/#]bot? (off)" }, 88 | run = run, 89 | pre_process = pre_process 90 | } 91 | -------------------------------------------------------------------------------- /plugins/commands.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | do 15 | local function run(msg, matches) 16 | text = '#⃣ '..lang_text(msg.to.id, 'commandsT')..':\n' 17 | local space = '\n' 18 | if matches[1] == 'commands' and not matches[2] then 19 | if permissions(msg.from.id, msg.to.id, "mod_commands") then 20 | local langHash = 'langset:'..msg.to.id 21 | local lang = redis:get(langHash) 22 | for v,plugin in pairs(_config.enabled_plugins) do 23 | local textHash = 'lang:'..lang..':'..plugin..':0' 24 | if redis:get(textHash) then 25 | for i=1, tonumber(lang_text(msg.to.id, plugin..':0')), 1 do 26 | text = text..lang_text(msg.to.id, plugin..':'..i)..'\n' 27 | end 28 | text = text..space 29 | end 30 | end 31 | else 32 | text = text..lang_text(msg.to.id, 'moderation:5')..'\n' 33 | text = text..lang_text(msg.to.id, 'version:1')..'\n' 34 | text = text..lang_text(msg.to.id, 'rules:1')..'\n' 35 | end 36 | elseif matches[1] == 'commands' and matches[2] then 37 | if permissions(msg.from.id, msg.to.id, "mod_commands") then 38 | local langHash = 'langset:'..msg.to.id 39 | local lang = redis:get(langHash) 40 | for v,plugin in pairs(_config.enabled_plugins) do 41 | if plugin == matches[2] then 42 | local textHash = 'lang:'..lang..':'..plugin..':0' 43 | if redis:get(textHash) then 44 | for i=1, tonumber(lang_text(msg.to.id, plugin..':0')), 1 do 45 | text = text..lang_text(msg.to.id, plugin..':'..i)..'\n' 46 | end 47 | end 48 | return text 49 | end 50 | end 51 | return 'ℹ️ '..lang_text(msg.to.id, 'errorNoPlug') 52 | else 53 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 54 | end 55 | end 56 | return text 57 | end 58 | 59 | return { 60 | patterns = { 61 | "^[!/#](commands)$", 62 | "^[!/#](commands) (.+)" 63 | }, 64 | run = run 65 | } 66 | end 67 | 68 | for v,user in pairs(_gbans.gbans_users) do 69 | if tonumber(user) == tonumber(user_id) then 70 | return true 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /libs/mimetype.lua: -------------------------------------------------------------------------------- 1 | -- Thanks to https://github.com/catwell/lua-toolbox/blob/master/mime.types 2 | do 3 | 4 | local mimetype = {} 5 | 6 | -- TODO: Add more? 7 | local types = { 8 | ["text/html"] = "html", 9 | ["text/css"] = "css", 10 | ["text/xml"] = "xml", 11 | ["image/gif"] = "gif", 12 | ["image/jpeg"] = "jpg", 13 | ["application/x-javascript"] = "js", 14 | ["application/atom+xml"] = "atom", 15 | ["application/rss+xml"] = "rss", 16 | ["text/mathml"] = "mml", 17 | ["text/plain"] = "txt", 18 | ["text/vnd.sun.j2me.app-descriptor"] = "jad", 19 | ["text/vnd.wap.wml"] = "wml", 20 | ["text/x-component"] = "htc", 21 | ["image/png"] = "png", 22 | ["image/tiff"] = "tiff", 23 | ["image/vnd.wap.wbmp"] = "wbmp", 24 | ["image/x-icon"] = "ico", 25 | ["image/x-jng"] = "jng", 26 | ["image/x-ms-bmp"] = "bmp", 27 | ["image/svg+xml"] = "svg", 28 | ["image/webp"] = "webp", 29 | ["application/java-archive"] = "jar", 30 | ["application/mac-binhex40"] = "hqx", 31 | ["application/msword"] = "doc", 32 | ["application/pdf"] = "pdf", 33 | ["application/postscript"] = "ps", 34 | ["application/rtf"] = "rtf", 35 | ["application/vnd.ms-excel"] = "xls", 36 | ["application/vnd.ms-powerpoint"] = "ppt", 37 | ["application/vnd.wap.wmlc"] = "wmlc", 38 | ["application/vnd.google-earth.kml+xml"] = "kml", 39 | ["application/vnd.google-earth.kmz"] = "kmz", 40 | ["application/x-7z-compressed"] = "7z", 41 | ["application/x-cocoa"] = "cco", 42 | ["application/x-java-archive-diff"] = "jardiff", 43 | ["application/x-java-jnlp-file"] = "jnlp", 44 | ["application/x-makeself"] = "run", 45 | ["application/x-perl"] = "pl", 46 | ["application/x-pilot"] = "prc", 47 | ["application/x-rar-compressed"] = "rar", 48 | ["application/x-redhat-package-manager"] = "rpm", 49 | ["application/x-sea"] = "sea", 50 | ["application/x-shockwave-flash"] = "swf", 51 | ["application/x-stuffit"] = "sit", 52 | ["application/x-tcl"] = "tcl", 53 | ["application/x-x509-ca-cert"] = "crt", 54 | ["application/x-xpinstall"] = "xpi", 55 | ["application/xhtml+xml"] = "xhtml", 56 | ["application/zip"] = "zip", 57 | ["application/octet-stream"] = "bin", 58 | ["audio/midi"] = "mid", 59 | ["audio/mpeg"] = "mp3", 60 | ["audio/ogg"] = "ogg", 61 | ["audio/x-m4a"] = "m4a", 62 | ["audio/x-realaudio"] = "ra", 63 | ["video/3gpp"] = "3gpp", 64 | ["video/mp4"] = "mp4", 65 | ["video/mpeg"] = "mpeg", 66 | ["video/quicktime"] = "mov", 67 | ["video/webm"] = "webm", 68 | ["video/x-flv"] = "flv", 69 | ["video/x-m4v"] = "m4v", 70 | ["video/x-mng"] = "mng", 71 | ["video/x-ms-asf"] = "asf", 72 | ["video/x-ms-wmv"] = "wmv", 73 | ["video/x-msvideo"] = "avi" 74 | } 75 | 76 | -- Returns the common file extension from a content-type 77 | function mimetype.get_mime_extension(content_type) 78 | return types[content_type] 79 | end 80 | 81 | -- Returns the mimetype and subtype 82 | function mimetype.get_content_type(extension) 83 | for k,v in pairs(types) do 84 | if v == extension then 85 | return k 86 | end 87 | end 88 | end 89 | 90 | -- Returns the mimetype without the subtype 91 | function mimetype.get_content_type_no_sub(extension) 92 | for k,v in pairs(types) do 93 | if v == extension then 94 | -- Before / 95 | return k:match('([%w-]+)/') 96 | end 97 | end 98 | end 99 | 100 | return mimetype 101 | end -------------------------------------------------------------------------------- /patches/disable-python-and-libjansson.patch: -------------------------------------------------------------------------------- 1 | --- tg/configure.ac 2015-10-24 14:23:51.964259062 +0200 2 | +++ tg/configure.ac 2015-10-24 14:05:10.111062758 +0200 3 | @@ -61,93 +61,43 @@ 4 | ],[ 5 | ]) 6 | 7 | +# liblua is required 8 | AC_MSG_CHECKING([for liblua]) 9 | -AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua], 10 | - [ 11 | - if test "x$enableval" = "xno" ; then 12 | - AC_MSG_RESULT([disabled]) 13 | - else 14 | - AC_MSG_RESULT([enabled]) 15 | - AX_PROG_LUA([],[], 16 | - [ 17 | - AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])]) 18 | - AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])]) 19 | - [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ] 20 | - [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ] 21 | - AC_DEFINE(USE_LUA,1,[use lua]) 22 | - ], 23 | - [ 24 | - AC_MSG_ERROR([No lua found. Try --disable-liblua]) 25 | - ]) 26 | - fi 27 | - ],[ 28 | - AC_MSG_RESULT([enabled]) 29 | - AX_PROG_LUA([],[], 30 | - [ 31 | - AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])]) 32 | - AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])]) 33 | - [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ] 34 | - [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ] 35 | - AC_DEFINE(USE_LUA,1,[use lua]) 36 | - ], 37 | - [ 38 | - AC_MSG_ERROR([No lua found. Try --disable-liblua]) 39 | - ]) 40 | - ]) 41 | - 42 | -AC_MSG_CHECKING([for python]) 43 | -AC_ARG_ENABLE(python,[--enable-python/--disable-python], 44 | +AC_MSG_RESULT([enabled]) 45 | +AX_PROG_LUA([],[], 46 | [ 47 | - if test "x$enableval" = "xno" ; then 48 | - AC_MSG_RESULT([disabled]) 49 | - else 50 | - AC_MSG_RESULT([enabled]) 51 | - 52 | - AX_PYTHON() 53 | - AC_SUBST([PYTHON_FOUND]) 54 | - if test $PYTHON_FOUND = no ; then 55 | - AC_MSG_ERROR([No supported python lib version found. Try --disable-python]) 56 | - else 57 | - AC_SUBST([PYTHON_LIBS]) 58 | - AC_SUBST([PYTHON_CFLAGS]) 59 | - EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}" 60 | - CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}" 61 | - AC_DEFINE(USE_PYTHON,1,[use python]) 62 | - fi 63 | - fi 64 | - ],[ 65 | - AC_MSG_RESULT([enabled]) 66 | - 67 | - AX_PYTHON() 68 | - AC_SUBST([PYTHON_FOUND]) 69 | - if test $PYTHON_FOUND = no ; then 70 | - AC_MSG_ERROR([No supported python lib version found. Try --disable-python]) 71 | - else 72 | - AC_SUBST([PYTHON_LIBS]) 73 | - AC_SUBST([PYTHON_CFLAGS]) 74 | - EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}" 75 | - CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}" 76 | - AC_DEFINE(USE_PYTHON,1,[use python]) 77 | - fi 78 | + AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Install them])]) 79 | + AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Install them])]) 80 | + [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ] 81 | + [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ] 82 | + AC_DEFINE(USE_LUA,1,[use lua]) 83 | + ], 84 | + [ 85 | + AC_MSG_ERROR([No lua found. Install lua]) 86 | ]) 87 | 88 | +# Optional 89 | +AC_MSG_CHECKING([for python]) 90 | +AX_PYTHON() 91 | +AC_SUBST([PYTHON_FOUND]) 92 | +if test $PYTHON_FOUND = no ; then 93 | + AC_MSG_RESULT([disabled]) 94 | +else 95 | + AC_SUBST([PYTHON_LIBS]) 96 | + AC_SUBST([PYTHON_CFLAGS]) 97 | + EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}" 98 | + CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}" 99 | + AC_DEFINE(USE_PYTHON,1,[use python]) 100 | +fi 101 | 102 | - 103 | +# Optional 104 | AC_MSG_CHECKING([for libjansson]) 105 | -AC_ARG_ENABLE(json,[--enable-json/--disable-json], 106 | - [ 107 | - if test "x$enableval" = "xno" ; then 108 | - AC_MSG_RESULT([disabled]) 109 | - else 110 | - AC_MSG_RESULT([enabled]) 111 | - AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json])) 112 | - AC_DEFINE(USE_JSON,1,[use json]) 113 | - fi 114 | - ],[ 115 | +AC_CHECK_LIB([jansson],[json_array_set_new], 116 | + [ 117 | AC_MSG_RESULT([enabled]) 118 | - AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json])) 119 | AC_DEFINE(USE_JSON,1,[use json]) 120 | - ]) 121 | + ], 122 | + [AC_MSG_RESULT([disabled])]) 123 | 124 | #check for custom prog name 125 | AC_MSG_CHECKING([progname]) 126 | @@ -193,4 +143,3 @@ 127 | AC_SUBST(EXTRA_LIBS) 128 | AC_CONFIG_FILES([Makefile]) 129 | AC_OUTPUT 130 | - 131 | -------------------------------------------------------------------------------- /launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | THIS_DIR=$(cd $(dirname $0); pwd) 4 | cd $THIS_DIR 5 | 6 | update() { 7 | git pull 8 | git submodule update --init --recursive 9 | install_rocks 10 | } 11 | 12 | # Will install luarocks on THIS_DIR/.luarocks 13 | install_luarocks() { 14 | git clone https://github.com/keplerproject/luarocks.git 15 | cd luarocks 16 | git checkout tags/v2.3.0-rc2 # Release Candidate 17 | 18 | PREFIX="$THIS_DIR/.luarocks" 19 | 20 | ./configure --prefix=$PREFIX --sysconfdir=$PREFIX/luarocks --force-config 21 | 22 | RET=$?; if [ $RET -ne 0 ]; 23 | then echo "Error. Exiting."; exit $RET; 24 | fi 25 | 26 | make build && make install 27 | RET=$?; if [ $RET -ne 0 ]; 28 | then echo "Error. Exiting.";exit $RET; 29 | fi 30 | 31 | cd .. 32 | rm -rf luarocks 33 | } 34 | 35 | install_rocks() { 36 | ./.luarocks/bin/luarocks install luasec 37 | RET=$?; if [ $RET -ne 0 ]; 38 | then echo "Error. Exiting."; exit $RET; 39 | fi 40 | 41 | ./.luarocks/bin/luarocks install lbase64 20120807-3 42 | RET=$?; if [ $RET -ne 0 ]; 43 | then echo "Error. Exiting."; exit $RET; 44 | fi 45 | 46 | ./.luarocks/bin/luarocks install luafilesystem 47 | RET=$?; if [ $RET -ne 0 ]; 48 | then echo "Error. Exiting."; exit $RET; 49 | fi 50 | 51 | ./.luarocks/bin/luarocks install lub 52 | RET=$?; if [ $RET -ne 0 ]; 53 | then echo "Error. Exiting."; exit $RET; 54 | fi 55 | 56 | ./.luarocks/bin/luarocks install luaexpat 57 | RET=$?; if [ $RET -ne 0 ]; 58 | then echo "Error. Exiting."; exit $RET; 59 | fi 60 | 61 | ./.luarocks/bin/luarocks install redis-lua 62 | RET=$?; if [ $RET -ne 0 ]; 63 | then echo "Error. Exiting."; exit $RET; 64 | fi 65 | 66 | ./.luarocks/bin/luarocks install lua-cjson 67 | RET=$?; if [ $RET -ne 0 ]; 68 | then echo "Error. Exiting."; exit $RET; 69 | fi 70 | 71 | ./.luarocks/bin/luarocks install fakeredis 72 | RET=$?; if [ $RET -ne 0 ]; 73 | then echo "Error. Exiting."; exit $RET; 74 | fi 75 | 76 | ./.luarocks/bin/luarocks install xml 77 | RET=$?; if [ $RET -ne 0 ]; 78 | then echo "Error. Exiting."; exit $RET; 79 | fi 80 | 81 | ./.luarocks/bin/luarocks install feedparser 82 | RET=$?; if [ $RET -ne 0 ]; 83 | then echo "Error. Exiting."; exit $RET; 84 | fi 85 | 86 | ./.luarocks/bin/luarocks install serpent 87 | RET=$?; if [ $RET -ne 0 ]; 88 | then echo "Error. Exiting."; exit $RET; 89 | fi 90 | } 91 | 92 | install() { 93 | git pull 94 | git submodule update --init --recursive 95 | patch -i "patches/disable-python-and-libjansson.patch" -p 0 --batch --forward 96 | RET=$?; 97 | 98 | cd tg 99 | if [ $RET -ne 0 ]; then 100 | autoconf -i 101 | fi 102 | ./configure && make 103 | 104 | RET=$?; if [ $RET -ne 0 ]; then 105 | echo "Error. Exiting."; exit $RET; 106 | fi 107 | cd .. 108 | install_luarocks 109 | install_rocks 110 | 111 | if [ -d /mnt/c/Windows ]; then 112 | echo "Patching bot.lua for Windows 10 support..." 113 | sed -i '5d' bot/bot.lua 114 | sed -i '5d' bot/bot.lua 115 | sed -i '5i\require("bot/utils")' bot/bot.lua 116 | sed -i '6i\require("bot/permissions")' bot/bot.lua 117 | sed -i '7i\--File patched to support W10' bot/bot.lua 118 | fi 119 | 120 | } 121 | 122 | if [ "$1" = "install" ]; then 123 | install 124 | elif [ "$1" = "update" ]; then 125 | update 126 | else 127 | if [ ! -f ./tg/telegram.h ]; then 128 | echo "tg not found" 129 | echo "Run $0 install" 130 | exit 1 131 | fi 132 | 133 | if [ ! -f ./tg/bin/telegram-cli ]; then 134 | echo "tg binary not found" 135 | echo "Run $0 install" 136 | exit 1 137 | fi 138 | 139 | chmod 777 steady.sh 140 | chmod 777 start.sh 141 | chmod 777 config_fix.sh 142 | 143 | #Adding some color. By @iicc1 :D 144 | echo -e "\033[38;5;208m" 145 | echo -e " ____ ____ _____ " 146 | echo -e " | \| _ )_ _|___ ____ __ __ " 147 | echo -e " | |_ ) _ \ | |/ .__| _ \_| \/ | " 148 | echo -e " |____/|____/ |_|\____/\_____|_/\/\_| " 149 | echo -e " \033[0;00m" 150 | echo -e "\e[36m" 151 | 152 | if [ -f data/config.lua ]; then 153 | ./config_fix.sh 154 | fi 155 | 156 | if [ -f plugins/gban_installer.lua ]; then 157 | 158 | L=$(wc -l plugins/gban_installer.lua | cut -d " " -f1) 159 | R=$(echo $L -20 | bc) 160 | 161 | #N=$(grep -nr "send_msg('chat#id'.*" plugins/gban_installer.lua | cut -d ":" -f1) 162 | #M=$(grep -nr "send_msg('channel#id'.*" plugins/gban_installer.lua | cut -d ":" -f1) 163 | 164 | grep -v "send_msg('chat#id'.*" plugins/gban_installer.lua > gban1 165 | grep -v "send_msg('channel#id'.*" gban1 > plugins/gban_installer.lua 166 | sed -i "s/.*chat.*/&\n send_msg('chat#id'..msg.to.id, '$R accounts globally banned. ☠', ok_cb, false)/" plugins/gban_installer.lua 167 | sed -i "s/.*channel.*/&\n send_msg('channel#id'..msg.to.id, '$R accounts globally banned. ☠', ok_cb, false)/" plugins/gban_installer.lua 168 | rm gban1 169 | 170 | fi 171 | 172 | ./tg/bin/telegram-cli -k ./tg/tg-server.pub -s ./bot/bot.lua -l 1 -E $@ 173 | fi 174 | -------------------------------------------------------------------------------- /plugins/welcome.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------ 2 | -- DBTeam DBTeam DBTeam DBTeam DBTeam --- 3 | -- Welcome by @xxdamage --- 4 | -- multilanguage and fix by@Jarriz --- 5 | ------------------------------------------ 6 | function chat_new_user(msg) 7 | local name = msg.action.user.first_name:gsub('_', ' ') 8 | local id = msg.action.user.id 9 | if msg.action.user.username then 10 | name = name 11 | end 12 | local chat = msg.to.print_name:gsub('_', ' ') 13 | local receiver = get_receiver(msg) 14 | local message = redis:get('welcome:'..msg.to.id) 15 | local custom_message = message:gsub('$id', msg.action.user.id):gsub('$name', msg.action.user.first_name):gsub('$user', '@'..msg.action.user.username) 16 | if not message then 17 | return '😀 ' ..lang_text(msg.to.id, 'welcome1') ..name.. '! ' ..lang_text(msg.to.id, 'welcome2') ..chat..'!\n🆔 ' ..id 18 | end 19 | send_msg(receiver, custom_message, ok_cb, false) 20 | end 21 | 22 | local function wlc_enabled(msg) 23 | local var = true 24 | local hash = 'wlcstatus:'..msg.to.id 25 | local cstatus = redis:get(hash) 26 | if cstatus == 'off' then 27 | var = false 28 | end 29 | 30 | return var 31 | end 32 | 33 | local function bye_enabled(msg) 34 | local var = true 35 | local hash = 'byestatus:'..msg.to.id 36 | local cstatus = redis:get(hash) 37 | if cstatus == 'off' then 38 | var = false 39 | end 40 | 41 | return var 42 | end 43 | 44 | local function run(msg, matches) 45 | 46 | 47 | local receiver = get_receiver(msg) 48 | if matches[1] == "chat_add_user" then 49 | if not wlc_enabled(msg) then 50 | return 51 | end 52 | return chat_new_user(msg) 53 | elseif matches[1] == "chat_add_user_link" then 54 | if not wlc_enabled(msg) then 55 | return 56 | end 57 | local name = msg.from.first_name:gsub('_', ' ') 58 | local chat = msg.to.print_name:gsub('_', ' ') 59 | local message 60 | if msg.from.username then 61 | name = name 62 | end 63 | message = redis:get('welcome:'..msg.to.id) 64 | if not message then 65 | return '😀' ..lang_text(msg.to.id, 'welcome1') ..name.. '!' ..lang_text(msg.to.id, 'welcome2') ..chat..'!\n🆔 ' ..id 66 | end 67 | send_msg(receiver, message, ok_cb, false) 68 | elseif matches[1] == "chat_del_user" then 69 | if not bye_enabled(msg) then 70 | return 71 | end 72 | local name = msg.action.user.first_name:gsub('_', ' ') 73 | if msg.action.user.username then 74 | name = name 75 | end 76 | local message = redis:get('bye:'..msg.to.id) 77 | if not message then 78 | return '😀 ' ..lang_text(msg.to.id, 'bye1') ..name.. '!' ..lang_text(msg.to.id, 'bye2') 79 | end 80 | send_msg(receiver, message, ok_cb, false) 81 | elseif matches[1] == 'setwelcome' then 82 | if not permissions(msg.from.id, msg.to.id, "welcome") then 83 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 84 | end 85 | print(msg.to.id) 86 | local hash = 'welcome:'..msg.to.id 87 | redis:set(hash, matches[2]) 88 | return '✅ ' ..lang_text(msg.to.id, 'welnew') .. ': \n' ..matches[2] 89 | elseif matches[1] == 'getwelcome' then 90 | print(msg.to.id) 91 | local hash = 'welcome:'..msg.to.id 92 | local wel = redis:get(hash) 93 | if not wel then 94 | return 'ℹ️ ' ..lang_text(msg.to.id, 'weldefault') 95 | end 96 | return wel 97 | elseif matches[1] == 'setbye' then 98 | if not permissions(msg.from.id, msg.to.id, "welcome") then 99 | return ' 🚫'..lang_text(msg.to.id, 'require_mod') 100 | end 101 | print(msg.to.id) 102 | local hash = 'bye:'..msg.to.id 103 | redis:set(hash, matches[2]) 104 | return '✅ ' ..lang_text(msg.to.id, 'newbye') .. ':\n'..matches[2] 105 | elseif matches[1] == 'getbye' then 106 | if not permissions(msg.from.id, msg.to.id, "welcome") then 107 | return ' 🚫'..lang_text(msg.to.id, 'require_mod') 108 | end 109 | print(msg.to.id) 110 | local hash = 'bye:'..msg.to.id 111 | local wel = redis:get(hash) 112 | if not wel then 113 | return 'ℹ️ ' ..lang_text(msg.to.id, 'byedefault') 114 | end 115 | return wel 116 | elseif matches[1] == 'welcome on' then 117 | if not permissions(msg.from.id, msg.to.id, "welcome") then 118 | return ' 🚫'..lang_text(msg.to.id, 'require_mod') 119 | end 120 | local hash = 'wlcstatus:'..msg.to.id 121 | redis:set(hash, 'on') 122 | return 'ℹ️ '..lang_text(msg.to.id, 'welon') 123 | elseif matches[1] == 'welcome off' then 124 | if not permissions(msg.from.id, msg.to.id, "welcome") then 125 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 126 | end 127 | local hash = 'wlcstatus:'..msg.to.id 128 | redis:set(hash, 'off') 129 | return 'ℹ️ '..lang_text(msg.to.id, 'weloff') 130 | elseif matches[1] == 'bye on' then 131 | if not permissions(msg.from.id, msg.to.id, "welcome") then 132 | return ' 🚫'..lang_text(msg.to.id, 'require_mod') 133 | end 134 | local hash = 'byestatus:'..msg.to.id 135 | redis:set(hash, 'on') 136 | return 'ℹ️ '..lang_text(msg.to.id, 'byeon') 137 | elseif matches[1] == 'bye off' then 138 | if not permissions(msg.from.id, msg.to.id, "welcome") then 139 | return ' 🚫'..lang_text(msg.to.id, 'require_mod') 140 | end 141 | local hash = 'byestatus:'..msg.to.id 142 | redis:set(hash, 'off') 143 | return 'ℹ️ '..lang_text(msg.to.id, 'byeoff') 144 | end 145 | end 146 | 147 | return { 148 | description = "Service plugin that sends a custom message when an user enters a chat.", 149 | usage = "", 150 | patterns = { 151 | "^!!tgservice (chat_add_user)$", 152 | "^!!tgservice (chat_del_user)$", 153 | "^!!tgservice (chat_add_user_link)$", 154 | "^[!/#](setwelcome) (.*)", 155 | "^[!/#](getwelcome)", 156 | "^[!/#](setbye) (.*)", 157 | "^[!/#](getbye)", 158 | "^[!/#](welcome on)", 159 | "^[!/#](welcome off)", 160 | "^[!/#](bye on)", 161 | "^[!/#](bye off)" 162 | }, 163 | run = run 164 | } 165 | -------------------------------------------------------------------------------- /plugins/plugins.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | do 15 | 16 | to_id = "" 17 | 18 | -- Returns the key (index) in the config.enabled_plugins table 19 | local function plugin_enabled( name ) 20 | for k,v in pairs(_config.enabled_plugins) do 21 | if name == v then 22 | return k 23 | end 24 | end 25 | -- If not found 26 | return false 27 | end 28 | 29 | -- Returns true if file exists in plugins folder 30 | local function plugin_exists( name ) 31 | for k,v in pairs(plugins_names()) do 32 | if name..'.lua' == v then 33 | return true 34 | end 35 | end 36 | return false 37 | end 38 | 39 | local function list_plugins(only_enabled) 40 | local text = 'ℹ️ '..lang_text(to_id, 'plugins')..':\n' 41 | local psum = 0 42 | for k, v in pairs( plugins_names( )) do 43 | -- ✅ enabled, ❎ disabled 44 | local status = '❎' 45 | psum = psum+1 46 | pact = 0 47 | -- Check if is enabled 48 | for k2, v2 in pairs(_config.enabled_plugins) do 49 | if v == v2..'.lua' then 50 | status = '✅' 51 | end 52 | pact = pact+1 53 | end 54 | if not only_enabled or status == '✅' then 55 | -- get the name 56 | v = string.match (v, "(.*)%.lua") 57 | text = text..status..' '..v..'\n' 58 | end 59 | end 60 | local text = text..'\n🔢 '..psum..' '..lang_text(to_id, 'installedPlugins')..'\n✅ ' 61 | ..pact..' '..lang_text(to_id, 'pEnabled')..'\n❎ '..psum-pact..' '..lang_text(to_id, 'pDisabled')..'' 62 | return text 63 | end 64 | 65 | local function reload_plugins( ) 66 | plugins = {} 67 | load_plugins() 68 | return list_plugins(true) 69 | end 70 | 71 | 72 | local function enable_plugin( plugin_name ) 73 | print('checking if '..plugin_name..' exists') 74 | -- Check if plugin is enabled 75 | if plugin_enabled(plugin_name) then 76 | return 'ℹ️ '..lang_text(to_id, 'isEnabled:1')..' '..plugin_name..' '..lang_text(to_id, 'isEnabled:2') 77 | end 78 | -- Checks if plugin exists 79 | if plugin_exists(plugin_name) then 80 | -- Add to the config table 81 | table.insert(_config.enabled_plugins, plugin_name) 82 | print(plugin_name..' added to _config table') 83 | save_config() 84 | -- Reload the plugins 85 | return reload_plugins( ) 86 | else 87 | return 'ℹ️ '..lang_text(to_id, 'notExist:1')..' '..plugin_name..' '..lang_text(to_id, 'notExist:2') 88 | end 89 | end 90 | 91 | local function disable_plugin( name, chat ) 92 | -- Check if plugins exists 93 | if not plugin_exists(name) then 94 | return 'ℹ️ '..lang_text(to_id, 'notExist:1')..' '..name..' '..lang_text(to_id, 'notExist:2') 95 | end 96 | local k = plugin_enabled(name) 97 | -- Check if plugin is enabled 98 | if not k then 99 | return 'ℹ️ '..lang_text(to_id, 'notEnabled:1')..' '..name..' '..lang_text(to_id, 'notEnabled:2') 100 | end 101 | -- Disable and reload 102 | table.remove(_config.enabled_plugins, k) 103 | save_config( ) 104 | return reload_plugins(true) 105 | end 106 | 107 | local function disable_plugin_on_chat(receiver, plugin) 108 | if not plugin_exists(plugin) then 109 | return 'ℹ️ '..lang_text(to_id, 'pNotExists') 110 | end 111 | 112 | if not _config.disabled_plugin_on_chat then 113 | _config.disabled_plugin_on_chat = {} 114 | end 115 | 116 | if not _config.disabled_plugin_on_chat[receiver] then 117 | _config.disabled_plugin_on_chat[receiver] = {} 118 | end 119 | 120 | _config.disabled_plugin_on_chat[receiver][plugin] = true 121 | 122 | save_config() 123 | return 'ℹ️ '..lang_text(to_id, 'pDisChat:1')..' '..plugin..' '..lang_text(to_id, 'pDisChat:2') 124 | end 125 | 126 | local function reenable_plugin_on_chat(receiver, plugin) 127 | if not _config.disabled_plugin_on_chat then 128 | return 'ℹ️ '..lang_text(to_id, 'anyDisPlugin') 129 | end 130 | 131 | if not _config.disabled_plugin_on_chat[receiver] then 132 | return 'ℹ️ '..lang_text(to_id, 'anyDisPluginChat') 133 | end 134 | 135 | if not _config.disabled_plugin_on_chat[receiver][plugin] then 136 | return 'ℹ️ '..lang_text(to_id, 'notDisabled') 137 | end 138 | 139 | _config.disabled_plugin_on_chat[receiver][plugin] = false 140 | save_config() 141 | return 'ℹ️ '..lang_text(to_id, 'enabledAgain:1')..' '..plugin..' '..lang_text(to_id, 'enabledAgain:2') 142 | end 143 | 144 | local function run(msg, matches) 145 | to_id = msg.to.id 146 | -- Show the available plugins 147 | if permissions(msg.from.id, msg.to.id, "plugins") then 148 | if matches[1] == '!plugins' or matches[1] == '#plugins' or matches[1] == '/plugins' then 149 | return list_plugins() 150 | end 151 | 152 | -- Re-enable a plugin for this chat 153 | if matches[1] == 'enable' and matches[3] == 'chat' then 154 | local receiver = get_receiver(msg) 155 | local plugin = matches[2] 156 | print("enable "..plugin..' on this chat') 157 | return reenable_plugin_on_chat(receiver, plugin) 158 | end 159 | 160 | -- Enable a plugin 161 | if matches[1] == 'enable' then 162 | local plugin_name = matches[2] 163 | print("enable: "..matches[2]) 164 | return enable_plugin(plugin_name) 165 | end 166 | 167 | -- Disable a plugin on a chat 168 | if matches[1] == 'disable' and matches[3] == 'chat' then 169 | local plugin = matches[2] 170 | local receiver = get_receiver(msg) 171 | print("disable "..plugin..' on this chat') 172 | return disable_plugin_on_chat(receiver, plugin) 173 | end 174 | 175 | -- Disable a plugin 176 | if matches[1] == 'disable' then 177 | print("disable: "..matches[2]) 178 | return disable_plugin(matches[2]) 179 | end 180 | 181 | -- Reload all the plugins! 182 | if matches[1] == 'reload' then 183 | return reload_plugins(true) 184 | end 185 | else 186 | return '🚫 '..lang_text(msg.to.id, 'require_sudo') 187 | end 188 | end 189 | 190 | return { 191 | patterns = { 192 | "^[!/#]plugins$", 193 | "^[!/#]plugins? (enable) ([%w_%.%-]+)$", 194 | "^[!/#]plugins? (disable) ([%w_%.%-]+)$", 195 | "^[!/#]plugins? (enable) ([%w_%.%-]+) (chat)", 196 | "^[!/#]plugins? (disable) ([%w_%.%-]+) (chat)", 197 | "^[!/#]plugins? (reload)$" }, 198 | run = run 199 | } 200 | 201 | end 202 | -------------------------------------------------------------------------------- /plugins/id.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | local function usernameinfo (user) 15 | if user.username then 16 | return '@'..user.username 17 | end 18 | if user.print_name then 19 | return user.print_name 20 | end 21 | local text = '' 22 | if user.first_name then 23 | text = user.last_name..' ' 24 | end 25 | if user.lastname then 26 | text = text..user.last_name 27 | end 28 | return text 29 | end 30 | 31 | local function whoisname(cb_extra, success, result) 32 | chat_type = cb_extra.chat_type 33 | chat_id = cb_extra.chat_id 34 | user_id = result.peer_id 35 | user_username = result.username 36 | if chat_type == 'chat' then 37 | send_msg('chat#id'..chat_id, '👤 '..lang_text(chat_id, 'user')..' @'..user_username..' ('..user_id..')', ok_cb, false) 38 | elseif chat_type == 'channel' then 39 | send_msg('channel#id'..chat_id, '👤 '..lang_text(chat_id, 'user')..' @'..user_username..' ('..user_id..')', ok_cb, false) 40 | end 41 | end 42 | 43 | local function whoisid(cb_extra, success, result) 44 | chat_id = cb_extra.chat_id 45 | user_id = cb_extra.user_id 46 | if cb_extra.chat_type == 'chat' then 47 | send_msg('chat#id'..chat_id, '👤 '..lang_text(chat_id, 'user')..' @'..result.username..' ('..user_id..')', ok_cb, false) 48 | elseif cb_extra.chat_type == 'channel' then 49 | send_msg('channel#id'..chat_id, '👤 '..lang_text(chat_id, 'user')..' @'..result.username..' ('..user_id..')', ok_cb, false) 50 | end 51 | end 52 | 53 | local function channelUserIDs (extra, success, result) 54 | local receiver = extra.receiver 55 | print('Result') 56 | vardump(result) 57 | local text = '' 58 | for k,user in ipairs(result) do 59 | local id = user.peer_id 60 | local username = usernameinfo (user) 61 | text = text..("%s - %s\n"):format(username, id) 62 | end 63 | send_large_msg(receiver, text) 64 | end 65 | 66 | local function get_id_who(extra, success, result) 67 | result = backward_msg_format(result) 68 | local msg = result 69 | local chat = msg.to.id 70 | local user = msg.from.id 71 | if msg.to.type == 'chat' then 72 | send_msg('chat#id'..msg.to.id, '🆔 '..lang_text(chat, 'user')..' ID: '..msg.from.id, ok_cb, false) 73 | elseif msg.to.type == 'channel' then 74 | send_msg('channel#id'..msg.to.id, '🆔 '..lang_text(chat, 'user')..' ID: '..msg.from.id, ok_cb, false) 75 | end 76 | end 77 | 78 | local function returnids (extra, success, result) 79 | local receiver = extra.receiver 80 | local chatname = result.print_name 81 | local id = result.peer_id 82 | local text = ('ID for chat %s (%s):\n'):format(chatname, id) 83 | for k,user in ipairs(result.members) do 84 | local username = usernameinfo(user) 85 | local id = user.peer_id 86 | local userinfo = ("%s - %s\n"):format(username, id) 87 | text = text .. userinfo 88 | end 89 | send_large_msg(receiver, text) 90 | end 91 | 92 | local function run(msg, matches) 93 | local receiver = get_receiver(msg) 94 | local chat = msg.to.id 95 | -- Id of the user and info about group / channel 96 | if matches[1] == "id" then 97 | if permissions(msg.from.id, msg.to.id, "id") then 98 | if msg.to.type == 'channel' then 99 | send_msg(msg.to.peer_id, '🔠 '..lang_text(chat, 'supergroupName')..': '..msg.to.print_name:gsub("_", " ")..'\n👥 '..lang_text(chat, 'supergroup')..' ID: '..msg.to.id..'\n🆔 '..lang_text(chat, 'user')..' ID: '..msg.from.id, ok_cb, false) 100 | elseif msg.to.type == 'chat' then 101 | send_msg(msg.to.peer_id, '🔠 '..lang_text(chat, 'chatName')..': '..msg.to.print_name:gsub("_", " ")..'\n👥 '..lang_text(chat, 'chat')..' ID: '..msg.to.id..'\n🆔 '..lang_text(chat, 'user')..' ID: '..msg.from.id, ok_cb, false) 102 | end 103 | end 104 | elseif matches[1] == 'whois' then 105 | if permissions(msg.from.id, msg.to.id, "whois") then 106 | chat_type = msg.to.type 107 | chat_id = msg.to.id 108 | if msg.reply_id then 109 | get_message(msg.reply_id, get_id_who, {receiver=get_receiver(msg)}) 110 | return 111 | end 112 | if is_id(matches[2]) then 113 | print(1) 114 | user_info('user#id'..matches[2], whoisid, {chat_type=chat_type, chat_id=chat_id, user_id=matches[2]}) 115 | return 116 | else 117 | local member = string.gsub(matches[2], '@', '') 118 | resolve_username(member, whoisname, {chat_id=chat_id, member=member, chat_type=chat_type}) 119 | return 120 | end 121 | else 122 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 123 | end 124 | elseif matches[1] == 'chat' or matches[1] == 'channel' then 125 | if permissions(msg.from.id, msg.to.id, "whois") then 126 | local type = matches[1] 127 | local chanId = matches[2] 128 | -- !ids? (chat) (%d+) 129 | if chanId then 130 | local chan = ("%s#id%s"):format(type, chanId) 131 | if type == 'chat' then 132 | chat_info(chan, returnids, {receiver=receiver}) 133 | else 134 | channel_get_users(chan, channelUserIDs, {receiver=receiver}) 135 | end 136 | else 137 | -- !id chat/channel 138 | local chan = ("%s#id%s"):format(msg.to.type, msg.to.id) 139 | if msg.to.type == 'channel' then 140 | channel_get_users(chan, channelUserIDs, {receiver=receiver}) 141 | end 142 | if msg.to.type == 'chat' then 143 | chat_info(chan, returnids, {receiver=receiver}) 144 | end 145 | end 146 | else 147 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 148 | end 149 | end 150 | end 151 | 152 | return { 153 | patterns = { 154 | "^[!/#](whois)$", 155 | "^[!/#](id)$", 156 | "^[!/#]ids? (chat)$", 157 | "^[!/#]ids? (channel)$", 158 | "^[!/#](whois) (.*)$" 159 | }, 160 | run = run 161 | } 162 | -------------------------------------------------------------------------------- /bot/bot.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ';.luarocks/share/lua/5.2/?.lua' 2 | ..';.luarocks/share/lua/5.2/?/init.lua' 3 | package.cpath = package.cpath .. ';.luarocks/lib/lua/5.2/?.so' 4 | 5 | require("./bot/utils") 6 | require("./bot/permissions") 7 | 8 | local f = assert(io.popen('/usr/bin/git describe --tags', 'r')) 9 | VERSION = assert(f:read('*a')) 10 | f:close() 11 | 12 | -- This function is called when tg receive a msg 13 | function on_msg_receive (msg) 14 | if not started then 15 | return 16 | end 17 | 18 | msg = backward_msg_format(msg) 19 | 20 | local receiver = get_receiver(msg) 21 | 22 | -- vardump(msg) 23 | msg = pre_process_service_msg(msg) 24 | if msg_valid(msg) then 25 | msg = pre_process_msg(msg) 26 | if msg then 27 | match_plugins(msg) 28 | mark_read(receiver, ok_cb, false) 29 | end 30 | end 31 | end 32 | 33 | function ok_cb(extra, success, result) 34 | end 35 | 36 | function on_binlog_replay_end() 37 | started = true 38 | postpone (cron_plugins, false, 60*5.0) 39 | -- See plugins/isup.lua as an example for cron 40 | 41 | _config = load_config() 42 | 43 | _gbans = load_gbans() 44 | 45 | -- load plugins 46 | plugins = {} 47 | load_plugins() 48 | 49 | -- load language 50 | lang = {} 51 | load_lang() 52 | end 53 | 54 | function msg_valid(msg) 55 | -- Don't process outgoing messages 56 | if msg.out then 57 | print('\27[36mNot valid: msg from us\27[39m') 58 | return false 59 | end 60 | 61 | -- Before bot was started 62 | if msg.date < now then 63 | print('\27[36mNot valid: old msg\27[39m') 64 | return false 65 | end 66 | 67 | if msg.unread == 0 then 68 | print('\27[36mNot valid: readed\27[39m') 69 | return false 70 | end 71 | 72 | if not msg.to.id then 73 | print('\27[36mNot valid: To id not provided\27[39m') 74 | return false 75 | end 76 | 77 | if not msg.from.id then 78 | print('\27[36mNot valid: From id not provided\27[39m') 79 | return false 80 | end 81 | 82 | if msg.from.id == our_id then 83 | print('\27[36mNot valid: Msg from our id\27[39m') 84 | return false 85 | end 86 | 87 | if msg.to.type == 'encr_chat' then 88 | print('\27[36mNot valid: Encrypted chat\27[39m') 89 | return false 90 | end 91 | 92 | if msg.from.id == 777000 then 93 | print('\27[36mNot valid: Telegram message\27[39m') 94 | return false 95 | end 96 | 97 | return true 98 | end 99 | 100 | -- 101 | function pre_process_service_msg(msg) 102 | if msg.service then 103 | local action = msg.action or {type=""} 104 | -- Double ! to discriminate of normal actions 105 | msg.text = "!!tgservice " .. action.type 106 | 107 | -- wipe the data to allow the bot to read service messages 108 | if msg.out then 109 | msg.out = false 110 | end 111 | if msg.from.id == our_id then 112 | msg.from.id = 0 113 | end 114 | end 115 | return msg 116 | end 117 | 118 | -- Apply plugin.pre_process function 119 | function pre_process_msg(msg) 120 | for name,plugin in pairs(plugins) do 121 | if plugin.pre_process and msg then 122 | print('Preprocess', name) 123 | msg = plugin.pre_process(msg) 124 | end 125 | end 126 | 127 | return msg 128 | end 129 | 130 | -- Go over enabled plugins patterns. 131 | function match_plugins(msg) 132 | for name, plugin in pairs(plugins) do 133 | match_plugin(plugin, name, msg) 134 | end 135 | end 136 | 137 | -- Check if plugin is on _config.disabled_plugin_on_chat table 138 | local function is_plugin_disabled_on_chat(plugin_name, receiver) 139 | local disabled_chats = _config.disabled_plugin_on_chat 140 | -- Table exists and chat has disabled plugins 141 | if disabled_chats and disabled_chats[receiver] then 142 | -- Checks if plugin is disabled on this chat 143 | for disabled_plugin,disabled in pairs(disabled_chats[receiver]) do 144 | if disabled_plugin == plugin_name and disabled then 145 | local warning = 'Plugin '..disabled_plugin..' is disabled on this chat' 146 | print(warning) 147 | send_msg(receiver, warning, ok_cb, false) 148 | return true 149 | end 150 | end 151 | end 152 | return false 153 | end 154 | 155 | function match_plugin(plugin, plugin_name, msg) 156 | local receiver = get_receiver(msg) 157 | 158 | -- Go over patterns. If one matches it's enough. 159 | for k, pattern in pairs(plugin.patterns) do 160 | local matches = match_pattern(pattern, msg.text) 161 | if matches then 162 | print("msg matches: ", pattern) 163 | 164 | if is_plugin_disabled_on_chat(plugin_name, receiver) then 165 | return nil 166 | end 167 | -- Function exists 168 | if plugin.run then 169 | -- If plugin is for privileged users only 170 | if not warns_user_not_allowed(plugin, msg) then 171 | local result = plugin.run(msg, matches) 172 | if result then 173 | send_large_msg(receiver, result) 174 | end 175 | end 176 | end 177 | -- One patterns matches 178 | return 179 | end 180 | end 181 | end 182 | 183 | -- DEPRECATED, use send_large_msg(destination, text) 184 | function _send_msg(destination, text) 185 | send_large_msg(destination, text) 186 | end 187 | 188 | -- Save the content of _config to config.lua 189 | function save_config( ) 190 | serialize_to_file(_config, './data/config.lua') 191 | print ('saved config into ./data/config.lua') 192 | end 193 | 194 | function save_gbans( ) 195 | serialize_to_file(_gbans, './data/gbans.lua') 196 | print ('saved gban into ./data/gbans.lua') 197 | end 198 | 199 | -- Returns the config from config.lua file. 200 | -- If file doesn't exist, create it. 201 | function load_config( ) 202 | local f = io.open('./data/config.lua', "r") 203 | -- If config.lua doesn't exist 204 | if not f then 205 | print ("Created new config file: data/config.lua") 206 | create_config() 207 | else 208 | f:close() 209 | end 210 | local config = loadfile ("./data/config.lua")() 211 | for v,user in pairs(config.sudo_users) do 212 | print('\27[93mAllowed user:\27[39m ' .. user) 213 | end 214 | return config 215 | end 216 | 217 | function load_gbans( ) 218 | local f = io.open('./data/gbans.lua', "r") 219 | -- If gbans.lua doesn't exist 220 | if not f then 221 | print ("Created new gbans file: data/gbans.lua") 222 | create_gbans() 223 | else 224 | f:close() 225 | end 226 | local gbans = loadfile ("./data/gbans.lua")() 227 | return gbans 228 | end 229 | 230 | -- Create a basic config.json file and saves it. 231 | function create_config( ) 232 | -- A simple config with basic plugins and ourselves as privileged user 233 | config = { 234 | enabled_plugins = { 235 | "arabic", 236 | "bot", 237 | "commands", 238 | "export_gban", 239 | "giverank", 240 | "id", 241 | "links", 242 | "moderation", 243 | "plugins", 244 | "rules", 245 | "settings", 246 | "spam", 247 | "version", 248 | }, 249 | enabled_lang = { 250 | "arabic_lang", 251 | "catalan_lang", 252 | "english_lang", 253 | "galician_lang", 254 | "italian_lang", 255 | "persian_lang", 256 | "portuguese_lang", 257 | "spanish_lang", 258 | }, 259 | sudo_users = {our_id}, 260 | admin_users = {}, 261 | disabled_channels = {} 262 | } 263 | serialize_to_file(config, './data/config.lua') 264 | print ('saved config into ./data/config.lua') 265 | end 266 | 267 | function create_gbans( ) 268 | -- A simple config with basic plugins and ourselves as privileged user 269 | gbans = { 270 | gbans_users = {} 271 | } 272 | serialize_to_file(gbans, './data/gbans.lua') 273 | print ('saved gbans into ./data/gbans.lua') 274 | end 275 | 276 | function on_our_id (id) 277 | our_id = id 278 | end 279 | 280 | function on_user_update (user, what) 281 | --vardump (user) 282 | end 283 | 284 | function on_chat_update (chat, what) 285 | --vardump (chat) 286 | end 287 | 288 | function on_secret_chat_update (schat, what) 289 | --vardump (schat) 290 | end 291 | 292 | function on_get_difference_end () 293 | end 294 | 295 | -- Enable plugins in config.lua 296 | function load_plugins() 297 | for k, v in pairs(_config.enabled_plugins) do 298 | print('\27[92mLoading plugin '.. v..'\27[39m') 299 | 300 | local ok, err = pcall(function() 301 | local t = loadfile("plugins/"..v..'.lua')() 302 | plugins[v] = t 303 | end) 304 | 305 | if not ok then 306 | print('\27[31mError loading plugin '..v..'\27[39m') 307 | print(tostring(io.popen("lua plugins/"..v..".lua"):read('*all'))) 308 | print('\27[31m'..err..'\27[39m') 309 | end 310 | end 311 | end 312 | 313 | -- Enable lang in config.lua 314 | function load_lang() 315 | for k, v in pairs(_config.enabled_lang) do 316 | print('\27[92mLoading language '.. v..'\27[39m') 317 | 318 | local ok, err = pcall(function() 319 | local t = loadfile("lang/"..v..'.lua')() 320 | plugins[v] = t 321 | end) 322 | 323 | if not ok then 324 | print('\27[31mError loading language '..v..'\27[39m') 325 | print(tostring(io.popen("lua lang/"..v..".lua"):read('*all'))) 326 | print('\27[31m'..err..'\27[39m') 327 | end 328 | end 329 | end 330 | 331 | -- Call and postpone execution for cron plugins 332 | function cron_plugins() 333 | 334 | for name, plugin in pairs(plugins) do 335 | -- Only plugins with cron function 336 | if plugin.cron ~= nil then 337 | plugin.cron() 338 | end 339 | end 340 | 341 | -- Called again in 5 mins 342 | postpone (cron_plugins, false, 5*60.0) 343 | end 344 | 345 | -- Start and load values 346 | our_id = 0 347 | now = os.time() 348 | math.randomseed(now) 349 | started = false -------------------------------------------------------------------------------- /plugins/giverank.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | -- ____ ____ _____ -- 3 | -- | \| _ )_ _|___ ____ __ __ -- 4 | -- | |_ ) _ \ | |/ ·__| _ \_| \/ | -- 5 | -- |____/|____/ |_|\____/\_____|_/\/\_| -- 6 | -- -- 7 | -------------------------------------------------- 8 | -- -- 9 | -- Developers: @Josepdal & @MaSkAoS -- 10 | -- Support: @Skneos, @iicc1 & @serx666 -- 11 | -- -- 12 | -------------------------------------------------- 13 | 14 | local function index_function(user_id) 15 | for k,v in pairs(_config.admin_users) do 16 | if user_id == v[1] then 17 | print(k) 18 | return k 19 | end 20 | end 21 | -- If not found 22 | return false 23 | end 24 | 25 | local function admin_by_username(cb_extra, success, result) 26 | local chat_type = cb_extra.chat_type 27 | local chat_id = cb_extra.chat_id 28 | local user_id = result.peer_id 29 | local user_name = result.username 30 | if is_admin(user_id) then 31 | if chat_type == 'chat' then 32 | send_msg('chat#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyAdmin'), ok_cb, false) 33 | elseif chat_type == 'channel' then 34 | send_msg('channel#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyAdmin'), ok_cb, false) 35 | end 36 | else 37 | table.insert(_config.admin_users, {tonumber(user_id), user_name}) 38 | print(user_id..' added to _config table') 39 | save_config() 40 | if chat_type == 'chat' then 41 | send_msg('chat#id'..chat_id, '🆕 '..lang_text(chat_id, 'newAdmin')..' @'..user_name..' ('..user_id..')', ok_cb, false) 42 | elseif chat_type == 'channel' then 43 | send_msg('channel#id'..chat_id, '🆕 '..lang_text(chat_id, 'newAdmin')..' @'..user_name..' ('..user_id..')', ok_cb, false) 44 | end 45 | end 46 | end 47 | 48 | local function mod_by_username(cb_extra, success, result) 49 | local chat_type = cb_extra.chat_type 50 | local chat_id = cb_extra.chat_id 51 | local user_id = result.peer_id 52 | local user_name = result.username 53 | local hash = 'mod:'..chat_id..':'..user_id 54 | if redis:get(hash) then 55 | if chat_type == 'chat' then 56 | send_msg('chat#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyMod'), ok_cb, false) 57 | elseif chat_type == 'channel' then 58 | send_msg('channel#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyMod'), ok_cb, false) 59 | end 60 | else 61 | redis:set(hash, true) 62 | if chat_type == 'chat' then 63 | send_msg('chat#id'..chat_id, '🆕 '..lang_text(chat_id, 'newMod')..' @'..user_name..' ('..user_id..')', ok_cb, false) 64 | elseif chat_type == 'channel' then 65 | send_msg('channel#id'..chat_id, '🆕 '..lang_text(chat_id, 'newMod')..' @'..user_name..' ('..user_id..')', ok_cb, false) 66 | end 67 | end 68 | end 69 | 70 | local function guest_by_username(cb_extra, success, result) 71 | local chat_type = cb_extra.chat_type 72 | local chat_id = cb_extra.chat_id 73 | local user_id = result.peer_id 74 | local user_name = result.username 75 | local nameid = index_function(user_id) 76 | local hash = 'mod:'..chat_id..':'..user_id 77 | if redis:get(hash) then 78 | redis:del(hash) 79 | end 80 | if is_admin(user_id) then 81 | table.remove(_config.admin_users, nameid) 82 | print(user_id..' added to _config table') 83 | save_config() 84 | end 85 | if chat_type == 'chat' then 86 | send_msg('chat#id'..chat_id, 'ℹ️ @'..user_name..' ('..user_id..') '..lang_text(chat_id, 'nowUser'), ok_cb, false) 87 | elseif chat_type == 'channel' then 88 | send_msg('channel#id'..chat_id, 'ℹ️ @'..user_name..' ('..user_id..') '..lang_text(chat_id, 'nowUser'), ok_cb, false) 89 | end 90 | end 91 | 92 | local function set_admin(cb_extra, success, result) 93 | local chat_id = cb_extra.chat_id 94 | local user_id = cb_extra.user_id 95 | local user_name = result.username 96 | local chat_type = cb_extra.chat_type 97 | if is_admin(tonumber(user_id)) then 98 | if chat_type == 'chat' then 99 | send_msg('chat#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyAdmin'), ok_cb, false) 100 | elseif chat_type == 'channel' then 101 | send_msg('channel#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyAdmin'), ok_cb, false) 102 | end 103 | else 104 | table.insert(_config.admin_users, {tonumber(user_id), user_name}) 105 | print(user_id..' added to _config table') 106 | save_config() 107 | if cb_extra.chat_type == 'chat' then 108 | send_msg('chat#id'..chat_id, '🆕 '..lang_text(chat_id, 'newAdmin')..' @'..user_name..' ('..user_id..')', ok_cb, false) 109 | elseif cb_extra.chat_type == 'channel' then 110 | send_msg('channel#id'..chat_id, '🆕 '..lang_text(chat_id, 'newAdmin')..' @'..user_name..' ('..user_id..')', ok_cb, false) 111 | end 112 | end 113 | end 114 | 115 | local function set_mod(cb_extra, success, result) 116 | local chat_id = cb_extra.chat_id 117 | local user_id = cb_extra.user_id 118 | local user_name = result.username 119 | local chat_type = cb_extra.chat_type 120 | local hash = 'mod:'..chat_id..':'..user_id 121 | if redis:get(hash) then 122 | if chat_type == 'chat' then 123 | send_msg('chat#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyMod'), ok_cb, false) 124 | elseif chat_type == 'channel' then 125 | send_msg('channel#id'..chat_id, 'ℹ️ '..lang_text(chat_id, 'alreadyMod'), ok_cb, false) 126 | end 127 | else 128 | redis:set(hash, true) 129 | if cb_extra.chat_type == 'chat' then 130 | send_msg('chat#id'..chat_id, '🆕 '..lang_text(chat_id, 'newMod')..' @'..user_name..' ('..user_id..')', ok_cb, false) 131 | elseif cb_extra.chat_type == 'channel' then 132 | send_msg('channel#id'..chat_id, '🆕 '..lang_text(chat_id, 'newMod')..' @'..user_name..' ('..user_id..')', ok_cb, false) 133 | end 134 | end 135 | end 136 | 137 | local function set_guest(cb_extra, success, result) 138 | local chat_id = cb_extra.chat_id 139 | local user_id = cb_extra.user_id 140 | local user_name = result.username 141 | local chat_type = cb_extra.chat_type 142 | local nameid = index_function(tonumber(user_id)) 143 | local hash = 'mod:'..chat_id..':'..user_id 144 | if redis:get(hash) then 145 | redis:del(hash) 146 | end 147 | if is_admin(user_id) then 148 | table.remove(_config.admin_users, nameid) 149 | print(user_id..' added to _config table') 150 | save_config() 151 | end 152 | if cb_extra.chat_type == 'chat' then 153 | send_msg('chat#id'..chat_id, 'ℹ️ @'..user_name..' ('..user_id..') '..lang_text(chat_id, 'nowUser'), ok_cb, false) 154 | elseif cb_extra.chat_type == 'channel' then 155 | send_msg('channel#id'..chat_id, 'ℹ️ @'..user_name..' ('..user_id..') '..lang_text(chat_id, 'nowUser'), ok_cb, false) 156 | end 157 | end 158 | 159 | local function admin_by_reply(extra, success, result) 160 | local result = backward_msg_format(result) 161 | local msg = result 162 | local chat_id = msg.to.id 163 | local user_id = msg.from.id 164 | local chat_type = msg.to.type 165 | user_info('user#id'..user_id, set_admin, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 166 | end 167 | 168 | local function mod_by_reply(extra, success, result) 169 | local result = backward_msg_format(result) 170 | local msg = result 171 | local chat_id = msg.to.id 172 | local user_id = msg.from.id 173 | local chat_type = msg.to.type 174 | user_info('user#id'..user_id, set_mod, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 175 | end 176 | 177 | local function guest_by_reply(extra, success, result) 178 | local result = backward_msg_format(result) 179 | local msg = result 180 | local chat_id = msg.to.id 181 | local user_id = msg.from.id 182 | local chat_type = msg.to.type 183 | user_info('user#id'..user_id, set_guest, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 184 | end 185 | 186 | local function members_chat(cb_extra, success, result) 187 | local chat_id = cb_extra.chat_id 188 | local text = "" 189 | for k,v in pairs(result.members) do 190 | if v.username then 191 | text = text..'@'..v.username..' ' 192 | end 193 | end 194 | return send_large_msg('chat#id'..chat_id, text, ok_cb, true) 195 | end 196 | 197 | local function members_channel(extra, success, result) 198 | local chat_id = extra.chat_id 199 | local text = "" 200 | for k,user in ipairs(result) do 201 | if user.username then 202 | text = text..'@'..user.username..' ' 203 | end 204 | end 205 | return send_large_msg('channel#id'..chat_id, text, ok_cb, true) 206 | end 207 | 208 | local function members_chat_msg(cb_extra, success, result) 209 | local chat_id = cb_extra.chat_id 210 | local text = ' ' 211 | for k,v in pairs(result.members) do 212 | if v.username then 213 | text = text..'@'..v.username..' ' 214 | end 215 | end 216 | text = text..'\n\n'..extra.text_msg 217 | return send_large_msg('chat#id'..chat_id, text, ok_cb, true) 218 | end 219 | 220 | local function members_channel_msg(extra, success, result) 221 | local chat_id = extra.chat_id 222 | local text = ' ' 223 | for k,user in ipairs(result) do 224 | if user.username then 225 | text = text..'@'..user.username..' ' 226 | end 227 | end 228 | text = text..'\n\n'..extra.text_msg 229 | return send_large_msg('channel#id'..chat_id, text, ok_cb, true) 230 | end 231 | 232 | local function mods_channel(extra, success, result) 233 | local chat_id = extra.chat_id 234 | local text = '🔆 '..lang_text(chat_id, 'modList')..':\n' 235 | local compare = text 236 | for k,user in ipairs(result) do 237 | hash = 'mod:'..chat_id..':'..user.peer_id 238 | if redis:get(hash) then 239 | text = text..'🔅 '..user.username..'\n' 240 | end 241 | end 242 | if text == compare then 243 | text = text..'🔅 '..lang_text(chat_id, 'modEmpty') 244 | end 245 | return send_large_msg('channel#id'..chat_id, text, ok_cb, true) 246 | end 247 | 248 | local function mods_chat(extra, success, result) 249 | local chat_id = extra.chat_id 250 | local text = '🔆 '..lang_text(chat_id, 'modList')..':\n' 251 | local compare = text 252 | for k,user in ipairs(result.members) do 253 | if user.username then 254 | hash = 'mod:'..chat_id..':'..user.peer_id 255 | if redis:get(hash) then 256 | text = text..'🔅 '..user.username..'\n' 257 | end 258 | end 259 | end 260 | if text == compare then 261 | text = text..'🔅 '..lang_text(chat_id, 'modEmpty') 262 | end 263 | return send_large_msg('chat#id'..chat_id, text, ok_cb, true) 264 | end 265 | 266 | local function run(msg, matches) 267 | user_id = msg.from.id 268 | chat_id = msg.to.id 269 | if matches[1] == 'rank' then 270 | if matches[2] == 'admin' then 271 | if permissions(user_id, chat_id, "rank_admin") then 272 | if msg.reply_id then 273 | get_message(msg.reply_id, admin_by_reply, false) 274 | end 275 | if is_id(matches[3]) then 276 | chat_type = msg.to.type 277 | chat_id = msg.to.id 278 | user_id = matches[3] 279 | user_info('user#id'..user_id, set_admin, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 280 | else 281 | chat_type = msg.to.type 282 | chat_id = msg.to.id 283 | local member = string.gsub(matches[3], '@', '') 284 | resolve_username(member, admin_by_username, {chat_id=chat_id, member=member, chat_type=chat_type}) 285 | end 286 | else 287 | return '🚫 '..lang_text(msg.to.id, 'require_sudo') 288 | end 289 | end 290 | if matches[2] == 'mod' then 291 | if permissions(user_id, chat_id, "rank_mod") then 292 | if msg.reply_id then 293 | get_message(msg.reply_id, mod_by_reply, false) 294 | end 295 | if is_id(matches[3]) then 296 | chat_type = msg.to.type 297 | chat_id = msg.to.id 298 | user_id = matches[3] 299 | user_info('user#id'..user_id, set_mod, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 300 | else 301 | chat_type = msg.to.type 302 | chat_id = msg.to.id 303 | local member = string.gsub(matches[3], '@', '') 304 | resolve_username(member, mod_by_username, {chat_id=chat_id, member=member, chat_type=chat_type}) 305 | end 306 | else 307 | return '🚫 '..lang_text(msg.to.id, 'require_admin') 308 | end 309 | end 310 | if matches[2] == 'guest' then 311 | if permissions(user_id, chat_id, "rank_guest") then 312 | if msg.reply_id then 313 | get_message(msg.reply_id, guest_by_reply, false) 314 | end 315 | if is_id(matches[3]) then 316 | chat_type = msg.to.type 317 | chat_id = msg.to.id 318 | user_id = matches[3] 319 | user_info('user#id'..user_id, set_guest, {chat_type=chat_type, chat_id=chat_id, user_id=user_id}) 320 | else 321 | chat_type = msg.to.type 322 | chat_id = msg.to.id 323 | local member = string.gsub(matches[3], '@', '') 324 | resolve_username(member, guest_by_username, {chat_id=chat_id, member=member, chat_type=chat_type}) 325 | end 326 | else 327 | return '🚫 '..lang_text(msg.to.id, 'require_sudo') 328 | end 329 | end 330 | elseif matches[1] == 'admins' then 331 | if permissions(user_id, chat_id, "admins") then 332 | -- Check users id in config 333 | local text = '🔆 '..lang_text(msg.to.id, 'adminList')..':\n' 334 | local compare = text 335 | for v,user in pairs(_config.admin_users) do 336 | text = text..'🔅 '..user[2]..' ('..user[1]..')\n' 337 | end 338 | if compare == text then 339 | text = text..'🔅 '..lang_text(chat_id, 'adminEmpty') 340 | end 341 | return text 342 | else 343 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 344 | end 345 | elseif matches[1] == 'members' then 346 | if permissions(user_id, chat_id, "members") then 347 | local chat_id = msg.to.id 348 | if matches[2] then 349 | if msg.to.type == 'chat' then 350 | local receiver = 'chat#id'..msg.to.id 351 | chat_info(receiver, members_chat_msg, {chat_id=chat_id, text_msg=matches[2]}) 352 | else 353 | local chan = ("%s#id%s"):format(msg.to.type, msg.to.id) 354 | channel_get_users(chan, members_channel_msg, {chat_id=chat_id, text_msg=matches[2]}) 355 | end 356 | delete_msg(msg.id, ok_cb, false) 357 | else 358 | if msg.to.type == 'chat' then 359 | local receiver = 'chat#id'..msg.to.id 360 | chat_info(receiver, members_chat, {chat_id=chat_id}) 361 | else 362 | local chan = ("%s#id%s"):format(msg.to.type, msg.to.id) 363 | channel_get_users(chan, members_channel, {chat_id=chat_id}) 364 | end 365 | end 366 | else 367 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 368 | end 369 | elseif matches[1] == 'mods' then 370 | if permissions(user_id, chat_id, "mods") then 371 | local chat_id = msg.to.id 372 | if msg.to.type == 'chat' then 373 | local receiver = 'chat#id'..msg.to.id 374 | chat_info(receiver, mods_chat, {chat_id=chat_id}) 375 | else 376 | local chan = ("%s#id%s"):format(msg.to.type, msg.to.id) 377 | channel_get_users(chan, mods_channel, {chat_id=chat_id}) 378 | end 379 | else 380 | return '🚫 '..lang_text(msg.to.id, 'require_mod') 381 | end 382 | end 383 | end 384 | 385 | 386 | 387 | return { 388 | patterns = { 389 | "^[!/#](rank) (.*) (.*)$", 390 | "^[!/#](rank) (.*)$", 391 | "^[!/#](admins)$", 392 | "^[!/#](mods)$", 393 | "^[!/#](members)$", 394 | "^[!/#](members) (.*)$" 395 | }, 396 | run = run 397 | } 398 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # If ./start then 4 | if [ ! "$1" ]; then 5 | clear 6 | echo -e "\033[38;5;208m" 7 | echo -e " ____ ____ _____ " 8 | echo -e " | \| _ )_ _|___ ____ __ __ " 9 | echo -e " | |_ ) _ \ | |/ .__| _ \_| \/ | " 10 | echo -e " |____/|____/ |_|\____/\_____|_/\/\_| " 11 | echo -e " \033[0;00m" 12 | echo -e " Developers @Josepdal @MaSkAoS " 13 | echo -e " steady by @iicc1 start by @Jarriz " 14 | echo -e "\e[34m" 15 | echo "Please, select your language." 16 | echo -e "\033[38;5;208m" 17 | echo " 1) English." 18 | echo " 2) Spanish." 19 | echo " 3) Portuguese." 20 | echo -e "\e[0m" 21 | # Read VAR of languages. First language Spanish. 22 | # options 23 | read VAR 24 | if [ "$VAR" = 2 ]; then 25 | clear 26 | echo -e "\e[34m" 27 | echo "Por favor, selecciona tu opcion." 28 | echo -e "\033[38;5;208m" 29 | echo " 1) Iniciar DBTeam (tmux)." 30 | echo " 2) Abrir sesion anterior (registros)" 31 | echo " 3) Abrir sesion anterior (tmux)." 32 | echo " 4) Cerrar todas las sesiones." 33 | echo " 5) Reiniciar DBTeam (tmux)." 34 | echo " 6) Actualizar DBTeam." 35 | echo " 7) Respaldar DBTeam" 36 | echo " 8) Cambiar telefono." 37 | echo " 9) Restaurar y actualizar plugins." 38 | echo " 10) Instalar DBTeam." 39 | echo " 11) Salir." 40 | echo -e "\e[0m" 41 | # Suboptions spanish 42 | read VAR 43 | if [ "$VAR" = 1 ]; then 44 | tmux new-session -s script "bash steady.sh -t" 45 | elif [ "$VAR" = 2 ]; then 46 | tmux attach-session -t DBTeam 47 | elif [ "$VAR" = 3 ]; then 48 | tmux attach-session -t script 49 | elif [ "$VAR" = 4 ]; then 50 | killall telegram-cli 51 | tmux kill-session -t DBTeam 52 | tmux kill-session -t script 53 | clear 54 | echo -e '\e[34mSesiones cerradas.\e[0m' 55 | elif [ "$VAR" = 5 ]; then 56 | clear 57 | tmux kill-session -t DBTeam 58 | tmux kill-session -t script 59 | read -n1 -r -p 'Presiona cualquier tecla para continuar...' 60 | tmux new-session -s script "bash steady.sh -t" 61 | elif [ "$VAR" = 6 ]; then 62 | clear 63 | git pull 64 | elif [ "$VAR" = 7 ]; then 65 | clear 66 | mkdir /home/DBTeamBackup 67 | rm -R /home/DBTeamBackup/DBTeam 68 | clear 69 | cp -R ../DBTeam/ /home/DBTeamBackup 70 | echo "Respaldo exitoso! Guardado en /home/DBTeamBackup." 71 | read -n1 -r -p 'Si quieres borrar los backups escribe bkpdel al iniciar start.sh. Presiona cualquier tecla para finalizar' 72 | clear 73 | elif [ "$VAR" = 8 ]; then 74 | clear 75 | killall telegram-cli 76 | tmux kill-session -t DBTeam 77 | tmux kill-session -t script 78 | rm -R ../.telegram-cli 79 | ./launch.sh install 80 | read -n1 -r -p 'Terminado!, presiona cualquier tecla para el paso siguente' 81 | ./launch.sh 82 | elif [ "$VAR" = 9 ]; then 83 | clear 84 | echo -e "\e[31m" 85 | echo "IMPORTANTE: Todos tus plugins se restableceran y actualizaran a la configuracion por defecto de DBTeam." 86 | echo " Cualquier otra modificacion externa de DBTeam sera sustituida." 87 | echo " Se creara un backup en /home/DBTeamBackup/plugins." 88 | echo " Si deseas eliminar todos los backups escribe bkpdel al iniciar start.sh." 89 | echo "Quieres continuar?" 90 | echo " Si = y No = n " 91 | # SubVar confirmation and change color. 92 | echo -e '\e[0m' 93 | read subVAR 94 | if [ "$subVAR" = y ]; then 95 | mkdir /home/DBTeamBackup 96 | rm -R /home/DBTeamBackup/plugins 97 | clear 98 | cp -R plugins/ /home/DBTeamBackup 99 | clear 100 | echo -e "\e[32m" 101 | dpkg -s subversion 2>/dev/null >/dev/null || sudo apt-get -y install subversion 102 | rm -rf plugins 103 | svn export https://github.com/Josepdal/DBTeam/trunk/plugins 104 | echo "Plugins restaurados y actualizados!" 105 | read -n1 -r -p 'Presiona cualquier tecla para volver al inicio.' 106 | ./start.sh 107 | elif [ "$subVAR" = n ]; then 108 | clear 109 | echo -e "\e[0m" 110 | exit 111 | elif [ "$subVAR" = "" ]; then 112 | clear 113 | echo -e '\e[31mOpcion invalida\e[0m' 114 | else 115 | clear 116 | echo -e '\e[31mOpcion invalida\e[0m' 117 | fi 118 | # end 119 | elif [ "$VAR" = 10 ]; then 120 | clear 121 | echo -e " La instalacion de DBTeam comenzara. " 122 | echo -e "DBTeam fue desarrollado por @Josepdal y @MaSkAoS" 123 | echo -e "Gracias a @iicc1 y a @Jarriz por hacer que DBTeam funcione con mas estabilidad y facilidad" 124 | read -n1 -r -p 'Presiona cualquier tecla para comenzar la instalación' 125 | sudo apt-get update && apt-get upgrade 126 | read -n1 -r -p 'Paso 1/3. Paquetes actualizados, Presiona cualquier tecla para seguir con el siguiente paso' 127 | sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git redis-server g++ libjansson-dev libpython-dev expat libexpat1-dev 128 | read -n1 -r -p 'Paso 2/3. Dependencias instaladas, Presiona cualquier tecla para seguir con el siguiente paso' 129 | ./launch.sh install 130 | read -n1 -r -p 'Paso 3/3. Instalacion completa! Gracias por preferir DBTeam el equipo de DBTeam te lo agradece! Esperamos que DBTeam sea de tu agrado. A continuacion te pedira tu numero telefonico y el codigo de confirmacion que te llegara por sms o Telegram, por favor, ingresa tu numero con + [Codigo De Pais] [Numero telefonico]' 131 | clear 132 | service redis-server start 133 | clear 134 | ./launch.sh 135 | elif [ "$VAR" = 11 ]; then 136 | clear 137 | exit 138 | elif [ "$VAR" = "" ]; then 139 | clear 140 | echo -e '\e[31mOpcion invalida\e[0m' 141 | else 142 | clear 143 | echo -e '\e[31mOpcion invalida\e[0m' 144 | fi 145 | 146 | # English Lang 147 | elif [ "$VAR" = 1 ]; then 148 | 149 | clear 150 | echo -e "\e[34m" 151 | echo "Please, select your option." 152 | echo -e "\033[38;5;208m" 153 | echo " 1) Run DBTeam (tmux)." 154 | echo " 2) Last session (register)." 155 | echo " 3) Last session (tmux)." 156 | echo " 4) Close all sessions." 157 | echo " 5) Restart DBTeam (tmux)." 158 | echo " 6) Update DBTeam." 159 | echo " 7) Backup DBTeam." 160 | echo " 8) Change number." 161 | echo " 9) Restore and Update plugins." 162 | echo " 10) Install DBTeam." 163 | echo " 11) Exit." 164 | echo -e '\e[0m' 165 | # options 166 | read VAR 167 | if [ "$VAR" = 1 ]; then 168 | tmux new-session -s script "bash steady.sh -t" 169 | elif [ "$VAR" = 2 ]; then 170 | tmux attach-session -t DBTeam 171 | elif [ "$VAR" = 3 ]; then 172 | tmux attach-session -t script 173 | elif [ "$VAR" = 4 ]; then 174 | killall telegram-cli 175 | tmux kill-session -t DBTeam 176 | tmux kill-session -t script 177 | clear 178 | echo -e '\e[34mSessions closed\e[0m' 179 | echo 180 | elif [ "$VAR" = 5 ]; then 181 | clear 182 | tmux kill-session -t DBTeam 183 | tmux kill-session -t script 184 | read -n1 -r -p 'Press any key to continue...' 185 | tmux new-session -s script "bash steady.sh -t" 186 | elif [ "$VAR" = 6 ]; then 187 | clear 188 | git pull 189 | elif [ "$VAR" = 7 ]; then 190 | clear 191 | mkdir /home/DBTeamBackup 192 | rm -R /home/DBTeamBackup/DBTeam 193 | clear 194 | cp -R ../DBTeam/ /home/DBTeamBackup 195 | echo "Backup finished! Saved in /home/DBTeamBackup." 196 | read -n1 -r -p 'If you want delete all backups type bkpdel at run start.sh. Press any key to exit' 197 | clear 198 | elif [ "$VAR" = 8 ]; then 199 | clear 200 | killall telegram-cli 201 | tmux kill-session -t DBTeam 202 | tmux kill-session -t script 203 | rm -R ../.telegram-cli 204 | ./launch.sh install 205 | read -n1 -r -p 'Finished!, press any key to the next step.' 206 | ./launch.sh 207 | elif [ "$VAR" = 9 ]; then 208 | clear 209 | echo -e "\e[31m" 210 | echo "IMPORTANT: All your plugins will be deleted and updated." 211 | echo " Any Modifications will be replaced with the DBTeam repository." 212 | echo " Start.sh will make a backup in /home/DBTeamBackup/plugins." 213 | echo " If you want delete all backups, type bkpdel at run Start.sh." 214 | echo "Are you sure?" 215 | echo " Yes = y Not= n " 216 | # SubVar confirmation and change color 217 | echo -e "\e[0m" 218 | read subVAR 219 | if [ "$subVAR" = y ]; then 220 | mkdir /home/DBTeamBackup/ 221 | rm -R /home/DBTeamBackup/plugins 222 | clear 223 | cp -R plugins/ /home/DBTeamBackup 224 | clear 225 | echo -e "\e[32m" 226 | dpkg -s subversion 2>/dev/null >/dev/null || sudo apt-get -y install subversion 227 | rm -rf plugins 228 | svn export https://github.com/Josepdal/DBTeam/trunk/plugins 229 | echo "Plugins restored and updated!" 230 | read -n1 -r -p 'Press any key to back.' 231 | ./start.sh 232 | elif [ "$subVAR" = n ]; then 233 | clear 234 | echo -e "\e[0m" 235 | exit 236 | elif [ "$subVAR" = "" ]; then 237 | clear 238 | echo -e '\e[31mOption invalid\e[0m' 239 | else 240 | clear 241 | echo -e '\e[31mOption invalid\e[0m' 242 | fi 243 | # end 244 | elif [ "$VAR" = 10 ]; then 245 | clear 246 | echo -e " DBTeam installation will start. " 247 | echo -e "DBTeam was developed by @Josepdal and @MaSkAoS" 248 | echo -e "Thanks to @iicc1 and @Jarriz because DBTeam works easily and more stable." 249 | read -n1 -r -p 'Press any key to start install' 250 | sudo apt-get update && apt-get upgrade 251 | read -n1 -r -p 'Step 1/3. Packages updated, Press any key to the next step' 252 | sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git redis-server g++ libjansson-dev libpython-dev expat libexpat1-dev 253 | read -n1 -r -p 'Step 2/3. Dependences installed. Press any key to the next step' 254 | ./launch.sh install 255 | read -n1 -r -p 'Step 3/3. Instalation finished! Thanks to install DBTeam, the team of DBTeam say thank you! We hope you like DBTeam. Then, the script will ask your number y and the confirmation code, Telegram will send a sms o Telegram msg, please, type your numer with + [Code state] [Your phone]' 256 | clear 257 | service redis-server start 258 | clear 259 | ./launch.sh 260 | elif [ "$VAR" = 11 ]; then 261 | clear 262 | exit 263 | elif [ "$VAR" = "" ]; then 264 | clear 265 | echo -e '\e[31mOption invalid\e[0m' 266 | else 267 | clear 268 | echo -e '\e[31mOption invalid\e[0m' 269 | fi 270 | 271 | # Portuguese Lang 272 | 273 | elif [ "$VAR" = 3 ]; then 274 | 275 | clear 276 | echo -e "\e[34m" 277 | echo "Por favor, selecione uma opção." 278 | echo -e "\033[38;5;208m" 279 | echo " 1) Executar DBTeam (tmux)." 280 | echo " 2) Última sessão (registrado)." 281 | echo " 3) Última sessão (tmux)." 282 | echo " 4) Fechar todas as sessões." 283 | echo " 5) Reiniciar DBTeam (tmux)." 284 | echo " 6) Atualizar DBTeam." 285 | echo " 7) Backup DBTeam." 286 | echo " 8) Mudar número." 287 | echo " 9) Excluir e Atualizar plugins." 288 | echo " 10) Instalar DBTeam." 289 | echo " 11) Sair." 290 | echo -e "\e[0m" 291 | # Suboptions portuguese 292 | read VAR 293 | if [ "$VAR" = 1 ]; then 294 | tmux new-session -s script "bash steady.sh -t" 295 | elif [ "$VAR" = 2 ]; then 296 | tmux attach-session -t DBTeam 297 | elif [ "$VAR" = 3 ]; then 298 | tmux attach-session -t script 299 | elif [ "$VAR" = 4 ]; then 300 | killall telegram-cli 301 | tmux kill-session -t DBTeam 302 | tmux kill-session -t script 303 | clear 304 | echo -e '\e[34mSessões fechadas.\e[0m' 305 | echo 306 | elif [ "$VAR" = 5 ]; then 307 | clear 308 | killall telegram-cli 309 | tmux kill-session -t DBTeam 310 | tmux kill-session -t script 311 | read -n1 -r -p 'Pressione qualquer tecla para continuar...' 312 | tmux new-session -s script "bash steady.sh -t" 313 | elif [ "$VAR" = 6 ]; then 314 | clear 315 | git pull 316 | elif [ "$VAR" = 7 ]; then 317 | clear 318 | rm -R /home/DBTeamBackup/DBTeam 319 | mkdir /home/DBTeamBackup 320 | clear 321 | cp -R ../DBTeam/ /home/DBTeamBackup 322 | echo "Backup finalizado! Salvo em /home/DBTeamBackup." 323 | read -n1 -r -p 'If you want delete all backups type bkpdel at run start.sh. Pressione qualquer tecla para finalizar.' 324 | clear 325 | elif [ "$VAR" = 8 ]; then 326 | clear 327 | killall telegram-cli 328 | tmux kill-session -t DBTeam 329 | tmux kill-session -t script 330 | rm -R ../.telegram-cli 331 | ./launch.sh install 332 | read -n1 -r -p 'Finalizado!, Pressione qualquer tecla para o próximo passo.' 333 | ./launch.sh 334 | elif [ "$VAR" = 9 ]; then 335 | clear 336 | echo -e "\e[31m" 337 | echo "IMPORTANT: All your plugins will be deleted and updated." 338 | echo " Any Modifications will be replaced with the DBTeam repository." 339 | echo " Start.sh will make a backup in /home/DBTeamBackup/plugins." 340 | echo " If you want delete all backups, type bkpdel at run Start.sh." 341 | echo "Are you sure?" 342 | echo " Yes = y Not = n " 343 | # SubVar confirmation and change color. 344 | echo -e "\e[0m" 345 | read subVAR 346 | if [ "$subVAR" = y ]; then 347 | mkdir /home/DBTeamBackup 348 | rm -R /home/DBTeamBackup/plugins 349 | clear 350 | cp -R plugins/ /home/DBTeamBackup 351 | clear 352 | echo -e "\e[32m" 353 | dpkg -s subversion 2>/dev/null >/dev/null || sudo apt-get -y install subversion 354 | rm -rf plugins 355 | svn export https://github.com/Josepdal/DBTeam/trunk/plugins 356 | echo "Plugins restored and updated!" 357 | read -n1 -r -p 'Press any key to back.' 358 | ./start.sh 359 | elif [ "$subVAR" = n ]; then 360 | clear 361 | echo -e "\e[0m" 362 | exit 363 | elif [ "$subVAR" = "" ]; then 364 | clear 365 | echo -e '\e[31mOpção invalida\e[0m' 366 | else 367 | clear 368 | echo -e '\e[31mOpção invalida\e[0m' 369 | fi 370 | elif [ "$VAR" = 10 ]; then 371 | clear 372 | echo -e " A Instalação DBTeam será iniciada. " 373 | echo -e "DBTeam foi desenvolvida por @Josepdal e @MaSkAoS" 374 | echo -e "Obrigado para @iicc1 e @Jarriz por fazer DBTeam trabalhar de forma fácil e mais estável" 375 | read -n1 -r -p 'Pressione qualquer tecla para iniciar a instalação' 376 | sudo apt-get update && apt-get upgrade 377 | read -n1 -r -p 'Passo 1/3. Pacotes atualizados, pressione qualquer tecla para o próximo passo' 378 | sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git redis-server g++ libjansson-dev libpython-dev expat libexpat1-dev 379 | read -n1 -r -p 'Passo 2/3. Dependências instaladas. Pressione qualquer tecla para o próximo passo' 380 | ./launch.sh install 381 | read -n1 -r -p 'Passo 3/3. Instalação finalizada! Obrigado por instalar o DBTeam, a equipe do DBTeam diz obrigado! Esperamos que você goste do DBTeam. Então, o script irá pedir o seu número e o código de confirmação, Telegram irá enviar um sms com o código do Telegram, por favor, digite o número com +[DDI] [Seu Telefone]' 382 | clear 383 | service redis-server start 384 | clear 385 | ./launch.sh 386 | echo -e "\e[0m" 387 | elif [ "$VAR" = 11 ]; then 388 | clear 389 | exit 390 | elif [ "$VAR" = "" ]; then 391 | clear 392 | echo -e '\e[31mOpção invalida\e[0m' 393 | else 394 | clear 395 | echo -e '\e[31mOpção invalida\e[0m' 396 | fi 397 | # DELETE BACKUPS 398 | elif [ "$VAR" = bkpdel ]; then 399 | clear 400 | echo -e "\e[31m" 401 | echo "1) Delete plugins backup." 402 | echo "2) Delete DBTeam backup." 403 | echo "3) Delete all backups." 404 | read BKPVAR 405 | if [ "$BKPVAR" = 1 ]; then 406 | rm -R /home/DBTeamBackup/plugins 407 | clear 408 | echo -e '\e[31mBackups of Plugins removed\e[0m' 409 | elif [ "$BKPVAR" = 2 ]; then 410 | rm -R /home/DBTeamBackup/DBTeam 411 | clear 412 | echo -e '\e[31mBackups of DBTeam removed\e[0m' 413 | elif [ "$BKPVAR" = 3 ]; then 414 | rm -R /home/DBTeamBackup/ 415 | clear 416 | echo -e '\e[31mBackups removed\e[0m' 417 | elif [ "$BKPVAR" = "" ]; then 418 | clear 419 | echo -e '\e[31mOption invalid\e[0m' 420 | else 421 | clear 422 | echo -e '\e[31mOption invalid\e[0m' 423 | fi 424 | # If not type a valor 425 | elif [ "$VAR" = "" ]; then 426 | clear 427 | echo -e '\e[31mOption invalid\e[0m' 428 | else 429 | clear 430 | echo -e '\e[31mOption invalid\e[0m' 431 | fi 432 | fi 433 | 434 | # Options in ./start.sh