From d43e431c542daf393e7f5a40262fd2e58878edd5 Mon Sep 17 00:00:00 2001 From: osmarks Date: Thu, 16 Jun 2022 18:56:26 +0100 Subject: [PATCH] I forgot weird telephone changes, helloboiseconds, I think IRC bridge fixes --- src/irc_link.py | 4 ++-- src/telephone.py | 27 +++++++++++---------------- src/util.py | 6 ++++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/irc_link.py b/src/irc_link.py index c054dbe..091087b 100644 --- a/src/irc_link.py +++ b/src/irc_link.py @@ -102,7 +102,7 @@ async def initialize(): def disconnect(conn, event): logging.warn("Disconnected from IRC, reinitializing") teardown() - asyncio.create_task(initialize) + asyncio.create_task(initialize()) # TODO: do better thing conn.add_global_handler("welcome", connect) @@ -116,6 +116,6 @@ async def initialize(): def setup(bot): asyncio.create_task(initialize()) -def teardown(bot): +def teardown(bot=None): if global_conn: global_conn.disconnect() if unlisten: unlisten() diff --git a/src/telephone.py b/src/telephone.py index f6282f3..ee8b3db 100644 --- a/src/telephone.py +++ b/src/telephone.py @@ -182,33 +182,29 @@ When you want to end a call, use hangup. pass - async def _find_recent(self, chs, query): + async def find_recent(self, chs, query): one_week = timedelta(seconds=60*60*24*7) - one_week_ago = datetime.now()-one_week + one_week_ago = datetime.now() - one_week - found = collections.defaultdict(list) - async def find_msgs(ch): - # the parameters to history() here might need to be tweaked - # somewhat, for more general usage + for ch in chs: + yield True, ch async for msg in ch.history(limit=None,after=one_week_ago): if query in msg.content.lower(): - found[ch].append(msg) - await asyncio.gather(*(find_msgs(ch) for ch in chs)) - return found + yield False, ch, msg - @telephone.command(brief="find recent messages in channels linked to this") + @telephone.command(brief="Find recent messages in channels linked to this") @commands.check(util.extpriv_check) async def searchrecent(self, ctx, ch: discord.TextChannel, *, query): author = ctx.author chs = [] - for dest in eventbus.find_all_destinations(('discord',ch.id)): - if dest[0] == 'discord': + for dest in eventbus.find_all_destinations(("discord",ch.id)): + if dest[0] == "discord": chs.append(self.bot.get_channel(dest[1])) - found = await self._find_recent(chs, query) + found = await self.find_recent(chs, query) out = "" - for ch,ms in found.items(): + async for ch,ms in found.items(): out += f"{ch.mention} (`#{ch.name}` in `{ch.guild.name}`)\n" for m in ms: u = m.author.name if m.author else None @@ -220,7 +216,7 @@ When you want to end a call, use hangup. return found - @telephone.command(brief="delete recent messages in channels linked to this") + @telephone.command(brief="Delete recent messages in channels linked to this") @commands.check(util.extpriv_check) async def delrecent(self, ctx, ch: discord.TextChannel, *, query): author = ctx.author @@ -262,7 +258,6 @@ When you want to end a call, use hangup. await author.send("done") - @telephone.command(brief="Generate a webhook") @commands.check(util.server_mod_check) async def init_webhook(self, ctx): diff --git a/src/util.py b/src/util.py index e311034..6f1677f 100644 --- a/src/util.py +++ b/src/util.py @@ -50,7 +50,8 @@ time_units = ( # Wikipedia tells me this is a traditional Chinese timekeeping unit ("ke",), ("minutes", "m"), - ("seconds", "s") + ("seconds", "s"), + ("helloboiseconds", "hbseconds", "hbs") ) tu_mappings = { @@ -60,7 +61,8 @@ tu_mappings = { "beelifespans": lambda: (random.randint(122, 152), "days"), "semesters": (18, "weeks"), "fortnights": (2, "weeks"), - "ke": (864, "seconds") + "ke": (864, "seconds"), + "helloboiseconds": (1800, "seconds") } fractional_tu_mappings = {