Files
payphone/payphone/cogs/utility/cog.py
T

61 lines
1.7 KiB
Python

from datetime import datetime, timezone
import discord
from discord.ext import commands, tasks
from payphone import bot
from payphone.cogs import base
from payphone.core import config, constants, checks
class Utility(base.Cog):
def __init__(self, bot_instance: bot.Payphone):
self.bot = bot_instance
self.update_heartbeat.start()
def cog_unload(self) -> None:
self.update_heartbeat.cancel()
@tasks.loop(seconds=5)
async def update_heartbeat(self) -> None:
"""Updates the heartbeat timestamp."""
self.bot.heartbeat.value = int(datetime.now(timezone.utc).timestamp())
@commands.command()
@commands.cooldown(1, 60, commands.BucketType.user)
@checks.is_unbanned()
async def suggest(self, ctx: commands.Context, *, suggestion: str) -> None:
"""
Make a suggestion to improve Payphone.
"""
embed = discord.Embed(
color=constants.EMBED_COLOR,
title="Suggestion",
description=suggestion,
timestamp=datetime.now(timezone.utc),
author=discord.EmbedAuthor(
name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url
),
footer=discord.EmbedFooter(text=ctx.author.name),
thumbnail=self.bot.user.display_avatar.url,
)
await self.bot.get_partial_messageable(config.SUGGESTIONS_CHANNEL_ID).send(
embed=embed
)
await ctx.send("✅ Thank you for your suggestion!")
def setup(b: bot.Payphone) -> None:
"""Load the cog into the bot.
Args:
b (bot.Payphone): The bot instance to load the cog into.
"""
b.add_cog(Utility(b))