Skip to content

Commit fe1c9ef

Browse files
committed
allow multipe require_accces (comma sep), support "low"/"high"/"admin"
1 parent 822a445 commit fe1c9ef

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

modules/channel_op.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _kick(self, server, channel, target_user, reason):
6262
@utils.hook("received.command.kick")
6363
@utils.hook("received.command.k", alias_of="kick")
6464
@utils.kwarg("require_mode", "o")
65-
@utils.kwarg("require_access", "kick")
65+
@utils.kwarg("require_access", "high,kick")
6666
@utils.kwarg("help", "Kick a user from a channel")
6767
@utils.spec("!<#channel>r~channel !<nickname>cuser ?<reason>string")
6868
def kick(self, event):
@@ -105,15 +105,15 @@ def _ban(self, server, channel, target, allow_hostmask, time, add):
105105
@utils.hook("received.command.ban")
106106
@utils.hook("received.command.b", alias_of="ban")
107107
@utils.kwarg("require_mode", "o")
108-
@utils.kwarg("require_access", "ban")
108+
@utils.kwarg("require_access", "high,ban")
109109
@utils.spec("!<#channel>r~channel ?duration !<nickname>user|<mask>word")
110110
def ban(self, event):
111111
self._ban(event["server"], event["spec"][0], event["spec"][2], True,
112112
event["spec"][1], True)
113113

