Add ctc2 commands, closes #4
This commit is contained in:
parent
244d98979f
commit
65b671faa2
4 changed files with 133 additions and 70 deletions
|
@ -19,7 +19,7 @@ restart_ctx = None
|
||||||
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
|
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "0.4.0"
|
__version__ = "0.4.1"
|
||||||
|
|
||||||
|
|
||||||
@jarvis.event
|
@jarvis.event
|
||||||
|
|
58
jarvis/cogs/ctc2.py
Normal file
58
jarvis/cogs/ctc2.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
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))
|
|
@ -1,13 +1,12 @@
|
||||||
import jarvis
|
import jarvis
|
||||||
import re
|
import re
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import html
|
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from jarvis.data.dbrand import shipping_lookup
|
from jarvis.data.dbrand import shipping_lookup
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord_slash import cog_ext, SlashContext
|
from discord_slash import cog_ext
|
||||||
|
|
||||||
|
|
||||||
class DbrandCog(commands.Cog):
|
class DbrandCog(commands.Cog):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# J.A.R.V.I.S. database layout
|
# J.A.R.V.I.S. database layout
|
||||||
|
|
||||||
|
jarvis:
|
||||||
config:
|
config:
|
||||||
key: String, config name
|
key: String, config name
|
||||||
value: Any, config value
|
value: Any, config value
|
||||||
|
@ -77,3 +78,8 @@ modlog:
|
||||||
user: User ID
|
user: User ID
|
||||||
activity: String
|
activity: String
|
||||||
time: Datetime
|
time: Datetime
|
||||||
|
ctc2:
|
||||||
|
guesses:
|
||||||
|
guess: String
|
||||||
|
user: User ID
|
||||||
|
correct: boolean
|
||||||
|
|
Loading…
Add table
Reference in a new issue