-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
1124 lines (995 loc) · 26.1 KB
/
init.lua
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local register_on_receive = minetest.register_on_receiving_chat_message or minetest.register_on_receiving_chat_messages
if not register_on_receive then
return
end
local f = string.format
local colorize = minetest.colorize
local mod_name = minetest.get_current_modname()
local function log(level, messagefmt, ...)
minetest.log(level, ("[%s] %s"):format(mod_name, messagefmt:format(...)))
end
log("action", "CSM loading...")
-- configurable values --
local ignore_messages = {
"Not chiselable",
"You are now a human",
"You are now a werewolf",
--"Werewolves only can eat raw meat!",
"You missed the snake",
"Nothing to replace.",
"Node replacement tool set to:",
"Your hit glanced off of the protection and turned you around. The protection deals you 1 damage.",
'Error: "nothing" is not a node.',
">>> You missed <<<",
}
local alert_history = {}
local function escape_regex(x)
return (
x:gsub("%%", "%%%%")
:gsub("^%^", "%%^")
:gsub("%$$", "%%$")
:gsub("%(", "%%(")
:gsub("%)", "%%)")
:gsub("%.", "%%.")
:gsub("%[", "%%[")
:gsub("%]", "%%]")
:gsub("%*", "%%*")
:gsub("%+", "%%+")
:gsub("%-", "%%-")
:gsub("%?", "%%?")
)
end
local function should_ignore(text)
for _, ignore_message in ipairs(ignore_messages) do
local match, _ = text:match("(" .. escape_regex(ignore_message) .. ")")
if match and match ~= "" then
return true
end
end
return false
end
local PER_SERVER = true -- set to false if you want to use the same player statuses on all servers
local AUTO_ALERT_ON_NAME = true -- set to false if you don't want messages that mention you to highlight automatically
local COLOR_BY_STATUS = {
default = "#888888", -- don't remove or change the name of this status!
server = "#8888FF", -- don't remove or change the name of this status!
self = "#FF8888", -- don't remove or change the name of this status!
-- these can be changed to your liking.
-- TODO: make these configurable in game?
secretz = "#000000",
admin = "#88FFFF",
privileged = "#00FFFF",
poweruser = "#55FFAA",
ally = "#00FF55",
friend = "#00FF00",
acquaintance = "#55FF00",
contact = "#AAFF00",
noob = "#FFFF00",
sus = "#FF8800",
trouble = "#FF0000",
rival = "#FF0088",
other = "#FF00FF",
}
local LIGHTEN_TEXT_BY = 0.8 -- 0 == same color as status; 1 == pure white.
local DATE_FORMAT = "%Y%m%dT%H%M%S"
-- END configurable values --
-- general functions --
local function safe(func)
-- wrap a function w/ logic to avoid crashing the game
local f = function(...)
local status, out = pcall(func, ...)
if status then
return out
else
log("warning", "Error (func): ", out)
return nil
end
end
return f
end
local function lc_cmp(a, b)
return a:lower() < b:lower()
end
local function pairsByKeys(t, f)
local a = {}
for n in pairs(t) do
table.insert(a, n)
end
table.sort(a, f)
local i = 0
return function()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
end
local function round(x)
-- approved by kahan
if x % 2 ~= 0.5 then
return math.floor(x + 0.5)
else
return x - 0.5
end
end
local function bound(min, val, max)
return math.min(max, math.max(min, val))
end
local function lighten(hex_color, percent)
-- lighten a hexcolor (#XXXXXX) by a percent (0.0=none, 1.0=full white)
local r = tonumber(hex_color:sub(2, 3), 16)
local g = tonumber(hex_color:sub(4, 5), 16)
local b = tonumber(hex_color:sub(6, 7), 16)
r = bound(0, round(((1 - percent) * r) + (percent * 255)), 255)
g = bound(0, round(((1 - percent) * g) + (percent * 255)), 255)
b = bound(0, round(((1 - percent) * b) + (percent * 255)), 255)
return ("#%02x%02x%02x"):format(r, g, b)
end
local function get_date_string()
return os.date(DATE_FORMAT, os.time())
end
-- END general functions --
-- mod_storage access --
local mod_storage = minetest.get_mod_storage()
local server_id
if PER_SERVER then
local server_info = minetest.get_server_info()
server_id = server_info.address .. ":" .. server_info.port
else
server_id = ""
end
-- -- mod_storage: status_by_name -- --
local status_by_name
local function load_status_by_name()
local serialized_storage = mod_storage:get_string(server_id)
if string.find(serialized_storage, "return") then
return minetest.deserialize(serialized_storage)
else
mod_storage:set_string(server_id, minetest.serialize({}))
return {}
end
end
local function save_status_by_name()
mod_storage:set_string(server_id, minetest.serialize(status_by_name))
end
status_by_name = load_status_by_name()
local function get_name_status(name)
return status_by_name[name] or "default"
end
local function set_name_status(name, status)
status_by_name = load_status_by_name()
status_by_name[name] = status
save_status_by_name()
end
-- -- END mod_storage: status_by_name -- --
-- -- mod_storage: alert_patterns -- --
local function load_alert_patterns()
local serialized_storage = mod_storage:get_string(("%s:alert_patterns"):format(server_id))
if string.find(serialized_storage, "return") then
return minetest.deserialize(serialized_storage)
else
mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize({}))
return {}
end
end
local alert_patterns = load_alert_patterns()
local function save_alert_patterns()
mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize(alert_patterns))
end
local function add_alert_pattern(pattern)
alert_patterns = load_alert_patterns()
alert_patterns[pattern] = true
save_alert_patterns()
end
local function remove_alert_pattern(pattern)
alert_patterns = load_alert_patterns()
alert_patterns[pattern] = nil
save_alert_patterns()
end
-- -- END mod_storage: alert_patterns -- --
-- -- mod_storage: disabled_servers -- --
local function load_disabled_servers()
local serialized_storage = mod_storage:get_string("disabled_servers")
if string.find(serialized_storage, "return") then
return minetest.deserialize(serialized_storage)
else
local ds = { ["94.16.121.151:2500"] = true } -- disable on IFS by default
mod_storage:set_string("disabled_servers", minetest.serialize(ds))
return ds
end
end
local disabled_servers = load_disabled_servers()
local function save_disabled_servers()
mod_storage:set_string("disabled_servers", minetest.serialize(disabled_servers))
end
local function toggle_disable_this_server()
local current_status
disabled_servers = load_disabled_servers()
if disabled_servers[server_id] then
disabled_servers[server_id] = nil
current_status = false
else
disabled_servers[server_id] = true
current_status = true
end
save_disabled_servers()
return current_status
end
-- -- END mod_storage: disabled_servers -- --
-- END mod_storage access --
-- initalization --
local set_my_name_tries = 0
local function set_my_name()
local name
if minetest.localplayer then
name = minetest.localplayer:get_name()
log("action", ("you are %s"):format(name))
set_name_status(name, "self")
if AUTO_ALERT_ON_NAME then
add_alert_pattern(name)
end
elseif set_my_name_tries < 20 then
set_my_name_tries = set_my_name_tries + 1
minetest.after(1, set_my_name)
else
log("warning", "could not determine name!")
end
end
if minetest.register_on_connect then
minetest.register_on_connect(set_my_name)
elseif minetest.register_on_mods_loaded then
minetest.register_on_mods_loaded(set_my_name)
else
minetest.after(1, set_my_name)
end
-- END initalization --
-- chat commands --
minetest.register_chatcommand("ch_toggle", {
description = ("turn %s on/off for this server"):format(mod_name),
func = safe(function()
local current_status = toggle_disable_this_server()
if current_status then
current_status = "off"
else
current_status = "on"
end
minetest.display_chat_message(("%s is now %s for server %q"):format(mod_name, current_status, server_id))
end),
})
minetest.register_chatcommand("ch_statuses", {
description = "list statuses",
func = safe(function()
for name, color in pairsByKeys(COLOR_BY_STATUS) do
if name and color then
minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, color)))
end
end
end),
})
minetest.register_chatcommand("ch_set", {
params = "<name> <status>",
description = "associate a name w/ a status",
func = safe(function(param)
local name, status = param:match("^(%S+)%s+(%S+)$")
if name ~= nil then
if not COLOR_BY_STATUS[status] then
minetest.display_chat_message(colorize("#FF0000", ('unknown status "%s"'):format(status)))
return false
end
set_name_status(name, status)
minetest.display_chat_message(colorize(COLOR_BY_STATUS[status], ("%s is now %s"):format(name, status)))
return true
else
minetest.display_chat_message(colorize("#FF0000", "invalid syntax"))
return false
end
end),
})
minetest.register_chatcommand("ch_unset", {
params = "<name>",
description = "unregister a name",
func = safe(function(name)
set_name_status(name, nil)
minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, ("unregistered %s"):format(name)))
end),
})
minetest.register_chatcommand("ch_list", {
description = "list all statuses",
func = safe(function()
for name, status in pairsByKeys(status_by_name, lc_cmp) do
local color = COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default
minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, status)))
end
end),
})
minetest.register_chatcommand("ch_alert_list", {
description = "list all alert patterns",
func = safe(function()
for pattern, _ in pairsByKeys(alert_patterns, lc_cmp) do
minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, pattern))
end
end),
})
minetest.register_chatcommand("ch_alert_set", {
params = "<pattern>",
description = "alert on a given pattern",
func = safe(function(pattern)
add_alert_pattern(pattern)
end),
})
minetest.register_chatcommand("ch_alert_unset", {
params = "<pattern>",
description = "no longer alert on a given pattern",
func = safe(function(pattern)
remove_alert_pattern(pattern)
end),
})
minetest.register_chatcommand("ch_alerts", {
params = "[<limit>]",
description = "show last n alerts",
func = safe(function(limit)
limit = tonumber(limit) or 10
for i = math.max(1, #alert_history - limit + 1), #alert_history do
minetest.display_chat_message(alert_history[i])
end
end),
})
-- END chat commands --
local function clean_android(msg)
-- supposedly, android surrounds messages with (c@#ffffff)
if msg:sub(1, 4) == "(c@#" then -- strip preceeding
msg = msg:sub(msg:find(")") + 1, -1)
if msg:sub(-11, -8) == "(c@#" then -- strip trailing
msg = msg:sub(-11)
end
end
return msg
end
local function tokenize(s)
local tokens = {}
local i = 1
local j = 1
while true do
if s:sub(j, j) == "" then
if i < j then
table.insert(tokens, s:sub(i, j - 1))
end
return tokens
elseif s:sub(j, j):byte() == 27 then
if i < j then
table.insert(tokens, s:sub(i, j - 1))
end
i = j
local n = s:sub(i + 1, i + 1)
if n == "(" then
local m = s:sub(i + 2, i + 2)
local k = s:find(")", i + 3, true)
if m == "T" then
table.insert(tokens, {
type = "translation",
domain = s:sub(i + 4, k - 1),
})
elseif m == "c" then
table.insert(tokens, {
type = "color",
color = s:sub(i + 4, k - 1),
})
elseif m == "b" then
table.insert(tokens, {
type = "bgcolor",
color = s:sub(i + 4, k - 1),
})
else
error(("couldn't parse %s"):format(s))
end
i = k + 1
j = k + 1
elseif n == "F" then
table.insert(tokens, {
type = "start",
})
i = j + 2
j = j + 2
elseif n == "E" then
table.insert(tokens, {
type = "stop",
})
i = j + 2
j = j + 2
else
error(("couldn't parse %s"):format(s))
end
else
j = j + 1
end
end
end
local function parse(tokens, i, parsed)
parsed = parsed or {}
i = i or 1
while i <= #tokens do
local token = tokens[i]
if type(token) == "string" then
table.insert(parsed, token)
i = i + 1
elseif token.type == "color" or token.type == "bgcolor" then
table.insert(parsed, token)
i = i + 1
elseif token.type == "translation" then
local contents = {
type = "translation",
domain = token.domain,
}
i = i + 1
contents, i = parse(tokens, i, contents)
table.insert(parsed, contents)
elseif token.type == "start" then
local contents = {
type = "escape",
}
i = i + 1
contents, i = parse(tokens, i, contents)
table.insert(parsed, contents)
elseif token.type == "stop" then
i = i + 1
return parsed, i
else
error(("couldn't parse %s"):format(dump(token)))
end
end
return parsed, i
end
local function unparse(parsed, parts)
parts = parts or {}
for _, part in ipairs(parsed) do
if type(part) == "string" then
table.insert(parts, part)
else
if part.type == "bgcolor" then
table.insert(parts, ("\27(b@%s)"):format(part.color))
elseif part.type == "color" then
table.insert(parts, ("\27(c@%s)"):format(part.color))
elseif part.domain then
--table.insert(parts, ("\27(T@%s)"):format(part.domain))
unparse(part, parts)
--table.insert(parts, "\27E")
else
--table.insert(parts, "\27F")
unparse(part, parts)
--table.insert(parts, "\27E")
end
end
end
return parts
end
local function strip_translation(msg)
local tokens = tokenize(msg)
local parsed = parse(tokens)
return table.concat(unparse(parsed), "")
end
local function get_color_by_name(name)
local _
name, _ = name:match("^([^@]+).*$") -- strip @... from IRC users
name, _ = name:match("^([^[]+).*$") -- strip [m] from matrix users
local status = get_name_status(name)
return COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default
end
local function color_name(name)
local color = get_color_by_name(name)
return colorize(color, name)
end
local function color_names(names, delim)
local sorted_names = {}
for name in names:gmatch("[%w_%-]+") do
table.insert(sorted_names, name)
end
table.sort(sorted_names, lc_cmp)
for i, name in ipairs(sorted_names) do
sorted_names[i] = color_name(name)
end
return table.concat(sorted_names, delim)
end
local should_alert = false -- ugh this is hacky
local function color_text(name, text)
for pattern, _ in pairs(alert_patterns) do
if text:lower():match(pattern:lower()) then
should_alert = true
return colorize(COLOR_BY_STATUS.self, text)
end
end
local color = get_color_by_name(name)
if color == COLOR_BY_STATUS.default then
return colorize(COLOR_BY_STATUS.default, text)
else
color = lighten(color, LIGHTEN_TEXT_BY)
return colorize(color, text)
end
end
local function idiv(a, b)
return (a - (a % b)) / b
end
local function seconds_to_interval(time)
local s = time % 60
time = idiv(time, 60)
local m = time % 60
time = idiv(time, 60)
local h = time % 24
time = idiv(time, 24)
if time ~= 0 then
return ("%d days %02d:%02d:%02d"):format(time, h, m, s)
elseif h ~= 0 then
return ("%02d:%02d:%02d"):format(h, m, s)
elseif m ~= 0 then
return ("%02d:%02d"):format(m, s)
else
return ("%d seconds"):format(s)
end
end
local function sort_privs(text)
local sorted_privs = {}
for priv in text:gmatch("[%w_%-]+") do
table.insert(sorted_privs, priv)
end
table.sort(sorted_privs, lc_cmp)
return table.concat(sorted_privs, ", ")
end
local t = {
-- SORT PRIVILEGES
{
"^Privileges of ([^:]+): (.*)$",
function(name, text)
return ("%s%s%s%s"):format(
color_text(name, "Privileges of "),
color_name(name),
color_text(name, ": "),
color_text(name, sort_privs(text))
)
end,
},
-- join/part messages
{
"^%*%*%* (%S+) (.*)$",
function(name, text)
return ("%s %s %s"):format(color_text(name, "***"), color_name(name), color_text(name, text))
end,
},
-- yl discord messages
{
"^<([^|%s]+)|([^>%s]+)>%s+(.*)$",
function(source, name, text)
return ("%s%s%s%s%s %s"):format(
color_text(name, "<"),
color_text(name, source),
color_text(name, "|"),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end,
},
-- normal messages
{
"^<([^>%s]+)>%s+(.*)$",
function(name, text)
return ("%s%s%s %s"):format(
color_text(name, "<"),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end,
},
-- YL chatroom stuff
-- {"^\[([^@]+}@([^\]]+)\] (.*)$", function(name, channel, text)
-- return ("%s%s%s %s"):format(
-- color_text(name, "["),
-- color_name(name),
-- color_text(name, "@"),
-- color_name(channel),
-- color_text(name, "]"),
-- color_text(name, text)
-- )
-- end},
-- YL announce
{
"^%[ANNOUNCE%]%s(.*)$",
function(announcement)
should_alert = true
return ("[ANNOUNCE] %s"):format(colorize(COLOR_BY_STATUS.server, announcement))
end,
},
{
"^(%[[^%]]+%])%s(.*)$",
function(t1, t2)
return ("%s %s"):format(colorize(COLOR_BY_STATUS.server, t1), colorize(COLOR_BY_STATUS.server, t2))
end,
},
-- prefixed messages
{
"^(%S+)%s+<([^>]+)>%s+(.*)$",
function(prefix, name, text)
return ("%s %s%s%s %s"):format(
color_text(name, prefix),
color_text(name, "<"),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end,
},
-- Empire of Legends messages
{
"^<(%S+)%s+([^>]+)>%s+(.*)$",
function(prefix, name, text)
return ("%s%s %s%s %s"):format(
color_text(name, "<"),
color_text(name, prefix),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end,
},
-- /me messages
{
"^%* (%S+) (.*)$",
function(name, text)
return ("%s %s %s"):format(color_text(name, "*"), color_name(name), color_text(name, text))
end,
},
-- /msg messages
{
"^[DP]M from (%S+): (.*)$",
function(name, text)
should_alert = true
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.self, "DM from "),
color_name(name),
colorize(COLOR_BY_STATUS.self, ": "),
colorize(COLOR_BY_STATUS.self, text)
)
end,
},
-- /tell messages
{
"^(%S+) whispers: (.*)$",
function(name, text)
should_alert = true
return ("%s%s%s%s"):format(
color_name(name),
colorize(COLOR_BY_STATUS.self, " whispers: "),
colorize(COLOR_BY_STATUS.self, text)
)
end,
},
-- /who
{
"^Players in channel: (.*)$",
function(names)
return ("%s%s"):format(colorize(COLOR_BY_STATUS.server, "Players in channel: "), color_names(names, ", "))
end,
},
-- /status
{
"^# Server: (.*) clients={([^}]*)}(.*)\n(.*)",
function(text, names, lastbit, line2)
return ("%s%s%s%s%s%s\n%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, " clients={"),
color_names(names, ", "),
colorize(COLOR_BY_STATUS.server, "}"),
colorize(COLOR_BY_STATUS.server, lastbit),
colorize(COLOR_BY_STATUS.server, line2)
)
end,
},
-- /status
{
"^# Server: (.*) clients={([^}]*)}(.*)",
function(text, names, lastbit)
return ("%s%s%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, " clients={"),
color_names(names, ", "),
colorize(COLOR_BY_STATUS.server, "}"),
colorize(COLOR_BY_STATUS.server, lastbit)
)
end,
},
-- /status on YL
{
"^# Server: (.*) clients %((%d+)/(%d+)%): (.*)\n?(.*)",
function(text, on, max_, names, line2)
return ("%s%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, f(" clients (%s/%s): ", on, max_)),
color_names(names, ", "),
colorize(COLOR_BY_STATUS.server, line2)
)
end,
},
-- /status on YL
{
"^# Server: (.*) clients: (.*)",
function(text, names)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, " clients: "),
color_names(names, ", ")
)
end,
},
-- IRC join messages
{
"^%-!%- ([%w_%-]+) joined (.*)$",
function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
color_name(name),
color_text(name, " joined "),
color_text(name, rest)
)
end,
},
-- IRC part messages
{
"^%-!%- ([%w_%-]+) has quit (.*)$",
function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
color_name(name),
color_text(name, " has quit "),
color_text(name, rest)
)
end,
},
-- IRC part messages
{
"^%-!%- ([%w_%-]+) has left (.*)$",
function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
color_name(name),
color_text(name, " has left "),
color_text(name, rest)
)
end,
},
-- IRC mode messages
{
"^%-!%- mode/(.*)$",
function(rest)
return colorize(COLOR_BY_STATUS.default, ("^%-!%- mode/%s$"):format(rest))
end,
},
-- IRC /nick messages
{
"^%-!%- (.*) is now known as (.*)$",
function(name1, name2)
return ("%s%s%s%s"):format(
color_text(name1, "-!- "),
color_name(name1),
color_text(name2, " is now know as "),
color_name(name2)
)
end,
},
-- DM sent
{
"^[DP]M to (%S+): (.*)$",
function(name, text)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.self, "DM to "),
color_name(name),
colorize(COLOR_BY_STATUS.self, ": "),
colorize(COLOR_BY_STATUS.self, text)
)
end,
},
-- BlS moderator PM snooping
{
"^([%w_%-]+) to ([%w_%-]+): (.*)$",
function(name1, name2, text)
return ("%s%s%s%s%s"):format(
color_name(name1),
colorize(COLOR_BY_STATUS.server, " to "),
color_name(name2),
colorize(COLOR_BY_STATUS.server, ": "),
colorize(COLOR_BY_STATUS.server, text)
)
end,
},
-- BlS unverified player notice
{
"^Player ([%w_%-]+) is unverified%.$",
function(name)
minetest.sound_play("default_dug_metal")
return colorize("#FF0000", ("Player %s is unverified."):format(name))
end,
},
-- BlS unverified player chat
{
"^%[unverified] <([^>]+)>%s+(.*)$",
function(name, text)
minetest.sound_play("default_dug_metal")
return colorize("#FF0000", ("[unverified] <%s> (%s)$"):format(name, text))
end,
},
-- BlS cloaked chat
{
"^%-Cloaked%-%s+<([^>]+)>%s+(.*)$",
function(name, text)
return ("%s%s%s%s %s"):format(
colorize(COLOR_BY_STATUS.server, "-Cloaked- "),
color_text(name, "<"),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end,
},
-- death messages
{
"^(%S+) was killed by (%S+), using (.+), near (.+)$",
function(victim, killer, weapon, location)
return ("%s%s%s%s%s%s%s"):format(
color_name(victim),
color_text(victim, " was killed by "),
color_name(killer),
color_text(killer, ", using "),
color_text(killer, weapon),
color_text(victim, ", near "),
color_text(victim, location)
)
end,
},
{
"^(%S+) was killed by (.*)$",
function(name, text)
return ("%s%s%s"):format(color_name(name), color_text(name, " was killed by "), color_text(name, text))
end,
},
{
"^(%S+) should not play with ([^,]+), near ([^%.]+)%.",
function(name, what, where)
return ("%s%s%s%s%s%s"):format(
color_name(name),
color_text(name, " should not play with "),
color_text(name, what),
color_text(name, ", near "),
color_text(name, where),
color_text(name, ".")
)
end,
},
{
"^(%S+) shouldn't play with (.*)$",
function(name, text)
return ("%s%s%s"):format(
color_name(name),
color_text(name, " shouldn't play with "),
color_text(name, text)
)
end,
},
{
"^(%S+) was killed near (.*)$",
function(name, text)
return ("%s%s%s"):format(color_name(name), color_text(name, " was killed near "), color_text(name, text))