From 5077b79b754292b1cae3f65efba0b89e07230dd1 Mon Sep 17 00:00:00 2001 From: Tibo Ulens Date: Mon, 15 Jan 2024 20:31:36 +0100 Subject: [PATCH 1/3] feat(bot): add redis cache --- Makefile | 8 +++++++- bot/bot.py | 12 ++++++++++-- docker-compose.yaml | 21 +++++++++++++++++++++ poetry.lock | 17 ++++++++++++++++- pyproject.toml | 1 + 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4552691..9da73f2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all fmt migrate down dbd setup +.PHONY: all dev fmt lint setup dbd migrate psql chd redis down all: docker compose up --build freud_bot freud_bot_webconfig @@ -27,5 +27,11 @@ migrate: dbd psql: dbd docker exec -it freud_bot_db psql -d freud_bot -h freud_bot_db -U postgres_user +chd: + docker compose up --build freud_bot_cache --remove-orphans -d + +redis: chd + docker exec -it freud_bot_cache redis-cli -h freud_bot_cache -p 6379 + down: docker compose down diff --git a/bot/bot.py b/bot/bot.py index efcb0d6..f6a5389 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,14 +1,16 @@ import asyncio from contextlib import suppress import importlib.util -from typing import Sequence - import logging from logging import Logger +import os +from typing import Sequence + import discord from discord.abc import Snowflake from discord.ext import commands from discord.utils import MISSING +import redis.asyncio as redis from bot.log.guild_adapter import GuildAdapter @@ -26,6 +28,9 @@ def __init__(self, *args, **kwargs): self.discord_logger: GuildAdapter = None self.loop = asyncio.get_running_loop() + self.redis = redis.Redis.from_url(os.environ["CH_URL"]) + logger.info("cache connected") + @classmethod async def create(cls) -> "Bot": """Create and return a new bot instance""" @@ -112,6 +117,9 @@ async def close(self) -> None: await super().close() logger.info("client closed") + await self.redis.aclose() + logger.info("cache closed") + await self.db.dispose() logger.info("database closed") diff --git a/docker-compose.yaml b/docker-compose.yaml index ebf11e7..d2297c7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,8 @@ services: environment: - DB_URL=postgresql+asyncpg://postgres_user@freud_bot_db/freud_bot - PGPASSWORD=postgres_password + + - CH_URL=redis://@freud_bot_cache:6379/0 logging: options: max-size: "4096m" @@ -15,6 +17,7 @@ services: - smtp_credentials depends_on: - freud_bot_db + - freud_bot_cache freud_bot_dev: build: @@ -25,6 +28,8 @@ services: environment: - DB_URL=postgresql+asyncpg://postgres_user@freud_bot_db/freud_bot - PGPASSWORD=postgres_password + + - CH_URL=redis://@freud_bot_cache:6379/0 logging: options: max-size: "4096m" @@ -33,6 +38,7 @@ services: - smtp_credentials depends_on: - freud_bot_db + - freud_bot_cache freud_bot_webconfig: image: ghcr.io/tibo-ulens/freud_bot_webconfig:latest @@ -100,6 +106,21 @@ services: timeout: 5s retries: 2 + freud_bot_cache: + image: redis:7.2-alpine + container_name: freud_bot_cache + restart: unless-stopped + logging: + options: + max-size: "4096m" + ports: + - "6379:6379" + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10m + timeout: 5s + retries: 2 + volumes: freud_bot_data: external: true diff --git a/poetry.lock b/poetry.lock index 820b9a2..ef452e4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1156,6 +1156,21 @@ files = [ [package.extras] dev = ["atomicwrites (==1.2.1)", "attrs (==19.2.0)", "coverage (==6.5.0)", "hatch", "invoke (==1.7.3)", "more-itertools (==4.3.0)", "pbr (==4.3.0)", "pluggy (==1.0.0)", "py (==1.11.0)", "pytest (==7.2.0)", "pytest-cov (==4.0.0)", "pytest-timeout (==2.1.0)", "pyyaml (==5.1)"] +[[package]] +name = "redis" +version = "5.0.1" +description = "Python client for Redis database and key-value store" +optional = false +python-versions = ">=3.7" +files = [ + {file = "redis-5.0.1-py3-none-any.whl", hash = "sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f"}, + {file = "redis-5.0.1.tar.gz", hash = "sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f"}, +] + +[package.extras] +hiredis = ["hiredis (>=1.0.0)"] +ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)"] + [[package]] name = "requests" version = "2.31.0" @@ -1528,4 +1543,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "=3.11.5" -content-hash = "a6479a3f6bbe629ac0417f64077b75e94e67e3e0c5b441a8380a0260340acf4d" +content-hash = "64c0912a81677edd7844047da6d6bdcac0f26a99ba7a9c0c7c317f13f57da7f8" diff --git a/pyproject.toml b/pyproject.toml index 0228c97..e6cbc5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ asyncpg = "^0.28.0" selenium = "^4.4.3" requests = "^2.28.1" CairoSVG = "^2.5.2" +redis = "^5.0.1" [tool.poetry.group.webconfig.dependencies] fastapi = "^0.97.0" From 1defe4207d58cb0c55cc58ab2d07b81a15472841 Mon Sep 17 00:00:00 2001 From: Tibo Ulens Date: Mon, 15 Jan 2024 22:58:58 +0100 Subject: [PATCH 2/3] feat(bot): add confession replies --- bot/bot.py | 2 +- bot/extensions/fun/confess.py | 105 +++++++++++++++++++++++++---- poetry.lock | 123 +++++++++++++++++++++++++++++++++- pyproject.toml | 2 +- 4 files changed, 216 insertions(+), 16 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index f6a5389..a46fd38 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -28,7 +28,7 @@ def __init__(self, *args, **kwargs): self.discord_logger: GuildAdapter = None self.loop = asyncio.get_running_loop() - self.redis = redis.Redis.from_url(os.environ["CH_URL"]) + self.redis = redis.Redis.from_url(os.environ["CH_URL"], decode_responses=True) logger.info("cache connected") @classmethod diff --git a/bot/extensions/fun/confess.py b/bot/extensions/fun/confess.py index b0f860a..f18cd41 100644 --- a/bot/extensions/fun/confess.py +++ b/bot/extensions/fun/confess.py @@ -1,5 +1,6 @@ import random from enum import Enum +import logging import discord from discord import ( @@ -11,7 +12,9 @@ Colour, Member, ) +from discord.ext.commands import Context from discord.ui import View, Button +from redis.asyncio import Redis from models.config import Config from models.profile_statistics import ProfileStatistics @@ -24,6 +27,9 @@ from bot.extensions import ErrorHandledCog +logger = logging.getLogger("bot") + + class ConfessionType(Enum): NORMAL = (None, "🥷 Anonymous Confession 🥷", "Confession sent") RUSSIAN = ( @@ -56,12 +62,16 @@ def __init__( confession: str, poster: Member, type_: ConfessionType, + reply: str | None, + redis: Redis, confession_channel: TextChannel, approval_channel: TextChannel, ): self.confession = confession self.poster = poster self.type_ = type_ + self.reply = reply + self.redis = redis self.confession_channel = confession_channel self.approval_channel = approval_channel @@ -72,8 +82,13 @@ async def send_pending(self): description=self.confession, ) + if self.reply is not None: + pending_embed.set_author(name=f"Reply to #{self.reply}") + pending_view = PendingApprovalView( + redis=self.redis, confession=pending_embed, + reply=self.reply, confession_channel=self.confession_channel, poster=self.poster, chance=self.type_.chance, @@ -88,13 +103,17 @@ async def send_pending(self): class PendingApprovalView(View): def __init__( self, + redis: Redis, confession: Embed, + reply: str | None, confession_channel: TextChannel, poster: Member, - chance: None | float, + chance: float | None, ): super().__init__(timeout=None) + self.redis = redis self.confession = confession + self.reply = reply self.confession_channel = confession_channel self.poster = poster self.chance = chance @@ -104,7 +123,10 @@ async def approve(self, ia: Interaction, _btn: Button): for item in self.children: item.disabled = True + confession_id = await self.redis.incr("confessionid") + self.confession.colour = Colour.from_str("#3fc03f") + self.confession.title = f"{self.confession.title} (#{confession_id})" await self.message.edit(embed=self.confession, view=self) await ia.response.defer() @@ -118,7 +140,25 @@ async def approve(self, ia: Interaction, _btn: Button): actual_confession.add_field(name="Sent By", value=self.poster.mention) - await self.confession_channel.send(embed=actual_confession) + if self.reply is not None: + reply_msg_id = int(await self.redis.get(f"confession:{self.reply}")) + reply_msg = self.confession_channel.get_partial_message(reply_msg_id) + + try: + thread = await reply_msg.create_thread( + name="confession", reason="confession reply" + ) + except discord.errors.HTTPException as err: + if err.code == 160004: + thread = self.confession_channel.get_thread(reply_msg_id) + else: + raise err + + actual_msg = await thread.send(embed=actual_confession) + else: + actual_msg = await self.confession_channel.send(embed=actual_confession) + + await self.redis.set(f"confession:{confession_id}", actual_msg.id) @discord.ui.button(label="⨯", style=ButtonStyle.red) async def reject(self, ia: Interaction, _btn: Button): @@ -136,8 +176,13 @@ class Confess(ErrorHandledCog): name="confess", description="Confession related commands", guild_only=True ) - @staticmethod - async def confess_inner(ia: Interaction, confession: str, type_: ConfessionType): + async def confess_inner( + self, + ia: Interaction, + confession: str, + type_: ConfessionType, + reply: str | None = None, + ): config = await Config.get(ia.guild_id) approval_channel = discord.utils.get( ia.guild.channels, id=config.confession_approval_channel @@ -146,10 +191,29 @@ async def confess_inner(ia: Interaction, confession: str, type_: ConfessionType) ia.guild.channels, id=config.confession_channel ) + if reply is not None: + reply_msg_id = await self.bot.redis.get(f"confession:{reply}") + if reply_msg_id is None: + await ia.response.send_message( + f"{reply} is not a valid confession ID", ephemeral=True + ) + return + else: + try: + await confession_channel.fetch_message(int(reply_msg_id)) + except discord.errors.HTTPException: + await ia.response.send_message( + f"{reply} is not a valid confession ID (keep in mind that you cannot reply to other replies)", + ephemeral=True, + ) + return + confession_wrapper = Confession( confession=confession, poster=ia.user, type_=type_, + reply=reply, + redis=self.bot.redis, confession_channel=confession_channel, approval_channel=approval_channel, ) @@ -163,34 +227,49 @@ async def confess_inner(ia: Interaction, confession: str, type_: ConfessionType) @confess_group.command( name="normal", description="send a normal, anonymous confession" ) - @app_commands.describe(confession="The confession you want to post") + @app_commands.describe( + confession="The confession you want to post", + reply="The ID of the confession you want to reply to", + ) @check_has_config_option("confession_approval_channel") @check_has_config_option("confession_channel") @check_user_is_verified() - async def normal_confess(self, ia: Interaction, confession: str): - await self.confess_inner(ia, confession, ConfessionType.NORMAL) + async def normal_confess( + self, ia: Interaction, confession: str, reply: str | None = None + ): + await self.confess_inner(ia, confession, ConfessionType.NORMAL, reply) @confess_group.command( name="russian", description="send a russian roulette confession with a 1 in 6 chance of not being anonymous", ) - @app_commands.describe(confession="The confession you want to post") + @app_commands.describe( + confession="The confession you want to post", + reply="The ID of the confession you want to reply to", + ) @check_has_config_option("confession_approval_channel") @check_has_config_option("confession_channel") @check_user_is_verified() - async def russian_confess(self, ia: Interaction, confession: str): - await self.confess_inner(ia, confession, ConfessionType.RUSSIAN) + async def russian_confess( + self, ia: Interaction, confession: str, reply: str | None = None + ): + await self.confess_inner(ia, confession, ConfessionType.RUSSIAN, reply) @confess_group.command( name="extreme", description="send an extreme roulette confession with a 1 in 2 chance of not being anonymous", ) - @app_commands.describe(confession="The confession you want to post") + @app_commands.describe( + confession="The confession you want to post", + reply="The ID of the confession you want to reply to", + ) @check_has_config_option("confession_approval_channel") @check_has_config_option("confession_channel") @check_user_is_verified() - async def russian_confess(self, ia: Interaction, confession: str): - await self.confess_inner(ia, confession, ConfessionType.EXTREME) + async def russian_confess( + self, ia: Interaction, confession: str, reply: str | None = None + ): + await self.confess_inner(ia, confession, ConfessionType.EXTREME, reply) async def setup(bot: Bot): diff --git a/poetry.lock b/poetry.lock index ef452e4..d5c57f3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -749,6 +749,124 @@ files = [ {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, ] +[[package]] +name = "hiredis" +version = "2.3.2" +description = "Python wrapper for hiredis" +optional = false +python-versions = ">=3.7" +files = [ + {file = "hiredis-2.3.2-cp310-cp310-macosx_10_15_universal2.whl", hash = "sha256:742093f33d374098aa21c1696ac6e4874b52658c870513a297a89265a4d08fe5"}, + {file = "hiredis-2.3.2-cp310-cp310-macosx_10_15_x86_64.whl", hash = "sha256:9e14fb70ca4f7efa924f508975199353bf653f452e4ef0a1e47549e208f943d7"}, + {file = "hiredis-2.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6d7302b4b17fcc1cc727ce84ded7f6be4655701e8d58744f73b09cb9ed2b13df"}, + {file = "hiredis-2.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed63e8b75c193c5e5a8288d9d7b011da076cc314fafc3bfd59ec1d8a750d48c8"}, + {file = "hiredis-2.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6b4edee59dc089bc3948f4f6fba309f51aa2ccce63902364900aa0a553a85e97"}, + {file = "hiredis-2.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a6481c3b7673a86276220140456c2a6fbfe8d1fb5c613b4728293c8634134824"}, + {file = "hiredis-2.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:684840b014ce83541a087fcf2d48227196576f56ae3e944d4dfe14c0a3e0ccb7"}, + {file = "hiredis-2.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1c4c0bcf786f0eac9593367b6279e9b89534e008edbf116dcd0de956524702c8"}, + {file = "hiredis-2.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:66ab949424ac6504d823cba45c4c4854af5c59306a1531edb43b4dd22e17c102"}, + {file = "hiredis-2.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:322c668ee1c12d6c5750a4b1057e6b4feee2a75b3d25d630922a463cfe5e7478"}, + {file = "hiredis-2.3.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:bfa73e3f163c6e8b2ec26f22285d717a5f77ab2120c97a2605d8f48b26950dac"}, + {file = "hiredis-2.3.2-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:7f39f28ffc65de577c3bc0c7615f149e35bc927802a0f56e612db9b530f316f9"}, + {file = "hiredis-2.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:55ce31bf4711da879b96d511208efb65a6165da4ba91cb3a96d86d5a8d9d23e6"}, + {file = "hiredis-2.3.2-cp310-cp310-win32.whl", hash = "sha256:3dd63d0bbbe75797b743f35d37a4cca7ca7ba35423a0de742ae2985752f20c6d"}, + {file = "hiredis-2.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:ea002656a8d974daaf6089863ab0a306962c8b715db6b10879f98b781a2a5bf5"}, + {file = "hiredis-2.3.2-cp311-cp311-macosx_10_15_universal2.whl", hash = "sha256:adfbf2e9c38b77d0db2fb32c3bdaea638fa76b4e75847283cd707521ad2475ef"}, + {file = "hiredis-2.3.2-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:80b02d27864ebaf9b153d4b99015342382eeaed651f5591ce6f07e840307c56d"}, + {file = "hiredis-2.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bd40d2e2f82a483de0d0a6dfd8c3895a02e55e5c9949610ecbded18188fd0a56"}, + {file = "hiredis-2.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dfa904045d7cebfb0f01dad51352551cce1d873d7c3f80c7ded7d42f8cac8f89"}, + {file = "hiredis-2.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:28bd184b33e0dd6d65816c16521a4ba1ffbe9ff07d66873c42ea4049a62fed83"}, + {file = "hiredis-2.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f70481213373d44614148f0f2e38e7905be3f021902ae5167289413196de4ba4"}, + {file = "hiredis-2.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb8797b528c1ff81eef06713623562b36db3dafa106b59f83a6468df788ff0d1"}, + {file = "hiredis-2.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:02fc71c8333586871602db4774d3a3e403b4ccf6446dc4603ec12df563127cee"}, + {file = "hiredis-2.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:0da56915bda1e0a49157191b54d3e27689b70960f0685fdd5c415dacdee2fbed"}, + {file = "hiredis-2.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:e2674a5a3168349435b08fa0b82998ed2536eb9acccf7087efe26e4cd088a525"}, + {file = "hiredis-2.3.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:dc1c3fd49930494a67dcec37d0558d99d84eca8eb3f03b17198424538f2608d7"}, + {file = "hiredis-2.3.2-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:14c7b43205e515f538a9defb4e411e0f0576caaeeda76bb9993ed505486f7562"}, + {file = "hiredis-2.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:7bac7e02915b970c3723a7a7c5df4ba7a11a3426d2a3f181e041aa506a1ff028"}, + {file = "hiredis-2.3.2-cp311-cp311-win32.whl", hash = "sha256:63a090761ddc3c1f7db5e67aa4e247b4b3bb9890080bdcdadd1b5200b8b89ac4"}, + {file = "hiredis-2.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:70d226ab0306a5b8d408235cabe51d4bf3554c9e8a72d53ce0b3c5c84cf78881"}, + {file = "hiredis-2.3.2-cp312-cp312-macosx_10_15_universal2.whl", hash = "sha256:5c614552c6bd1d0d907f448f75550f6b24fb56cbfce80c094908b7990cad9702"}, + {file = "hiredis-2.3.2-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:9c431431abf55b64347ddc8df68b3ef840269cb0aa5bc2d26ad9506eb4b1b866"}, + {file = "hiredis-2.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a45857e87e9d2b005e81ddac9d815a33efd26ec67032c366629f023fe64fb415"}, + {file = "hiredis-2.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e138d141ec5a6ec800b6d01ddc3e5561ce1c940215e0eb9960876bfde7186aae"}, + {file = "hiredis-2.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:387f655444d912a963ab68abf64bf6e178a13c8e4aa945cb27388fd01a02e6f1"}, + {file = "hiredis-2.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4852f4bf88f0e2d9bdf91279892f5740ed22ae368335a37a52b92a5c88691140"}, + {file = "hiredis-2.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d711c107e83117129b7f8bd08e9820c43ceec6204fff072a001fd82f6d13db9f"}, + {file = "hiredis-2.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:92830c16885f29163e1c2da1f3c1edb226df1210ec7e8711aaabba3dd0d5470a"}, + {file = "hiredis-2.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:16b01d9ceae265d4ab9547be0cd628ecaff14b3360357a9d30c029e5ae8b7e7f"}, + {file = "hiredis-2.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:5986fb5f380169270a0293bebebd95466a1c85010b4f1afc2727e4d17c452512"}, + {file = "hiredis-2.3.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:49532d7939cc51f8e99efc326090c54acf5437ed88b9c904cc8015b3c4eda9c9"}, + {file = "hiredis-2.3.2-cp312-cp312-musllinux_1_1_s390x.whl", hash = "sha256:8f34801b251ca43ad70691fb08b606a2e55f06b9c9fb1fc18fd9402b19d70f7b"}, + {file = "hiredis-2.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:7298562a49d95570ab1c7fc4051e72824c6a80e907993a21a41ba204223e7334"}, + {file = "hiredis-2.3.2-cp312-cp312-win32.whl", hash = "sha256:e1d86b75de787481b04d112067a4033e1ecfda2a060e50318a74e4e1c9b2948c"}, + {file = "hiredis-2.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:6dbfe1887ffa5cf3030451a56a8f965a9da2fa82b7149357752b67a335a05fc6"}, + {file = "hiredis-2.3.2-cp37-cp37m-macosx_10_15_x86_64.whl", hash = "sha256:4fc242e9da4af48714199216eb535b61e8f8d66552c8819e33fc7806bd465a09"}, + {file = "hiredis-2.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e81aa4e9a1fcf604c8c4b51aa5d258e195a6ba81efe1da82dea3204443eba01c"}, + {file = "hiredis-2.3.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:419780f8583ddb544ffa86f9d44a7fcc183cd826101af4e5ffe535b6765f5f6b"}, + {file = "hiredis-2.3.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6871306d8b98a15e53a5f289ec1106a3a1d43e7ab6f4d785f95fcef9a7bd9504"}, + {file = "hiredis-2.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:88cb0b35b63717ef1e41d62f4f8717166f7c6245064957907cfe177cc144357c"}, + {file = "hiredis-2.3.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8c490191fa1218851f8a80c5a21a05a6f680ac5aebc2e688b71cbfe592f8fec6"}, + {file = "hiredis-2.3.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:4baf4b579b108062e91bd2a991dc98b9dc3dc06e6288db2d98895eea8acbac22"}, + {file = "hiredis-2.3.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:e627d8ef5e100556e09fb44c9571a432b10e11596d3c4043500080ca9944a91a"}, + {file = "hiredis-2.3.2-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:ba3dc0af0def8c21ce7d903c59ea1e8ec4cb073f25ece9edaec7f92a286cd219"}, + {file = "hiredis-2.3.2-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:56e9b7d6051688ca94e68c0c8a54a243f8db841911b683cedf89a29d4de91509"}, + {file = "hiredis-2.3.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:380e029bb4b1d34cf560fcc8950bf6b57c2ef0c9c8b7c7ac20b7c524a730fadd"}, + {file = "hiredis-2.3.2-cp37-cp37m-win32.whl", hash = "sha256:948d9f2ca7841794dd9b204644963a4bcd69ced4e959b0d4ecf1b8ce994a6daa"}, + {file = "hiredis-2.3.2-cp37-cp37m-win_amd64.whl", hash = "sha256:cfa67afe2269b2d203cd1389c00c5bc35a287cd57860441fb0e53b371ea6a029"}, + {file = "hiredis-2.3.2-cp38-cp38-macosx_10_15_universal2.whl", hash = "sha256:bcbe47da0aebc00a7cfe3ebdcff0373b86ce2b1856251c003e3d69c9db44b5a7"}, + {file = "hiredis-2.3.2-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:f2c9c0d910dd3f7df92f0638e7f65d8edd7f442203caf89c62fc79f11b0b73f8"}, + {file = "hiredis-2.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:01b6c24c0840ac7afafbc4db236fd55f56a9a0919a215c25a238f051781f4772"}, + {file = "hiredis-2.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c1f567489f422d40c21e53212a73bef4638d9f21043848150f8544ef1f3a6ad1"}, + {file = "hiredis-2.3.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:28adecb308293e705e44087a1c2d557a816f032430d8a2a9bb7873902a1c6d48"}, + {file = "hiredis-2.3.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:27e9619847e9dc70b14b1ad2d0fb4889e7ca18996585c3463cff6c951fd6b10b"}, + {file = "hiredis-2.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9a0026cfbf29f07649b0e34509091a2a6016ff8844b127de150efce1c3aff60b"}, + {file = "hiredis-2.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f9de7586522e5da6bee83c9cf0dcccac0857a43249cb4d721a2e312d98a684d1"}, + {file = "hiredis-2.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:e58494f282215fc461b06709e9a195a24c12ba09570f25bdf9efb036acc05101"}, + {file = "hiredis-2.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:de3a32b4b76d46f1eb42b24a918d51d8ca52411a381748196241d59a895f7c5c"}, + {file = "hiredis-2.3.2-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:1979334ccab21a49c544cd1b8d784ffb2747f99a51cb0bd0976eebb517628382"}, + {file = "hiredis-2.3.2-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:0c0773266e1c38a06e7593bd08870ac1503f5f0ce0f5c63f2b4134b090b5d6a4"}, + {file = "hiredis-2.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:bd1cee053416183adcc8e6134704c46c60c3f66b8faaf9e65bf76191ca59a2f7"}, + {file = "hiredis-2.3.2-cp38-cp38-win32.whl", hash = "sha256:5341ce3d01ef3c7418a72e370bf028c7aeb16895e79e115fe4c954fff990489e"}, + {file = "hiredis-2.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:8fc7197ff33047ce43a67851ccf190acb5b05c52fd4a001bb55766358f04da68"}, + {file = "hiredis-2.3.2-cp39-cp39-macosx_10_15_universal2.whl", hash = "sha256:f47775e27388b58ce52f4f972f80e45b13c65113e9e6b6bf60148f893871dc9b"}, + {file = "hiredis-2.3.2-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:9412a06b8a8e09abd6313d96864b6d7713c6003a365995a5c70cfb9209df1570"}, + {file = "hiredis-2.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f3020b60e3fc96d08c2a9b011f1c2e2a6bdcc09cb55df93c509b88be5cb791df"}, + {file = "hiredis-2.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:53d0f2c59bce399b8010a21bc779b4f8c32d0f582b2284ac8c98dc7578b27bc4"}, + {file = "hiredis-2.3.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:57c0d0c7e308ed5280a4900d4468bbfec51f0e1b4cde1deae7d4e639bc6b7766"}, + {file = "hiredis-2.3.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1d63318ca189fddc7e75f6a4af8eae9c0545863619fb38cfba5f43e81280b286"}, + {file = "hiredis-2.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e741ffe4e2db78a1b9dd6e5d29678ce37fbaaf65dfe132e5b82a794413302ef1"}, + {file = "hiredis-2.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eb98038ccd368e0d88bd92ee575c58cfaf33e77f788c36b2a89a84ee1936dc6b"}, + {file = "hiredis-2.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:eae62ed60d53b3561148bcd8c2383e430af38c0deab9f2dd15f8874888ffd26f"}, + {file = "hiredis-2.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:ca33c175c1cf60222d9c6d01c38fc17ec3a484f32294af781de30226b003e00f"}, + {file = "hiredis-2.3.2-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:0c5f6972d2bdee3cd301d5c5438e31195cf1cabf6fd9274491674d4ceb46914d"}, + {file = "hiredis-2.3.2-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:a6b54dabfaa5dbaa92f796f0c32819b4636e66aa8e9106c3d421624bd2a2d676"}, + {file = "hiredis-2.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e96cd35df012a17c87ae276196ea8f215e77d6eeca90709eb03999e2d5e3fd8a"}, + {file = "hiredis-2.3.2-cp39-cp39-win32.whl", hash = "sha256:63b99b5ea9fe4f21469fb06a16ca5244307678636f11917359e3223aaeca0b67"}, + {file = "hiredis-2.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:a50c8af811b35b8a43b1590cf890b61ff2233225257a3cad32f43b3ec7ff1b9f"}, + {file = "hiredis-2.3.2-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:7e8bf4444b09419b77ce671088db9f875b26720b5872d97778e2545cd87dba4a"}, + {file = "hiredis-2.3.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5bd42d0d45ea47a2f96babd82a659fbc60612ab9423a68e4a8191e538b85542a"}, + {file = "hiredis-2.3.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80441b55edbef868e2563842f5030982b04349408396e5ac2b32025fb06b5212"}, + {file = "hiredis-2.3.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ec444ab8f27562a363672d6a7372bc0700a1bdc9764563c57c5f9efa0e592b5f"}, + {file = "hiredis-2.3.2-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:f9f606e810858207d4b4287b4ef0dc622c2aa469548bf02b59dcc616f134f811"}, + {file = "hiredis-2.3.2-pp37-pypy37_pp73-macosx_10_15_x86_64.whl", hash = "sha256:c3dde4ca00fe9eee3b76209711f1941bb86db42b8a75d7f2249ff9dfc026ab0e"}, + {file = "hiredis-2.3.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d4dd676107a1d3c724a56a9d9db38166ad4cf44f924ee701414751bd18a784a0"}, + {file = "hiredis-2.3.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce42649e2676ad783186264d5ffc788a7612ecd7f9effb62d51c30d413a3eefe"}, + {file = "hiredis-2.3.2-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8e3f8b1733078ac663dad57e20060e16389a60ab542f18a97931f3a2a2dd64a4"}, + {file = "hiredis-2.3.2-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:532a84a82156a82529ec401d1c25d677c6543c791e54a263aa139541c363995f"}, + {file = "hiredis-2.3.2-pp38-pypy38_pp73-macosx_10_15_x86_64.whl", hash = "sha256:4d59f88c4daa36b8c38e59ac7bffed6f5d7f68eaccad471484bf587b28ccc478"}, + {file = "hiredis-2.3.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a91a14dd95e24dc078204b18b0199226ee44644974c645dc54ee7b00c3157330"}, + {file = "hiredis-2.3.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bb777a38797c8c7df0444533119570be18d1a4ce5478dffc00c875684df7bfcb"}, + {file = "hiredis-2.3.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d47c915897a99d0d34a39fad4be97b4b709ab3d0d3b779ebccf2b6024a8c681e"}, + {file = "hiredis-2.3.2-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:333b5e04866758b11bda5f5315b4e671d15755fc6ed3b7969721bc6311d0ee36"}, + {file = "hiredis-2.3.2-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:c8937f1100435698c18e4da086968c4b5d70e86ea718376f833475ab3277c9aa"}, + {file = "hiredis-2.3.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fa45f7d771094b8145af10db74704ab0f698adb682fbf3721d8090f90e42cc49"}, + {file = "hiredis-2.3.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:33d5ebc93c39aed4b5bc769f8ce0819bc50e74bb95d57a35f838f1c4378978e0"}, + {file = "hiredis-2.3.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a797d8c7df9944314d309b0d9e1b354e2fa4430a05bb7604da13b6ad291bf959"}, + {file = "hiredis-2.3.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:e15a408f71a6c8c87b364f1f15a6cd9c1baca12bbc47a326ac8ab99ec7ad3c64"}, + {file = "hiredis-2.3.2.tar.gz", hash = "sha256:733e2456b68f3f126ddaf2cd500a33b25146c3676b97ea843665717bda0c5d43"}, +] + [[package]] name = "idna" version = "3.4" @@ -1167,6 +1285,9 @@ files = [ {file = "redis-5.0.1.tar.gz", hash = "sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f"}, ] +[package.dependencies] +hiredis = {version = ">=1.0.0", optional = true, markers = "extra == \"hiredis\""} + [package.extras] hiredis = ["hiredis (>=1.0.0)"] ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)"] @@ -1543,4 +1664,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "=3.11.5" -content-hash = "64c0912a81677edd7844047da6d6bdcac0f26a99ba7a9c0c7c317f13f57da7f8" +content-hash = "4a1c51728a19969fc73d8f8bda3e1878365238b80694cd18446932562d8776b2" diff --git a/pyproject.toml b/pyproject.toml index e6cbc5b..7e30ca8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ asyncpg = "^0.28.0" selenium = "^4.4.3" requests = "^2.28.1" CairoSVG = "^2.5.2" -redis = "^5.0.1" +redis = {extras = ["hiredis"], version = "^5.0.1"} [tool.poetry.group.webconfig.dependencies] fastapi = "^0.97.0" From e8870b7f2fba2a0fa329732e3c309485d2f58947 Mon Sep 17 00:00:00 2001 From: Tibo Ulens Date: Mon, 15 Jan 2024 23:09:16 +0100 Subject: [PATCH 3/3] feat(bot): set confession id keys to expire after 1 day --- bot/extensions/fun/confess.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/extensions/fun/confess.py b/bot/extensions/fun/confess.py index f18cd41..e6ce6bd 100644 --- a/bot/extensions/fun/confess.py +++ b/bot/extensions/fun/confess.py @@ -159,6 +159,7 @@ async def approve(self, ia: Interaction, _btn: Button): actual_msg = await self.confession_channel.send(embed=actual_confession) await self.redis.set(f"confession:{confession_id}", actual_msg.id) + await self.redis.expire(f"confession:{confession_id}", 86400) @discord.ui.button(label="⨯", style=ButtonStyle.red) async def reject(self, ia: Interaction, _btn: Button):