Skip to content

Commit

Permalink
Merge pull request #1693 from sopel-irc/event-default-rule
Browse files Browse the repository at this point in the history
loader: default rule for events
  • Loading branch information
dgw authored Sep 18, 2019
2 parents 39f0740 + 2d11bf1 commit c752b10
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
15 changes: 0 additions & 15 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def auth_after_register(bot):


@sopel.module.event(events.RPL_WELCOME, events.RPL_LUSERCLIENT)
@sopel.module.rule('.*')
@sopel.module.thread(False)
@sopel.module.unblockable
def startup(bot, trigger):
Expand Down Expand Up @@ -133,7 +132,6 @@ def enable_service_auth(bot, trigger):


@sopel.module.event(events.ERR_NOCHANMODES)
@sopel.module.rule('.*')
@sopel.module.priority('high')
def retry_join(bot, trigger):
"""Give NickServer enough time to identify on a +R channel.
Expand Down Expand Up @@ -295,7 +293,6 @@ def track_modes(bot, trigger):
bot.channels[channel].privileges[nick] = priv


@sopel.module.rule('.*')
@sopel.module.event('NICK')
@sopel.module.priority('high')
@sopel.module.thread(False)
Expand Down Expand Up @@ -345,7 +342,6 @@ def track_part(bot, trigger):
_remove_from_channel(bot, nick, channel)


@sopel.module.rule('.*')
@sopel.module.event('KICK')
@sopel.module.priority('high')
@sopel.module.thread(False)
Expand Down Expand Up @@ -403,7 +399,6 @@ def _send_who(bot, channel):
bot.write(['WHO', channel])


@sopel.module.rule('.*')
@sopel.module.event('JOIN')
@sopel.module.priority('high')
@sopel.module.thread(False)
Expand All @@ -430,7 +425,6 @@ def track_join(bot, trigger):
user.account = trigger.args[1]


@sopel.module.rule('.*')
@sopel.module.event('QUIT')
@sopel.module.priority('high')
@sopel.module.thread(False)
Expand All @@ -443,7 +437,6 @@ def track_quit(bot, trigger):
bot.users.pop(trigger.nick, None)


@sopel.module.rule('.*')
@sopel.module.event('CAP')
@sopel.module.thread(False)
@sopel.module.priority('high')
Expand Down Expand Up @@ -625,7 +618,6 @@ def send_authenticate(bot, token):


@sopel.module.event('AUTHENTICATE')
@sopel.module.rule('.*')
def auth_proceed(bot, trigger):
if trigger.args[0] != '+':
# How did we get here? I am not good with computer.
Expand All @@ -645,7 +637,6 @@ def auth_proceed(bot, trigger):


@sopel.module.event(events.RPL_SASLSUCCESS)
@sopel.module.rule('.*')
def sasl_success(bot, trigger):
bot.write(('CAP', 'END'))

Expand Down Expand Up @@ -737,7 +728,6 @@ def blocks(bot, trigger):


@sopel.module.event('ACCOUNT')
@sopel.module.rule('.*')
def account_notify(bot, trigger):
if trigger.nick not in bot.users:
bot.users[trigger.nick] = User(trigger.nick, trigger.user, trigger.host)
Expand All @@ -748,7 +738,6 @@ def account_notify(bot, trigger):


@sopel.module.event(events.RPL_WHOSPCRPL)
@sopel.module.rule('.*')
@sopel.module.priority('high')
@sopel.module.unblockable
def recv_whox(bot, trigger):
Expand Down Expand Up @@ -801,7 +790,6 @@ def _record_who(bot, channel, user, host, nick, account=None, away=None, modes=N


@sopel.module.event(events.RPL_WHOREPLY)
@sopel.module.rule('.*')
@sopel.module.priority('high')
@sopel.module.unblockable
def recv_who(bot, trigger):
Expand All @@ -811,15 +799,13 @@ def recv_who(bot, trigger):


@sopel.module.event(events.RPL_ENDOFWHO)
@sopel.module.rule('.*')
@sopel.module.priority('high')
@sopel.module.unblockable
def end_who(bot, trigger):
if _whox_enabled(bot):
who_reqs.pop(trigger.args[1], None)


@sopel.module.rule('.*')
@sopel.module.event('AWAY')
@sopel.module.priority('high')
@sopel.module.thread(False)
Expand All @@ -831,7 +817,6 @@ def track_notify(bot, trigger):
user.away = bool(trigger.args)


@sopel.module.rule('.*')
@sopel.module.event('TOPIC')
@sopel.module.event(events.RPL_TOPIC)
@sopel.module.priority('high')
Expand Down
5 changes: 4 additions & 1 deletion sopel/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def clean_callable(func, config):


def is_triggerable(obj):
return any(hasattr(obj, attr) for attr in ('rule', 'intents', 'commands', 'nickname_commands'))
return any(
hasattr(obj, attr)
for attr in ('rule', 'event', 'intents', 'commands',
'nickname_commands'))


def clean_module(module, config):
Expand Down
2 changes: 0 additions & 2 deletions sopel/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def me(bot, trigger):


@sopel.module.event('INVITE')
@sopel.module.rule('.*')
@sopel.module.priority('low')
def invite_join(bot, trigger):
"""Join a channel Sopel is invited to, if the inviter is an admin."""
Expand All @@ -232,7 +231,6 @@ def invite_join(bot, trigger):


@sopel.module.event('KICK')
@sopel.module.rule(r'.*')
@sopel.module.priority('low')
def hold_ground(bot, trigger):
"""
Expand Down
1 change: 0 additions & 1 deletion sopel/modules/find_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@


@sopel.module.event(sopel.tools.events.RPL_LUSERCLIENT)
@sopel.module.rule('.*')
def startup_version_check(bot, trigger):
global startup_check_run
if not startup_check_run:
Expand Down
5 changes: 3 additions & 2 deletions test/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ def test_clean_module_commands(tmpdir, tmpconfig):
callables, jobs, shutdowns, urls = loader.clean_module(
test_mod, tmpconfig)

assert len(callables) == 2
assert len(callables) == 3
assert test_mod.first_command in callables
assert test_mod.second_command in callables
assert test_mod.on_topic_command in callables
assert len(jobs) == 2
assert test_mod.interval5s in jobs
assert test_mod.interval10s in jobs
Expand Down Expand Up @@ -272,7 +273,7 @@ def test_clean_callable_events(tmpconfig, func):
assert func.event == ['TOPIC', 'JOIN', 'NICK']


def test_clean_callable_events_basetring(tmpconfig, func):
def test_clean_callable_events_basestring(tmpconfig, func):
setattr(func, 'event', 'topic')
loader.clean_callable(func, tmpconfig)

Expand Down

0 comments on commit c752b10

Please sign in to comment.