1ere version fonctionnelle
This commit is contained in:
parent
dde7a33f90
commit
fe7937f0ee
41
getgif.py
Normal file
41
getgif.py
Normal file
@ -0,0 +1,41 @@
|
||||
import requests
|
||||
import json
|
||||
import random
|
||||
|
||||
################################
|
||||
# #
|
||||
# Config #
|
||||
# #
|
||||
################################
|
||||
apikey = "---------------------"
|
||||
ckey = "KpopBot"
|
||||
lmt = 100000
|
||||
debug = False
|
||||
|
||||
def getGifFromTenor(recherche:str)-> str:
|
||||
"""
|
||||
Cette fonction va faire une requette sur le site tenor et retourne
|
||||
le lien d'un gif aleatoire correspondant a la recherche
|
||||
|
||||
:param recherche: Le terme de la recherche sur tenor
|
||||
:type recherche: chaine de caractere (str)
|
||||
:return: lien vers un gif
|
||||
:rtype: chaine de caractere (str)
|
||||
|
||||
exemple:
|
||||
>>> getGifFromTenor("kim dahyun")
|
||||
"https://c.tenor.com/HGS52u8LsWgAAAAC/thumbs-up-dahyun.gif"
|
||||
"""
|
||||
if debug : print("request :","https://tenor.googleapis.com/v2/search?q=%s&key=%s&client_key=%s" % (recherche, apikey, ckey))
|
||||
r = requests.get("https://tenor.googleapis.com/v2/search?q=%s&key=%s&client_key=%s" % (recherche, apikey, ckey))
|
||||
if debug : print("status code :",r.status_code)
|
||||
if r.status_code == 200 :
|
||||
dictGif = json.loads(r.content)
|
||||
if debug : print(dictGif)
|
||||
return(dictGif["results"][random.randint(0, len(dictGif["results"])-1)]["media_formats"]["gif"]['url'])
|
||||
return "Sorry no gif for you T-T"
|
||||
|
||||
if __name__ == "__main__":
|
||||
#10 gif aleatoire de kim dahyn
|
||||
for i in range(10):
|
||||
print(getGifFromTenor("kim dahyun"))
|
12
main.py
Normal file
12
main.py
Normal file
@ -0,0 +1,12 @@
|
||||
import discord
|
||||
import getgif
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
client = discord.Client(intents=intents)
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
if message.author == client.user:
|
||||
return
|
||||
if message.content.startswith('KIM DAHYUN'):
|
||||
await message.channel.send(getGif.getGifFromTenor("kim dahyun"))
|
||||
client.run('---------------------------------')
|
Loading…
Reference in New Issue
Block a user