Every Fun and User commands sends an embed now

This commit is contained in:
Akumatic 2019-10-05 04:58:59 +02:00
parent d33253e4a9
commit 52655b0c4b
2 changed files with 109 additions and 48 deletions

View File

@ -8,32 +8,59 @@ class Fun(commands.Cog):
@commands.command() @commands.command()
async def ping(self, ctx): async def ping(self, ctx):
"""Ping, Pong""" """Ping, Pong"""
await ctx.send("{} Pong!".format(ctx.author.mention)) e = discord.Embed(title="<< Ping >>", description=ctx.author.mention, color=discord.Color.blue())
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
e.add_field(name=":ping_pong:", value="Pong!")
await ctx.send(embed=e)
@commands.command() @commands.command()
async def dice(self, ctx, *, countstr: str = "4"): async def dice(self, ctx, countstr: str = "6", dicesstr: str = "1"):
"""Throws a four-sided dice.""" """Throws a dice."""
e = discord.Embed(description=ctx.author.mention)
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
try: try:
count = int(countstr) count = int(countstr)
dices = int(dicesstr)
except: except:
await ctx.send(embed=discord.Embed(color=discord.Color.red(), description="Please enter a valid number for ``dice``")) e.title="<< Dice >>"
return e.color = discord.Color.red()
e.add_field(name=":game_die:", value="Please enter a valid number for `dice`")
return await ctx.send(embed=e)
limit = 1000 # The limit for the amount of sides of the dice can be set here limit = 120 # The limit for the amount of sides of the dice can be set here
if count > limit: if count > limit:
await ctx.send(embed=discord.Embed(color=discord.Color.red(), description=f"The limit for the number of sides of the dice is {limit}. Please use a smaller number next time.")) e.title="<< Dice >>"
count = limit e.add_field(name=":game_die:", value=f"You tried to throw {count} sided dices. Allowed are {limit} sides.")
e.color=discord.Color.red()
return await ctx.send(embed=e)
#Embed limitation
if dices > 25:
e.title="<< Dice >>"
e.add_field(name=":game_die:", value=f"You tried to throw {dices} dices. Allowed are 25 dices.")
e.color=discord.Color.red()
return await ctx.send(embed=e)
await ctx.send(embed=discord.Embed(title=f"<< Dice {count} >>", description=f"{random.randint(1, int(count))}", color=0x53ff28)) e.color = discord.Color.blue()
e.title = f"<< {dices} Dice {count} >>"
for i in range(dices):
e.add_field(name=":game_die:", value = random.randint(1, count), inline=True)
await ctx.send(embed=e)
@commands.command(name="8ball") @commands.command(name="8ball")
async def magic8ball(self,ctx, *, msg : str = None): async def magic8ball(self, ctx, *, msg: str = None):
e = discord.Embed(title="<< 8Ball >>", description=ctx.author.mention)
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
if msg is None: if msg is None:
await ctx.send(":8ball: You need to specify a question.") e.color = discord.Color.red()
e.add_field(name=":8ball:", value="You need to specify a question.")
return await ctx.send(embed=e)
else: else:
e = discord.Embed(color=0x3296ff) e.color = discord.Color.blue()
e.set_author(name = str(ctx.author), icon_url=ctx.author.avatar_url) if len(msg) < 1025:
e.add_field(name=":grey_question: Question", value=msg, inline=False) e.add_field(name=":grey_question: Question", value=msg, inline=False)
else:
e.add_field(name=":grey_question: Question", value=msg[:1024], inline=False)
e.add_field(name="[...]", value=msg[1024:], inline=False)
e.add_field(name=":8ball: Answer", value=random.choice( e.add_field(name=":8ball: Answer", value=random.choice(
["Yes.", "As I see it, yes.", "Outlook good.", "For sure", "Without a doubt.", "It is decidedly so.", ["Yes.", "As I see it, yes.", "Outlook good.", "For sure", "Without a doubt.", "It is decidedly so.",
"Without a doubt.", "Maybe", "Perhaps","It is uncertain", "Dont even think about it.", "Nope.", "Don't " "Without a doubt.", "Maybe", "Perhaps","It is uncertain", "Dont even think about it.", "Nope.", "Don't "
@ -43,41 +70,59 @@ class Fun(commands.Cog):
@commands.command() @commands.command()
async def coin(self, ctx): async def coin(self, ctx):
"""Throws a coin.""" """Flip a coin."""
await ctx.send("{} Your coin flip is {}".format(ctx.author.mention, random.choice(["Head", "Tail"]))) e = discord.Embed(title="<< Flip a coin >>", description=ctx.author.mention, color=discord.Color.blue())
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
e.add_field(name="Your coin shows ", value=f"{random.choice(['Heads', 'Tails'])}")
await ctx.send(embed=e)
@commands.command() @commands.command()
async def rps(self, ctx, userChoice : str = None): async def rps(self, ctx, user: str = None):
"""Play Rock, Paper, Scissors with the Bot """Play Rock, Paper, Scissors with the Bot
Input \"r\" for Rock, \"p\" for Paper and \"s\" for Scissors""" Input 'r' for Rock, 'p' for Paper and 's' for Scissors"""
if userChoice == None or str.lower(userChoice) not in ["r", "p", "s"]: e = discord.Embed(title="<< Rock, Paper, Scissors >>", description=ctx.author.mention)
return await ctx.send("{} Invalid input. Please enter \"r\", \"p\" or \"s\"".format(ctx.author.mention)) e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
if user == None or str.lower(user) not in ["r", "p", "s"]:
e.color=discord.Color.red()
e.add_field(name=":moyai::newspaper::scissors:", value="Invalid input. Please use 'r', 'p' or 's'")
return await ctx.send(embed=e)
botChoice = ["r", "p", "s"][random.randint(0,2)] emote = {"r":":moyai:", "p":":newspaper:", "s":":scissors:"}
if userChoice == "r" and botChoice == "p": e.color=discord.Color.blue()
await ctx.send("{} You lose".format(ctx.author.mention)) com = random.choice(["r", "p", "s"])
elif userChoice == "p" and botChoice == "s": e.add_field(name="You", value=emote[user], inline=True)
await ctx.send("{} You lose".format(ctx.author.mention)) e.add_field(name="Computers", value=emote[com], inline=True)
elif userChoice == "s" and botChoice == "r": if (user == "r" and com == "p") or (user == "p" and com == "s") or (user == "s" and com == "r"):
await ctx.send("{} You lose".format(ctx.author.mention)) e.add_field(name=":moyai::newspaper::scissors:", value="You lose")
elif userChoice == "r" and botChoice == "s": elif (user == "r" and com == "s") or (user == "p" and com == "r") or (user == "s" and com == "p"):
await ctx.send("{} You win".format(ctx.author.mention)) e.add_field(name=":moyai::newspaper::scissors:", value="You win")
elif userChoice == "p" and botChoice == "r":
await ctx.send("{} You win".format(ctx.author.mention))
elif userChoice == "s" and botChoice == "p":
await ctx.send("{} You win".format(ctx.author.mention))
else: else:
await ctx.send("{} It's a tie".format(ctx.author.mention)) e.add_field(name=":moyai::newspaper::scissors:", value="It's a tie")
await ctx.send(embed=e)
@commands.command() @commands.command()
async def roll(self, ctx, a : int = 0, b : int= 100): async def roll(self, ctx, astr: str = "0", bstr: str = "100"):
"""Rolls a random number between min and max. """Rolls a random number between min and max.
Default values are 0 and 100""" Default values are 0 and 100"""
e = discord.Embed(description=ctx.author.mention)
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
try:
a = int(astr)
b = int(bstr)
except:
e.title="<< Roll >>"
e.color = discord.Color.red()
e.add_field(name=":game_die:", value="Please enter valid numbers for `roll`")
return await ctx.send(embed=e)
e.color = discord.Color.blue()
if a > b: if a > b:
temp = a temp = a
a = b a = b
b = temp b = temp
await ctx.send("{} Random roll between {} and {}: {}".format(ctx.author.mention, a, b, random.randint(a, b))) e.title = f"<< Random roll in [{a}, {b}] >>"
e.add_field(name=":game_die:", value = random.randint(a, b))
await ctx.send(embed=e)
#Setup #Setup
def setup(bot): def setup(bot):

View File

@ -13,12 +13,19 @@ class User(commands.Cog):
info = await self.bot.application_info() info = await self.bot.application_info()
user = info.owner user = info.owner
if user is not None: if user is not None:
e = discord.Embed(color=0x802080) e = discord.Embed(title="A DM forwarded by your Bot", color=discord.Color.gold())
e.set_author(name = str(message.author) + " sent a DM.", e.set_author(name=f"Author: {message.author}", icon_url=message.author.avatar_url)
icon_url=message.author.avatar_url) e.add_field(name="From", value=message.author.mention, inline=False)
e.add_field(name="Profile", value=message.author.mention, inline=False)
if message.content: if message.content:
e.add_field(name="Content", value=message.content, inline=False) if len(message.content) < 1025:
e.add_field(name="Message", value=message.content, inline=False)
else:
i = 1
while len(message.content) > 1018:
e.add_field(name=f"Message ({i})", value=f"{message.content[:1019]}[...]", inline=False)
message.content = message.content[1019:]
i += 1
e.add_field(name=f"Message ({i})", value=f"{message.content}", inline=False)
numAtch = len(message.attachments) numAtch = len(message.attachments)
if numAtch == 0: if numAtch == 0:
await user.send(embed=e) await user.send(embed=e)
@ -29,14 +36,14 @@ class User(commands.Cog):
f = discord.File(x, filename = name) f = discord.File(x, filename = name)
extention = name.split(".")[-1] extention = name.split(".")[-1]
if extention in ["jpg", "jpeg", "png", "webp", "gif"]: if extention in ["jpg", "jpeg", "png", "webp", "gif"]:
e.set_image(url = "attachment://"+name) e.set_image(url = f"attachment://{name}")
await user.send(embed=e, file=f) await user.send(embed=e, file=f)
else: else:
e.add_field(name="Attachment",value=name, inline=False) e.add_field(name="Attachment",value=name, inline=False)
await user.send(embed=e) await user.send(embed=e)
await user.send(file=f) await user.send(file=f)
else: else:
e.add_field(name="Attachments",value=str(numAtch)+" Attachments sent", e.add_field(name="Attachments",value=f"{numAtch} Attachments sent",
inline=False) inline=False)
await user.send(embed=e) await user.send(embed=e)
for a in message.attachments: for a in message.attachments:
@ -44,11 +51,20 @@ class User(commands.Cog):
await a.save(x) await a.save(x)
await user.send(file=discord.File(x, filename=a.filename)) await user.send(file=discord.File(x, filename=a.filename))
@commands.command(hidden=True) @commands.command()
async def botinvite(self, ctx): async def botinvite(self, ctx):
await ctx.send(f"Invite this bot to your server: <https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot" e = discord.Embed(title="<< Invite this bot to your server >>", description=f"[Click here to invite this bot to"
"&permissions=8>\nPlease read <https://github.com/Akumatic/Akuma-Matata/blob/master/README.md> for informat" f" your server.](https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot&permissions"
"ions") f"=8)", color=discord.Color.blue())
e.set_thumbnail(url=self.bot.user.avatar_url)
await ctx.send(embed=e)
@commands.command()
async def source(self, ctx):
e = discord.Embed(title="<< Source Code >>", description=f"[Click here to view the source code of this bot on G"
f"ithub.](https://github.com/Akumatic/Akuma-Matata)", color=discord.Color.blue())
e.set_thumbnail(url="https://github.githubassets.com/images/modules/logos_page/Octocat.png")
await ctx.send(embed=e)
#Setup #Setup
def setup(bot): def setup(bot):