diff --git a/src/kwaylon/jokes/base.py b/src/kwaylon/jokes/base.py index 17a6b55..a74fcb0 100644 --- a/src/kwaylon/jokes/base.py +++ b/src/kwaylon/jokes/base.py @@ -1,7 +1,11 @@ +import logging +import random import re from nextcord import Message, Client +LOGGER = logging.getLogger(__name__) + class Joke: @property @@ -19,4 +23,11 @@ class GifJoke(Joke): url: str async def respond(self, message: Message, client: Client, match: re.Match): + if hasattr(self, 'chance'): + roll = random.random() + if roll > self.chance: + LOGGER.info(f'Roll was too high {roll:.2f} > {self.chance:.2f}') + return + else: + LOGGER.info(f'Passed roll threshold {roll:.2f} <= {self.chance:.2f}') await message.reply(self.url) diff --git a/src/kwaylon/jokes/jokes.py b/src/kwaylon/jokes/jokes.py index 4af887b..12b11a5 100644 --- a/src/kwaylon/jokes/jokes.py +++ b/src/kwaylon/jokes/jokes.py @@ -123,6 +123,7 @@ class NotLikeThisJoke(base.GifJoke): class ChiliJoke(base.GifJoke): url = 'https://tenor.com/view/office-gif-20038284' + chance: float = 1 / 5 @property def regex(self) -> re.Pattern: diff --git a/src/kwaylon/reactions.py b/src/kwaylon/reactions.py index f6a93ca..dc92cdc 100644 --- a/src/kwaylon/reactions.py +++ b/src/kwaylon/reactions.py @@ -51,7 +51,7 @@ class ReactionData: def read_sql(self, query: str, con: sqlite3.Connection = None): close = con is None - con = con or sqlite3.connect(self.path) + con = con or self.connect() res = pd.read_sql(query, con=con, index_col=None) LOGGER.info(f'Read {res.shape[0]} reactions')