Converting Enso cog into commands/subcommands

pull/8/head
sgoudham 4 years ago
parent e06e662447
commit 4ecf54e22e

@ -1,10 +1,10 @@
import datetime import datetime
import random import random
import string import string
from typing import Optional
from discord import Embed, Colour from discord import Embed, Colour
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import cooldown, BucketType, command
from settings import colour_list from settings import colour_list
@ -31,8 +31,7 @@ def getMember(msg):
# Function to turn the user inputted name into the full name # Function to turn the user inputted name into the full name
def Abbrev(anime_msg): def Abbrev(anime_msg):
# Get the lowercase # Get the lowercase
lowercase_anime = anime_msg.lower() split_anime = anime_msg.split()
split_anime = lowercase_anime.split()
new_msg = "" new_msg = ""
# For each word in split_anime # For each word in split_anime
@ -101,111 +100,108 @@ def displayAnimeImage(array, msg, name):
return anime_embed return anime_embed
# List of Waifu's
def waifus():
return ["toga", "yumeko", "maki"]
# List of Husbando's
def husbandos():
return ["husk", "kakashi", "tamaki"]
class Anime(commands.Cog): class Anime(commands.Cog):
"""Waifus and Husbandos!""" """Waifus and Husbandos!"""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# Bot ~w/waifu command for the waifu's stored in the bot @commands.group(invoke_without_command=True)
@command(name="w", aliases=['W']) async def waifu(self, ctx, waifu: Optional[str]):
@cooldown(1, 1, BucketType.user) """Shows a Waifu"""
async def waifu(self, ctx, waifu=None):
# Defining array for the list of waifus available
waifu_array = ["toga", "yumeko", "maki"]
# if a name is specified
if waifu: if waifu:
# Get the lowercase lcase_waifu = waifu.lower()
proper_waifu = waifu.lower()
# if the user does ~w list
if proper_waifu == "list":
# Tell the user to try the waifus in the array
await ctx.send(f"Try the waifu's listed below!")
# Send the list of waifus in the bot to the channel
waifu_list = string.capwords(', '.join(map(str, waifu_array)))
await ctx.send(waifu_list)
else:
# Surround with try/except to catch any exceptions that may occur
try: try:
# Retrieve image of the waifu specified # Retrieve image of the waifu specified
with open(f'images/AnimeImages/Waifus/{proper_waifu}.txt') as file: with open(f'images/AnimeImages/Waifus/{lcase_waifu}.txt') as file:
w_array = file.readlines() w_array = file.readlines()
# Get the full name of the waifu # Get the full name of the waifu
full_name = Abbrev(proper_waifu) full_name = Abbrev(lcase_waifu)
# Embed the image into a message and send it to the channel # Embed the image into a message and send it to the channel
embed = displayAnimeImage(w_array, ctx, full_name) embed = displayAnimeImage(w_array, ctx, full_name)
await ctx.send(embed=embed) await ctx.send(embed=embed)
except Exception as e: except FileNotFoundError as e:
print(e) print(e)
# Send error message saying that the person isn't recognised # Send error message saying that the person isn't recognised
await ctx.send(f"Sorry! That waifu doesn't exist!" await ctx.send(f"Sorry! That waifu doesn't exist!"
f"\nPlease do **~w list** to see the list of waifu's") f"\nPlease do **{ctx.prefix}waifu list** to see the list of Waifu's")
else: else:
# Get embed from randomWaifu() and send it to the channel # Get embed from randomWaifu() and send it to the channel
embed = randomWaifu(ctx, waifu_array) embed = randomWaifu(ctx, waifus())
await ctx.send(embed=embed) await ctx.send(embed=embed)
# Bot ~h/husbando command for the husbando's stored in the bot @commands.group(invoke_without_command=True)
@command(name="h", aliases=['H']) async def husbando(self, ctx, husbando: Optional[str]):
@cooldown(1, 1, BucketType.user) """Shows a Husbando"""
async def husbando(self, ctx, husbando=None):
# Defining array for the list of husbando's available
husbando_array = ["husk", "kakashi", "tamaki"]
# if a name is specified
if husbando: if husbando:
# Get the lowercase # Get the lowercase
proper_husbando = husbando.lower() lcase_husbando = husbando.lower()
# Surround with try/except to catch any exceptions that may occur
try: try:
# if the user does ~h list
if proper_husbando == "list":
# Tell the user to try the husbando's in the array
await ctx.send(f"Try the husbando's listed below!")
# Send the list of waifus in the bot to the channel
husbando_list = string.capwords(', '.join(map(str, husbando_array)))
await ctx.send(husbando_list)
else:
# Retrieve image of the husbando specified # Retrieve image of the husbando specified
with open(f'images/AnimeImages/Husbandos/{proper_husbando}.txt') as file: with open(f'images/AnimeImages/Husbandos/{lcase_husbando}.txt') as file:
h_array = file.readlines() h_array = file.readlines()
# Get the full name of the husbando # Get the full name of the husbando
full_name = Abbrev(proper_husbando) full_name = Abbrev(lcase_husbando)
# Embed the image into a message and send it to the channel # Embed the image into a message and send it to the channel
embed = displayAnimeImage(h_array, ctx, full_name) embed = displayAnimeImage(h_array, ctx, full_name)
await ctx.send(embed=embed) await ctx.send(embed=embed)
except Exception as e: except FileNotFoundError as e:
print(e) print(e)
# Send error message saying that the person isn't recognised # Send error message saying that the person isn't recognised
await ctx.send( await ctx.send(
f"Sorry! That husbando doesn't exist!" f"Sorry! That husbando doesn't exist!"
f"\nPlease do **~h list** to see the list of husbando's") f"\nPlease do **{ctx.prefix}h list** to see the list of husbando's")
else: else:
# Get embed from randomHusbando() and send it to the channel # Get embed from randomHusbando() and send it to the channel
embed = randomHusbando(ctx, husbando_array) embed = randomHusbando(ctx, husbandos())
await ctx.send(embed=embed) await ctx.send(embed=embed)
@waifu.command(name="list")
async def wlist(self, ctx):
"""Returns a list of Waifu's Available"""
# Send the list of waifus in the bot to the channel
waifu_list = string.capwords(', '.join(map(str, waifus())))
# Tell the user to try the waifus in the array
await ctx.send(f"Try the waifu's listed below!"
f"\n{waifu_list}")
@husbando.command(name="list")
async def hlist(self, ctx):
"""Returns a list of Husbando's Available"""
# Send the list of waifus in the bot to the channel
husbando_list = string.capwords(', '.join(map(str, husbandos())))
# Tell the user to try the husbando's in the array
await ctx.send(f"Try the husbando's listed below!"
f"\n{husbando_list}")
def setup(bot): def setup(bot):
bot.add_cog(Anime(bot)) bot.add_cog(Anime(bot))

Loading…
Cancel
Save