fancy messages

pull/1/head
Matt Compton 3 years ago
parent 9c47fdc56e
commit 6f8bdb799c

@ -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()) + "`")

@ -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):

@ -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
Loading…
Cancel
Save