utilisation nouvelle méthode pour les slashcommands et changement complet de la commande NSFW
This commit is contained in:
parent
e5d3319841
commit
a46cb38b2d
1 changed files with 38 additions and 58 deletions
|
@ -5,7 +5,7 @@ from discord.ext import commands
|
||||||
from random import choice
|
from random import choice
|
||||||
from asyncpraw import Reddit
|
from asyncpraw import Reddit
|
||||||
from discord_slash import cog_ext
|
from discord_slash import cog_ext
|
||||||
from utils.core import randomImage
|
from utils.core import randomImage, isSlash
|
||||||
|
|
||||||
def setup(client):
|
def setup(client):
|
||||||
client.add_cog(Internet(client))
|
client.add_cog(Internet(client))
|
||||||
|
@ -18,15 +18,7 @@ class Internet(commands.Cog):
|
||||||
@commands.command(name='memes', aliases = ['meme'])
|
@commands.command(name='memes', aliases = ['meme'])
|
||||||
async def _memes(self, ctx, *args):
|
async def _memes(self, ctx, *args):
|
||||||
"""Envoie un meme de reddit.\n ➡ Syntaxe: {PREFIX}memes/meme [subreddit]"""
|
"""Envoie un meme de reddit.\n ➡ Syntaxe: {PREFIX}memes/meme [subreddit]"""
|
||||||
fromSlash = False
|
args, fromSlash, _ = isSlash(args)
|
||||||
if len(args) > 0:
|
|
||||||
if args[-1] == True:
|
|
||||||
fromSlash = args[-1]
|
|
||||||
args = args[:-1]
|
|
||||||
if len(args) > 0:
|
|
||||||
args = args[0]
|
|
||||||
else:
|
|
||||||
args = None
|
|
||||||
|
|
||||||
if args: # s'il y a un subreddit de défini
|
if args: # s'il y a un subreddit de défini
|
||||||
subredditchoix = args
|
subredditchoix = args
|
||||||
|
@ -36,6 +28,9 @@ class Internet(commands.Cog):
|
||||||
'physicsmemes', 'blackpeopletwitter', 'metal_me_irl', '195', 'shittyadviceanimals', 'meirl',
|
'physicsmemes', 'blackpeopletwitter', 'metal_me_irl', '195', 'shittyadviceanimals', 'meirl',
|
||||||
'2meirl4meirl', 'AdviceAnimals', 'weirdmemes', 'LeagueOfMemes'])
|
'2meirl4meirl', 'AdviceAnimals', 'weirdmemes', 'LeagueOfMemes'])
|
||||||
|
|
||||||
|
if fromSlash != None and subredditchoix == "nsfw": # demande de nsfw sans passé par la commande appropriée
|
||||||
|
return await ctx.send(f"Désolé, tu demandes du nsfw... Fais plutôt **{ctx.prefix}sexe**.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with Reddit(client_id = environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit:
|
async with Reddit(client_id = environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit:
|
||||||
subreddit = await reddit.subreddit(subredditchoix) # récupération du subreddit
|
subreddit = await reddit.subreddit(subredditchoix) # récupération du subreddit
|
||||||
|
@ -43,18 +38,28 @@ class Internet(commands.Cog):
|
||||||
all_subs = [item async for item in hot] # liste des memes
|
all_subs = [item async for item in hot] # liste des memes
|
||||||
submission = choice(all_subs) # choix aléatoire
|
submission = choice(all_subs) # choix aléatoire
|
||||||
|
|
||||||
image = ["png", "jpg", "jpeg", "bmp", "gif"]
|
image = ["png", "jpg", "jpeg", "bmp", "gif"] # gifv not working
|
||||||
if submission.url[-3:] in image:
|
if submission.url[-3:] in image:
|
||||||
embed = discord.Embed(title = f"r/{subredditchoix} pour {ctx.author.name}", color = discord.Colour.random(), description = f"[lien du meme]({submission.url})")
|
if fromSlash != None:
|
||||||
embed.set_footer(text = f"Meme de Reddit")
|
footer = "Meme de Reddit"
|
||||||
|
memeOuImage = "[lien du meme]"
|
||||||
|
else:
|
||||||
|
footer = "NSFW de Reddit"
|
||||||
|
memeOuImage = "[lien de l'image]"
|
||||||
|
embed = discord.Embed(title = f"r/{subredditchoix} pour {ctx.author.name}", color = discord.Colour.random(), description = f"{memeOuImage}({submission.url})")
|
||||||
|
embed.set_footer(text = footer)
|
||||||
embed.set_image(url = submission.url)
|
embed.set_image(url = submission.url)
|
||||||
message = await ctx.send(embed = embed)
|
message = await ctx.send(embed = embed)
|
||||||
else:
|
else:
|
||||||
message = await ctx.send(f"```r/{subredditchoix} pour {ctx.author.name}```\n{submission.url}")
|
if fromSlash != None:
|
||||||
if fromSlash != True:
|
message = await ctx.send(f"`r/{subredditchoix} pour {ctx.author.name}`\n{submission.url}")
|
||||||
|
else:
|
||||||
|
message = await ctx.send(f"`{subredditchoix.capitalize()} pour {ctx.author.name}`\n{submission.url}")
|
||||||
|
if fromSlash != True and fromSlash != None:
|
||||||
await ctx.message.add_reaction(emoji = '✅')
|
await ctx.message.add_reaction(emoji = '✅')
|
||||||
await message.add_reaction('🔺')
|
if fromSlash != None:
|
||||||
return await message.add_reaction('🔻')
|
for emoji in ['🔺', '🔻']:
|
||||||
|
await message.add_reaction(emoji)
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(f"Error in _memes command = args: {args}, subreddit: {subredditchoix}, error: {error}")
|
print(f"Error in _memes command = args: {args}, subreddit: {subredditchoix}, error: {error}")
|
||||||
|
@ -63,14 +68,17 @@ class Internet(commands.Cog):
|
||||||
return await ctx.send(f"Ce subreddit est interdit, mis en quarantaine ou n'existe pas. ({subredditchoix})")
|
return await ctx.send(f"Ce subreddit est interdit, mis en quarantaine ou n'existe pas. ({subredditchoix})")
|
||||||
@cog_ext.cog_slash(name="meme", description = "Envoie un meme de reddit.")
|
@cog_ext.cog_slash(name="meme", description = "Envoie un meme de reddit.")
|
||||||
async def __memes(self, ctx, subreddit = None):
|
async def __memes(self, ctx, subreddit = None):
|
||||||
|
ctx.prefix = "/"
|
||||||
if subreddit == None:
|
if subreddit == None:
|
||||||
return await self._memes(ctx, True)
|
return await self._memes(ctx, True)
|
||||||
else:
|
else:
|
||||||
return await self._memes(ctx, subreddit, True)
|
return await self._memes(ctx, subreddit, True)
|
||||||
|
|
||||||
@commands.command(name='cat', aliases = ['chat'])
|
@commands.command(name='cat', aliases = ['chat'])
|
||||||
async def _cat(self, ctx, fromSlash = False):
|
async def _cat(self, ctx, fromSlash = None):
|
||||||
"""Te montre un magnifique chat.\n ➡ Syntaxe: {PREFIX}cat/chat"""
|
"""Te montre un magnifique chat.\n ➡ Syntaxe: {PREFIX}cat/chat"""
|
||||||
|
if fromSlash != True:
|
||||||
|
fromSlash = False
|
||||||
|
|
||||||
if ctx.author.nick:
|
if ctx.author.nick:
|
||||||
name = f"{ctx.author.nick} ({ctx.author.name}#{ctx.author.discriminator})"
|
name = f"{ctx.author.nick} ({ctx.author.name}#{ctx.author.discriminator})"
|
||||||
|
@ -91,7 +99,7 @@ class Internet(commands.Cog):
|
||||||
@commands.command(name='dog', aliases = ['chien'])
|
@commands.command(name='dog', aliases = ['chien'])
|
||||||
async def _dog(self, ctx, fromSlash = None):
|
async def _dog(self, ctx, fromSlash = None):
|
||||||
"""Te montre un magnifique chien.\n ➡ Syntaxe: {PREFIX}dog/chien"""
|
"""Te montre un magnifique chien.\n ➡ Syntaxe: {PREFIX}dog/chien"""
|
||||||
if fromSlash == None:
|
if fromSlash != True:
|
||||||
fromSlash = False
|
fromSlash = False
|
||||||
|
|
||||||
if ctx.author.nick:
|
if ctx.author.nick:
|
||||||
|
@ -111,57 +119,29 @@ class Internet(commands.Cog):
|
||||||
return await self._dog(ctx, True)
|
return await self._dog(ctx, True)
|
||||||
|
|
||||||
@commands.command(name='sexe', aliases=['sexes', 'nude', 'nudes', 'nsfw'])
|
@commands.command(name='sexe', aliases=['sexes', 'nude', 'nudes', 'nsfw'])
|
||||||
async def _sexe(self, ctx, *choice_of_nsfw):
|
async def _sexe(self, ctx, fromSlash = None):
|
||||||
"""Envois une image coquine. (NSFW)\n ➡ Syntaxe: {PREFIX}sexe/sexes/nude/nudes [butts/boobs]"""
|
"""Envois une image coquine. (NSFW)\n ➡ Syntaxe: {PREFIX}sexe/sexes/nude/nudes"""
|
||||||
|
if fromSlash != True:
|
||||||
fromSlash = False
|
fromSlash = False
|
||||||
if len(choice_of_nsfw) > 0:
|
|
||||||
if choice_of_nsfw[-1] == True:
|
|
||||||
fromSlash = choice_of_nsfw[-1]
|
|
||||||
choice_of_nsfw = choice_of_nsfw[:-1]
|
|
||||||
if len(choice_of_nsfw) > 0:
|
|
||||||
choice_of_nsfw = choice_of_nsfw[0]
|
|
||||||
else:
|
|
||||||
choice_of_nsfw = None
|
|
||||||
|
|
||||||
liste_hot = ['butts', 'boobs']
|
|
||||||
if choice_of_nsfw == 'butt':
|
|
||||||
choice_of_nsfw = 'butts'
|
|
||||||
if choice_of_nsfw == 'boob':
|
|
||||||
choice_of_nsfw = 'boobs'
|
|
||||||
if choice_of_nsfw in liste_hot:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
choice_of_nsfw = choice(liste_hot)
|
|
||||||
if ctx.channel.is_nsfw():
|
if ctx.channel.is_nsfw():
|
||||||
embed = discord.Embed(title = f"{choice_of_nsfw.capitalize()} pour {ctx.author.name}", colour = discord.Colour.random())
|
|
||||||
nsfw = randomImage(f'http://api.o{choice_of_nsfw}.ru/noise/')
|
|
||||||
embed.set_image(url = f"http://media.o{choice_of_nsfw}.ru/{nsfw[0][0]['preview']}")
|
|
||||||
embed.set_footer(text = f"o{choice_of_nsfw}.ru a pris {nsfw[1]} ms pour sortir l'image n°{nsfw[0][1]}-{nsfw[1]}.")
|
|
||||||
if fromSlash != True:
|
if fromSlash != True:
|
||||||
await ctx.message.add_reaction(emoji = '✅')
|
await ctx.message.add_reaction(emoji = '✅')
|
||||||
await ctx.send(embed = embed)
|
else:
|
||||||
|
ctx.prefix = "/"
|
||||||
|
return await self._memes(ctx, "nsfw", None)
|
||||||
else:
|
else:
|
||||||
if fromSlash != True:
|
if fromSlash != True:
|
||||||
await ctx.message.add_reaction(emoji = '❌')
|
await ctx.message.add_reaction(emoji = '❌')
|
||||||
await ctx.send(f"Désolé mais je n'envois ce genre de message seulement dans les salons NSFW !")
|
await ctx.send(f"Désolé mais je n'envois ce genre de message seulement dans les salons NSFW !")
|
||||||
@cog_ext.cog_slash(name="sexe", description = "Envois une image coquine. (NSFW)")
|
@cog_ext.cog_slash(name="sexe", description = "Envois une image coquine. (NSFW)")
|
||||||
async def __sexe(self, ctx, buttsorboobs = None):
|
async def __sexe(self, ctx):
|
||||||
if buttsorboobs == None:
|
|
||||||
return await self._sexe(ctx, True)
|
return await self._sexe(ctx, True)
|
||||||
else:
|
|
||||||
return await self._sexe(ctx, buttsorboobs, True)
|
|
||||||
|
|
||||||
@commands.command(name='news', aliases=['rss'])
|
@commands.command(name='news', aliases=['rss'])
|
||||||
async def _news(self, ctx, *arg):
|
async def _news(self, ctx, *arg):
|
||||||
"""Info random dans le domaine de l'informatique\n ➡ Syntaxe: {PREFIX}news/rss [site/liste]"""
|
"""Info random dans le domaine de l'informatique\n ➡ Syntaxe: {PREFIX}news/rss [site/liste]"""
|
||||||
fromSlash = False
|
arg, fromSlash, _ = isSlash(arg)
|
||||||
if len(arg) > 0:
|
if arg == None:
|
||||||
if arg[-1] == True:
|
|
||||||
fromSlash = arg[-1]
|
|
||||||
arg = arg[:-1]
|
|
||||||
if len(arg) > 0:
|
|
||||||
arg = arg[0]
|
|
||||||
else:
|
|
||||||
arg = ""
|
arg = ""
|
||||||
|
|
||||||
rss_website = {
|
rss_website = {
|
||||||
|
|
Reference in a new issue