2023-07-25 03:39:17 +02:00
|
|
|
import nextcord
|
2023-07-27 02:45:11 +02:00
|
|
|
import datetime
|
2023-07-25 03:39:17 +02:00
|
|
|
|
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
async def send(
|
|
|
|
ctx,
|
|
|
|
title: str,
|
|
|
|
text: str,
|
2023-07-27 02:45:11 +02:00
|
|
|
content: str = '',
|
2023-07-25 03:39:17 +02:00
|
|
|
ephemeral: bool = False,
|
2023-08-01 02:39:20 +02:00
|
|
|
color: nextcord.Color = nextcord.Color.blue(),
|
|
|
|
**kwargs
|
2023-07-25 03:39:17 +02:00
|
|
|
):
|
2023-07-27 02:45:11 +02:00
|
|
|
edit = False
|
|
|
|
|
|
|
|
if isinstance(ctx, nextcord.PartialInteractionMessage):
|
|
|
|
ctx = await ctx.fetch()
|
|
|
|
edit = True
|
|
|
|
|
2023-07-25 03:39:17 +02:00
|
|
|
embed = nextcord.Embed(
|
|
|
|
title=title,
|
|
|
|
description=text,
|
|
|
|
color=color
|
|
|
|
)
|
2023-07-27 02:45:11 +02:00
|
|
|
|
|
|
|
time_difference = datetime.datetime.now(datetime.timezone.utc) - ctx.created_at
|
|
|
|
milliseconds = int(time_difference.total_seconds() * 1000)
|
|
|
|
|
|
|
|
end = ''
|
|
|
|
|
2023-08-01 02:39:20 +02:00
|
|
|
if milliseconds > 5000: # https://youtu.be/-5wpm-gesOY
|
2023-07-27 02:45:11 +02:00
|
|
|
end = f' in {milliseconds}ms'
|
|
|
|
|
|
|
|
embed.set_footer(text=f'Powered by NovaAI{end}', icon_url='https://i.ibb.co/LDyFcSh/fav-blurple.png')
|
2023-07-25 03:39:17 +02:00
|
|
|
embed.set_author(name='NovaCord', url='https://nova-oss.com/novacord')
|
|
|
|
|
2023-07-27 02:45:11 +02:00
|
|
|
interaction_type = Union[nextcord.Interaction, nextcord.InteractionResponse]
|
|
|
|
|
2023-08-01 02:39:20 +02:00
|
|
|
# these checks are done so this function is easy to use
|
2023-07-27 02:45:11 +02:00
|
|
|
|
|
|
|
if edit:
|
2023-08-01 02:39:20 +02:00
|
|
|
return await ctx.edit(embed=embed, content=content, **kwargs)
|
2023-07-27 02:45:11 +02:00
|
|
|
|
2023-07-25 03:39:17 +02:00
|
|
|
if isinstance(ctx, nextcord.Message):
|
2023-08-01 02:39:20 +02:00
|
|
|
response = await ctx.reply(embed=embed, content=content, **kwargs)
|
2023-07-27 02:45:11 +02:00
|
|
|
|
|
|
|
elif isinstance(ctx, interaction_type):
|
2023-08-01 02:39:20 +02:00
|
|
|
response = await ctx.send(embed=embed, ephemeral=ephemeral, content=content, **kwargs)
|
2023-07-27 02:45:11 +02:00
|
|
|
|
2023-07-25 03:39:17 +02:00
|
|
|
else:
|
2023-08-01 02:39:20 +02:00
|
|
|
response = await ctx.send(embed=embed, content=content, **kwargs)
|
2023-07-25 03:39:17 +02:00
|
|
|
|
|
|
|
return response
|
|
|
|
|
2023-07-27 02:45:11 +02:00
|
|
|
async def ok(ctx, text: str, title: str=':white_check_mark: Success', *args, **kwargs):
|
2023-07-25 03:39:17 +02:00
|
|
|
return await send(ctx, title, text, color=nextcord.Color.green(), *args, **kwargs)
|
|
|
|
|
2023-07-27 02:45:11 +02:00
|
|
|
async def info(ctx, text: str, title: str=':information_source: Information', *args, **kwargs):
|
2023-07-25 03:39:17 +02:00
|
|
|
return await send(ctx, title, text, color=nextcord.Color.blue(), *args, **kwargs)
|
|
|
|
|
2023-07-27 02:45:11 +02:00
|
|
|
async def warn(ctx, text: str, title: str=':warning: Warning', *args, **kwargs):
|
2023-07-25 03:39:17 +02:00
|
|
|
return await send(ctx, title, text, color=nextcord.Color.orange(), *args, **kwargs)
|
|
|
|
|
2023-07-27 02:45:11 +02:00
|
|
|
async def error(ctx, text: str, title: str=':x: Error - Command Failed', *args, **kwargs):
|
2023-07-25 03:39:17 +02:00
|
|
|
return await send(ctx, title, text, color=nextcord.Color.red(), *args, **kwargs)
|