From 952271851ed8946bf4ae6a39be0dce8f1e5ec9da Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sat, 23 May 2015 16:37:42 +0200 Subject: [PATCH] new plugins kick.lua pokedex.lua router_status.lua whereisip.lua --- .gitignore | 4 ++- plugins/kick.lua | 61 +++++++++++++++++++++++++++++++++++++++ plugins/pokedex.lua | 29 +++++++++++++++++++ plugins/router_status.lua | 52 +++++++++++++++++++++++++++++++++ plugins/weather.lua | 2 +- plugins/whereisip.lua | 40 +++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 plugins/kick.lua create mode 100644 plugins/pokedex.lua create mode 100644 plugins/router_status.lua create mode 100644 plugins/whereisip.lua diff --git a/.gitignore b/.gitignore index c561e12..8eb8a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,6 @@ plugins/vimeo.lua plugins/vine.lua plugins/youtube_playlist.lua plugins/yandere.lua -plugins/e621.lua \ No newline at end of file +plugins/e621.lua +plugins/random.lua +plugins/youtube_dl.lua \ No newline at end of file diff --git a/plugins/kick.lua b/plugins/kick.lua new file mode 100644 index 0000000..9bb092e --- /dev/null +++ b/plugins/kick.lua @@ -0,0 +1,61 @@ +-- Kick an user from the chat group. +-- Use !kick name User_name or !kick id id_number +-- The User_name is the print_name (there are no spaces but _) + +--~ TODO: +--~ - !kick all + --~ Get a list of users and kick them all (Useful for delete groups) +--~ - !kick new // !protect + --~ Kick each new user who entered in the group +--~ - !ban user#id + --~ Blacklist an user to enter a group + +do + +function ban(usr,chat) + print ("Trying to kick: "..usr.." to "..chat) + local success = chat_del_user (chat, usr, ok_cb, false) + if not success then + return "An error happened" + else + local kicked = "Kicked user: "..usr.." from "..chat + return kicked + end +end + +function run(msg, matches) + chat_ = 'chat#id'..msg.to.id + -- The message must come from a chat group OR + if msg.to.type ~= 'chat' then + return 'This isn\'t a chat group!' + end + + -- User submitted a user name + if matches[1] == "name" then + user_ = matches[2] + user_ = string.gsub(user_," ","_") + ban(user_,chat_) + -- User submitted an id + elseif matches[1] == "id" then + for i=2,#matches do + user_ = 'user#id'..matches[i] + ban(user_,chat_) + end + end + user_ = nil + chat_ = nil +end + +return { + description = "Ban an user from the chat group. Credits: @Rutrus", + usage = { + "/kick name [user_name]", + "/kick id [user_id]+" }, + patterns = { + "^/kick (name) (.*)", + "^/kick (id) (%d+)" + }, + run = run, + privileged = true +} +end \ No newline at end of file diff --git a/plugins/pokedex.lua b/plugins/pokedex.lua new file mode 100644 index 0000000..c81d26e --- /dev/null +++ b/plugins/pokedex.lua @@ -0,0 +1,29 @@ +do + +local function get_pokemon(query) + local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/" + local b,c = http.request(url) + local pokemon = json:decode(b) + + if pokemon == nil then + return 'No pokémon found.' + end + return 'Pokédex ID: ' .. pokemon.pkdx_id .. '\n' + ..'Name: ' .. pokemon.name .. '\n' + ..'Weight: ' .. pokemon.weight .. '\n' + ..'Height: ' .. pokemon.height .. '\n' + ..'Speed: ' .. pokemon.speed .. '\n' +end + +local function run(msg, matches) + return get_pokemon(matches[1]) +end + +return { + description = "Pokedex searcher for Telegram", + usage = "/pokedex [Name/ID]: Search the pokédex for Name/ID and get info of the pokémon!", + patterns = {"^/pokedex (.*)$"}, + run = run + } + + end \ No newline at end of file diff --git a/plugins/router_status.lua b/plugins/router_status.lua new file mode 100644 index 0000000..77b684d --- /dev/null +++ b/plugins/router_status.lua @@ -0,0 +1,52 @@ +do + +function getRouterStatus(attempt) + command = "curl 'https://www.pcfactory.cl/ordenservicio' -H 'Pragma: no-cache' -H 'Origin: https://www.pcfactory.cl' -H 'Accept-Encoding: gzip,deflate' -H 'Accept-Language: en-US,en;q=0.8,es;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: https://www.pcfactory.cl/ordenservicio' -H 'Cookie: PHPSESSID=i96mfj26t2cjgimojv08m7n934; SphinxID=5548c195553200.30873318; sphinxCONTACTO=0; __asc=014d05c814d24321517a9255ba1; __auc=2fe469c51466d6c6237c3ff1a1c' -H 'Connection: keep-alive' --data '%40sphinx=ORDENSERVICIO&rut=76247226-0&buscar=Buscar' --compressed | grep 'masinfo'" + -- aRouterStatusattempt = attempt or 0 + -- attempt = attempt + 1 + + -- local res,status = http.request("") + + -- if status ~= 200 then return nil end + -- local data = json:decode(res)[1] + + -- -- The OpenBoobs API sometimes returns an empty array + -- if not data and attempt < 10 then + -- print('Cannot get router status...') + -- return getRouterStatus(attempt) + -- end + + local handle = io.popen(command) + local result = handle:read("*a") + handle:close() + + return result +end + + +function run(msg, matches) + status = getRouterStatus() + + if status ~= nil then + return status + else + return 'Error getting boobs/butts for you, please try again later.' + end +end + +return { + description = "Gets the router status", + usage = { + "/router", + "/router_status", + "/routerstatus" + }, + patterns = { + "^/router$", + "^/router_status$", + "^/routerstatus$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/weather.lua b/plugins/weather.lua index 9c02b4e..2a669df 100644 --- a/plugins/weather.lua +++ b/plugins/weather.lua @@ -57,4 +57,4 @@ return { run = run } -end +end \ No newline at end of file diff --git a/plugins/whereisip.lua b/plugins/whereisip.lua new file mode 100644 index 0000000..6eb7607 --- /dev/null +++ b/plugins/whereisip.lua @@ -0,0 +1,40 @@ +do + +function where_is_ip(msg, domain) + local receiver = get_receiver(msg) + ip = domain + local res,code = http.request("http://freegeoip.net/json/" .. ip) + if code ~= 200 then return "HTTP ERROR" end + local data = json:decode(res) + local location = data.country_code .. ":" .. data.country_name .. " - " .. data.city + if data.region_name ~= "" then + location = location .. " (" .. data.region_name .. ")" + end + message = data.ip .. " -> " .. location + return send_msg(receiver, message, ok_cb, false) + end +end + +function run(msg,matches) + local receiver = get_receiver(msg) + if matches[1] == "/whereisip" or matches[1] == "/ip" then + message = "How to use:\n" .. matches[1] .. " nasa.gov\n" + send_msg(receiver, message, ok_cb, false) + return false + else --~ matches[1] should be IP or domain + vardump(matches) + print (where_is_ip(msg,matches[1])) + end +end + +return { + description = "Send the origin of an IP or domain", + usage = {"!ip (ip): Send the origin of an IP.\n!ip (domain.com) Looks for his IP origin.\nYou can find your ip in: http://lorenzomoreno.es/myip Credits: @rutrus"}, + patterns = { + "^/whereisip$", + "^/ip$", + "^/whereisip ([%w.:]*)", + "^!/ip ([%w.:]*)$" + }, + run = run +} \ No newline at end of file