added optional chance to GifJoke
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
|
import logging
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from nextcord import Message, Client
|
from nextcord import Message, Client
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Joke:
|
class Joke:
|
||||||
@property
|
@property
|
||||||
@@ -19,4 +23,11 @@ class GifJoke(Joke):
|
|||||||
url: str
|
url: str
|
||||||
|
|
||||||
async def respond(self, message: Message, client: Client, match: re.Match):
|
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)
|
await message.reply(self.url)
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class NotLikeThisJoke(base.GifJoke):
|
|||||||
|
|
||||||
class ChiliJoke(base.GifJoke):
|
class ChiliJoke(base.GifJoke):
|
||||||
url = 'https://tenor.com/view/office-gif-20038284'
|
url = 'https://tenor.com/view/office-gif-20038284'
|
||||||
|
chance: float = 1 / 5
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def regex(self) -> re.Pattern:
|
def regex(self) -> re.Pattern:
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class ReactionData:
|
|||||||
|
|
||||||
def read_sql(self, query: str, con: sqlite3.Connection = None):
|
def read_sql(self, query: str, con: sqlite3.Connection = None):
|
||||||
close = con is 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)
|
res = pd.read_sql(query, con=con, index_col=None)
|
||||||
LOGGER.info(f'Read {res.shape[0]} reactions')
|
LOGGER.info(f'Read {res.shape[0]} reactions')
|
||||||
|
|||||||
Reference in New Issue
Block a user