From b7be0d0902b092ff1b7e57e7fc819150e85cfd16 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 01:07:39 +0100 Subject: chat --- chat.dat | 1 - chat.lua | 14 ++++-- md5.lua | 167 --------------------------------------------------------------- 3 files changed, 10 insertions(+), 172 deletions(-) delete mode 100644 chat.dat delete mode 100644 md5.lua diff --git a/chat.dat b/chat.dat deleted file mode 100644 index 5086928..0000000 --- a/chat.dat +++ /dev/null @@ -1 +0,0 @@ -dep md5 diff --git a/chat.lua b/chat.lua index e21da68..b757185 100644 --- a/chat.lua +++ b/chat.lua @@ -1,5 +1,3 @@ -local md5 = require("md5").hash - local p = peripheral.find"manipulator" assert(p and p.hasModule"plethora:chat") local m = peripheral.wrap"monitor" @@ -11,9 +9,17 @@ local function p(...) term.redirect(term.native()) end +local score(msg) + local s = 0 + for m in a:gmatch"%-?%d+" do s=s+m end + return s +end + while true do local _,user,msg = os.pullEvent"chat_message" - local h = md5(msg) + local s = score(msg) + p(string.format("(%d) <%s> %s",s,user,msg)) +end - p("<"..user.."> ["..h.."] "..msg) + end diff --git a/md5.lua b/md5.lua deleted file mode 100644 index b421587..0000000 --- a/md5.lua +++ /dev/null @@ -1,167 +0,0 @@ --- from https://github.com/philanc/plc/blob/master/plc/md5.lua ------------------------------------------------------------------------- --- md5 hash - see RFC 1321 - https://www.ietf.org/rfc/rfc1321.txt - -local spack, sunpack = string.pack, string.unpack - ------------------------------------------------------------------------- - -local function FF(a, b, c, d, x, s, ac) - a = (a + ((b & c) | ((~b) & d)) + x + ac) & 0xffffffff - a = ((a << s) | (a >> (32-s))) & 0xffffffff - a = (a + b) & 0xffffffff - return a -end - -local function GG(a, b, c, d, x, s, ac) - a = (a + ((b & d) | c & (~d) ) + x + ac) & 0xffffffff - a = ((a << s) | (a >> (32-s))) & 0xffffffff - a = (a + b) & 0xffffffff - return a -end - -local function HH(a, b, c, d, x, s, ac) - a = (a + ((b ~ c ~ d)) + x + ac) & 0xffffffff - a = ((a << s) | (a >> (32-s))) & 0xffffffff - a = (a + b) & 0xffffffff - return a -end - -local function II(a, b, c, d, x, s, ac) - a = (a + (c ~ (b | ~d)) + x + ac) & 0xffffffff - a = ((a << s) | (a >> (32-s))) & 0xffffffff - a = (a + b) & 0xffffffff - return a -end - -local function transform(state, input, i, t) - -- process the 64-byte input block in string 'input' at offset 'i' - -- t is a uint32[16] array. It is passed as a parameter - -- for performance reasons - -- - local a, b, c, d = state[1], state[2], state[3], state[4] - - -- load array - for j = 1, 16 do - t[j] = sunpack("= 64 do - -- process block - transform(state, input, i, ibt) - i = i + 64 -- update input index - r = r - 64 -- update number of unprocessed bytes - end - -- finalize. must append to input a mandatory 0x80 byte, some - -- padding, and the input bit-length ('inputbits') - local lastblock -- the rest of input .. some padding .. inputbits - local padlen -- padding length in bytes - if r < 56 then padlen = 55 - r else padlen = 119 - r end - lastblock = input:sub(i) -- remaining input - .. '\x80' .. ('\0'):rep(padlen) --padding - .. spack("