Merge branch 'osmarks:master' into master

This commit is contained in:
what 2021-10-16 16:59:37 -07:00 committed by GitHub
commit 50b425da5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import metrics
def setup(bot):
@bot.listen()
async def on_member_join(member):
if member.guild.id == util.config["heavserver"]["id"]:
if member.guild and member.guild.id == util.config["heavserver"]["id"]:
logging.info("%s (%d) joined heavserver", member.display_name, member.id)
if member.bot:
await member.add_roles(discord.utils.get(member.guild.roles, id=util.config["heavserver"]["quarantine_role"]))

View File

@ -77,9 +77,14 @@ async def initialize():
logging.info("Connected to %s on IRC", channel)
joined.add(channel)
def disconnect(conn, event):
logging.warn("Disconnected from IRC, reinitializing")
teardown()
asyncio.create_task(initialize)
# TODO: do better thing
conn.add_global_handler("welcome", connect)
conn.add_global_handler("disconnect", lambda conn, event: logging.warn("Disconnected from IRC"))
conn.add_global_handler("disconnect", disconnect)
conn.add_global_handler("nicknameinuse", inuse)
conn.add_global_handler("pubmsg", pubmsg)

View File

@ -26,7 +26,7 @@ class Userdata(commands.Cog):
@userdata.command(help="Get a userdata key. Checks guild first, then global.")
async def get(self, ctx, *, key):
row = await self.get_userdata(ctx.author.id, ctx.guild.id, key)
row = await self.get_userdata(ctx.author.id, ctx.guild and ctx.guild.id, key)
if not row:
raise ValueError("No such key")
await ctx.send(row["value"])
@ -37,7 +37,7 @@ class Userdata(commands.Cog):
if scope == "global":
rows = await self.bot.database.execute_fetchall("SELECT * FROM user_data WHERE user_id = ? AND guild_id = '_global' AND key LIKE ?", (ctx.author.id, query))
else:
rows = await self.bot.database.execute_fetchall("SELECT * FROM user_data WHERE user_id = ? AND guild_id = ? AND key LIKE ?", (ctx.author.id, ctx.guild.id, query))
rows = await self.bot.database.execute_fetchall("SELECT * FROM user_data WHERE user_id = ? AND guild_id = ? AND key LIKE ?", (ctx.author.id, ctx.guild and ctx.guild.id, query))
out = []
for row in rows:
if show_values:
@ -51,7 +51,7 @@ class Userdata(commands.Cog):
async def set_cmd(self, ctx, key, *, value):
check_key(key)
value = preprocess_value(value)
await self.set_userdata(ctx.author.id, ctx.guild.id, key, value)
await self.set_userdata(ctx.author.id, ctx.guild and ctx.guild.id, key, value)
await ctx.send(f"**{key}** set (scope guild)")
@userdata.command(help="Set a userdata key in the global scope.")
@ -68,7 +68,7 @@ class Userdata(commands.Cog):
row = await self.get_userdata(ctx.author.id, ctx.guild.id, key)
if not row:
value = 0
guild = ctx.guild.id
guild = ctx.guild and ctx.guild.id
else:
value = int(row["value"])
guild = row["guild_id"]
@ -80,7 +80,7 @@ class Userdata(commands.Cog):
async def delete(self, ctx, *keys):
"Delete the specified keys (smallest scope first)."
for key in keys:
row = await self.get_userdata(ctx.author.id, ctx.guild.id, key)
row = await self.get_userdata(ctx.author.id, ctx.guild and ctx.guild.id, key)
if not row:
return await ctx.send(embed=util.error_embed(f"No such key {key}"))
await self.bot.database.execute("DELETE FROM user_data WHERE user_id = ? AND guild_id = ? AND key = ?", (ctx.author.id, row["guild_id"], key))

View File

@ -278,7 +278,7 @@ AltCtx = collections.namedtuple("AltCtx", ["author", "guild", "bot"])
async def user_config_lookup(ctx, cfg):
userdata = ctx.bot.get_cog("Userdata")
if userdata is None: return
row = await userdata.get_userdata(ctx.author.id, ctx.guild.id, cfg)
row = await userdata.get_userdata(ctx.author.id, ctx.guild and ctx.guild.id, cfg)
if row is None: return
return row["value"]