|
|
|
@ -1,12 +1,9 @@
|
|
|
|
|
import asyncio
|
|
|
|
|
from typing import List, Union
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from redbot.core import Config
|
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
|
from redbot.core import commands
|
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReactRestrictCombo:
|
|
|
|
@ -95,10 +92,10 @@ class ReactRestrict:
|
|
|
|
|
|
|
|
|
|
async def remove_react(self, message_id: int, role: discord.Role):
|
|
|
|
|
"""
|
|
|
|
|
Removes a given reaction.
|
|
|
|
|
Removes a given reaction
|
|
|
|
|
|
|
|
|
|
:param int message_id:
|
|
|
|
|
:param str or int emoji:
|
|
|
|
|
:param message_id:
|
|
|
|
|
:param role:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
current_combos = await self.combo_list()
|
|
|
|
@ -109,14 +106,13 @@ class ReactRestrict:
|
|
|
|
|
if to_keep != current_combos:
|
|
|
|
|
await self.set_combo_list(to_keep)
|
|
|
|
|
|
|
|
|
|
async def has_reactrestrict_combo(self, message_id: int)\
|
|
|
|
|
async def has_reactrestrict_combo(self, message_id: int) \
|
|
|
|
|
-> (bool, List[ReactRestrictCombo]):
|
|
|
|
|
"""
|
|
|
|
|
Determines if there is an existing role combo for a given message
|
|
|
|
|
and emoji ID.
|
|
|
|
|
|
|
|
|
|
:param int message_id:
|
|
|
|
|
:param str or int emoji:
|
|
|
|
|
:param message_id:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
if not await self.is_registered(message_id):
|
|
|
|
@ -170,7 +166,7 @@ class ReactRestrict:
|
|
|
|
|
|
|
|
|
|
return role
|
|
|
|
|
|
|
|
|
|
async def _get_message_from_channel(self, channel_id: int, message_id: int)\
|
|
|
|
|
async def _get_message_from_channel(self, channel_id: int, message_id: int) \
|
|
|
|
|
-> Union[discord.Message, None]:
|
|
|
|
|
"""
|
|
|
|
|
Tries to find a message by ID in the current guild context.
|
|
|
|
@ -185,7 +181,7 @@ class ReactRestrict:
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
async def _get_message(self, ctx: commands.Context, message_id: int)\
|
|
|
|
|
async def _get_message(self, ctx: commands.Context, message_id: int) \
|
|
|
|
|
-> Union[discord.Message, None]:
|
|
|
|
|
"""
|
|
|
|
|
Tries to find a message by ID in the current guild context.
|
|
|
|
@ -204,8 +200,6 @@ class ReactRestrict:
|
|
|
|
|
except discord.Forbidden: # No access to channel, skip
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
@commands.group()
|
|
|
|
@ -232,14 +226,14 @@ class ReactRestrict:
|
|
|
|
|
# except asyncio.TimeoutError:
|
|
|
|
|
# await ctx.send("You didn't respond in time, please redo this command.")
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# try:
|
|
|
|
|
# await message.add_reaction(actual_emoji)
|
|
|
|
|
# except discord.HTTPException:
|
|
|
|
|
# await ctx.send("I can't add that emoji because I'm not in the guild that"
|
|
|
|
|
# " owns it.")
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# noinspection PyTypeChecker
|
|
|
|
|
await self.add_reactrestrict(message_id, role)
|
|
|
|
|
|
|
|
|
@ -306,12 +300,12 @@ class ReactRestrict:
|
|
|
|
|
# await member.add_roles(*roles)
|
|
|
|
|
# except discord.Forbidden:
|
|
|
|
|
# pass
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# async def on_raw_reaction_remove(self, emoji: discord.PartialReactionEmoji,
|
|
|
|
|
# message_id: int, channel_id: int, user_id: int):
|
|
|
|
|
# """
|
|
|
|
|
# Event handler for long term reaction watching.
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# :param discord.PartialReactionEmoji emoji:
|
|
|
|
|
# :param int message_id:
|
|
|
|
|
# :param int channel_id:
|
|
|
|
@ -322,25 +316,25 @@ class ReactRestrict:
|
|
|
|
|
# emoji_id = emoji.id
|
|
|
|
|
# else:
|
|
|
|
|
# emoji_id = emoji.name
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# has_reactrestrict, combos = await self.has_reactrestrict_combo(message_id, emoji_id)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# if not has_reactrestrict:
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# try:
|
|
|
|
|
# member = self._get_member(channel_id, user_id)
|
|
|
|
|
# except LookupError:
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# if member.bot:
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# try:
|
|
|
|
|
# roles = [self._get_role(member.guild, c.role_id) for c in combos]
|
|
|
|
|
# except LookupError:
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# try:
|
|
|
|
|
# await member.remove_roles(*roles)
|
|
|
|
|
# except discord.Forbidden:
|
|
|
|
|