Skip to content

Commit c777bdb

Browse files
committed
chan_track: Ensure the hooks acquire their locks
1 parent b4e5fb6 commit c777bdb

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Update tvdb.py to v3 TVDB API
3333
- Fix channel parameter handling in IRC client
3434
- Ensure hooks are triggered according to priority
35+
- chan_track: Ensure hooks acquire the needed locks
3536
### Removed
3637
- twitch.py removed due to outdated API and lack of maintainer
3738
- metacritic.py removed due to broken scraper and lack of maintainer

plugins/core/chan_track.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Requires:
55
server_info.py
66
"""
7+
import asyncio
78
import gc
89
import json
910
import logging
@@ -27,6 +28,8 @@
2728

2829
logger = logging.getLogger("cloudbot")
2930

31+
data_lock = asyncio.Lock()
32+
3033

3134
class WeakDict(dict):
3235
"""
@@ -517,7 +520,7 @@ def replace_user_data(conn, chan_data):
517520
del chan_data.users[old_nick]
518521

519522

520-
@hook.irc_raw(["353", "366"], singlethread=True, do_sieve=False)
523+
@hook.irc_raw(['353', '366'], singlethread=True, lock=data_lock, do_sieve=False)
521524
def on_names(conn, irc_paramlist, irc_command):
522525
"""
523526
:type conn: cloudbot.client.Client
@@ -587,7 +590,7 @@ def serialize(self, mapping, **kwargs):
587590
return json.dumps(self._serialize(mapping), **kwargs)
588591

589592

590-
@hook.permission("chanop")
593+
@hook.permission("chanop", lock=data_lock, do_sieve=False)
591594
def perm_check(chan, conn, nick):
592595
"""
593596
:type chan: str
@@ -678,7 +681,7 @@ def getdata_cmd(conn, chan, nick):
678681
return web.paste(MappingSerializer().serialize(memb, indent=2))
679682

680683

681-
@hook.irc_raw(["PRIVMSG", "NOTICE"], do_sieve=False)
684+
@hook.irc_raw(['PRIVMSG', 'NOTICE'], lock=data_lock, do_sieve=False)
682685
def on_msg(conn, nick, user, host, irc_paramlist):
683686
chan, *other_data = irc_paramlist
684687

@@ -702,7 +705,7 @@ def on_msg(conn, nick, user, host, irc_paramlist):
702705
memb.data["last_privmsg"] = time.time()
703706

704707

705-
@hook.periodic(600)
708+
@hook.periodic(600, lock=data_lock, do_sieve=False)
706709
def clean_pms(bot):
707710
cutoff = time.time() - 600
708711
for conn in bot.connections.values():
@@ -719,7 +722,7 @@ def clean_pms(bot):
719722
pass
720723

721724

722-
@hook.irc_raw("JOIN", do_sieve=False)
725+
@hook.irc_raw("JOIN", lock=data_lock, do_sieve=False)
723726
def on_join(nick, user, host, conn, irc_paramlist):
724727
"""
725728
:type nick: str
@@ -746,7 +749,7 @@ def on_join(nick, user, host, conn, irc_paramlist):
746749
user_data.join_channel(chan_data)
747750

748751

749-
@hook.irc_raw("MODE", do_sieve=False)
752+
@hook.irc_raw('MODE', lock=data_lock, do_sieve=False)
750753
def on_mode(chan, irc_paramlist, conn):
751754
"""
752755
:type chan: str
@@ -784,7 +787,7 @@ def on_mode(chan, irc_paramlist, conn):
784787
member.sort_status()
785788

786789

787-
@hook.irc_raw("PART", do_sieve=False)
790+
@hook.irc_raw('PART', lock=data_lock, do_sieve=False)
788791
def on_part(chan, nick, conn):
789792
"""
790793
:type chan: str
@@ -799,7 +802,7 @@ def on_part(chan, nick, conn):
799802
del chan_data.users[nick]
800803

801804

802-
@hook.irc_raw("KICK", do_sieve=False)
805+
@hook.irc_raw('KICK', lock=data_lock, do_sieve=False)
803806
def on_kick(chan, target, conn):
804807
"""
805808
:type chan: str
@@ -809,7 +812,7 @@ def on_kick(chan, target, conn):
809812
on_part(chan, target, conn)
810813

