insert2-cogs/misc.py

69 lines
2.8 KiB
Python
Raw Normal View History

2024-08-11 17:02:24 +00:00
import nextcord
from nextcord.ext import commands, application_checks
from nextcord import TextInputStyle
import traceback
import random
import aiosqlite as sqlite3
import aiohttp
from urllib.parse import urlparse
import os
import sys
2024-08-11 17:17:50 +00:00
errormsg = ["How could you do this to me!", "I tried my best...", "Maybe this will be fixed next patch", "There's always next time", "Simply processed too hard", "Perhaps this will be fixed", "You found an easter egg! Wait no it's just an error..."]
2024-08-11 17:02:24 +00:00
class misc(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener('on_application_command_error')
async def errorhandler(self, interaction: nextcord.Interaction, error: nextcord.DiscordException):
error = traceback.format_exception(type(error), error, error.__traceback__)
random.shuffle(errormsg)
2024-08-11 17:12:28 +00:00
strerror = "".join(error)
2024-08-11 17:17:50 +00:00
print(strerror, file=sys.stderr)
2024-08-11 17:10:03 +00:00
message = f"{errormsg[0]}\n```py\n{strerror[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists"
2024-08-11 17:02:24 +00:00
try:
await interaction.response.send_message(message, ephemeral=True)
except:
await interaction.followup.send(message, ephemeral=True)
2024-08-12 17:11:19 +00:00
@nextcord.slash_command(
name="testcommand",
description="Testing user installable",
integration_types=[
2024-08-12 17:12:08 +00:00
nextcord.IntegrationType.user_install,
2024-08-12 17:11:19 +00:00
],
2024-08-12 17:17:08 +00:00
contexts=[
nextcord.InteractionContextType.guild,
nextcord.InteractionContextType.bot_dm,
nextcord.InteractionContextType.private_channel,
],
2024-08-12 17:11:19 +00:00
force_global=True,
)
async def testcmd(self, interaction: nextcord.Interaction):
await interaction.response.send_message("Hey there this is a user installable command!")
2024-10-24 00:43:21 +00:00
@nextcord.message_command(
name="Pin Thread Message",
2024-10-24 00:59:33 +00:00
guild_ids=[732793772697583623],
2024-10-24 00:43:21 +00:00
)
2024-10-24 00:46:08 +00:00
async def pinthreadmessage(self, interaction: nextcord.Interaction, message: nextcord.Message):
2024-10-24 00:59:33 +00:00
if message.channel.type != nextcord.ChannelType.public_thread and message.channel.type != nextcord.ChannelType.private_thread:
await interaction.response.send_message("You don't have permission in this context", ephemeral=True)
return
2024-10-24 00:46:08 +00:00
if message.channel.owner_id == interaction.user.id:
2024-10-24 01:01:27 +00:00
if not message.pinned:
2024-10-24 00:59:33 +00:00
await message.pin()
await interaction.response.send_message("Pinned", ephemeral=True)
else:
await message.unpin()
await interaction.response.send_message("Unpinned", ephemeral=True)
2024-10-24 00:43:21 +00:00
else:
2024-10-24 00:48:07 +00:00
await interaction.response.send_message("You don't have permission in this context", ephemeral=True)
2024-08-12 17:11:19 +00:00
2024-08-11 17:42:11 +00:00
2024-08-11 17:03:37 +00:00
def setup(bot: commands.Bot):
bot.add_cog(misc(bot))