@@ -45,7 +45,7 @@ bot.on('message', (msg) => {
4545 const args = msg . content . slice ( config . prefix . length ) . split ( / ( .+ ) / ) ;
4646 const command = args . shift ( ) ;
4747 if ( commands . hasOwnProperty ( command ) ) commands [ command ] ( msg , args ) ;
48- } else if ( / \[ \[ ( [ ^ \] | ] + ) (?: | [ ^ \] ] + ) ? \] \] / g. test ( msg . cleanContent ) || / \{ \{ ( [ ^ } | ] + ) (?: | [ ^ } ] + ) ? \} \} / g. test ( msg . cleanContent ) || / - - ( [ ^ \- | ] + ) (?: | [ ^ - ] + ) ? - - / g. test ( msg . cleanContent ) ) {
48+ } else if ( / \[ \[ ( [ ^ \] | ] + ) (?: | [ ^ \] ] + ) ? \] \] / g. test ( msg . cleanContent ) || / \{ \{ ( [ ^ } | ] + ) (?: | [ ^ } ] + ) ? \} \} / g. test ( msg . cleanContent ) || / - - ( [ ^ | ] + ? ) - - / g. test ( msg . cleanContent ) ) {
4949 // eslint-disable-next-line consistent-return
5050 sql . get ( `SELECT * FROM guilds WHERE id="${ msg . guild . id } "` ) . then ( row => {
5151 if ( ! row . mainWiki ) {
@@ -91,8 +91,8 @@ bot.on('message', (msg) => {
9191 } ) ;
9292 }
9393
94- if ( / - - ( [ ^ \- | ] + ) (?: | [ ^ - ] + ) ? - - / g. test ( cleaned ) ) {
95- const name = cleaned . replace ( / .* ?- - ( [ ^ \- | ] + ) (?: | [ ^ - ] + ) ? - - / g, '$1\u200B' ) . replace ( / .* (?: \n | \r ) / g, '' ) ;
94+ if ( / - - ( [ ^ | ] + ? ) - - / g. test ( cleaned ) ) {
95+ const name = cleaned . replace ( / .* ?- - ( [ ^ | ] + ? ) - - / g, '$1\u200B' ) . replace ( / .* (?: \n | \r ) / g, '' ) ;
9696 const allLinks = name . split ( '\u200B' ) . slice ( 0 , - 1 ) ;
9797 const unique = new Set ( allLinks ) ;
9898
@@ -102,14 +102,14 @@ bot.on('message', (msg) => {
102102 }
103103
104104 Promise . all ( mps )
105- . then ( preparedSend => {
106- preparedSend = preparedSend . filter ( item => item !== undefined ) ;
107- if ( preparedSend . length > 1 ) {
108- console . log ( 'Sending message...' ) ;
109- msg . channel . send ( preparedSend ) ;
110- }
111- } )
112- . catch ( console . error ) ;
105+ . then ( preparedSend => {
106+ preparedSend = preparedSend . filter ( item => item !== undefined ) ;
107+ if ( preparedSend . length > 1 ) {
108+ console . log ( 'Sending message...' ) ;
109+ msg . channel . send ( preparedSend ) ;
110+ }
111+ } )
112+ . catch ( console . error ) ;
113113 } ) . catch ( console . error ) ;
114114 } ) . catch ( console . error ) ;
115115 } ) . catch ( console . error ) ;
@@ -138,13 +138,15 @@ const commands = {
138138 return ;
139139 }
140140
141- sql . each ( ` SELECT * FROM guilds` , ( err , row ) => {
141+ sql . each ( ' SELECT * FROM guilds' , ( err , row ) => {
142142 if ( row . broadcastChannel && ! err ) {
143143 if ( row . broadcastChannel !== '-1' ) {
144144 bot . channels . get ( row . broadcastChannel ) . send ( globalMessage ) ;
145145 }
146- } else if ( bot . guilds . get ( row . id ) ) {
147- bot . guilds . get ( row . id ) . defaultChannel . send ( globalMessage ) ;
146+ } else if ( bot . guilds . has ( row . id ) ) {
147+ defaultChannel ( bot . guilds . get ( row . id ) ) . then ( channel => {
148+ channel . send ( globalMessage ) ;
149+ } ) ;
148150 }
149151 } ) . catch ( console . error ) ;
150152 } ,
@@ -162,7 +164,7 @@ const commands = {
162164 msg . reply ( `Wiki is now set to: ${ wiki } ` )
163165 ) . catch ( ( ) => msg . reply ( 'Database error - please contact the developer!' ) ) ;
164166 } else {
165- sql . run ( ` UPDATE guilds SET mainWiki=? WHERE id=?` , [ wiki , msg . guild . id ] ) . then ( ( ) =>
167+ sql . run ( ' UPDATE guilds SET mainWiki=? WHERE id=?' , [ wiki , msg . guild . id ] ) . then ( ( ) =>
166168 msg . reply ( `Wiki is now set to: ${ wiki } ` ) ) ;
167169 }
168170 } ) . catch ( console . error ) ;
@@ -180,9 +182,9 @@ const commands = {
180182 wiki = wiki . split ( ' ' ) [ 0 ] ;
181183 sql . get ( `SELECT * FROM overrides WHERE guildID="${ msg . guild . id } " AND channelID="${ msg . channel . id } "` ) . then ( row => {
182184 if ( row ) {
183- sql . run ( ` UPDATE overrides SET wiki=? WHERE guildID=? AND channelID=?` , [ wiki , msg . guild . id , msg . channel . id ] ) ;
185+ sql . run ( ' UPDATE overrides SET wiki=? WHERE guildID=? AND channelID=?' , [ wiki , msg . guild . id , msg . channel . id ] ) ;
184186 } else {
185- sql . run ( ` INSERT INTO overrides (guildID, channelID, wiki) VALUES (?,?,?)` , [ msg . guild . id , msg . channel . id , wiki ] ) ;
187+ sql . run ( ' INSERT INTO overrides (guildID, channelID, wiki) VALUES (?,?,?)' , [ msg . guild . id , msg . channel . id , wiki ] ) ;
186188 }
187189 } ) . then ( ( ) => msg . reply ( `The wiki override for channel ${ msg . channel . name } is now set to ${ wiki } ` ) ) . catch ( console . error ) ;
188190 } ,
@@ -209,7 +211,7 @@ const commands = {
209211 sql . get ( `SELECT * FROM guilds WHERE id="${ msg . guild . id } "` ) . then ( row => {
210212 console . log ( row ) ;
211213 if ( row ) {
212- sql . run ( ` UPDATE guilds SET broadcastChannel=? WHERE id=?` , [ channel . id , msg . guild . id ] ) . then ( ( ) =>
214+ sql . run ( ' UPDATE guilds SET broadcastChannel=? WHERE id=?' , [ channel . id , msg . guild . id ] ) . then ( ( ) =>
213215 msg . reply ( `The broadcast channel for this server is now set to: ${ channel . name } .` )
214216 ) ;
215217 } else {
@@ -262,6 +264,20 @@ const reqAPI = (wiki, requestname) => new Promise((resolve, reject) => {
262264 } ) ;
263265} ) ;
264266
267+ const defaultChannel = ( guild ) => new Promise ( ( resolve , reject ) => {
268+ guild . channels . forEach ( ( value , key , map ) => {
269+ if ( value . name === 'general' ) {
270+ return resolve ( value ) ;
271+ }
272+ } ) ;
273+ let alt = guild . channels . filter ( ( channel ) => channel . type === 'text' && channel . permissionsFor ( bot . user ) . has ( 'SEND_MESSAGES' ) ) . first ( ) ;
274+ if ( alt ) {
275+ return resolve ( alt ) ;
276+ } else {
277+ return reject ( 'No applicable channel found.' ) ;
278+ }
279+ } ) ;
280+
265281if ( config . admin_snowflake === '' ) {
266282 console . log ( 'Admin snowflake empty. Startup disallowed.' ) ;
267283 process . exit ( 1 ) ;
0 commit comments