Defining Constants in variables for it to be more modular

Turning repeated code into functions
pull/4/head
sgoudham 4 years ago
parent fe249809f2
commit b86aa2a576

@ -6,7 +6,22 @@ from discord.ext import commands
from discord.ext.commands import cooldown, command, BucketType from discord.ext.commands import cooldown, command, BucketType
import settings import settings
from settings import time, colour_list from settings import time, colour_list, enso_ensochancommands_Mention
# Gets the member and user avatar
def getMember(ctx):
# Set member as the author
member = ctx.message.author
# Get the member avatar
userAvatar = member.avatar_url
return member, userAvatar
# Error handling function to make sure that the commands only work in "enso-chan-commands"
def error_function():
return f"Sorry! I only work in {enso_ensochancommands_Mention}"
# Set up the Cog # Set up the Cog
@ -30,10 +45,8 @@ class Interactive(commands.Cog):
# Store content of the file in kissing_array # Store content of the file in kissing_array
kissing_array = file.readlines() kissing_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 avatar
userAvatar = member.avatar_url
# Set up the embed to display a random kissing gif # Set up the embed to display a random kissing gif
embed = Embed( embed = Embed(
@ -75,10 +88,8 @@ class Interactive(commands.Cog):
# Store content of the file in killing_array # Store content of the file in killing_array
killing_array = file.readlines() killing_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 avatar
userAvatar = member.avatar_url
# Set up the embed to display a random killing gif # Set up the embed to display a random killing gif
embed = Embed( embed = Embed(
@ -120,10 +131,8 @@ class Interactive(commands.Cog):
# Store content of the file in cuddling_array # Store content of the file in cuddling_array
cuddling_array = file.readlines() cuddling_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 avatar
userAvatar = member.avatar_url
# Set up the embed to display a random cuddling gif # Set up the embed to display a random cuddling gif
embed = Embed( embed = Embed(
@ -165,10 +174,8 @@ class Interactive(commands.Cog):
# Store content of the file in cuddling_array # Store content of the file in cuddling_array
slapping_array = file.readlines() slapping_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 avatar
userAvatar = member.avatar_url
# Set up the embed to display a random slapping gif # Set up the embed to display a random slapping gif
embed = Embed( embed = Embed(
@ -210,10 +217,8 @@ class Interactive(commands.Cog):
# Store content of the file in patting_array # Store content of the file in patting_array
patting_array = file.readlines() patting_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 avatar
userAvatar = member.avatar_url
# Set up the embed to display a random patting gif # Set up the embed to display a random patting gif
embed = Embed( embed = Embed(
@ -254,10 +259,8 @@ class Interactive(commands.Cog):
# If the channel that the command has been sent is in the list of accepted channels # If the channel that the command has been sent is in the list of accepted channels
if str(ctx.channel) in settings.channels: if str(ctx.channel) in settings.channels:
# Set member as the author # Get the member and the userAvatar
member = ctx.message.author member, userAvatar = getMember(ctx)
# Get the member avatar
userAvatar = member.avatar_url
# Set up the embed to display a random lemon gif # Set up the embed to display a random lemon gif
embed = Embed( embed = Embed(
@ -322,10 +325,5 @@ class Interactive(commands.Cog):
await ctx.send("Awww they waited too long (✖╭╮✖)") await ctx.send("Awww they waited too long (✖╭╮✖)")
# Error handling function to make sure that the commands only work in "enso-chan-commands"
def error_function():
return "Sorry! I only work in <#721449922838134876>"
def setup(bot): def setup(bot):
bot.add_cog(Interactive(bot)) bot.add_cog(Interactive(bot))

Loading…
Cancel
Save