mirror of
				https://github.com/osmarks/autobotrobot
				synced 2025-10-31 16:02:59 +00:00 
			
		
		
		
	generalization
This commit is contained in:
		| @@ -26,7 +26,7 @@ class Userdata(commands.Cog): | |||||||
|  |  | ||||||
|     @userdata.command(help="Get a userdata key. Checks guild first, then global.") |     @userdata.command(help="Get a userdata key. Checks guild first, then global.") | ||||||
|     async def get(self, ctx, *, key): |     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: |         if not row: | ||||||
|             raise ValueError("No such key") |             raise ValueError("No such key") | ||||||
|         await ctx.send(row["value"]) |         await ctx.send(row["value"]) | ||||||
| @@ -37,7 +37,7 @@ class Userdata(commands.Cog): | |||||||
|         if scope == "global": |         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)) |             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: |         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 = [] |         out = [] | ||||||
|         for row in rows: |         for row in rows: | ||||||
|             if show_values: |             if show_values: | ||||||
| @@ -51,7 +51,7 @@ class Userdata(commands.Cog): | |||||||
|     async def set_cmd(self, ctx, key, *, value): |     async def set_cmd(self, ctx, key, *, value): | ||||||
|         check_key(key) |         check_key(key) | ||||||
|         value = preprocess_value(value) |         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)") |         await ctx.send(f"**{key}** set (scope guild)") | ||||||
|  |  | ||||||
|     @userdata.command(help="Set a userdata key in the global scope.") |     @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) |         row = await self.get_userdata(ctx.author.id, ctx.guild.id, key) | ||||||
|         if not row: |         if not row: | ||||||
|             value = 0 |             value = 0 | ||||||
|             guild = ctx.guild.id |             guild = ctx.guild and ctx.guild.id | ||||||
|         else: |         else: | ||||||
|             value = int(row["value"]) |             value = int(row["value"]) | ||||||
|             guild = row["guild_id"] |             guild = row["guild_id"] | ||||||
| @@ -80,7 +80,7 @@ class Userdata(commands.Cog): | |||||||
|     async def delete(self, ctx, *keys): |     async def delete(self, ctx, *keys): | ||||||
|         "Delete the specified keys (smallest scope first)." |         "Delete the specified keys (smallest scope first)." | ||||||
|         for key in keys: |         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: |             if not row: | ||||||
|                 return await ctx.send(embed=util.error_embed(f"No such key {key}")) |                 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)) |             await self.bot.database.execute("DELETE FROM user_data WHERE user_id = ? AND guild_id = ? AND key = ?", (ctx.author.id, row["guild_id"], key)) | ||||||
|   | |||||||
| @@ -278,7 +278,7 @@ AltCtx = collections.namedtuple("AltCtx", ["author", "guild", "bot"]) | |||||||
| async def user_config_lookup(ctx, cfg): | async def user_config_lookup(ctx, cfg): | ||||||
|     userdata = ctx.bot.get_cog("Userdata") |     userdata = ctx.bot.get_cog("Userdata") | ||||||
|     if userdata is None: return |     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 |     if row is None: return | ||||||
|     return row["value"] |     return row["value"] | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user