811814

812-
@hook.irc_raw("QUIT", do_sieve=False)
815+
@hook.irc_raw('QUIT', lock=data_lock, do_sieve=False)
813816
def on_quit(nick, conn):
814817
"""
815818
:type nick: str
@@ -823,7 +826,7 @@ def on_quit(nick, conn):
823826
del chan.users[nick]
824827

825828

826-
@hook.irc_raw("NICK", do_sieve=False)
829+
@hook.irc_raw('NICK', lock=data_lock, do_sieve=False)
827830
def on_nick(nick, irc_paramlist, conn):
828831
"""
829832
:type nick: str
@@ -850,7 +853,7 @@ def on_nick(nick, irc_paramlist, conn):
850853
user_chans[new_nick] = user_chans.pop(nick)
851854

852855

853-
@hook.irc_raw("ACCOUNT", do_sieve=False)
856+
@hook.irc_raw('ACCOUNT', lock=data_lock, do_sieve=False)
854857
def on_account(conn, nick, irc_paramlist):
855858
"""
856859
:type nick: str
@@ -860,7 +863,7 @@ def on_account(conn, nick, irc_paramlist):
860863
get_users(conn).getuser(nick).account = irc_paramlist[0]
861864

862865

863-
@hook.irc_raw("CHGHOST", do_sieve=False)
866+
@hook.irc_raw('CHGHOST', lock=data_lock, do_sieve=False)
864867
def on_chghost(conn, nick, irc_paramlist):
865868
"""
866869
:type nick: str
@@ -873,7 +876,7 @@ def on_chghost(conn, nick, irc_paramlist):
873876
user.host = host
874877

875878

876-
@hook.irc_raw("AWAY", do_sieve=False)
879+
@hook.irc_raw('AWAY', lock=data_lock, do_sieve=False)
877880
def on_away(conn, nick, irc_paramlist):
878881
"""
879882
:type nick: str
@@ -890,7 +893,7 @@ def on_away(conn, nick, irc_paramlist):
890893
user.away_message = reason
891894

892895

893-
@hook.irc_raw("352", do_sieve=False)
896+
@hook.irc_raw('352', lock=data_lock, do_sieve=False)
894897
def on_who(conn, irc_paramlist):
895898
"""
896899
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -910,7 +913,7 @@ def on_who(conn, irc_paramlist):
910913
user.is_oper = is_oper
911914

912915

913-
@hook.irc_raw("311", do_sieve=False)
916+
@hook.irc_raw('311', lock=data_lock, do_sieve=False)
914917
def on_whois_name(conn, irc_paramlist):
915918
"""
916919
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -923,7 +926,7 @@ def on_whois_name(conn, irc_paramlist):
923926
user.realname = realname
924927

925928

926-
@hook.irc_raw("330", do_sieve=False)
929+
@hook.irc_raw('330', lock=data_lock, do_sieve=False)
927930
def on_whois_acct(conn, irc_paramlist):
928931
"""
929932
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -933,7 +936,7 @@ def on_whois_acct(conn, irc_paramlist):
933936
get_users(conn).getuser(nick).account = acct
934937

935938

936-
@hook.irc_raw("301", do_sieve=False)
939+
@hook.irc_raw('301', lock=data_lock, do_sieve=False)
937940
def on_whois_away(conn, irc_paramlist):
938941
"""
939942
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -945,7 +948,7 @@ def on_whois_away(conn, irc_paramlist):
945948
user.away_message = msg
946949

947950

948-
@hook.irc_raw("312", do_sieve=False)
951+
@hook.irc_raw('312', lock=data_lock, do_sieve=False)
949952
def on_whois_server(conn, irc_paramlist):
950953
"""
951954
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -955,7 +958,7 @@ def on_whois_server(conn, irc_paramlist):
955958
get_users(conn).getuser(nick).server = server
956959

957960

958-
@hook.irc_raw("313", do_sieve=False)
961+
@hook.irc_raw('313', lock=data_lock, do_sieve=False)
959962
def on_whois_oper(conn, irc_paramlist):
960963
"""
961964
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList

0 commit comments

Comments
 (0)