Removing restriction on Doggo command

pull/8/head
sgoudham 4 years ago
parent 74ce5cd2fb
commit 79f579eeda

@ -1,4 +1,3 @@
import asyncio
import datetime import datetime
import random import random
import string import string
@ -8,8 +7,6 @@ from discord import Colour, Embed
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import BucketType, cooldown, command from discord.ext.commands import BucketType, cooldown, command
import settings
from cogs.anime.interactive import error_function
from settings import colour_list from settings import colour_list
@ -23,91 +20,61 @@ class Doggo(commands.Cog):
async def doggo(self, ctx, breed=None): async def doggo(self, ctx, breed=None):
"""Allows an API to grab images of dogs""" """Allows an API to grab images of dogs"""
# If the channel that the command has been sent is in the list of accepted channels # Set member as the author
if str(ctx.channel) in settings.channels: member = ctx.message.author
# Get the member avatar
userAvatar = member.avatar_url
# Set member as the author # Initialise array to store doggo pics
member = ctx.message.author b_list = []
# Get the member avatar
userAvatar = member.avatar_url
# Initialise array to store doggo pics # If a breed if specified
b_list = [] if breed:
# Get the lowercase string input
lowercase_breed = breed.lower()
# If a breed if specified # If the user wants to know what breeds there are
if breed: if lowercase_breed == "breeds":
# Get the lowercase string input # Get the list of breeds
lowercase_breed = breed.lower() breed_url = "https://dog.ceo/api/breeds/list/all"
# If the user wants to know what breeds there are # Using API, retrieve the full list of breeds available
if lowercase_breed == "breeds": async with request("GET", breed_url, headers={}) as response:
# Get the list of breeds if response.status == 200:
breed_url = "https://dog.ceo/api/breeds/list/all" data = await response.json()
breed_link = data["message"]
# Using API, retrieve the full list of breeds available
async with request("GET", breed_url, headers={}) as response:
if response.status == 200:
data = await response.json()
breed_link = data["message"]
# Store every Doggo in an array
for doggo in breed_link:
b_list.append(doggo)
# Join together all the breeds into a string
doggo_string = string.capwords(", ".join(b_list))
# Tell the user to try the breeds listed below
await ctx.send(f"Try the Breeds listed below!\n{doggo_string}")
# If no breed has been specified
else:
# Grab a random image of a doggo with the breed specified
image_url = f"https://dog.ceo/api/breed/{lowercase_breed}/images/random"
# Using API, retrieve the image of a doggo of the breed specified
async with request("GET", image_url, headers={}) as response:
if response.status == 200:
data = await response.json()
image_link = data["message"]
# Set up the embed for a doggo image # Store every Doggo in an array
doggo_embed = Embed( for doggo in breed_link:
title=f"**It's a {lowercase_breed.capitalize()} Doggo!!** ", b_list.append(doggo)
colour=Colour(random.choice(colour_list)),
timestamp=datetime.datetime.utcnow())
doggo_embed.set_image(url=image_link)
doggo_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
# Send the doggo image # Join together all the breeds into a string
await ctx.send(embed=doggo_embed) doggo_string = string.capwords(", ".join(b_list))
else: # Tell the user to try the breeds listed below
await ctx.send(f"Try the Breeds listed below!\n{doggo_string}")
# Send error message that Doggo was not found! # If no breed has been specified
await ctx.send(
"Doggo Not Found! Please do **~doggo `breeds`** to see the full list of Doggos!")
else: else:
# Grab a random image of a doggo of any breed # Grab a random image of a doggo with the breed specified
image_url = "https://dog.ceo/api/breeds/image/random" image_url = f"https://dog.ceo/api/breed/{lowercase_breed}/images/random"
# Using API, retrieve the image of a doggo of any breed # Using API, retrieve the image of a doggo of the breed specified
async with request("GET", image_url, headers={}) as response: async with request("GET", image_url, headers={}) as response:
if response.status == 200: if response.status == 200:
data = await response.json() data = await response.json()
image_link = data["message"] image_link = data["message"]
# Set up the embed for a random doggo image # Set up the embed for a doggo image
doggo_embed = Embed( doggo_embed = Embed(
title=f"**Doggo!** ", title=f"**It's a {lowercase_breed.capitalize()} Doggo!!** ",
colour=Colour(random.choice(colour_list)), colour=Colour(random.choice(colour_list)),
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow())
doggo_embed.set_image(url=image_link) doggo_embed.set_image(url=image_link)
doggo_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar)) doggo_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
# Send random doggo image to the channel # Send the doggo image
await ctx.send(embed=doggo_embed) await ctx.send(embed=doggo_embed)
else: else:
@ -117,13 +84,31 @@ class Doggo(commands.Cog):
"Doggo Not Found! Please do **~doggo `breeds`** to see the full list of Doggos!") "Doggo Not Found! Please do **~doggo `breeds`** to see the full list of Doggos!")
else: else:
# Call error_function() and display it to the user # Grab a random image of a doggo of any breed
message = await ctx.send(error_function()) image_url = "https://dog.ceo/api/breeds/image/random"
# Using API, retrieve the image of a doggo of any breed
async with request("GET", image_url, headers={}) as response:
if response.status == 200:
data = await response.json()
image_link = data["message"]
# Set up the embed for a random doggo image
doggo_embed = Embed(
title=f"**Doggo!** ",
colour=Colour(random.choice(colour_list)),
timestamp=datetime.datetime.utcnow())
doggo_embed.set_image(url=image_link)
doggo_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
# Send random doggo image to the channel
await ctx.send(embed=doggo_embed)
else:
# Let the user read the message for 2.5 seconds # Send error message that Doggo was not found!
await asyncio.sleep(2.5) await ctx.send(
# Delete the message "Doggo Not Found! Please do **~doggo `breeds`** to see the full list of Doggos!")
await message.delete()
def setup(bot): def setup(bot):

Loading…
Cancel
Save