aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ip.lua21
-rw-r--r--plugins/urban.lua42
2 files changed, 57 insertions, 6 deletions
diff --git a/plugins/ip.lua b/plugins/ip.lua
index 57cb0f5..2e9afad 100644
--- a/plugins/ip.lua
+++ b/plugins/ip.lua
@@ -2,22 +2,31 @@ local milla = require("milla")
local os = require("os")
local json = require("json")
+-- setting the proxy value before loading the http module
+-- this way, only this script will be using this proxy
os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")
local http = require("http")
-local function get_ip(arg)
+-- this function should be global
+-- one string arg that holds all args
+-- should only return one string value
+function milla_get_ip(arg)
local ip = arg
- local response, err = http.request("GET",
- "https://getip-api.com/json?" .. ip)
+ local response, err = http.request("GET", "http://ip-api.com/json?" .. ip)
+ if err ~= nil then print(err) end
+
local json_response, err = json.decode(response.body)
+ if err ~= nil then print(err) end
+ for k, v in pairs(json_response) do print(k, v) end
local result = ""
- for key, value in ipairs(json_response) do
- result = result .. key .. ": " .. value .. "\n"
+ for key, value in pairs(json_response) do
+ result = result .. key .. ": " .. value .. " -- "
end
return result
end
-milla.register_cmd("ip", "get_ip")
+-- script_path, command_name, function_name
+milla.register_cmd("/plugins/ip.lua", "ip", "milla_get_ip")
diff --git a/plugins/urban.lua b/plugins/urban.lua
new file mode 100644
index 0000000..08c610b
--- /dev/null
+++ b/plugins/urban.lua
@@ -0,0 +1,42 @@
+local milla = require("milla")
+local os = require("os")
+local json = require("json")
+
+os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")
+
+local http = require("http")
+
+function milla_urban(arg)
+ local user_agent =
+ "Mozilla/5.0 (X11; U; Linux x86_64; pl-PL; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10"
+ local term = arg
+ local url = "http://api.urbandictionary.com/v0/define?term=" .. term
+ local response, err = http.request("GET", url, {
+ timeout = "10s",
+ headers = {
+ ["User-Agent"] = user_agent,
+ ["Accept"] = "application/json",
+ ["Host"] = "api.urbandictionary.com",
+ ["Connection"] = "keep-alive",
+ ["Cache-Control"] = "no-cache",
+ ["DNT"] = 1,
+ ["sec-ch-ua-platform"] = "Windows",
+ ["Pragma"] = "no-cache"
+ }
+ })
+ if err ~= nil then print(err) end
+ print(response.body)
+
+ local json_response, err = json.decode(response.body)
+ if err ~= nil then print(err) end
+
+ local result = ""
+ for k, v in ipairs(json_response["list"]) do
+ for kk, vv in pairs(v) do print(kk, vv) end
+ if k == 1 then result = v["definition"] end
+ end
+
+ return result
+end
+
+milla.register_cmd("/plugins/urban.lua", "urban", "milla_urban")