Skip to content

Commit c8a1781

Browse files
committed
Add typedocs to chan_track
1 parent baa93c0 commit c8a1781

1 file changed

Lines changed: 140 additions & 3 deletions

File tree

plugins/chan_track.py

Lines changed: 140 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ def getuser(self, nick):
7070

7171

7272
def update_chan_data(conn, chan):
73+
"""
74+
:type conn: cloudbot.client.Client
75+
:type chan: str
76+
"""
7377
chan_data = conn.memory["chan_data"].getchan(chan)
7478
chan_data["receiving_names"] = False
7579
conn.cmd("NAMES", chan)
7680

7781

7882
def update_conn_data(conn):
83+
"""
84+
:type conn: cloudbot.client.Client
85+
"""
7986
for chan in set(conn.channels):
8087
update_chan_data(conn, chan)
8188

@@ -96,26 +103,39 @@ def do_caps():
96103

97104

98105
def is_cap_available(conn, cap):
106+
"""
107+
:type conn: cloudbot.client.Client
108+
:type cap: str
109+
"""
99110
caps = conn.memory.get("server_caps", {})
100111
return bool(caps.get(cap, False))
101112

102113

103114
@hook.on_start
104115
def get_chan_data(bot):
116+
"""
117+
:type bot: cloudbot.bot.CloudBot
118+
"""
105119
for conn in bot.connections.values():
106120
if conn.connected:
107121
init_chan_data(conn, False)
108122
update_conn_data(conn)
109123

110124

111125
def clean_user_data(user):
126+
"""
127+
:type user: dict
128+
"""
112129
for memb in user.get("channels", {}).values():
113130
status = list(set(memb.get("status", [])))
114131
status.sort(key=attrgetter("level"), reverse=True)
115132
memb["status"] = status
116133

117134

118135
def clean_chan_data(chan):
136+
"""
137+
:type chan: dict
138+
"""
119139
with suppress(KeyError):
120140
del chan["new_users"]
121141

@@ -124,6 +144,9 @@ def clean_chan_data(chan):
124144

125145

126146
def clean_conn_data(conn):
147+
"""
148+
:type conn: cloudbot.client.Client
149+
"""
127150
for user in conn.memory.get("users", {}).values():
128151
clean_user_data(user)
129152

@@ -132,12 +155,19 @@ def clean_conn_data(conn):
132155

133156

134157
def clean_data(bot):
158+
"""
159+
:type bot: cloudbot.bot.CloudBot
160+
"""
135161
for conn in bot.connections.values():
136162
clean_conn_data(conn)
137163

138164

139165
@hook.connect
140166
def init_chan_data(conn, _clear=True):
167+
"""
168+
:type conn: cloudbot.client.Client
169+
:type _clear: bool
170+
"""
141171
chan_data = conn.memory.setdefault("chan_data", ChanDict())
142172
users = conn.memory.setdefault("users", UsersDict())
143173

@@ -153,10 +183,19 @@ def init_chan_data(conn, _clear=True):
153183

154184

155185
def add_user_membership(user, chan, membership):
186+
"""
187+
:type user: dict
188+
:type chan: str
189+
:type membership: dict
190+
"""
156191
user["channels"][chan] = membership
157192

158193

159194
def replace_user_data(conn, chan_data):
195+
"""
196+
:type conn: cloudbot.client.Client
197+
:type chan_data: dict
198+
"""
160199
statuses = {status.prefix: status for status in set(conn.memory["server_info"]["statuses"].values())}
161200
users = conn.memory["users"]
162201
old_users = chan_data["users"]
@@ -206,6 +245,11 @@ def replace_user_data(conn, chan_data):
206245

207246
@hook.irc_raw(['353', '366'], singlethread=True)
208247
def on_names(conn, irc_paramlist, irc_command):
248+
"""
249+
:type conn: cloudbot.client.Client
250+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
251+
:type irc_command: str
252+
"""
209253
chan = irc_paramlist[2 if irc_command == '353' else 1]
210254
chan_data = conn.memory["chan_data"].getchan(chan)
211255
if irc_command == '366':
@@ -226,6 +270,12 @@ def on_names(conn, irc_paramlist, irc_command):
226270

