1- const commando = require ( 'discord.js-commando' ) ;
2- const { MessageButton, MessageActionRow } = require ( 'discord-buttons' ) ;
3- import { load } from 'js-yaml' ;
1+ import { Command , CommandoClient , CommandoMessage } from 'discord.js-commando' ;
2+ import { MessageEmbed , TextChannel } from 'discord.js' ;
43import { readFileSync } from 'fs' ;
5- import DB from '../../db.js' ;
6- import { MessageEmbed } from 'discord.js' ;
4+ import DB from '../../db' ;
75
6+ import Config from '../../config' ;
87
9- const fileContents = readFileSync ( './config.yml' , 'utf8' ) ;
10- const config = load ( fileContents ) ;
8+ const config = Config . getConfig ( ) ;
119
12- export default class NickReq extends commando . Command {
13- constructor ( client ) {
10+ export default class NickReq extends Command {
11+ constructor ( client : CommandoClient ) {
1412 super ( client , {
1513 name : 'request' ,
1614 group : 'nickreq' ,
1715 memberName : 'request' ,
1816 description : 'Main Nickname Request commands' ,
17+ guildOnly : true ,
18+ examples : [ 'request example nickname' ] ,
1919 args : [
2020 {
2121 key : 'nick' ,
@@ -26,54 +26,72 @@ export default class NickReq extends commando.Command {
2626 } ) ;
2727 }
2828
29- async run ( message , { nick } ) {
30- if ( message . guild == null ) return ;
29+ async run ( message : CommandoMessage , { nick } : { nick : string } ) : Promise < null > {
3130 if ( nick . length > 32 ) {
3231 await message . reply ( 'The nickname must be less than 32 characters' ) ;
33- return ;
32+ return null ;
3433 }
3534
36- const re = / ^ [ \\ x 0 0 -\\ x 7 F ] / ;
37- const testx = re . test ( nick ) ;
38- if ( testx === true ) {
39- await message . send ( 'Illegal charecters in nickname!' ) ;
40- return ;
35+ const testx = / ^ [ A - Z a - z 0 - 9 ] / . test ( nick ) ;
36+ if ( ! testx ) {
37+ await message . reply ( 'Illegal charecters in start of nickname!' ) ;
38+ return null ;
4139 }
42-
4340 const check = await DB . check ( message . author . id ) ;
4441 if ( check . length !== 0 ) {
4542 await message . reply ( 'You already have an ongoing request!' ) ;
46- return ;
43+ return null ;
4744 }
48- await DB . insert ( message . author . id , nick ) ;
4945
50- const channel = await message . guild . channels . cache . get ( config . channelid ) ;
46+ const bannedWords = readFileSync ( './bannedwords.txt' , 'utf-8' ) . split ( '\n' ) . filter ( ( e ) => e !== '' ) ;
47+ const testy = new RegExp ( `(${ bannedWords . join ( '|' ) } )` , 'g' ) . test ( nick ) ;
48+ if ( testy ) {
49+ await message . reply ( 'You cannot use those words in your nickname.' ) ;
50+ return null ;
51+ }
52+ const channel = await this . client . channels . fetch ( config . channelid ) ;
53+ if ( channel === undefined || ! ( channel instanceof TextChannel ) ) {
54+ console . error ( 'Unable to fetch channel!' ) ;
55+ return null ;
56+ }
57+ await DB . insert ( message . author . id , nick ) ;
5158
5259 const embed = new MessageEmbed ( {
5360 title : 'Nickname Request' ,
54- description : `I would like to set my nickname to: \` ${ nick } \` ` ,
55- color : config . color ,
61+ description : `I would like to set my nickname to: ${ nick } ` ,
62+ color : ( config . color !== null ) ? config . color : 0xFFFF00 ,
5663 author : {
5764 name : `${ message . author . username } #${ message . author . discriminator } ` ,
58- iconURL : message . author . avatarURL ( ) ,
65+ iconURL : message . author . avatarURL ( ) || undefined ,
5966 } ,
60- footer : { text : message . author . id } ,
61- } ) ;
62- const button1 = new MessageButton ( )
63- . setLabel ( 'Accept' )
64- . setStyle ( 'green' )
65- . setID ( 'Accepted' ) ;
66- const button2 = new MessageButton ( )
67- . setLabel ( 'Reject' )
68- . setStyle ( 'red' )
69- . setID ( 'Rejected' ) ;
70- const row = new MessageActionRow ( )
71- . addComponent ( button1 )
72- . addComponent ( button2 ) ;
73- await channel . send ( {
67+ footer : { text : `${ message . author . id } ` } ,
68+ } ) . setTimestamp ( ) ;
69+ const buttonEmbed = {
70+ type : 1 ,
71+ components : [
72+ {
73+ type : 2 ,
74+ style : 3 ,
75+ label : 'Accept' ,
76+ emoji : undefined ,
77+ disabled : false ,
78+ url : undefined ,
79+ custom_id : 'Accepted' ,
80+ } ,
81+ {
82+ type : 2 ,
83+ style : 4 ,
84+ label : 'Reject' ,
85+ emoji : undefined ,
86+ disabled : false ,
87+ url : undefined ,
88+ custom_id : 'Rejected' ,
89+ } ,
90+ ] ,
7491 embed,
75- component : row ,
76- } ) ;
92+ } ;
93+ await channel . send ( buttonEmbed ) ;
7794 await message . reply ( 'Request sent.' ) ;
95+ return null ;
7896 }
7997}
0 commit comments