Add gif search and /reset-cache

This commit is contained in:
Cal Corum 2023-11-16 13:05:45 -06:00
parent 16225aea13
commit d1e731b57d
2 changed files with 33 additions and 14 deletions

View File

@ -1,6 +1,9 @@
import copy
import csv
import discord
import db_calls
from helpers import *
from db_calls import *
from discord import Member
@ -411,6 +414,15 @@ class Admins(commands.Cog):
logging.error(f'update errors:\n{e_string}')
await ctx.send(f'I encountered the following errors:\n\n{e_string}')
@app_commands.command(name='reset-cache', description='Reset all cached player cards for gameplay')
@app_commands.checks.has_any_role('Da Commish')
async def reset_cache_command(self, interaction: discord.Interaction):
await interaction.response.defer()
db_calls.PLAYER_CACHE = {}
await interaction.edit_original_response(
content=random_gif(random_from_list(['all done', 'yes sir', 'complete']))
)
@commands.command(name='tc', help='Mod: Test command')
@commands.is_owner()
async def test_choices_command(self, ctx):

View File

@ -1139,22 +1139,8 @@ def random_conf_gif():
'https://tenor.com/view/done-and-done-ron-swanson-gotchu-gif-10843254',
'https://tenor.com/view/sponge-bob-thumbs-up-ok-smile-gif-12038157',
'https://tenor.com/view/thumbs-up-cool-okay-bye-gif-8633196',
'https://media.giphy.com/media/zCME2Cd20Czvy/giphy.gif',
'https://media.giphy.com/media/xT0xeJpckCr0qGAFna/giphy.gif',
'https://media0.giphy.com/media/l0MYw3oeYCUJhj5FC/200.gif',
'https://media2.giphy.com/media/52FcaTVc9Y1rk7q1NQ/200.gif',
'https://i0.wp.com/media1.giphy.com/media/iwvuPyfi7z14I/giphy.gif',
'https://media1.tenor.com/images/859a2d3b201fbacec13904242976b9e0/tenor.gif',
'https://media.giphy.com/media/3o6ZsZbUukGiYMf2a4/giphy.gif',
'https://media.giphy.com/media/l0Iyl55kTeh71nTXy/giphy.gif',
'https://media.giphy.com/media/3o7qDEq2bMbcbPRQ2c/giphy.gif',
'https://media.giphy.com/media/3orieTbyzN9QNCDANa/giphy.gif',
'https://media.giphy.com/media/l3V0JGUuz4xght7Py/giphy.gif',
'https://media.giphy.com/media/o1H5mqZKB0RCE/giphy.gif',
'https://media.giphy.com/media/Rhf0uSWt1P2TFqVMZK/giphy.gif',
'https://media.giphy.com/media/UIMAFTRUcf6V71BGsd/giphy.gif',
'https://media.giphy.com/media/xUOwFYnEb6rv4Oxx6M/giphy.gif',
'https://media.giphy.com/media/6bdiLSKOwgR6ekaTSS/giphy.gif',
'https://tenor.com/bc1OJ.gif',
'https://tenor.com/1EmF.gif',
'https://tenor.com/ZYCh.gif',
@ -3149,3 +3135,24 @@ def player_bcard(this_player):
# return PITCHER_BATTING_CARD
else:
return this_player['image']
def random_gif(search_term: str):
req_url = f'https://api.giphy.com/v1/gifs/translate?s={search_term}&api_key=H86xibttEuUcslgmMM6uu74IgLEZ7UOD'
resp = requests.get(req_url, timeout=3)
if resp.status_code == 200:
data = resp.json()
if 'trump' in data['data']['title']:
return random_conf_gif()
else:
return data['data']['url']
else:
logging.warning(resp.text)
raise ValueError(f'DB: {resp.text}')
def random_from_list(data_list: list):
item = data_list[random.randint(0, len(data_list) - 1)]
logging.info(f'random_from_list: {item}')
return item