227271

228272
def dump_dict(data, indent=2, level=0, _objects=None):
273+
"""
274+
:type data: Mapping
275+
:type indent: int
276+
:type level: int
277+
:type _objects: list
278+
"""
229279
if _objects is None:
230280
_objects = [id(data)]
231281

@@ -243,6 +293,11 @@ def dump_dict(data, indent=2, level=0, _objects=None):
243293

244294
@hook.permission("chanop")
245295
def perm_check(chan, conn, nick):
296+
"""
297+
:type chan: str
298+
:type conn: cloudbot.client.Client
299+
:type nick: str
300+
"""
246301
if not (chan and conn):
247302
return False
248303

@@ -266,7 +321,9 @@ def perm_check(chan, conn, nick):
266321

267322
@hook.command(permissions=["botcontrol"], autohelp=False)
268323
def dumpchans(conn):
269-
"""- Dumps all stored channel data for this connection to the console"""
324+
"""- Dumps all stored channel data for this connection to the console
325+
:type conn: cloudbot.client.Client
326+
"""
270327
data = conn.memory["chan_data"]
271328
lines = list(dump_dict(data))
272329
print('\n'.join(lines))
@@ -275,7 +332,9 @@ def dumpchans(conn):
275332

276333
@hook.command(permissions=["botcontrol"], autohelp=False)
277334
def dumpusers(conn):
278-
"""- Dumps all stored user data for this connection to the console"""
335+
"""- Dumps all stored user data for this connection to the console
336+
:type conn: cloudbot.client.Client
337+
"""
279338
data = conn.memory["users"]
280339
lines = list(dump_dict(data))
281340
print('\n'.join(lines))
@@ -284,27 +343,42 @@ def dumpusers(conn):
284343

285344
@hook.command(permissions=["botcontrol"], autohelp=False)
286345
def updateusers(bot):
287-
"""- Forces an update of all /NAMES data for all channels"""
346+
"""- Forces an update of all /NAMES data for all channels
347+
:type bot: cloudbot.bot.CloudBot
348+
"""
288349
get_chan_data(bot)
289350
return "Updating all channel data"
290351

291352

292353
@hook.command(permissions=["botcontrol"], autohelp=False)
293354
def cleanusers(bot):
355+
"""
356+
:type bot: cloudbot.bot.CloudBot
357+
"""
294358
clean_data(bot)
295359
gc.collect()
296360
return "Data cleaned."
297361

298362

299363
@hook.command(permissions=["botcontrol"], autohelp=False)
300364
def clearusers(bot):
365+
"""
366+
:type bot: cloudbot.bot.CloudBot
367+
"""
301368
init_chan_data(bot, True)
302369
gc.collect()
303370
return "Data cleared."
304371

305372

306373
@hook.irc_raw('JOIN')
307374
def on_join(nick, user, host, conn, irc_paramlist):
375+
"""
376+
:type nick: str
377+
:type user: str
378+
:type host: str
379+
:type conn: cloudbot.client.Client
380+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
381+
"""
308382
chan, *other_data = irc_paramlist
309383

310384
if chan.startswith(':'):
@@ -332,6 +406,11 @@ def on_join(nick, user, host, conn, irc_paramlist):
332406

333407
@hook.irc_raw('MODE')
334408
def on_mode(chan, irc_paramlist, conn):
409+
"""
410+
:type chan: str
411+
:type conn: cloudbot.client.Client
412+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
413+
"""
335414
if chan.startswith(':'):
336415
chan = chan[1:]
337416

@@ -381,6 +460,11 @@ def on_mode(chan, irc_paramlist, conn):
381460

382461
@hook.irc_raw('PART')
383462
def on_part(chan, nick, conn):
463+
"""
464+
:type chan: str
465+
:type nick: str
466+
:type conn: cloudbot.client.Client
467+
"""
384468
if chan.startswith(':'):
385469
chan = chan[1:]
386470

@@ -394,11 +478,20 @@ def on_part(chan, nick, conn):
394478

