insert2-cogs/starboard.py
2024-12-26 12:43:40 -05:00

40 lines
No EOL
1.5 KiB
Python

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):
print("recieved emoji payload", file=sys.stderr)
print(payload.emoji.name, file=sys.stderr)
chann = self.bot.get_channel(payload.channel_id)
message = await chann.fetch_message(payload.message_id)
res = await.cur.execute(f"SELECT emoji, starchannel, minimumneeded, selfstar FROM starsettings WHERE serverid = {message.guild.id}")
try:
emoji, starchannel, minimumneeded, selfstar = await res.fetchone()
except TypeError:
return
if payload.emoji.name == emoji:
print("Recieved star payload", file=sys.stderr)
for r in message.reactions:
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
def setup(bot: commands.Bot):
bot.add_cog(starboard(bot))