insert2-cogs/starboard.py

71 lines
2.8 KiB
Python
Raw Normal View History

2024-12-26 17:13:02 +00:00
import nextcord
from nextcord.ext import commands
from nextcord import TextInputStyle
from dotenv import load_dotenv
from random import randint
import aiosqlite as sqlite3
import json
import traceback
import sys
from datetime import datetime
import base64
from urllib.parse import urlparse
import os
class starboard(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener('on_raw_reaction_add')
async def on_raw_reaction_add(self,payload):
2024-12-26 17:20:25 +00:00
print("recieved emoji payload", file=sys.stderr)
2024-12-26 17:23:41 +00:00
print(payload.emoji.name, file=sys.stderr)
2024-12-26 17:43:40 +00:00
chann = self.bot.get_channel(payload.channel_id)
message = await chann.fetch_message(payload.message_id)
2024-12-26 19:31:39 +00:00
res = await self.bot.cur.execute(f"SELECT emoji, starchannel, minimumneeded, selfstar FROM starsettings WHERE serverid = {message.guild.id}")
2024-12-26 17:43:40 +00:00
try:
emoji, starchannel, minimumneeded, selfstar = await res.fetchone()
except TypeError:
return
if payload.emoji.name == emoji:
2024-12-26 17:20:25 +00:00
print("Recieved star payload", file=sys.stderr)
2024-12-26 17:33:23 +00:00
for r in message.reactions:
2024-12-26 17:43:40 +00:00
if r.emoji == emoji:
if r.count == minimumneeded:
await chann.send(f"{r.count} {payload.emoji.name}")
await message.forward(self.bot.get_channel(starchannel))
return
2024-12-26 17:33:23 +00:00
2024-12-26 19:31:39 +00:00
@nextcord.slash_command(
2024-12-26 19:58:30 +00:00
name="starboardr",
2024-12-26 19:31:39 +00:00
description="For all your starring needs",
default_member_permissions=nextcord.Permissions(manage_messages=True),
2024-12-26 19:32:55 +00:00
force_global=True,
2024-12-26 19:31:39 +00:00
)
2024-12-26 19:58:30 +00:00
async def starboardr(self, interaction: nextcord.Interaction):
2024-12-26 19:31:39 +00:00
return
2024-12-26 19:58:30 +00:00
@starboardr.subcommand(
2024-12-26 19:31:39 +00:00
name="create",
description="Create a starboard, escape the emoji",
)
2024-12-26 19:35:32 +00:00
async def createstarboard(self, interaction: nextcord.Interaction, reaction: str, channel: nextcord.abc.GuildChannel, minimumneeded: int, selfstar: str = nextcord.SlashOption(choices=["Yes", "No"])):
2024-12-26 19:31:39 +00:00
selfstar = False
if selfstar == "Yes":
selfstar = True
await self.bot.cur.execute(f"""
2024-12-26 19:44:53 +00:00
INSERT INTO starsettings VALUES
('{reaction}', {channel.id}, '{minimumneeded}', {selfstar}, {interaction.guild_id})
2024-12-26 19:31:39 +00:00
""")
2024-12-26 19:44:53 +00:00
await interaction.response.send_message("Done!", ephemeral=True)
2024-12-26 19:58:30 +00:00
@starboardr.subcommand(
2024-12-26 19:45:45 +00:00
name="delete",
2024-12-26 19:44:53 +00:00
description="Delete a starboard",
)
async def createstarboard(self, interaction: nextcord.Interaction, channel: nextcord.abc.GuildChannel):
await self.bot.cur.execute(f"DELETE FROM starsettings WHERE starchannel = {channel.id}")
await interaction.response.send_message("Done!", ephemeral=True)
2024-12-26 19:31:39 +00:00
2024-12-26 17:13:02 +00:00
def setup(bot: commands.Bot):
bot.add_cog(starboard(bot))