import jarvis import re import aiohttp from jarvis.config import get_config from jarvis.utils import build_embed from jarvis.utils.db import DBManager from jarvis.utils.field import Field from jarvis.data.dbrand import shipping_lookup from discord.ext import commands from discord_slash import cog_ext class CTCCog(commands.Cog): def __init__(self, bot): self.bot = bot mconf = get_config().mongo self.db = DBManager(mconf).mongo self._session = aiohttp.ClientSession() self.url = "https://completethecodetwo.cards/pw" @cog_ext.cog_subcommand( base="ctc2", name="about", description="CTC2 related commands", guild_ids=[578757004059738142], ) async def _about(self, ctx): await ctx.send( "See https://phase2.completethecode.com for more information" ) @cog_ext.cog_subcommand( base="ctc2", name="pw", description="Guess a password for https://completethecodetwo.cards", guild_ids=[578757004059738142], ) async def _pw(self, ctx, guess: str): guessed = self.db.ctc2.guesses.find_one({"guess": guess}) if guessed: await ctx.send("Already guessed, dipshit.") return result = await self._session.post(self.url, data=guess) message = "" correct = False if 200 <= result.status < 400: message = f"{ctx.author.mention} got it! Password is {guess}!" correct = True else: message = "Nope." self.db.ctc2.guesses.insert_one( {"guess": guess, "user": ctx.author.id, "correct": correct} ) await ctx.send(message) def setup(bot): bot.add_cog(CTCCog(bot))