395479
@hook.irc_raw('KICK')
396480
def on_kick(chan, target, conn):
481+
"""
482+
:type chan: str
483+
:type target: str
484+
:type conn: cloudbot.client.Client
485+
"""
397486
on_part(chan, target, conn)
398487

399488

400489
@hook.irc_raw('QUIT')
401490
def on_quit(nick, conn):
491+
"""
492+
:type nick: str
493+
:type conn: cloudbot.client.Client
494+
"""
402495
users = conn.memory["users"]
403496
if nick in users:
404497
user = users[nick]
@@ -409,6 +502,11 @@ def on_quit(nick, conn):
409502

410503
@hook.irc_raw('NICK')
411504
def on_nick(nick, irc_paramlist, conn):
505+
"""
506+
:type nick: str
507+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
508+
:type conn: cloudbot.client.Client
509+
"""
412510
users = conn.memory["users"]
413511
new_nick = irc_paramlist[0]
414512
if new_nick.startswith(':'):
@@ -424,17 +522,32 @@ def on_nick(nick, irc_paramlist, conn):
424522

425523
@hook.irc_raw('ACCOUNT')
426524
def on_account(conn, nick, irc_paramlist):
525+
"""
526+
:type nick: str
527+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
528+
:type conn: cloudbot.client.Client
529+
"""
427530
conn.memory["users"][nick]["account"] = irc_paramlist[0]
428531

429532

430533
@hook.irc_raw('CHGHOST')
431534
def on_chghost(conn, nick, irc_paramlist):
535+
"""
536+
:type nick: str
537+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
538+
:type conn: cloudbot.client.Client
539+
"""
432540
ident, host = irc_paramlist
433541
conn.memory["users"][nick].update(ident=ident, host=host)
434542

435543

436544
@hook.irc_raw('AWAY')
437545
def on_away(conn, nick, irc_paramlist):
546+
"""
547+
:type nick: str
548+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
549+
:type conn: cloudbot.client.Client
550+
"""
438551
if irc_paramlist:
439552
reason = irc_paramlist[0]
440553
else:
@@ -445,6 +558,10 @@ def on_away(conn, nick, irc_paramlist):
445558

446559
@hook.irc_raw('352')
447560
def on_who(conn, irc_paramlist):
561+
"""
562+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
563+
:type conn: cloudbot.client.Client
564+
"""
448565
_, _, ident, host, server, nick, status, realname = irc_paramlist
449566
realname = realname.split(None, 1)[1]
450567
user = conn.memory["users"][nick]
@@ -463,29 +580,49 @@ def on_who(conn, irc_paramlist):
463580

464581
@hook.irc_raw('311')
465582
def on_whois_name(conn, irc_paramlist):
583+
"""
584+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
585+
:type conn: cloudbot.client.Client
586+
"""
466587
_, nick, ident, host, _, realname = irc_paramlist
467588
conn.memory["users"][nick].update(ident=ident, host=host, realname=realname)
468589

469590

470591
@hook.irc_raw('330')
471592
def on_whois_acct(conn, irc_paramlist):
593+
"""
594+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
595+
:type conn: cloudbot.client.Client
596+
"""
472597
_, nick, acct = irc_paramlist[:2]
473598
conn.memory["users"][nick]["account"] = acct
474599

475600

476601
@hook.irc_raw('301')
477602
def on_whois_away(conn, irc_paramlist):
603+
"""
604+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
605+
:type conn: cloudbot.client.Client
606+
"""
478607
_, nick, msg = irc_paramlist
479608
conn.memory["users"][nick].update(is_away=True, away_message=msg)
480609

481610

482611
@hook.irc_raw('312')
483612
def on_whois_server(conn, irc_paramlist):
613+
"""
614+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
615+
:type conn: cloudbot.client.Client
616+
"""
484617
_, nick, server, _ = irc_paramlist
485618
conn.memory["users"][nick].update(server=server)
486619

487620

488621
@hook.irc_raw('313')
489622
def on_whois_oper(conn, irc_paramlist):
623+
"""
624+
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
625+
:type conn: cloudbot.client.Client
626+
"""
490627
nick = irc_paramlist[1]
491628
conn.memory["users"][nick].update(is_oper=True)

0 commit comments

Comments
 (0)