Add ctc2 commands, closes #4

This commit is contained in:
Zeva Rose 2021-06-30 19:04:43 -06:00
parent 244d98979f
commit 65b671faa2
4 changed files with 133 additions and 70 deletions

View file

@ -19,7 +19,7 @@ restart_ctx = None
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
jarvis_self = Process()
__version__ = "0.4.0"
__version__ = "0.4.1"
@jarvis.event

58
jarvis/cogs/ctc2.py Normal file
View 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))

View file

@ -1,13 +1,12 @@
import jarvis
import re
import aiohttp
import html
from jarvis.config import get_config
from jarvis.utils import build_embed
from jarvis.utils.field import Field
from jarvis.data.dbrand import shipping_lookup
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
from discord_slash import cog_ext
class DbrandCog(commands.Cog):

View file

@ -1,10 +1,11 @@
# J.A.R.V.I.S. database layout
config:
jarvis:
config:
key: String, config name
value: Any, config value
bans:
bans:
user: User ID
reason: String, default "Mr. Stark is displeased with your presence. Please leave."
admin: User ID, admin who banned user
@ -14,14 +15,14 @@ bans:
length: Optional(int), required for type=="temp", ban length in days, default 1
active: boolean, if ban is active
kicks:
kicks:
user: User ID
reason: String, default "Mr. Stark is displeased with your presence. Please leave."
admin: User ID, admin who kicked user
time: Datetime
guild: Guild ID
mutes:
mutes:
user: User ID
reason: String, default "Mr. Stark is annoyed by your voice. Please be quiet."
admin: User ID, admin who muted user
@ -31,7 +32,7 @@ mutes:
length: int, mute length in minutes, default 30, -1 for permanent
active: boolean, if mute is active
warns:
warns:
user: User ID
reason: String, default "Mr. Stark has defined rules of conduct. Please read them."
admin: User ID, admin who warned user
@ -40,7 +41,7 @@ warns:
expiry: int, hours from warning until it expires, default 24
active: boolean, if warning is active or expired
jokes:
jokes:
id: String, Reddit post ID
body: String, joke text
created_utc: int, epoch timestamp of upload
@ -48,32 +49,37 @@ jokes:
score: int, Reddit upvote score
title: string, joke title
locks:
locks:
channel: Channel ID
reason: String, default "Mr. Stark is reviewing this channel. Please hold on."
admin: User ID, admin who locked channel
guild: Guild ID
settings:
settings:
guild: Guild ID
setting: String, setting name
value: Any, setting value
autoreact:
autoreact:
guild: Guild ID
channel: Channel ID
reactions: List[Emote ID]
admin: User ID, admin who added autoreact
time: datetime
stars:
stars:
message: Message ID
channel: Channel ID
guild: Guild ID
admin: User ID, admin who starred
time: Datetime
modlog:
modlog:
user: User ID
activity: String
time: Datetime
ctc2:
guesses:
guess: String
user: User ID
correct: boolean