reformat/refactor

This commit is contained in:
2025-04-26 21:59:46 -04:00
parent 5bde6ac880
commit a433dc2fb5
14 changed files with 150 additions and 107 deletions

View File

@@ -180,10 +180,11 @@ class Meme(commands.Cog):
def predicate(ctx):
try:
if not ctx.channel.id in BOT_CHANIDS:
if ctx.channel.id not in BOT_CHANIDS:
logging.debug("%s not found in %s", ctx.channel.id, BOT_CHANIDS)
return ctx.channel.id in BOT_CHANIDS
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
return False
@@ -198,7 +199,7 @@ class Meme(commands.Cog):
None
"""
if not uid in self.meme_leaderboard:
if uid not in self.meme_leaderboard:
self.meme_leaderboard[uid] = 1
else:
self.meme_leaderboard[uid] += 1
@@ -211,11 +212,13 @@ class Meme(commands.Cog):
query_2_params: tuple = (uid, self.meme_leaderboard[uid])
try:
await db_conn.execute(query_1, query_1_params)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
await db_conn.execute(query_2, query_2_params)
except:
except: # noqa
"""Safe to ignore"""
pass
await db_conn.commit()
try:
@@ -273,26 +276,29 @@ class Meme(commands.Cog):
try:
try:
explosm_comics = await explosm_grabber.get()
except:
except: # noqa
"""Safe to ignore"""
pass
try:
xkcd_comics = await xkcd_grabber.get()
except:
except: # noqa
"""Safe to ignore"""
pass
try:
smbc_comics = await smbc_grabber.get()
except:
except: # noqa
"""Safe to ignore"""
pass
try:
qc_comics = await qc_grabber.get()
print(f"QC: {qc_comics}")
except:
except: # noqa
"""Safe to ignore"""
pass
try:
dino_comics = await dino_grabber.get()
except Exception as e:
logging.debug("Dino failed: %s", str(e))
pass
try:
onions = await onion_grabber.get()
except Exception as e:
@@ -303,7 +309,8 @@ class Meme(commands.Cog):
except Exception as e:
logging.debug("THNs failed: %s", str(e))
pass
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
agents: list[str] = constants.HTTP_UA_LIST
headers: dict = {"User-Agent": random.choice(agents)}
@@ -335,7 +342,8 @@ class Meme(commands.Cog):
username="r/memes",
)
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for comic in explosm_comics:
@@ -371,7 +379,8 @@ class Meme(commands.Cog):
thread=thread,
)
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for comic in xkcd_comics:
@@ -406,7 +415,8 @@ class Meme(commands.Cog):
thread=thread,
)
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for comic in smbc_comics:
@@ -440,7 +450,8 @@ class Meme(commands.Cog):
thread=thread,
)
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for comic in qc_comics:
@@ -477,9 +488,9 @@ class Meme(commands.Cog):
thread=thread,
)
await asyncio.sleep(2)
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
pass
try:
for comic in dino_comics:
if not comic:
@@ -512,7 +523,8 @@ class Meme(commands.Cog):
thread=thread,
)
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for onion in onions:
@@ -537,7 +549,8 @@ class Meme(commands.Cog):
if onion_video:
await webhook.send(f"^ video: {onion_video}")
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
try:
for thn in thns:
@@ -563,10 +576,11 @@ class Meme(commands.Cog):
if thn_video:
await webhook.send(f"^ video: {thn_video}")
await asyncio.sleep(2)
except:
except: # noqa
"""Safe to ignore"""
pass
except:
# await self.bot.get_channel(self.MEMESTREAM_CHANID).send(f"FUCK, MY MEEMER! YOU DENTED MY MEEMER!")
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
@tasks.loop(hours=12.0)
@@ -579,7 +593,8 @@ class Meme(commands.Cog):
return await self.do_autos(only_comics=True) # Skip first iteration!
await self.do_autos()
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
@tasks.loop(hours=0.5)
@@ -588,7 +603,8 @@ class Meme(commands.Cog):
try:
await asyncio.sleep(10) # Try to ensure we are ready first
await self.do_autos(only_comics=True)
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
@bridge.bridge_command() # type: ignore
@@ -604,9 +620,10 @@ class Meme(commands.Cog):
try:
await ctx.respond("Trying!", ephemeral=True)
await self.do_autos()
except:
await ctx.respond("Fuck! :(", ephemeral=True)
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
await ctx.respond("Fuck! :(", ephemeral=True)
@bridge.bridge_command(hidden=True)
@commands.is_owner()
@@ -615,9 +632,10 @@ class Meme(commands.Cog):
try:
await ctx.respond("Trying!", ephemeral=True)
await self.do_autos(only_comics=True)
except:
await ctx.respond("Fuck! :(", ephemeral=True)
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
await ctx.respond("Fuck! :(", ephemeral=True)
@commands.Cog.listener()
async def on_message(self, message: discord.Message) -> None:
@@ -688,7 +706,8 @@ class Meme(commands.Cog):
if not member:
out_top.pop(x)
return out_top[0 : (n + 1)]
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
return None
@@ -739,7 +758,8 @@ class Meme(commands.Cog):
embed=top_embed,
content="## This message will automatically update periodically.",
)
except:
except Exception as e:
logging.debug("Exception: %s", str(e))
traceback.print_exc()
@bridge.bridge_command(hidden=True)