11import json
2+ import math
23from typing import *
34
45import discord
89
910from helpers import tools
1011from helpers .spark_module import SparkModule
12+ from helpers .view_helpers import ViewPaginator , CustomButton
1113from .settings import SETTINGS
1214
1315
@@ -65,16 +67,7 @@ def __init__(self, bot):
6567 @bot .has_permissions (administrator = True )
6668 async def add_emoji_action (ctx : discord .commands .context .ApplicationContext ,
6769 message : discord .Message ):
68- async def response (dropdown1 : CustomDropdown , interaction1 : discord .Interaction ):
69- if dropdown1 .values [0 ] != self .CUSTOM_EMOJI :
70- emoji = get (ctx .guild .emojis , id = int (dropdown1 .values [0 ]))
71- if not emoji :
72- return await ctx .edit (embed = discord .Embed (
73- description = self .bot .i18n .get ('UNKNOWN_ERROR' ),
74- color = discord .Color .red ()))
75- await self .add_emoji_reaction_action (ctx .guild , ctx , message , emoji )
76- return
77-
70+ async def custom_emoji_response (button : CustomButton , interaction1 : discord .Interaction ):
7871 m = await ctx .send (embed = discord .Embed (
7972 description = self .bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI_MESSAGE' ),
8073 color = discord .Color .blue ()))
@@ -84,33 +77,36 @@ async def response(dropdown1: CustomDropdown, interaction1: discord.Interaction)
8477
8578 self .activating_reactions [(m .channel .id , m .id )] = (ctx .author .id , ctx , message )
8679
87- if len (ctx .guild .emojis ) < 24 :
88- options = [discord .SelectOption (label = bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI_LABEL' ),
89- emoji = bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI' ),
90- value = self .CUSTOM_EMOJI )] + [
91- discord .SelectOption (label = str (emoji .name ),
92- emoji = str (emoji ),
93- value = str (emoji .id )) for emoji in ctx .guild .emojis
94- ]
95-
80+ async def response (dropdown1 : CustomDropdown , interaction1 : discord .Interaction ):
81+ emoji = get (ctx .guild .emojis , id = int (dropdown1 .values [0 ]))
82+ if not emoji :
83+ return await ctx .edit (embed = discord .Embed (
84+ description = self .bot .i18n .get ('UNKNOWN_ERROR' ),
85+ color = discord .Color .red ()))
86+ await self .add_emoji_reaction_action (ctx .guild , ctx , message , emoji )
87+
88+ options = [
89+ discord .SelectOption (label = str (emoji .name ),
90+ emoji = str (emoji ),
91+ value = str (emoji .id )) for emoji in ctx .guild .emojis
92+ ]
93+
94+ pages = []
95+ for i in range (math .ceil (len (options ) / 25 )):
9696 view = discord .ui .View ()
9797 view .add_item (
98- CustomDropdown (response , bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_EMOJI_PLACEHOLDER' ), options ))
99-
100- return await ctx .respond (
101- embed = discord .Embed (title = self .bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_EMOJI_TITLE' )),
102- view = view ,
103- ephemeral = True )
104-
105- else :
106- m = await ctx .send (embed = discord .Embed (
107- description = self .bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI_MESSAGE' ),
108- color = discord .Color .blue ()))
98+ CustomButton (custom_emoji_response ,
99+ label = bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI_LABEL' ),
100+ emoji = bot .i18n .get ('EMOJI_REACTIONS_CUSTOM_EMOJI' )))
101+ view .add_item (
102+ CustomDropdown (response ,
103+ bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_EMOJI_PLACEHOLDER' ),
104+ options [i * 25 :(i + 1 )* 25 ]))
105+ pages .append (view )
109106
110- await ctx .respond (embed = discord .Embed (title = self .bot .i18n .get ('EMOJI_REACTIONS_REACT_TO' ),
111- description = m .jump_url ), ephemeral = True )
107+ paginator = ViewPaginator (pages , hide_empty = True )
112108
113- self . activating_reactions [( m . channel . id , m . id )] = ( ctx . author . id , ctx , message )
109+ await ctx . respond ( view = paginator . view (), ephemeral = True )
114110
115111 @bot .has_permissions (administrator = True )
116112 async def get_emoji_reactions (ctx : discord .commands .context .ApplicationContext ):
@@ -271,13 +267,21 @@ async def response2(dropdown2: CustomDropdown, interaction2: discord.Interaction
271267 role_name = role .name
272268 options .append (discord .SelectOption (label = role_name , emoji = role_emoji , value = str (role .id )))
273269
274- view = discord .ui .View ()
275- view .add_item (CustomDropdown (response2 ,
276- self .bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_ROLE_PLACEHOLDER' ),
277- options ))
270+ pages = []
271+ for i in range (math .ceil (len (options ) / 25 )):
272+ view = discord .ui .View ()
273+
274+ view .add_item (
275+ CustomDropdown (response2 ,
276+ self .bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_ROLE_PLACEHOLDER' ),
277+ options [i * 25 :(i + 1 ) * 25 ]))
278+ pages .append (view )
279+
280+ paginator = ViewPaginator (pages , hide_empty = True )
281+
278282 await ctx .edit (embed = discord .Embed (title = self .bot .i18n .get ('EMOJI_REACTIONS_CHOOSE_ROLE_TITLE' )
279283 .format (str (emoji ), self .bot .i18n .get (self .reaction_types [v ]))),
280- view = view )
284+ view = paginator . view () )
281285
282286 else :
283287 await ctx .edit (
@@ -349,6 +353,6 @@ async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent):
349353 for action in actions :
350354 try :
351355 if action .action_type == self .TRIGGER_ROLE :
352- await tools .remove_role (payload . member .guild , payload . member , int (action .action ))
353- except :
354- pass
356+ await tools .remove_role (member .guild , member , int (action .action ))
357+ except Exception as e :
358+ self . bot . logger . warning ( '{} for user {} in {}' . format ( e , member , member . guild ))
0 commit comments