added optional chance to GifJoke

This commit is contained in:
jsl12
2022-02-24 17:17:39 -06:00
parent b82ab54ba6
commit bf99c4e40f
3 changed files with 13 additions and 1 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -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')