@@ -22,13 +22,15 @@ module.exports = {
2222 try {
2323 if ( ! serverSettings ) throw new Error ( "No server in database" ) ; // How did they even do this command?
2424 var cData = [ ] ;
25- await message . guild . channels . cache . forEach ( channel => {
26- if ( channel . type == "GUILD_TEXT" )
27- cData . push ( {
28- label : "#" + ( ( channel [ "id" ] == message . channel . id ) ? `${ channel [ "name" ] } (This channel)` : channel [ "name" ] ) ,
29- description : channel [ "topic" ] || "No topic." ,
30- value : channel [ "id" ]
31- } ) ;
25+ var bigChannelSize = ( message . guild . channels . cache . size > 25 ) ,
26+ filteredChannels = await message . guild . channels . cache . filter ( c => c . type == "GUILD_TEXT" ) . map ( x => ( { x, r : Math . random ( ) } ) ) . sort ( ( a , b ) => a . r - b . r ) . map ( a => a . x ) . slice ( 0 , 25 ) ;
27+ await filteredChannels . forEach ( channel => {
28+ var topic = ( channel [ "topic" ] ) ? channel [ "topic" ] . match ( / .{ 1 , 100 } / g) [ 0 ] : "No topic." ;
29+ cData . push ( {
30+ label : "#" + ( ( channel [ "id" ] == message . channel . id ) ? `${ channel [ "name" ] } (This channel)` : channel [ "name" ] ) ,
31+ description : topic ,
32+ value : channel [ "id" ]
33+ } ) ;
3234 } ) ;
3335
3436 var channelID = 0 ,
@@ -38,11 +40,13 @@ module.exports = {
3840 customDesc = "" ;
3941
4042
43+ var warning = ( bigChannelSize ) ? app . config . system . emotes . warning + "**You have more than the amount of channels we can show (25).** The list is random. If you do not see your desired channel, send `cancel` and rerun this command." : "" ;
44+
4145 await app . functions . msgHandler ( msg , {
4246 embeds : [ {
4347 title : `${ app . config . system . emotes . question } Reaction Roles - Select Channel` ,
4448 color : app . config . system . embedColors . purple ,
45- description : "Alright - from the dropdown - What channel are we going to be setting this up in?"
49+ description : "Alright - from the dropdown - What channel are we going to be setting this up in?\n" + warning ,
4650 } ] ,
4751 components : [ new MessageActionRow ( )
4852 . addComponents (
@@ -141,8 +145,6 @@ module.exports = {
141145 const filter = m => { return m . author . id === message . author . id } ;
142146 const collector = message . channel . createMessageCollector ( { filter, time : 90000 , errors : [ "time" ] } ) ;
143147
144- var reactionroles = [ ] ;
145-
146148 collector . on ( "collect" , async m => {
147149 if ( m . content == "done" ) {
148150 collector . stop ( "done" ) ;
@@ -158,7 +160,7 @@ module.exports = {
158160 } , 1 , true , ( async ( ) => {
159161 var channel = message . guild . channels . cache . get ( channelID ) ,
160162 reactionsList = [ ] ;
161- for ( var reaction in reactions ) { reactionsList . push ( reactions [ reaction ] [ "emoji" ] + " " + reactions [ reaction ] [ "roleMsg" ] ) ; } ;
163+ for ( var reaction in reactions ) { reactionsList . push ( ( app . functions . getEmoji ( app , reactions [ reaction ] [ "emoji" ] [ "id" ] , true ) || reactions [ reaction ] [ "emoji" ] [ "name" ] ) + " " + reactions [ reaction ] [ "roleMsg" ] ) ; } ;
162164 await channel . send ( {
163165 embeds : [ {
164166 title : customTitle ,
@@ -167,7 +169,7 @@ module.exports = {
167169 } ) . then ( msg => {
168170 messageID = msg . id ;
169171
170- for ( var reaction in reactions ) { msg . react ( reactions [ reaction ] [ "emoji" ] ) ; } ;
172+ for ( var reaction in reactions ) { msg . react ( reactions [ reaction ] [ "emoji" ] [ "id" ] ) ; } ;
171173 } ) . catch ( err => new Error ( err ) ) ;
172174
173175 var data = JSON . parse ( serverSettings [ "reactionRoles" ] ) || { } ;
@@ -205,12 +207,34 @@ module.exports = {
205207 roleMsg = splitMsg [ 1 ] ,
206208 roleID = app . functions . getID ( splitMsg [ 2 ] ) || splitMsg [ 2 ] ;
207209
210+ console . log ( emoji ) ;
211+ if ( emoji . startsWith ( "<:" ) || emoji . startsWith ( ":" ) ) {
212+ emoji = app . functions . getID ( emoji ) ;
213+ if ( emoji . startsWith ( "a:" ) ) emoji = emoji . split ( "a:" ) [ 1 ]
214+ emoji = emoji . split ( ":" ) [ 2 ] ;
215+
216+ const theEmoji = await app . client . emojis . cache . find ( e => e . id === emoji ) || false ;
217+
218+ if ( ! theEmoji ) {
219+ m . react ( app . config . system . emotes . error ) . catch ( err => { } ) ;
220+ app . functions . msgHandler ( m , { content : "Cannot use that custom emoji. Must be emoji from server I'm in!\n(You can also use built-in Discord emojis)" } , 0 , true , ( async errMsg => { setTimeout ( ( ) => { errMsg . delete ( ) } , 10000 ) } ) ) ;
221+ return ;
222+ } ;
223+ emoji = { name : theEmoji [ "name" ] , id : theEmoji [ "id" ] } ;
224+ } else
225+ emoji = { name : emoji , id : 0 } ;
208226 reactions . push ( {
209227 emoji : emoji ,
210228 roleID : roleID ,
211229 roleMsg : roleMsg
212230 } ) ;
213231
232+ if ( exMsg ) {
233+ var embs = exMsg . embeds ;
234+ embs [ 0 ] . description += ( ( reactions . length < 1 ) ? "\n" : "" ) + "\n" + ( ( app . functions . getEmoji ( app , emoji [ "id" ] , true ) || emoji [ "name" ] ) + " " + roleMsg ) ;
235+ exMsg . edit ( { embeds : embs } ) . catch ( err => { } ) ;
236+ } ;
237+
214238 m . react ( app . config . system . emotes . success ) . catch ( err => { } ) ;
215239 } ;
216240 } ) ;
0 commit comments