aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
committerterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
commit81469bbb1745a835676c3664e75a4a951223da9d (patch)
tree70a53b118c406d5958a8fb8c72e391fb6439f729 /plugins
parentwe can now add new commands from lua plugins (diff)
downloadmilla-81469bbb1745a835676c3664e75a4a951223da9d.tar.gz
milla-81469bbb1745a835676c3664e75a4a951223da9d.zip
* fixed a crash when unloading a lua script
* added event types, foreground and background color for watchlists * added a url_encode function to lua to encode urls. Underneath, it just calls the standard library function from golang * updated the README * the urban plugin now can take in the number of entries to return * reverted a bug where setting the http proxy for the lua http module was not working * fixed the url for the ip script so it is actually working. the current provider does not support ipv6 though
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ip.lua17
-rw-r--r--plugins/rss.lua2
-rw-r--r--plugins/urban.lua46
3 files changed, 49 insertions, 16 deletions
diff --git a/plugins/ip.lua b/plugins/ip.lua
index 2e9afad..79ac6e2 100644
--- a/plugins/ip.lua
+++ b/plugins/ip.lua
@@ -2,18 +2,19 @@ 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")
-
-- 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", "http://ip-api.com/json?" .. ip)
+ -- setting the proxy value before loading the http module
+ -- this way, only this script will be using this proxy
+ os.setenv("http_proxy", "http://172.17.0.1:8120")
+
+ local http = require("http")
+
+ local url = "http://ip-api.com/json/" .. arg
+
+ local response, err = http.request("GET", url)
if err ~= nil then print(err) end
local json_response, err = json.decode(response.body)
diff --git a/plugins/rss.lua b/plugins/rss.lua
index 880a0fd..111baa2 100644
--- a/plugins/rss.lua
+++ b/plugins/rss.lua
@@ -47,7 +47,6 @@ local function get_rss_feed(config)
end
path, err = xmlpath.compile("//entry/author/name")
- -- local path, err = xmlpath.compile("//entry/title")
if err ~= nil then
milla.send_message(err, "")
goto continue
@@ -58,7 +57,6 @@ local function get_rss_feed(config)
end
path, err = xmlpath.compile("//entry/author/uri")
- -- local path, err = xmlpath.compile("//entry/title")
if err ~= nil then
milla.send_message(err, "")
goto continue
diff --git a/plugins/urban.lua b/plugins/urban.lua
index 08c610b..7b7e71c 100644
--- a/plugins/urban.lua
+++ b/plugins/urban.lua
@@ -2,15 +2,42 @@ local milla = require("milla")
local os = require("os")
local json = require("json")
-os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")
+os.setenv("ALL_PROXY", "socks5://172.17.0.1:9004")
local http = require("http")
-function milla_urban(arg)
+function milla_urban(cli_args)
+ local args = {}
+ for i in string.gmatch(cli_args, "%S+") do table.insert(args, i) end
+
+ for k, v in ipairs(args) do print(k, v) end
+
+ local count = 1
+ local term = ""
+
+ local skip = false
+
+ for i = 1, #args do
+ if skip then
+ skip = false
+ goto continue
+ end
+ if args[i] == "-n" then
+ count = tonumber(args[i + 1])
+ skip = true
+ else
+ term = term .. args[i] .. " "
+ end
+ ::continue::
+ end
+ print("Term: " .. term)
+ print("Count: " .. count)
+
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 escaped_term = milla.url_encode(term)
+ local url = "http://api.urbandictionary.com/v0/define?term=" .. escaped_term
local response, err = http.request("GET", url, {
timeout = "10s",
headers = {
@@ -30,10 +57,17 @@ function milla_urban(arg)
local json_response, err = json.decode(response.body)
if err ~= nil then print(err) end
+ if response.status_code ~= 200 then
+ return "Error: " .. response.status_code
+ end
+
local result = ""
- for k, v in ipairs(json_response["list"]) do
+ for _, 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
+ if count > 0 then
+ result = result .. tostring(count) .. v["definition"] .. "----"
+ end
+ count = count - 1
end
return result