Skip to content

Commit c1e08f9

Browse files
Aman25taAltF02Matthew
authored
fixed compiler errors (#2)
* typescript new * Update config.json * updated * fixed * changed license, actually fixed sql file now * added license * Create LICENSE * Small update to license * fixed compiler errors, updated buttons * added config.example.yml * Delete config.yml * rest of the fixes * added config.ts * color, bug, added timestamp * added banned words, fixed regex * Refactor sql and eslint Co-authored-by: Matthew Bakhtiari <[email protected]> Co-authored-by: Matthew <[email protected]>
1 parent a365252 commit c1e08f9

File tree

16 files changed

+2147
-2149
lines changed

16 files changed

+2147
-2149
lines changed

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"airbnb-base"
8+
],
9+
"parser": "@typescript-eslint/parser",
10+
"parserOptions": {
11+
"ecmaVersion": 12,
12+
"sourceType": "module"
13+
},
14+
"plugins": [
15+
"@typescript-eslint"
16+
],
17+
"rules": {
18+
"import/extensions": "off",
19+
"import/no-unresolved": "off",
20+
"no-console": "off",
21+
"@typescript-eslint/no-var-requires": "warn",
22+
"class-methods-use-this": "off"
23+
}
24+
}

.eslintrc.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules
33
package-lock.json
44
*.js
55
*.map
6-
config.yaml
6+
.idea
7+
build
8+
config.yml

bannedwords.txt

Whitespace-only changes.

config.example.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
token:
2-
botId:
1+
token:
32
channelid:
4-
color: 0x20d84e
3+
color:
54
ownerid:
6-
postgres:
5+
modrole:
6+
database:
77
username:
88
password:
99
host:

migrations/init.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
CREATE TABLE if not exists nickreq (
1+
CREATE SCHEMA nickreq;
2+
3+
CREATE TABLE if not exists nickreq.requests (
24
user_id VARCHAR ( 50 ) NOT NULL,
35
nick VARCHAR ( 50 ) NOT NULL,
46
state BOOLEAN
5-
);
7+
);

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"discord-buttons": "^3.2.1",
3+
"discord-buttons": "github:discord-buttons/discord-buttons",
44
"discord.js": "^12.5.3",
55
"discord.js-commando": "^0.12.3",
66
"js-yaml": "^4.1.0",
@@ -9,11 +9,20 @@
99
"require": "^2.4.20"
1010
},
1111
"devDependencies": {
12+
"@types/js-yaml": "^4.0.2",
1213
"@types/node": "^15.12.5",
13-
"@typescript-eslint/eslint-plugin": "^4.28.2",
14-
"@typescript-eslint/parser": "^4.28.2",
15-
"eslint": "^7.30.0",
16-
"eslint-config-airbnb-typescript": "^12.3.1"
14+
"@types/pg": "^8.6.1",
15+
"@types/ws": "^7.4.6",
16+
"@typescript-eslint/eslint-plugin": "^4.29.3",
17+
"@typescript-eslint/parser": "^4.29.3",
18+
"eslint": "^7.32.0",
19+
"eslint-config-airbnb-base": "^14.2.1",
20+
"eslint-config-airbnb-typescript": "^12.3.1",
21+
"eslint-plugin-import": "^2.24.2",
22+
"typescript": "^4.3.5"
1723
},
18-
"license": "GPLv3"
24+
"license": "GPL-3.0",
25+
"scripts": {
26+
"start": "tsc && node build"
27+
}
1928
}

src/commands/nickreq/add.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';
2+
import { readFileSync, writeFileSync } from 'fs';
3+
4+
export default class NickReq extends Command {
5+
constructor(client: CommandoClient) {
6+
super(client, {
7+
name: 'add',
8+
group: 'nickreq',
9+
memberName: 'add',
10+
description: 'Add banned words to the filter.',
11+
guildOnly: true,
12+
userPermissions: ['MANAGE_MESSAGES'],
13+
examples: ['add word', 'add word1\nword2\nword3'],
14+
args: [
15+
{
16+
key: 'words',
17+
prompt: 'No words provided, please provide words to add.',
18+
type: 'string',
19+
},
20+
],
21+
});
22+
}
23+
24+
async run(message: CommandoMessage, { words }: { words: string }): Promise<null> {
25+
const wordArray = words.split('\n').filter((e) => e !== '');
26+
const bannedWords = readFileSync('./bannedwords.txt', 'utf-8').split('\n').filter((e) => e !== '');
27+
const finalStr = wordArray.concat(bannedWords.filter((item) => wordArray.indexOf(item) < 0)).join('\n');
28+
writeFileSync('bannedwords.txt', finalStr, 'utf8');
29+
await message.reply('Added words.');
30+
return null;
31+
}
32+
}

src/commands/nickreq/list.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';
2+
3+
export default class NickReq extends Command {
4+
constructor(client: CommandoClient) {
5+
super(client, {
6+
name: 'list',
7+
group: 'nickreq',
8+
memberName: 'list',
9+
description: 'List all banned words.',
10+
guildOnly: true,
11+
userPermissions: ['MANAGE_MESSAGES'],
12+
});
13+
}
14+
15+
async run(message: CommandoMessage): Promise<null> {
16+
await message.reply('Here is a file with all the banned words in nicknames.', {
17+
files: ['./bannedwords.txt'],
18+
});
19+
return null;
20+
}
21+
}

src/commands/nickreq/nickreq.ts

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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';
43
import { 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 = /^[\\x00-\\x7F]/;
37-
const testx = re.test(nick);
38-
if (testx === true) {
39-
await message.send('Illegal charecters in nickname!');
40-
return;
35+
const testx = /^[A-Za-z0-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

Comments
 (0)