114114
@utils.hook("received.command.unban")
115115
@utils.kwarg("require_mode", "o")
116-
@utils.kwarg("require_access", "ban")
116+
@utils.kwarg("require_access", "high,ban")
117117
@utils.spec("!<#channel>r~channel !<nickname>user|<mask>word")
118118
def unban(self, event):
119119
self._ban(event["server"], event["spec"][0], event["spec"][1],
@@ -122,7 +122,7 @@ def unban(self, event):
122122
@utils.hook("received.command.kickban")
123123
@utils.hook("received.command.kb", alias_of="kickban")
124124
@utils.kwarg("require_mode", "o")
125-
@utils.kwarg("require_access", "kickban")
125+
@utils.kwarg("require_access", "high,kickban")
126126
@utils.spec(
127127
"!<#channel>r~channel ?duration !<nickname>cuser| ?<reason>string")
128128
def kickban(self, event):
@@ -134,15 +134,15 @@ def kickban(self, event):
134134
@utils.hook("received.command.op")
135135
@utils.hook("received.command.up", alias_of="op")
136136
@utils.kwarg("require_mode", "o")
137-
@utils.kwarg("require_access", "op")
137+
@utils.kwarg("require_access", "high,op")
138138
@utils.spec("!<#channel>r~channel !<nickname>ruser")
139139
def op(self, event):
140140
self._op(True, event["spec"])
141141

142142
@utils.hook("received.command.deop")
143143
@utils.hook("received.command.down", alias_of="deop")
144144
@utils.kwarg("require_mode", "o")
145-
@utils.kwarg("require_access", "op")
145+
@utils.kwarg("require_access", "high,op")
146146
@utils.spec("!<#channel>r~channel !<nickname>ruser")
147147
def deop(self, event):
148148
self._op(False, event["spec"])
@@ -153,7 +153,7 @@ def _op(self, add, spec):
153153
@utils.hook("received.command.voice")
154154
@utils.hook("received.command.devoice")
155155
@utils.kwarg("require_mode", "o")
156-
@utils.kwarg("require_access", "voice")
156+
@utils.kwarg("require_access", "low,voice")
157157
@utils.spec("!<#channel>r~channel !<nickname>ruser")
158158
def voice(self, event):
159159
add = event["command"] == "voice"
@@ -162,15 +162,15 @@ def voice(self, event):
162162

163163
@utils.hook("received.command.topic")
164164
@utils.kwarg("require_mode", "o")
165-
@utils.kwarg("require_access", "topic")
165+
@utils.kwarg("require_access", "low,topic")
166166
@utils.kwarg("remove_empty", False)
167167
@utils.spec("!<#channel>r~channel !<topic>string")
168168
def topic(self, event):
169169
event["spec"][0].send_topic(event["spec"][1])
170170

171171
@utils.hook("received.command.tappend")
172172
@utils.kwarg("require_mode", "o")
173-
@utils.kwarg("require_access", "topic")
173+
@utils.kwarg("require_access", "low,topic")
174174
@utils.kwarg("remove_empty", False)
175175
@utils.spec("!<#channel>r~channel !<topic>string")
176176
def tappend(self, event):
@@ -192,7 +192,7 @@ def _quiet_method(self, server):
192192
@utils.hook("received.command.quiet")
193193
@utils.hook("received.command.mute")
194194
@utils.kwarg("require_mode", "o")
195-
@utils.kwarg("require_access", "quiet")
195+
@utils.kwarg("require_access", "high,quiet")
196196
@utils.kwarg("help", "Quiet a given user")
197197
@utils.spec("!<#channel>r~channel ?duration !<nickname>user|<mask>word")
198198
def quiet(self, event):
@@ -201,7 +201,7 @@ def quiet(self, event):
201201
@utils.hook("received.command.unquiet")
202202
@utils.hook("received.command.unmute")
203203
@utils.kwarg("require_mode", "o")
204-
@utils.kwarg("require_access", "unquiet")
204+
@utils.kwarg("require_access", "high,unquiet")
205205
@utils.kwarg("help", "Unquiet a given user")
206206
@utils.spec("!<#channel>r~channel !<nickname>user|<mask>word")
207207
def unquiet(self, event):
@@ -228,7 +228,7 @@ def _quiet(self, server, add, spec):
228228

229229
@utils.hook("received.command.invite")
230230
@utils.kwarg("require_mode", "o")
231-
@utils.kwarg("require_access", "invite")
231+
@utils.kwarg("require_access", "low,invite")
232232
@utils.kwarg("help", "Invite a given user")
233233
@utils.spec("!<#channel>r~channel !<nickname>word")
234234
def invite(self, event):
@@ -253,7 +253,7 @@ def _parse_flags(self, s):
253253
@utils.hook("received.command.flags")
254254
@utils.kwarg("help", "Configure access flags for a given user")
255255
@utils.kwarg("require_mode", "o")
256-
@utils.kwarg("require_access", "flags")
256+
@utils.kwarg("require_access", "admin,flags")
257257
@utils.spec("!<#channel>r~channel !<nickname>ouser ?<flags>word")
258258
def flags(self, event):
259259
target = event["spec"][1]
@@ -342,7 +342,7 @@ def _check_flags(self, server, channel, user):
342342

343343
@utils.hook("received.command.cmute")
344344
@utils.kwarg("require_mode", "o")
345-
@utils.kwarg("require_access", "cmute")
345+
@utils.kwarg("require_access", "high,cmute")
346346
@utils.kwarg("help", "Mute the current channel")
347347
@utils.spec("!<#channel>r~channel ?duration")
348348
def cmute(self, event):
@@ -354,7 +354,7 @@ def cmute(self, event):
354354

355355
@utils.hook("received.command.cunmute")
356356
@utils.kwarg("require_mode", "o")
357-
@utils.kwarg("require_access", "cmute")
357+
@utils.kwarg("require_access", "high,cmute")
358358
@utils.kwarg("help", "Mute the current channel")
359359
@utils.spec("!<#channel>r~channel")
360360
def cunmute(self, event):
@@ -400,7 +400,7 @@ def _list_query_event(self, server, channel, list_type, list_mask):
400400

401401
@utils.hook("received.command.clear")
402402
@utils.kwarg("require_mode", "o")
403-
@utils.kwarg("require_access", "clear")
403+
@utils.kwarg("require_access", "admin,clear")
404404
@utils.kwarg("help", "Clear a given channel list mode (e.g. +b)")
405405
@utils.spec("!<#channel>r~channel !<type>word|<mode>word ?<mask>word")
406406
def clear(self, event):
@@ -414,7 +414,7 @@ def clear(self, event):
414414

415415
@utils.hook("received.command.lsearch")
416416
@utils.kwarg("require_mode", "o")
417-
@utils.kwarg("require_access", "lsearch")
417+
@utils.kwarg("require_access", "high,lsearch")
418418
@utils.kwarg("help", "Search a given channel list mode (e.g. +b)")
419419
@utils.spec("!<#channel>r~channel !<type>word|<mode>word ?<mask>word")
420420
def lsearch(self, event):

src/core_modules/channel_access.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@
44

55
from src import ModuleManager, utils
66

7+
SPECIAL = ["low", "high", "admin"]
8+
79
class Module(ModuleManager.BaseModule):
810
_name = "ChanAccess"
911

10-
def _has_channel_access(self, target, user, require_access):
11-
access = target.get_user_setting(user.get_id(), "access", [])
12+
def _has_channel_access(self, target, user, names):
13+
required_access = []
14+
for name in names.split(","):
15+
name = name.strip()
16+
17+
if name in SPECIAL:
18+
required_access.extend(SPECIAL[:SPECIAL.index(name)+1])
19+
else:
20+
required_access.append(name)
21+
22+
print(required_access)
23+
24+
user_access = target.get_user_setting(user.get_id(), "access", [])
1225
identified = self.exports.get_one("is-identified")(user)
26+
matched = list(set(required_access)&set(user_access))
1327

14-
return (require_access in access or "*" in access) and identified
28+
return ("*" in required_access or matched) and identified
1529

1630
def _command_check(self, event, channel, require_access):
1731
if channel:

0 commit comments

Comments
 (0)