async def giphy(self, ctx, *, search): await ctx.message.delete() embed = discord.Embed(colour=discord.Colour.blue()) session = aiohttp.ClientSession() if search == '': response = await session.get( f'https://giphy.com/v1/gifs/random?api_key={giphy_api_key}') data = json.loads(await response.text()) embed.set_image(url=data['data']['images']['original']['url']) else: search.replace(' ', '+') response = await session.get( 'https://api.giphy.com/v1/gifs/search?q=' + search + f'&api_key={giphy_api_key}&limit=10') data = json.loads(await response.text()) gif_choice = random.randint(0, 9) embed.set_image( url=data['data'][gif_choice]['images']['original']['url']) await session.close() await ctx.send(embed=embed) message = 'I found a gif for ' + str( ctx.message.author.name) + ' using ***' + str( search) + '*** as a search!' if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message)
async def ping(self, ctx): await ctx.message.delete() message = f'Pong! {round(self.client.latency * 1000)}ms' if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message) else: await ctx.send(str(message))
async def rg(self, ctx, *, search): await ctx.message.delete() if ctx.channel.is_nsfw(): session = aiohttp.ClientSession() if search == '': return else: search.replace(' ', '+') response = await session.get(f'https://napi.redgifs.com/v1/gfycats/search?search_text={search}&count=25') data = json.loads(await response.text()) grabbing_gif = True attempt_num = 0 while grabbing_gif == True: if attempt_num >= 10: await session.close() if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send("Sorry, I couldn't find a gif.") return gif_choice = random.randint(0,20) try: link = (data['gfycats'][gif_choice]['mobileUrl']) request = requests.get(link) if request.status_code == 200: grabbing_gif = False else: print(f"link doesn't work. Status code: {request.status_code}.") except IndexError as e: attempt_num += 1 except Exception as e: print(e) await session.close() if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(f"Sorry, redgifs.com was unresponsive, please try again.") return await session.close() await ctx.send(link) message = 'I found a redgif for ' + str(ctx.message.author.name) + ' using ***' + str(search) + '*** as a search!' else: message = "You must submit redgif request in a NSFW channel." if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message)
async def unload(ctx, extension): await ctx.message.delete() client.unload_extension(f'cogs.{extension}') print(f'cogs.{extension} Unloaded.') message = f'I have unloaded the {extension} cog.' if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message) else: await ctx.send(str(message))
async def stop(self, ctx): await ctx.message.delete() global voice voice = get(self.client.voice_clients, guild=ctx.guild) if voice.is_playing(): voice.stop() if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(f'{ctx.message.author.name} silenced me!') if voice.is_connected(): await voice.disconnect()
async def clear(self, ctx, amount=2): await ctx.message.delete() if amount > 20: amount = 20 try: await ctx.channel.purge(limit=amount) if amount == 1: message = f'{amount} message cleared in {ctx.channel.name}.' else: message = f'{amount} messages cleared in {ctx.channel.name}.' if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message) except Exception as e: print(str(e))
async def del_console(ctx): await ctx.message.delete() if ctx.guild.id in spam_channels.keys(): element = spam_channels.pop(ctx.guild.id) with open("preferences.txt", "r+") as f: d = f.readlines() f.seak(0) for i in d: if int(i.split(':')[0]) != ctx.guild.id: f.write(i) f.truncate() await ctx.send("Successfully removed #" + str(element) + " as my console.") else: await ctx.send("I could not find a console.")
async def define(self, ctx, *search): await ctx.message.delete() wurd = ' '.join(search) wurd.replace(',', '') #If no word is given, it will return a random search. if wurd == '': rand = ud.random() w_definition = f"""\n>>> **{rand[0].word}**\n\nDefinition:\n```{rand[0].definition}``` \nExample:\n```{rand[0].example}```\n⬆️ {rand[0].upvotes} ⬇️ {rand[0].downvotes}\n""" await ctx.send(w_definition) #If there is something to search for it will try to find it else: rand = ud.define(str(wurd)) if not rand: print("list is empty") w_definition = f"""\n>>> **{rand[0].word}**\n\nDefinition:\n```{rand[0].definition}``` \nExample:\n```{rand[0].example}```\n⬆️ {rand[0].upvotes} ⬇️ {rand[0].downvotes}\n""" await ctx.send(w_definition) message = message = 'I found an urban definition for ' + str( ctx.message.author.name) + ' using ***' + str( wurd) + '*** as a search!' if ctx.guild.id in spam_channels.keys(): channel = spam_channels[ctx.guild.id] await channel.send(message)