Skip to content

Commit 9e22d7d

Browse files
committed
chan_track: Ensure the hooks acquire their locks
1 parent 40bf588 commit 9e22d7d

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
@@ -28,6 +29,8 @@
2829

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

32+
data_lock = asyncio.Lock()
33+
3134

3235
class MemberNotFoundException(KeyError):
3336
def __init__(self, name, chan):
@@ -513,7 +516,7 @@ def replace_user_data(conn, chan_data):
513516
del chan_data.users[old_nick]
514517

515518

516-
@hook.irc_raw(["353", "366"], singlethread=True, do_sieve=False)
519+
@hook.irc_raw(['353', '366'], singlethread=True, lock=data_lock, do_sieve=False)
517520
def on_names(conn, irc_paramlist, irc_command):
518521
"""
519522
:type conn: cloudbot.client.Client
@@ -583,7 +586,7 @@ def serialize(self, mapping, **kwargs):
583586
return json.dumps(self._serialize(mapping), **kwargs)
584587

585588

586-
@hook.permission("chanop")
589+
@hook.permission("chanop", lock=data_lock, do_sieve=False)
587590
def perm_check(chan, conn, nick):
588591
"""
589592
:type chan: str
@@ -685,7 +688,7 @@ def handle_tags(conn: IrcClient, nick: str, irc_tags: TagList) -> None:
685688
user_data.account = account_tag.value
686689

687690

688-
@hook.irc_raw(["PRIVMSG", "NOTICE"], do_sieve=False)
691+
@hook.irc_raw(["PRIVMSG", "NOTICE"], lock=data_lock, do_sieve=False)
689692
def on_msg(conn, nick, user, host, irc_paramlist):
690693
chan = irc_paramlist[0]
691694

@@ -709,7 +712,7 @@ def on_msg(conn, nick, user, host, irc_paramlist):
709712
memb.data["last_privmsg"] = time.time()
710713

711714

712-
@hook.periodic(600)
715+
@hook.periodic(600, lock=data_lock, do_sieve=False)
713716
def clean_pms(bot):
714717
cutoff = time.time() - 600
715718
for conn in bot.connections.values():
@@ -726,7 +729,7 @@ def clean_pms(bot):
726729
pass
727730

728731

729-
@hook.irc_raw("JOIN", do_sieve=False)
732+
@hook.irc_raw("JOIN", lock=data_lock, do_sieve=False)
730733
def on_join(nick, user, host, conn, irc_paramlist):
731734
"""
732735
:type nick: str
@@ -753,7 +756,7 @@ def on_join(nick, user, host, conn, irc_paramlist):
753756
user_data.join_channel(chan_data)
754757

755758

756-
@hook.irc_raw("MODE", do_sieve=False)
759+
@hook.irc_raw('MODE', lock=data_lock, do_sieve=False)
757760
def on_mode(chan, irc_paramlist, conn):
758761
"""
759762
:type chan: str
@@ -791,7 +794,7 @@ def on_mode(chan, irc_paramlist, conn):
791794
member.sort_status()
792795

793796

794-
@hook.irc_raw("PART", do_sieve=False)
797+
@hook.irc_raw('PART', lock=data_lock, do_sieve=False)
795798
def on_part(chan, nick, conn):
796799
"""
797800
:type chan: str
@@ -806,7 +809,7 @@ def on_part(chan, nick, conn):
806809
del chan_data.users[nick]
807810

808811

809-
@hook.irc_raw("KICK", do_sieve=False)
812+
@hook.irc_raw('KICK', lock=data_lock, do_sieve=False)
810813
def on_kick(chan, target, conn):
811814
"""
812815
:type chan: str
@@ -816,7 +819,7 @@ def on_kick(chan, target, conn):
816819
on_part(chan, target, conn)
817820

818821

