Skip to content

Commit

Permalink
chan_track: Ensure the hooks acquire their locks
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jun 28, 2020
1 parent b4e5fb6 commit c777bdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update tvdb.py to v3 TVDB API
- Fix channel parameter handling in IRC client
- Ensure hooks are triggered according to priority
- chan_track: Ensure hooks acquire the needed locks
### Removed
- twitch.py removed due to outdated API and lack of maintainer
- metacritic.py removed due to broken scraper and lack of maintainer
Expand Down
41 changes: 22 additions & 19 deletions plugins/core/chan_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Requires:
server_info.py
"""
import asyncio
import gc
import json
import logging
Expand All @@ -27,6 +28,8 @@

logger = logging.getLogger("cloudbot")

data_lock = asyncio.Lock()


class WeakDict(dict):
"""
Expand Down Expand Up @@ -517,7 +520,7 @@ def replace_user_data(conn, chan_data):
del chan_data.users[old_nick]


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


@hook.permission("chanop")
@hook.permission("chanop", lock=data_lock, do_sieve=False)
def perm_check(chan, conn, nick):
"""
:type chan: str
Expand Down Expand Up @@ -678,7 +681,7 @@ def getdata_cmd(conn, chan, nick):
return web.paste(MappingSerializer().serialize(memb, indent=2))


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

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


@hook.periodic(600)
@hook.periodic(600, lock=data_lock, do_sieve=False)
def clean_pms(bot):
cutoff = time.time() - 600
for conn in bot.connections.values():
Expand All @@ -719,7 +722,7 @@ def clean_pms(bot):
pass


@hook.irc_raw("JOIN", do_sieve=False)
@hook.irc_raw("JOIN", lock=data_lock, do_sieve=False)
def on_join(nick, user, host, conn, irc_paramlist):
"""
:type nick: str
Expand All @@ -746,7 +749,7 @@ def on_join(nick, user, host, conn, irc_paramlist):
user_data.join_channel(chan_data)


@hook.irc_raw("MODE", do_sieve=False)
@hook.irc_raw('MODE', lock=data_lock, do_sieve=False)
def on_mode(chan, irc_paramlist, conn):
"""
:type chan: str
Expand Down Expand Up @@ -784,7 +787,7 @@ def on_mode(chan, irc_paramlist, conn):
member.sort_status()


@hook.irc_raw("PART", do_sieve=False)
@hook.irc_raw('PART', lock=data_lock, do_sieve=False)
def on_part(chan, nick, conn):
"""
:type chan: str
Expand All @@ -799,7 +802,7 @@ def on_part(chan, nick, conn):
del chan_data.users[nick]


@hook.irc_raw("KICK", do_sieve=False)
@hook.irc_raw('KICK', lock=data_lock, do_sieve=False)
def on_kick(chan, target, conn):
"""
:type chan: str
Expand All @@ -809,7 +812,7 @@ def on_kick(chan, target, conn):
on_part(chan, target, conn)


@hook.irc_raw("QUIT", do_sieve=False)
@hook.irc_raw('QUIT', lock=data_lock, do_sieve=False)
def on_quit(nick, conn):
"""
:type nick: str
Expand All @@ -823,7 +826,7 @@ def on_quit(nick, conn):
del chan.users[nick]


@hook.irc_raw("NICK", do_sieve=False)
@hook.irc_raw('NICK', lock=data_lock, do_sieve=False)
def on_nick(nick, irc_paramlist, conn):
"""
:type nick: str
Expand All @@ -850,7 +853,7 @@ def on_nick(nick, irc_paramlist, conn):
user_chans[new_nick] = user_chans.pop(nick)


@hook.irc_raw("ACCOUNT", do_sieve=False)
@hook.irc_raw('ACCOUNT', lock=data_lock, do_sieve=False)
def on_account(conn, nick, irc_paramlist):
"""
:type nick: str
Expand All @@ -860,7 +863,7 @@ def on_account(conn, nick, irc_paramlist):
get_users(conn).getuser(nick).account = irc_paramlist[0]


@hook.irc_raw("CHGHOST", do_sieve=False)
@hook.irc_raw('CHGHOST', lock=data_lock, do_sieve=False)
def on_chghost(conn, nick, irc_paramlist):
"""
:type nick: str
Expand All @@ -873,7 +876,7 @@ def on_chghost(conn, nick, irc_paramlist):
user.host = host


@hook.irc_raw("AWAY", do_sieve=False)
@hook.irc_raw('AWAY', lock=data_lock, do_sieve=False)
def on_away(conn, nick, irc_paramlist):
"""
:type nick: str
Expand All @@ -890,7 +893,7 @@ def on_away(conn, nick, irc_paramlist):
user.away_message = reason


@hook.irc_raw("352", do_sieve=False)
@hook.irc_raw('352', lock=data_lock, do_sieve=False)
def on_who(conn, irc_paramlist):
"""
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
Expand All @@ -910,7 +913,7 @@ def on_who(conn, irc_paramlist):
user.is_oper = is_oper


@hook.irc_raw("311", do_sieve=False)
@hook.irc_raw('311', lock=data_lock, do_sieve=False)
def on_whois_name(conn, irc_paramlist):
"""
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
Expand All @@ -923,7 +926,7 @@ def on_whois_name(conn, irc_paramlist):
user.realname = realname


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


@hook.irc_raw("301", do_sieve=False)
@hook.irc_raw('301', lock=data_lock, do_sieve=False)
def on_whois_away(conn, irc_paramlist):
"""
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
Expand All @@ -945,7 +948,7 @@ def on_whois_away(conn, irc_paramlist):
user.away_message = msg


@hook.irc_raw("312", do_sieve=False)
@hook.irc_raw('312', lock=data_lock, do_sieve=False)
def on_whois_server(conn, irc_paramlist):
"""
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
Expand All @@ -955,7 +958,7 @@ def on_whois_server(conn, irc_paramlist):
get_users(conn).getuser(nick).server = server


@hook.irc_raw("313", do_sieve=False)
@hook.irc_raw('313', lock=data_lock, do_sieve=False)
def on_whois_oper(conn, irc_paramlist):
"""
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
Expand Down

0 comments on commit c777bdb

Please sign in to comment.