Reusing code by making functions

Increased modularity
pull/4/head
sgoudham 4 years ago
parent b96a267e5a
commit 1392c1b8cf

@ -1,5 +1,4 @@
import asyncio import asyncio
import datetime
import random import random
import string import string
@ -9,20 +8,29 @@ from discord.ext.commands import cooldown, BucketType, command
import settings import settings
from cogs.anime.interactive import error_function from cogs.anime.interactive import error_function
from settings import time, colour_list
# Function to display all the images requested of the people # Gets the member and user avatar
def displayServerImage(array, ctx, name): def getMember(ctx):
# Set member as the author # Set member as the author
member = ctx.message.author member = ctx.message.author
# Get the member's avatar # Get the member avatar
userAvatar = member.avatar_url userAvatar = member.avatar_url
return member, userAvatar
# Function to display all the images requested of the people
def displayServerImage(array, ctx, name):
# Get the member and the userAvatar
member, userAvatar = getMember(ctx)
# Set embed up for the person requested by the user # Set embed up for the person requested by the user
embed = Embed( embed = Embed(
title=f"**Look At What A Cutie {name.capitalize()} is!! <a:huh:676195228872474643> <a:huh:676195228872474643> **", title=f"**Look At What A Cutie {name.capitalize()} is!! <a:huh:676195228872474643> <a:huh:676195228872474643> **",
colour=Colour(random.choice(settings.colour_list)), colour=Colour(random.choice(colour_list)),
timestamp=datetime.datetime.utcnow()) timestamp=time)
embed.set_image(url=random.choice(array)) embed.set_image(url=random.choice(array))
embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar)) embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
@ -92,16 +100,14 @@ class Enso(commands.Cog):
with open(f'images/ServerMembers/{random.choice(array)}.txt') as file: with open(f'images/ServerMembers/{random.choice(array)}.txt') as file:
array = file.readlines() array = file.readlines()
# Set member as the author # Get the member and the userAvatar
member = ctx.message.author member, userAvatar = getMember(ctx)
# Get the member's avatar
userAvatar = member.avatar_url
# Embed the image in a message and send it to the channel # Embed the image in a message and send it to the channel
embed = Embed( embed = Embed(
title=f"Oh Look! A Cute Person <a:huh:676195228872474643> <a:huh:676195228872474643> ", title=f"Oh Look! A Cute Person <a:huh:676195228872474643> <a:huh:676195228872474643> ",
colour=Colour(random.choice(settings.colour_list)), colour=Colour(random.choice(colour_list)),
timestamp=datetime.datetime.utcnow()) timestamp=time)
embed.set_image(url=random.choice(array)) embed.set_image(url=random.choice(array))
embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar)) embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))

Loading…
Cancel
Save