Skip to content

Commit

Permalink
Merge pull request #1725 from sopel-irc/unblock-background-triggers
Browse files Browse the repository at this point in the history
plugins: unblock background triggers
  • Loading branch information
dgw authored Nov 20, 2019
2 parents 48f3d8d + 1d5f41a commit 415ecd2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion sopel/modules/seen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import datetime
import time

from sopel.module import commands, rule, priority, thread
from sopel.module import commands, rule, priority, thread, unblockable
from sopel.tools import Identifier
from sopel.tools.time import seconds_to_human

Expand Down Expand Up @@ -58,6 +58,7 @@ def seen(bot, trigger):
@thread(False)
@rule('(.*)')
@priority('low')
@unblockable
def note(bot, trigger):
if not trigger.is_privmsg:
bot.db.set_nick_value(trigger.nick, 'seen_timestamp', time.time())
Expand Down
13 changes: 7 additions & 6 deletions sopel/modules/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from collections import defaultdict

from sopel.config.types import StaticSection, ValidatedAttribute
from sopel.module import commands, nickname_commands, rule, priority, example
from sopel import module
from sopel.tools import Identifier
from sopel.tools.time import get_timezone, format_time

Expand Down Expand Up @@ -131,9 +131,9 @@ def shutdown(bot):
pass


@commands('tell', 'ask')
@nickname_commands('tell', 'ask')
@example('$nickname, tell dgw he broke something again.')
@module.commands('tell', 'ask')
@module.nickname_commands('tell', 'ask')
@module.example('$nickname, tell dgw he broke something again.')
def f_remind(bot, trigger):
"""Give someone a message the next time they're seen"""
teller = trigger.nick
Expand Down Expand Up @@ -224,8 +224,9 @@ def nick_match_tellee(nick, tellee):
return nick.lower() == tellee.lower()


@rule('(.*)')
@priority('low')
@module.rule('(.*)')
@module.priority('low')
@module.unblockable
def message(bot, trigger):
nick = trigger.nick

Expand Down
22 changes: 15 additions & 7 deletions sopel/modules/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@

import requests

from sopel.module import rule, commands, priority, example
from sopel.tools import web
from sopel.module import rule, commands, priority, example, unblockable
from sopel.tools import web, SopelMemory

if sys.version_info.major >= 3:
unicode = str


mangle_lines = {}
def setup(bot):
if 'mangle_lines' not in bot.memory:
bot.memory['mangle_lines'] = SopelMemory()


def shutdown(bot):
try:
del bot.memory['mangle_lines']
except KeyError:
pass


def translate(text, in_lang='auto', out_lang='en'):
Expand Down Expand Up @@ -169,15 +178,14 @@ def get_random_lang(long_list, short_list):
@commands('mangle', 'mangle2')
def mangle(bot, trigger):
"""Repeatedly translate the input until it makes absolutely no sense."""
global mangle_lines
long_lang_list = ['fr', 'de', 'es', 'it', 'no', 'he', 'la', 'ja', 'cy', 'ar', 'yi', 'zh', 'nl', 'ru', 'fi', 'hi', 'af', 'jw', 'mr', 'ceb', 'cs', 'ga', 'sv', 'eo', 'el', 'ms', 'lv']
lang_list = []
for __ in range(0, 8):
lang_list = get_random_lang(long_lang_list, lang_list)
random.shuffle(lang_list)
if trigger.group(2) is None:
try:
phrase = (mangle_lines[trigger.sender.lower()], '')
phrase = (bot.memory['mangle_lines'][trigger.sender.lower()], '')
except KeyError:
bot.reply("What do you want me to mangle?")
return
Expand Down Expand Up @@ -210,9 +218,9 @@ def mangle(bot, trigger):

@rule('(.*)')
@priority('low')
@unblockable
def collect_mangle_lines(bot, trigger):
global mangle_lines
mangle_lines[trigger.sender.lower()] = "%s said '%s'" % (trigger.nick, (trigger.group(0).strip()))
bot.memory['mangle_lines'][trigger.sender.lower()] = "%s said '%s'" % (trigger.nick, (trigger.group(0).strip()))


if __name__ == "__main__":
Expand Down

0 comments on commit 415ecd2

Please sign in to comment.