819-
@hook.irc_raw("QUIT", do_sieve=False)
822+
@hook.irc_raw('QUIT', lock=data_lock, do_sieve=False)
820823
def on_quit(nick, conn):
821824
"""
822825
:type nick: str
@@ -830,7 +833,7 @@ def on_quit(nick, conn):
830833
del chan.users[nick]
831834

832835

833-
@hook.irc_raw("NICK", do_sieve=False)
836+
@hook.irc_raw('NICK', lock=data_lock, do_sieve=False)
834837
def on_nick(nick, irc_paramlist, conn):
835838
"""
836839
:type nick: str
@@ -857,7 +860,7 @@ def on_nick(nick, irc_paramlist, conn):
857860
user_chans[new_nick] = user_chans.pop(nick)
858861

859862

860-
@hook.irc_raw("ACCOUNT", do_sieve=False)
863+
@hook.irc_raw('ACCOUNT', lock=data_lock, do_sieve=False)
861864
def on_account(conn, nick, irc_paramlist):
862865
"""
863866
:type nick: str
@@ -867,7 +870,7 @@ def on_account(conn, nick, irc_paramlist):
867870
get_users(conn).getuser(nick).account = irc_paramlist[0]
868871

869872

870-
@hook.irc_raw("CHGHOST", do_sieve=False)
873+
@hook.irc_raw('CHGHOST', lock=data_lock, do_sieve=False)
871874
def on_chghost(conn, nick, irc_paramlist):
872875
"""
873876
:type nick: str
@@ -880,7 +883,7 @@ def on_chghost(conn, nick, irc_paramlist):
880883
user.host = host
881884

882885

883-
@hook.irc_raw("AWAY", do_sieve=False)
886+
@hook.irc_raw('AWAY', lock=data_lock, do_sieve=False)
884887
def on_away(conn, nick, irc_paramlist):
885888
"""
886889
:type nick: str
@@ -897,7 +900,7 @@ def on_away(conn, nick, irc_paramlist):
897900
user.away_message = reason
898901

899902

900-
@hook.irc_raw("352", do_sieve=False)
903+
@hook.irc_raw('352', lock=data_lock, do_sieve=False)
901904
def on_who(conn, irc_paramlist):
902905
"""
903906
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -917,7 +920,7 @@ def on_who(conn, irc_paramlist):
917920
user.is_oper = is_oper
918921

919922

920-
@hook.irc_raw("311", do_sieve=False)
923+
@hook.irc_raw('311', lock=data_lock, do_sieve=False)
921924
def on_whois_name(conn, irc_paramlist):
922925
"""
923926
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -930,7 +933,7 @@ def on_whois_name(conn, irc_paramlist):
930933
user.realname = realname
931934

932935

933-
@hook.irc_raw("330", do_sieve=False)
936+
@hook.irc_raw('330', lock=data_lock, do_sieve=False)
934937
def on_whois_acct(conn, irc_paramlist):
935938
"""
936939
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -940,7 +943,7 @@ def on_whois_acct(conn, irc_paramlist):
940943
get_users(conn).getuser(nick).account = acct
941944

942945

943-
@hook.irc_raw("301", do_sieve=False)
946+
@hook.irc_raw('301', lock=data_lock, do_sieve=False)
944947
def on_whois_away(conn, irc_paramlist):
945948
"""
946949
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -952,7 +955,7 @@ def on_whois_away(conn, irc_paramlist):
952955
user.away_message = msg
953956

954957

955-
@hook.irc_raw("312", do_sieve=False)
958+
@hook.irc_raw('312', lock=data_lock, do_sieve=False)
956959
def on_whois_server(conn, irc_paramlist):
957960
"""
958961
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -962,7 +965,7 @@ def on_whois_server(conn, irc_paramlist):
962965
get_users(conn).getuser(nick).server = server
963966

964967

965-
@hook.irc_raw("313", do_sieve=False)
968+
@hook.irc_raw('313', lock=data_lock, do_sieve=False)
966969
def on_whois_oper(conn, irc_paramlist):
967970
"""
968971
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList

0 commit comments

Comments
 (0)