Added soak tracker

This commit is contained in:
Cal Corum 2023-06-20 16:57:52 -05:00
parent 61c464f6ba
commit 2c8e20e614

View File

@ -47,11 +47,20 @@ class Roles(Model):
database = db
class Soaks(Model):
user = IntegerField()
message_id = IntegerField()
timestamp = DateTimeField()
class Meta:
database = db
class Fun(commands.Cog):
def __init__(self, bot):
self.bot = bot
db.create_tables([Creator, Command, Roles])
db.create_tables([Creator, Command, Roles, Soaks])
db.close()
self.daily_check.start()
@ -156,6 +165,67 @@ class Fun(commands.Cog):
async def cog_command_error(self, ctx, error):
await ctx.send(f'{error}')
@commands.Cog.listener(name='on_message')
async def on_message_listener(self, message):
if message.author.bot or message.channel.guild.id != int(os.environ.get('GUILD_ID')) \
or message.content[:1] == '!':
logging.info(f'skipping mention of soaking')
return
tm = message.content.lower()
if 'soak' in tm or 'soaking' in tm:
squery = Soaks.select().order_by(-Soaks.id).limit(1)
if squery.count() > 0:
last_soak = squery[0]
else:
last_soak = None
new_soak = Soaks.insert(
{'user': message.author.id, 'message_id': message.id, 'timestamp': datetime.now()}
).execute()
db.close()
time_since = datetime.now() - last_soak.timestamp
# logging.info(f'time_since: {time_since} / seconds: {time_since.seconds} / days: {time_since.days}')
gif_search = None
if time_since.days >= 2:
ts_string = f'{time_since.days} days'
if time_since.days > 30:
gif_search = 'elite'
elif time_since.days > 14:
gif_search = 'pretty good'
else:
if time_since.seconds >= 7200:
ts_string = f'{time_since.seconds // 3600} hours'
gif_search = 'whats wrong with you'
else:
if time_since.seconds >= 120:
ts_string = f'{time_since.seconds // 60} minutes'
else:
ts_string = f'{time_since.seconds} seconds'
gif_search = 'pathetic'
await message.channel.send(
f'It has been {ts_string} since soaking was mentioned.'
)
if gif_search is not None:
try:
await message.channel.send(random_gif(gif_search))
except Exception as e:
logging.error(e)
@commands.command(name='lastsoak', aliases=['ls'], help='Get a link to the last mention of soaking')
async def last_soak_command(self, ctx):
squery = Soaks.select().order_by(-Soaks.id).limit(1)
if squery.count() > 0:
last_soak = squery[0]
else:
await ctx.send(f'I could not find the last mention of soaking.')
return
message = await ctx.fetch_message(last_soak.message_id)
await ctx.send(f'The last mention of soaking was: {message.jump_url}')
@commands.command(name='cc', help='Run custom custom command')
async def custom_command(self, ctx, command):
chosen = Command.get_or_none(fn.Lower(Command.name) == command.lower())