From 6f8bdb799c563214cdf4e2aff17e804e147471cd Mon Sep 17 00:00:00 2001 From: Matt Compton Date: Mon, 31 Jan 2022 16:41:16 +0000 Subject: [PATCH] fancy messages --- bot.py | 9 ++++++--- cogs/task.py | 12 +++++++++--- fancy.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 fancy.py diff --git a/bot.py b/bot.py index 58d2d81..6c37bb6 100644 --- a/bot.py +++ b/bot.py @@ -7,6 +7,9 @@ import discord from discord.ext import commands from pretty_help import DefaultMenu, PrettyHelp +# Custom +from fancy import * + intents = discord.Intents.default() intents.members = True @@ -33,7 +36,7 @@ async def distrohop(ctx, *, count=None): distrohops += int(count) with open("miku_distrohops.txt", "w") as f: f.write(str(distrohops)) - await ctx.send("Miku distrohops: " + str(distrohops)) + await ctx.send(embed=infmsg("Distrohops","Miku distrohops: `" + str(distrohops) + "`", "Good lord.")) @bot.event async def on_ready(): @@ -43,8 +46,8 @@ async def on_ready(): try: bot.load_extension(cogs_dir + "." + extension) except (Exception) as e: - await chan.send(f"Failed to load extension `{extension}`, reason was:") - await chan.send("```" + str(e) + "```") + await chan.send(embed=errmsg("Load error",f"Failed to load extension `{extension}`, traceback below.")) + await chan.send(embed=errmsg("Traceback","```" + str(e) + "```")) await chan.send("Started/restarted at: `" + str(datetime.now()) + "`") diff --git a/cogs/task.py b/cogs/task.py index 4927ca9..155daea 100644 --- a/cogs/task.py +++ b/cogs/task.py @@ -1,6 +1,12 @@ +# Pip from discord.ext import tasks, commands + +# Stdlib import feedparser,os +# Custom +from fancy import * + CHAN = 842491569176051712 ROLE = 825474723948265474 WATCHED = "grub,arch-install-scripts,base,filesystem,lsb-release,neofetch,pfetch" @@ -59,9 +65,9 @@ class Packages(commands.Cog): print(str(p)) print("-"*10) msg = "`" + p.name + "` is now `" + p.ver + "`" - await self.bot.get_channel(CHAN).send(msg) - #else: - # await self.bot.get_channel(CHAN).send("No new packages") + await self.bot.get_channel(CHAN).send(embed=infmsg("New package",msg)) + else: + await self.bot.get_channel(CHAN).send(embed=infmsg("Notice","No new packages","Lucky for us :)")) @check.before_loop async def before_check(self): diff --git a/fancy.py b/fancy.py new file mode 100644 index 0000000..88a07be --- /dev/null +++ b/fancy.py @@ -0,0 +1,33 @@ +import discord + +def fancymsg(title, text, color, footnote=None): + + e = discord.Embed(colour=color) + e.add_field(name=title, value=text, inline=False) + + if footnote is not None: + e.set_footer(text=footnote) + + return e + + +def errmsg(title, text, footnote=None): + return fancymsg(title, text, discord.Colour.red(), footnote) + + +def warnmsg(title, text, footnote=None): + return fancymsg(title, text, discord.Colour.gold(), footnote) + + +def infmsg(title, text, footnote=None): + return fancymsg(title, text, discord.Colour.blurple(), footnote) + +def imgbed(title, type, dat): + # see https://discordpy.readthedocs.io/en/stable/faq.html?highlight=embed#how-do-i-use-a-local-image-file-for-an-embed-image + e = discord.Embed(color=discord.Colour.blurple()) + e.add_field(name="foo", value=title, inline=False) + if type == "rem": + e.set_image(url=dat) + else: + e.set_image(url="attachment://" + dat) + return e \ No newline at end of file