From de835dfe08ba3f70bc70d02246ba246166da70e5 Mon Sep 17 00:00:00 2001 From: osmarks Date: Wed, 19 Jul 2023 14:51:52 +0100 Subject: [PATCH] changes --- .gitignore | 3 ++- requirements.txt | 13 +++++++++++++ src/db.py | 3 +++ src/main.py | 2 ++ src/reminders.py | 2 +- src/telephone.py | 9 ++++++--- 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 7b2cd46..40a0415 100755 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ config.toml bot-data.json __pycache__ data.sqlite3 -ts.py \ No newline at end of file +ts.py +deploy.sh \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..48b3986 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +# TODO +pytio==0.3.1 +aiohttp==3.8.3 +aiosqlite==0.17.0 +nextcord==2.0.0b4 +numpy==1.23 +prometheus-async==19.2.0 +prometheus-client==0.15.0 +pydot==1.4.2 +toml==0.10.2 +requests==2.28.1 +python-dateutil==2.8.2 +irc==20.1.0 \ No newline at end of file diff --git a/src/db.py b/src/db.py index e78338b..cffcdcc 100644 --- a/src/db.py +++ b/src/db.py @@ -100,6 +100,9 @@ DELETE FROM user_data WHERE guild_id IS NULL; """, """ ALTER TABLE links ADD COLUMN cause TEXT; +""", +""" +ALTER TABLE telephone_config ADD COLUMN disabled INTEGER; """ ] diff --git a/src/main.py b/src/main.py index 6f3d768..24e1ab5 100644 --- a/src/main.py +++ b/src/main.py @@ -27,6 +27,8 @@ logging.basicConfig(level=logging.INFO, format="%(levelname)s %(asctime)s %(mess intents = discord.Intents.default() intents.members = True +intents.presences = True +intents.message_content = True bot = commands.Bot(command_prefix=commands.when_mentioned_or(config["prefix"]), description="AutoBotRobot, the most useless bot in the known universe." + util.config.get("description_suffix", ""), case_insensitive=True, allowed_mentions=discord.AllowedMentions(everyone=False, users=True, roles=True), intents=intents) diff --git a/src/reminders.py b/src/reminders.py index 2db9547..aae7f0c 100644 --- a/src/reminders.py +++ b/src/reminders.py @@ -91,7 +91,7 @@ class Reminders(commands.Cog): async def send_by_dm(self, info, text): user = self.bot.get_user(info["author_id"]) if not user: - user = await bot.fetch_user(info["author_id"]) + user = await self.bot.fetch_user(info["author_id"]) if not user: raise Exception(f"user {info['author_id']} unavailable/nonexistent") if not user.dm_channel: await user.create_dm() await user.dm_channel.send(text) diff --git a/src/telephone.py b/src/telephone.py index 38c424d..0cc09f5 100644 --- a/src/telephone.py +++ b/src/telephone.py @@ -283,14 +283,14 @@ When you want to end a call, use hangup. except discord.Forbidden as f: logging.warn("Could not create webhook in #%s %s", ctx.channel.name, ctx.guild.name, exc_info=f) await ctx.send("Webhook creation failed - please ensure permissions are available. This is not necessary but is recommended.") - await self.bot.database.execute("INSERT OR REPLACE INTO telephone_config VALUES (?, ?, ?, ?)", (num, ctx.guild.id, ctx.channel.id, webhook)) + await self.bot.database.execute("INSERT OR REPLACE INTO telephone_config VALUES (?, ?, ?, ?, 0)", (num, ctx.guild.id, ctx.channel.id, webhook)) await self.bot.database.commit() await ctx.send("Configured.") @telephone.command(aliases=["rcall"], brief="Dial another telephone channel.") async def rdial(self, ctx): # TODO: this is not very performant - random = (await self.bot.database.execute_fetchone("SELECT id FROM telephone_config ORDER BY RANDOM()"))["id"] + random = (await self.bot.database.execute_fetchone("SELECT id FROM telephone_config WHERE disabled = 0 ORDER BY RANDOM()"))["id"] await self.dial(ctx, random) @telephone.command(aliases=["call"], brief="Dial another telephone channel.") @@ -308,6 +308,9 @@ When you want to end a call, use hangup. # post embed in the receiving channel prompting people to accept/decline call recv_channel = self.bot.get_channel(recv_info["channel_id"]) + if recv_channel is None: + await self.bot.database.execute("UPDATE telephone_config SET disabled = 1 WHERE id = ?", (address,)) + return await ctx.send(embed=util.error_embed("Target channel no longer exists.")) _, call_message = await asyncio.gather( ctx.send(embed=util.info_embed("Outgoing call", f"Dialing {address}...")), recv_channel.send(embed=util.info_embed("Incoming call", @@ -418,7 +421,7 @@ When you want to end a call, use hangup. seen_edges.add(edge) seen.add(current) (handle, tmppath) = tempfile.mkstemp(".png", "graphviz") - graph.write_png(tmppath) + graph.write_png(tmppath, prog="neato") try: await ctx.send(file=discord.File(handle, filename="out.png")) finally: