1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
local man = peripheral.find"manipulator"
assert(man and man.hasModule"plethora:chat","no chat thing")
local M = peripheral.find"monitor"
assert(M,"no monitor")
M.setTextScale(0.5)
local Mw,Mh = M.getSize()
local lbw = 4+16+10
local wLog = window.create(M,1,1,Mw-lbw,Mh)
-- wLog.setBackgroundColor(colors.blue)
-- wLog.clear()
-- wLog.write("LOG")
local wLb = window.create(M,Mw-lbw+1,1,lbw,11)
-- wLb.setBackgroundColor(colors.red)
-- wLb.clear()
-- wLb.write("LB")
-- utils
local function p(thing,...)
local o=term.redirect(thing)
print(...)
term.redirect(o)
end
local function pad_r(s,width)
return string.rep(" ",width-#tostring(s))..s
end
-- drawing
-- lb
local function draw_lb(W,scores)
W.setBackgroundColor(colors.gray)
W.clear()
-- numbers
W.setTextColor(colors.yellow)
for line=1,10 do
W.setCursorPos(1,line)
W.write(pad_r(line,2)..".")
end
end
draw_lb(wLb,nil)
local function score(msg)
local s = 0
for num in msg:gmatch"%-?%d+" do s=s+num end
return s
end
local userscores = setmetatable({},{__index=function()return 0 end})
while true do
local _,user,msg = os.pullEvent"chat_message"
local s = score(msg)
userscores[user] = userscores[user] + s
p(M,string.format("(%d) <%s> %s",s,user,msg))
end
|