summaryrefslogtreecommitdiff
path: root/plugins/degesch/prime.lua
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-08-06 16:12:15 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-08-06 16:43:59 +0200
commit50057d5149dda340b3b47aca4096f4a6ec66b9ee (patch)
tree79323d20b17c2c8e32942a1ac9b84d9da3041c6d /plugins/degesch/prime.lua
parent1f64710e795b0c5434d15813d4f1f568467ca087 (diff)
downloadxK-50057d5149dda340b3b47aca4096f4a6ec66b9ee.tar.gz
xK-50057d5149dda340b3b47aca4096f4a6ec66b9ee.tar.xz
xK-50057d5149dda340b3b47aca4096f4a6ec66b9ee.zip
Come up with sillier names for the binaries
I'm not entirely sure, but it looks like some people might not like jokes about the Holocaust. On a more serious note, the project has become more serious over the 7 or so years of its existence.
Diffstat (limited to 'plugins/degesch/prime.lua')
-rw-r--r--plugins/degesch/prime.lua68
1 files changed, 0 insertions, 68 deletions
diff --git a/plugins/degesch/prime.lua b/plugins/degesch/prime.lua
deleted file mode 100644
index 420124f..0000000
--- a/plugins/degesch/prime.lua
+++ /dev/null
@@ -1,68 +0,0 @@
---
--- prime.lua: highlight prime numbers in messages
---
--- Copyright (c) 2020, Přemysl Eric Janouch <p@janouch.name>
---
--- Permission to use, copy, modify, and/or distribute this software for any
--- purpose with or without fee is hereby granted.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
--- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
--- OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
--- CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
-
-local smallest, highlight = 0, "\x1f"
-degesch.setup_config {
- smallest = {
- type = "integer",
- default = "0",
- comment = "smallest number to scan for primality",
- on_change = function (v) smallest = math.max (v, 2) end
- },
- highlight = {
- type = "string",
- default = "\"\\x1f\"",
- comment = "the attribute to use for highlights",
- on_change = function (v) highlight = v end
- },
-}
-
--- The prime test is actually very fast, so there is no DoS concern
-local do_intercolour = function (text)
- return tostring (text:gsub ("%f[%w_]%d+", function (n)
- if tonumber (n) < smallest then return nil end
- for i = 2, n ^ (1 / 2) do if (n % i) == 0 then return nil end end
- return highlight .. n .. highlight
- end))
-end
-
-local do_interlink = function (text)
- local rebuilt, last = {""}, 1
- for start in text:gmatch ('()\x03') do
- table.insert (rebuilt, do_intercolour (text:sub (last, start - 1)))
- local sub = text:sub (start + 1)
- last = start + (sub:match ('^%d%d?,%d%d?()') or sub:match ('^%d?%d?()'))
- table.insert (rebuilt, text:sub (start, last - 1))
- end
- return table.concat (rebuilt) .. do_intercolour (text:sub (last))
-end
-
-local do_message = function (text)
- local rebuilt, last = {""}, 1
- for run, link, endpos in text:gmatch ('(.-)(%f[%g]https?://%g+)()') do
- last = endpos
- table.insert (rebuilt, do_interlink (run) .. link)
- end
- return table.concat (rebuilt) .. do_interlink (text:sub (last))
-end
-
--- XXX: sadly it won't typically highlight primes in our own messages,
--- unless IRCv3 echo-message is on
-degesch.hook_irc (function (hook, server, line)
- local start, message = line:match ("^(.- PRIVMSG .- :)(.*)$")
- return message and start .. do_message (message) or line
-end)