-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblocking.lua
More file actions
160 lines (130 loc) · 6.01 KB
/
blocking.lua
File metadata and controls
160 lines (130 loc) · 6.01 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
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
local player_blocklist = {}
local function block_player(user, blocked_name)
if not player_blocklist[user] then
player_blocklist[user] = {}
end
player_blocklist[user][blocked_name] = true
return "#! " .. user .. " is now blocking " .. blocked_name
end
local function unblock_player(user, blocked_name)
if player_blocklist[user] and player_blocklist[user][blocked_name] then
player_blocklist[user][blocked_name] = nil
end
if player_blocklist[user] and not next(player_blocklist[user]) then
player_blocklist[user] = nil
end
return "#! " .. user .. " allowing chats from " .. blocked_name
end
local function get_blocklist(name)
local blocklist = player_blocklist[name]
if blocklist and next(blocklist) then
local blocks = {}
for blocked_name,_ in pairs(blocklist) do
table.insert(blocks, blocked_name)
end
return "#! <" .. name .. ">'s Block list: " .. table.concat(blocks, ", ")
else
return "#! <" .. name .. ">'s Block list: No Players Blocked!"
end
end
local function check_invalid_names(user, blocked_name)
-- fail check if this function returns anything besides false or nil
if not user then
return "#! Please include a Player Name!"
elseif not blocked_name or blocked_name == "" or user == blocked_name then
return get_blocklist(user)
elseif not core.player_exists(blocked_name) then
return "#! Player <" .. blocked_name .. "> does not exist."
elseif not core.player_exists(user) then
return "#! Player <" .. user .. "> does not exist."
elseif core.check_player_privs(blocked_name, "staff") then
return "#! Staff cannot be blocked."
end
-- returned nil allows the caller to continue
end
core.register_chatcommand("block", {
description = "Block player chats or view block list",
params = "<player_name>",
privs = {shout = true},
func = function(user, param)
local blocked_name = param:match("^([a-zA-Z0-9_-]+)$") or user
-- staff priv allows viewing another player's blocklist
if core.check_player_privs(user, "staff") then
return true, check_invalid_names(blocked_name)
else
return true, check_invalid_names(user, blocked_name) or block_player(user, blocked_name)
end
end
})
core.register_chatcommand("unblock", {
description = "Remove a player from your blocklist",
params = "<player_name>",
privs = {shout = true},
func = function(user, param)
local blocked_name = param:match("^([a-zA-Z0-9_-]+)$") or user
-- staff priv allows viewing another player's blocklist
if core.check_player_privs(user, "staff") then
return true, check_invalid_names(blocked_name)
else
return true, check_invalid_names(user, blocked_name) or unblock_player(user, blocked_name)
end
end
})
core.register_chatcommand("forceblock", {
description = "Block two players from chatting each other",
params = "<player_name> <player_name>",
privs = {mute = true},
func = function(user, param)
local name_one, name_two = param:match("([a-zA-Z0-9_-]+)%s*([a-zA-Z0-9_-]*)")
if core.check_player_privs(user, "staff") and
core.check_player_privs(name_two, "staff") then
name_one, name_two = name_two, name_one
end
return true, check_invalid_names(name_one, name_two) or
block_player(name_one, name_two) and block_player(name_two, name_one)
end
})
core.register_chatcommand("forceunblock", {
description = "Unblock two players allowing chat with each other",
params = "<player_name> <player_name>",
privs = {mute = true},
func = function(user, param)
local name_one, name_two = param:match("([a-zA-Z0-9_-]+)%s*([a-zA-Z0-9_-]*)")
if core.check_player_privs(name_two, "staff") then
name_one, name_two = name_two, name_one
end
return true, check_invalid_names(name_one, name_two) or
unblock_player(name_one, name_two) and unblock_player(name_two, name_one)
end
})
local function blocking_messages(sender, receiver)
if (player_blocklist[sender] and player_blocklist[sender][receiver]) or
(player_blocklist[receiver] and player_blocklist[receiver][sender]) then
return true
end
return false
end
return blocking_messages
------------------------------------------------------------------------------------
-- MIT License --
-- --
-- Copyright © 2023-2026 monk (https://github.com/monk-afk) --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a copy --
-- of this software and associated documentation files (the "Software"), to deal --
-- in the Software without restriction, including without limitation the rights --
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included in all --
-- copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --
-- SOFTWARE. --
------------------------------------------------------------------------------------