-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatFormatter.lua
More file actions
68 lines (57 loc) · 1.73 KB
/
Copy pathChatFormatter.lua
File metadata and controls
68 lines (57 loc) · 1.73 KB
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
--This project is under the CC-BY-4.0 license
--https://github.com/morgatronday1234
--Read the license!
chat = peripheral.wrap("left")
nicknames = {
}
local function getNickname(name)
if not (name) then return false end
if (nicknames[name]) then
return nickanmes[name]
else
return name
end
end
function ChatModifier() while(true) do
event, user, message, _, invisible = os.pullEvent("chat")
if (invisible) and (string.find(message, "c ") == 1) then
print("color", string.find(message, "c "))
message = string.gsub(message, "c ", "")
messageOut = string.gsub(message, "&([0-9a-fkimnor])", utf8.char(167).."%1")
chat.sendMessage(messageOut, getNickname(user), "<>")
elseif (invisible) and (string.find(message, "f ") == 1) then
print("Format", string.find(message, "f "))
message = string.gsub(message, "f ", "")
messageOut = message
pass, err = pcall(chat.sendFormattedMessage, messageOut, getNickname(user), "<>")
if not (pass) then
errorMessageJson = textutils.serialiseJSON({
{
["text"] = "Error: ",
["color"] = "#FF5555",
["italic"] = true
},
{
["text"] = tostring(err),
["color"] = "#555555",
["italic"] = true,
["HoverEvent"] = {
["action"] = "show_text",
["contents"] = {
{["text"] = "Click to copy text"}
}
},
["clickEvent"] = {
["action"] = "copy_to_clipboard",
["value"] = tostring(err)
}
}
})
chat.sendFormattedMessageToPlayer(errorMessageJson, user, "Chat Modifier", "<>")
end
end
end end
parallel.waitForAny(ChatModifier)
--This project is under the CC-BY-4.0 license
--https://github.com/morgatronday1234
--Read the license!