mirror of https://github.com/sgoudham/Enso-Bot.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
210 lines
7.2 KiB
Python
210 lines
7.2 KiB
Python
4 years ago
|
import datetime
|
||
4 years ago
|
import random
|
||
|
import string
|
||
|
|
||
4 years ago
|
from discord import Embed, Colour
|
||
4 years ago
|
from discord.ext import commands
|
||
4 years ago
|
from discord.ext.commands import cooldown, BucketType, command
|
||
4 years ago
|
|
||
4 years ago
|
from settings import colour_list
|
||
4 years ago
|
|
||
4 years ago
|
# Defining the full names of the waifu's/husbando's
|
||
4 years ago
|
anime = {"yumeko": "Jabami Yumeko",
|
||
|
"toga": "Himiko Toga",
|
||
4 years ago
|
"maki": "Maki Oze",
|
||
4 years ago
|
"kakashi": "Hatake Kakashi",
|
||
4 years ago
|
"tamaki": "Tamaki Suoh",
|
||
|
"husk": "Husk"
|
||
4 years ago
|
}
|
||
|
|
||
|
|
||
4 years ago
|
# Gets the member and user avatar
|
||
|
def getMember(msg):
|
||
|
# Set member as the author
|
||
|
member = msg.author
|
||
|
# Get the member avatar
|
||
|
userAvatar = member.avatar_url
|
||
|
|
||
|
return member, userAvatar
|
||
|
|
||
|
|
||
4 years ago
|
# Function to turn the user inputted name into the full name
|
||
4 years ago
|
def Abbrev(anime_msg):
|
||
4 years ago
|
# Get the lowercase
|
||
4 years ago
|
lowercase_anime = anime_msg.lower()
|
||
|
split_anime = lowercase_anime.split()
|
||
|
new_msg = ""
|
||
4 years ago
|
|
||
4 years ago
|
# For each word in split_anime
|
||
4 years ago
|
for word in split_anime:
|
||
4 years ago
|
# If the word exists in the anime array
|
||
4 years ago
|
if word in anime:
|
||
4 years ago
|
# Set a new string equal to the full name of the waifu/husbando
|
||
4 years ago
|
new_msg = anime[word]
|
||
4 years ago
|
|
||
4 years ago
|
return new_msg
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
# Function to return a random image of a waifu
|
||
|
def randomWaifu(msg, waifu):
|
||
|
# Retrieve a random image of a waifu within the bot
|
||
|
with open(f'images/AnimeImages/Waifus/{random.choice(waifu)}.txt') as file:
|
||
|
array = file.readlines()
|
||
|
|
||
4 years ago
|
# Get the member and the userAvatar
|
||
|
member, userAvatar = getMember(msg)
|
||
4 years ago
|
|
||
|
# Set up the embed for a random waifu image
|
||
4 years ago
|
waifu_embed = Embed(
|
||
4 years ago
|
title=f"Oh Look! A Wonderful Waifu! <a:huh:676195228872474643> <a:huh:676195228872474643> ",
|
||
4 years ago
|
colour=Colour(random.choice(colour_list)),
|
||
4 years ago
|
timestamp=datetime.datetime.utcnow())
|
||
4 years ago
|
waifu_embed.set_image(url=random.choice(array))
|
||
|
waifu_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
|
||
|
|
||
|
return waifu_embed
|
||
|
|
||
|
|
||
|
# Function to return a random image of a husbando
|
||
|
def randomHusbando(msg, husbando):
|
||
|
# Retrieve a random image of a husbando within the bot
|
||
|
with open(f'images/AnimeImages/Husbandos/{random.choice(husbando)}.txt') as file:
|
||
|
array = file.readlines()
|
||
|
|
||
4 years ago
|
# Get the member and the userAvatar
|
||
|
member, userAvatar = getMember(msg)
|
||
4 years ago
|
|
||
|
# Set up the embed for a random husbando image
|
||
4 years ago
|
husbando_embed = Embed(
|
||
4 years ago
|
title=f"Oh Look! A Handsome Husbando! <a:huh:676195228872474643> <a:huh:676195228872474643> ",
|
||
4 years ago
|
colour=Colour(random.choice(colour_list)),
|
||
4 years ago
|
timestamp=datetime.datetime.utcnow())
|
||
4 years ago
|
husbando_embed.set_image(url=random.choice(array))
|
||
|
husbando_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
|
||
|
|
||
|
return husbando_embed
|
||
|
|
||
|
|
||
|
# Function to allow modular code and sets up the embed for the anime images
|
||
|
def displayAnimeImage(array, msg, name):
|
||
4 years ago
|
# Get the member and the userAvatar
|
||
|
member, userAvatar = getMember(msg)
|
||
4 years ago
|
|
||
|
# Set up embed for an image relating to a husbando or waifu
|
||
4 years ago
|
anime_embed = Embed(
|
||
4 years ago
|
title=f"**{name}**",
|
||
4 years ago
|
colour=Colour(random.choice(colour_list)),
|
||
4 years ago
|
timestamp=datetime.datetime.utcnow())
|
||
4 years ago
|
anime_embed.set_image(url=random.choice(array))
|
||
|
anime_embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
|
||
|
|
||
|
return anime_embed
|
||
|
|
||
|
|
||
4 years ago
|
class Anime(commands.Cog):
|
||
4 years ago
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
|
||
4 years ago
|
# Bot ~w/waifu command for the waifu's stored in the bot
|
||
4 years ago
|
@command(name="w", aliases=['W'])
|
||
4 years ago
|
@cooldown(1, 1, BucketType.user)
|
||
4 years ago
|
async def waifu(self, ctx, waifu=None):
|
||
4 years ago
|
|
||
4 years ago
|
# Defining array for the list of waifus available
|
||
4 years ago
|
waifu_array = ["toga", "yumeko", "maki"]
|
||
4 years ago
|
|
||
4 years ago
|
# if a name is specified
|
||
|
if waifu:
|
||
|
# Get the lowercase
|
||
|
proper_waifu = waifu.lower()
|
||
4 years ago
|
|
||
4 years ago
|
# 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!")
|
||
4 years ago
|
|
||
4 years ago
|
# 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)
|
||
4 years ago
|
|
||
4 years ago
|
else:
|
||
|
# Surround with try/except to catch any exceptions that may occur
|
||
|
try:
|
||
4 years ago
|
|
||
4 years ago
|
# Retrieve image of the waifu specified
|
||
|
with open(f'images/AnimeImages/Waifus/{proper_waifu}.txt') as file:
|
||
|
w_array = file.readlines()
|
||
4 years ago
|
|
||
4 years ago
|
# Get the full name of the waifu
|
||
|
full_name = Abbrev(proper_waifu)
|
||
4 years ago
|
|
||
4 years ago
|
# Embed the image into a message and send it to the channel
|
||
|
embed = displayAnimeImage(w_array, ctx, full_name)
|
||
|
await ctx.send(embed=embed)
|
||
4 years ago
|
|
||
4 years ago
|
except Exception as e:
|
||
|
print(e)
|
||
4 years ago
|
|
||
4 years ago
|
# Send error message saying that the person isn't recognised
|
||
|
await ctx.send(f"Sorry! That waifu doesn't exist!"
|
||
|
f"\nPlease do **~w list** to see the list of waifu's")
|
||
|
else:
|
||
4 years ago
|
|
||
4 years ago
|
# Get embed from randomWaifu() and send it to the channel
|
||
|
embed = randomWaifu(ctx, waifu_array)
|
||
|
await ctx.send(embed=embed)
|
||
4 years ago
|
|
||
4 years ago
|
# Bot ~h/husbando command for the husbando's stored in the bot
|
||
4 years ago
|
@command(name="h", aliases=['H'])
|
||
4 years ago
|
@cooldown(1, 1, BucketType.user)
|
||
4 years ago
|
async def husbando(self, ctx, husbando=None):
|
||
4 years ago
|
|
||
4 years ago
|
# Defining array for the list of husbando's available
|
||
|
husbando_array = ["husk", "kakashi", "tamaki"]
|
||
4 years ago
|
|
||
4 years ago
|
# if a name is specified
|
||
|
if husbando:
|
||
|
# Get the lowercase
|
||
|
proper_husbando = husbando.lower()
|
||
4 years ago
|
|
||
4 years ago
|
# Surround with try/except to catch any exceptions that may occur
|
||
|
try:
|
||
4 years ago
|
|
||
4 years ago
|
# 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!")
|
||
4 years ago
|
|
||
4 years ago
|
# 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)
|
||
4 years ago
|
|
||
4 years ago
|
else:
|
||
|
# Retrieve image of the husbando specified
|
||
|
with open(f'images/AnimeImages/Husbandos/{proper_husbando}.txt') as file:
|
||
|
h_array = file.readlines()
|
||
4 years ago
|
|
||
4 years ago
|
# Get the full name of the husbando
|
||
|
full_name = Abbrev(proper_husbando)
|
||
4 years ago
|
|
||
4 years ago
|
# Embed the image into a message and send it to the channel
|
||
|
embed = displayAnimeImage(h_array, ctx, full_name)
|
||
|
await ctx.send(embed=embed)
|
||
4 years ago
|
|
||
4 years ago
|
except Exception as e:
|
||
|
print(e)
|
||
4 years ago
|
|
||
4 years ago
|
# Send error message saying that the person isn't recognised
|
||
|
await ctx.send(
|
||
|
f"Sorry! That husbando doesn't exist!"
|
||
|
f"\nPlease do **~h list** to see the list of husbando's")
|
||
|
else:
|
||
4 years ago
|
|
||
4 years ago
|
# Get embed from randomHusbando() and send it to the channel
|
||
|
embed = randomHusbando(ctx, husbando_array)
|
||
|
await ctx.send(embed=embed)
|
||
4 years ago
|
|
||
|
|
||
|
def setup(bot):
|
||
4 years ago
|
bot.add_cog(Anime(bot))
|