|
|
|
@ -22,11 +22,17 @@ from discord.ext.commands import Cog, group, bot_has_permissions, has_permission
|
|
|
|
|
|
|
|
|
|
async def send_starboard_and_update_db(self, payload, action):
|
|
|
|
|
"""Send the starboard embed and update database/cache"""
|
|
|
|
|
deletion = False
|
|
|
|
|
|
|
|
|
|
if (starboard := self.bot.get_starboard(payload.guild_id)) and payload.emoji.name == "⭐":
|
|
|
|
|
message = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id)
|
|
|
|
|
|
|
|
|
|
if not message.author.bot and payload.member.id != message.author.id:
|
|
|
|
|
if action == "added":
|
|
|
|
|
check = not message.author.bot and payload.member.id != message.author.id
|
|
|
|
|
else:
|
|
|
|
|
check = not message.author.bot
|
|
|
|
|
|
|
|
|
|
if check:
|
|
|
|
|
channel = self.bot.get_channel(starboard)
|
|
|
|
|
msg_id, stars = await self.bot.check_starboard_messages_cache(message.id, payload.guild_id)
|
|
|
|
|
new_stars = stars + 1 if action == "added" else stars - 1
|
|
|
|
@ -46,11 +52,13 @@ async def send_starboard_and_update_db(self, payload, action):
|
|
|
|
|
|
|
|
|
|
if new_stars <= 0:
|
|
|
|
|
try:
|
|
|
|
|
deletion = True
|
|
|
|
|
star_message = await channel.fetch_message(msg_id)
|
|
|
|
|
await star_message.delete()
|
|
|
|
|
except NotFound:
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if deletion:
|
|
|
|
|
# Setup up pool connection
|
|
|
|
|
pool = self.bot.db
|
|
|
|
|
async with pool.acquire() as conn:
|
|
|
|
@ -182,7 +190,7 @@ class Starboard(Cog):
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
|
|
@group(name="starboard", case_insensitive=True, usage="`<setup|update|delete>`")
|
|
|
|
|
@group(name="starboarde", case_insensitive=True, usage="`<setup|update|delete>`")
|
|
|
|
|
@bot_has_permissions(embed_links=True)
|
|
|
|
|
@has_permissions(manage_guild=True)
|
|
|
|
|
async def starboard(self, ctx):
|
|
|
|
|