|
|
@ -13,28 +13,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from discord import Embed
|
|
|
|
from discord.ext import menus
|
|
|
|
from discord.ext import menus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AllPermissions(menus.Menu):
|
|
|
|
class SimpleMenu(menus.Menu):
|
|
|
|
def __init__(self, i, item, perms, embeds, bot, guild_bot):
|
|
|
|
def __init__(self, i, item, perms, embeds, bot):
|
|
|
|
super().__init__(timeout=125.0, clear_reactions_after=True)
|
|
|
|
super().__init__(timeout=125.0, clear_reactions_after=True)
|
|
|
|
self.i = i
|
|
|
|
self.i = i
|
|
|
|
self.perms = perms
|
|
|
|
self.perms = perms
|
|
|
|
self.dicts = embeds
|
|
|
|
self.dicts = embeds
|
|
|
|
self.type = item
|
|
|
|
self.type = item
|
|
|
|
self.bot = bot
|
|
|
|
self.bot = bot
|
|
|
|
self.guild_bot = guild_bot
|
|
|
|
|
|
|
|
|
|
|
|
async def remove_reaction(self, reaction):
|
|
|
|
|
|
|
|
"""Remove the reaction given"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.perms.manage_messages:
|
|
|
|
|
|
|
|
await self.message.remove_reaction(reaction, self.ctx.author)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def check(m, payload):
|
|
|
|
|
|
|
|
"""Simple check to make sure that the reaction is performed by the user"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return m.author == payload.member and m.channel.id == payload.channel_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def get_page(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Return the current page index
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur_page = self.i + 1
|
|
|
|
|
|
|
|
pages = len(self.dicts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cur_page, pages
|
|
|
|
|
|
|
|
|
|
|
|
async def send_initial_message(self, ctx, channel):
|
|
|
|
async def send_initial_message(self, ctx, channel):
|
|
|
|
"""Set the first embed to the first element in the pages[]"""
|
|
|
|
"""Set the first embed to the first element in the pages[]"""
|
|
|
|
|
|
|
|
|
|
|
|
initial = self.dicts[self.i]
|
|
|
|
initial = self.dicts[self.i]
|
|
|
|
|
|
|
|
|
|
|
|
cur_page = self.i + 1
|
|
|
|
cur_page, pages = self.get_page(self)
|
|
|
|
pages = len(self.dicts)
|
|
|
|
pages = len(self.dicts)
|
|
|
|
initial.set_author(name=f"{self.type} Permissions | Page {cur_page}/{pages}")
|
|
|
|
initial.set_author(name=f"{self.type} | Page {cur_page}/{pages}")
|
|
|
|
|
|
|
|
|
|
|
|
# Send embed
|
|
|
|
# Send embed
|
|
|
|
return await channel.send(embed=initial)
|
|
|
|
return await channel.send(embed=initial)
|
|
|
@ -43,58 +65,44 @@ class AllPermissions(menus.Menu):
|
|
|
|
async def on_left_arrow(self, payload):
|
|
|
|
async def on_left_arrow(self, payload):
|
|
|
|
"""Reaction to allow user to go to the previous page in the embed"""
|
|
|
|
"""Reaction to allow user to go to the previous page in the embed"""
|
|
|
|
|
|
|
|
|
|
|
|
# Simple check to make sure that the reaction is performed by the user
|
|
|
|
|
|
|
|
def check(m):
|
|
|
|
|
|
|
|
return m.author == payload.member
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
if check(self.ctx):
|
|
|
|
if self.check(self.ctx, payload):
|
|
|
|
# Set self.i to (i - 1) remainder length of the array
|
|
|
|
# Set self.i to (i - 1) remainder length of the array
|
|
|
|
self.i = (self.i - 1) % len(self.dicts)
|
|
|
|
self.i = (self.i - 1) % len(self.dicts)
|
|
|
|
prev_page = self.dicts[self.i]
|
|
|
|
prev_page = self.dicts[self.i]
|
|
|
|
|
|
|
|
|
|
|
|
cur_page = self.i + 1
|
|
|
|
cur_page, pages = self.get_page(self)
|
|
|
|
pages = len(self.dicts)
|
|
|
|
prev_page.set_author(name=f"{self.type} | Page {cur_page}/{pages}")
|
|
|
|
prev_page.set_author(name=f"{self.type} Permissions | Page {cur_page}/{pages}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send the embed and remove the reaction of the user
|
|
|
|
# Send the embed and remove the reaction of the user
|
|
|
|
await self.message.edit(embed=prev_page)
|
|
|
|
await self.message.edit(embed=prev_page)
|
|
|
|
if self.perms.manage_messages:
|
|
|
|
await self.remove_reaction("⬅")
|
|
|
|
await self.message.remove_reaction("⬅", self.ctx.author)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@menus.button('\N{BLACK RIGHTWARDS ARROW}')
|
|
|
|
@menus.button('\N{BLACK RIGHTWARDS ARROW}')
|
|
|
|
async def on_right_arrow(self, payload):
|
|
|
|
async def on_right_arrow(self, payload):
|
|
|
|
"""Reaction to allow user to go to the next page in the embed"""
|
|
|
|
"""Reaction to allow user to go to the next page in the embed"""
|
|
|
|
|
|
|
|
|
|
|
|
# Simple check to make sure that the reaction is performed by the user
|
|
|
|
|
|
|
|
def check(m):
|
|
|
|
|
|
|
|
return m.author == payload.member
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
if check(self.ctx):
|
|
|
|
if self.check(self.ctx, payload):
|
|
|
|
# Set self.i to (i + 1) remainder length of the array
|
|
|
|
# Set self.i to (i + 1) remainder length of the array
|
|
|
|
self.i = (self.i + 1) % len(self.dicts)
|
|
|
|
self.i = (self.i + 1) % len(self.dicts)
|
|
|
|
next_page = self.dicts[self.i]
|
|
|
|
next_page = self.dicts[self.i]
|
|
|
|
|
|
|
|
|
|
|
|
cur_page = self.i + 1
|
|
|
|
cur_page, pages = self.get_page(self)
|
|
|
|
pages = len(self.dicts)
|
|
|
|
next_page.set_author(name=f"{self.type} | Page {cur_page}/{pages}")
|
|
|
|
next_page.set_author(name=f"{self.type} Permissions | Page {cur_page}/{pages}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send the embed and remove the reaction of the user
|
|
|
|
# Send the embed and remove the reaction of the user
|
|
|
|
await self.message.edit(embed=next_page)
|
|
|
|
await self.message.edit(embed=next_page)
|
|
|
|
if self.perms.manage_messages:
|
|
|
|
await self.remove_reaction("➡")
|
|
|
|
await self.message.remove_reaction("➡", self.ctx.author)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@menus.button('\N{BLACK SQUARE FOR STOP}\ufe0f')
|
|
|
|
@menus.button('\N{BLACK SQUARE FOR STOP}\ufe0f')
|
|
|
|
async def on_stop(self, payload):
|
|
|
|
async def on_stop(self, payload):
|
|
|
|
"""Reaction to allow user to make the embed disappear"""
|
|
|
|
"""Reaction to allow user to make the embed disappear"""
|
|
|
|
|
|
|
|
|
|
|
|
# Simple check to make sure that the reaction is performed by the user
|
|
|
|
|
|
|
|
def check(m):
|
|
|
|
|
|
|
|
return m.author == payload.member
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
# Do nothing if the check does not return true
|
|
|
|
if check(self.ctx):
|
|
|
|
if self.check(self.ctx, payload):
|
|
|
|
# Delete the embed and stop the function from running
|
|
|
|
# Edit the embed and tell the member that the session has been closed
|
|
|
|
await self.message.delete()
|
|
|
|
embed = Embed(description="**Pagination Session Has Been Closed**",
|
|
|
|
|
|
|
|
colour=self.bot.admin_colour)
|
|
|
|
|
|
|
|
await self.message.edit(embed=embed)
|
|
|
|
self.stop()
|
|
|
|
self.stop()
|
|
|
|