Compare commits
54 Commits
1.0.0-beta
...
1.1.0-alph
Author | SHA1 | Date | |
---|---|---|---|
cb4bddf983
|
|||
b1b087e32c
|
|||
451b414fba
|
|||
b53c08a553 | |||
f34e06d31f
|
|||
173438395e
|
|||
59429ea548
|
|||
dbb64baae3
|
|||
eccb379b51 | |||
cb5516246f
|
|||
63c67f4992 | |||
b24cc4eba8 | |||
4466c138ab
|
|||
44e5cc8c91
|
|||
fc9f1c7c4c
|
|||
6be983b217
|
|||
781d2e547e | |||
ddf28c1612
|
|||
5fb9ad1e12
|
|||
bfabd62674
|
|||
5eb56efb79
|
|||
1c6c79dacf
|
|||
f4b7685f94
|
|||
c3b0a4316b
|
|||
ee9039c239
|
|||
361326c31e
|
|||
f7c878854b
|
|||
a8cd924e18
|
|||
3a6641be86
|
|||
c9df84b255
|
|||
0d69cf3e7b
|
|||
730151e34b
|
|||
d4457e89ce | |||
11845cae42 | |||
d853fa55d3
|
|||
88834703ef
|
|||
9cbb7799e9 | |||
005b9bd69c
|
|||
21812157f8
|
|||
52a349c1b9
|
|||
6242c09e4b | |||
24d39d471e
|
|||
545bda9bee
|
|||
966625bac4
|
|||
cc50a0a089 | |||
27f625155e
|
|||
8b72326419
|
|||
d9c81ef3f2
|
|||
71b401dbee
|
|||
fda6166483
|
|||
df2548dba6
|
|||
ca29f047e9
|
|||
7a5d7f46b6
|
|||
0c9000a48c
|
32
Changelog.md
Normal file
32
Changelog.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
This file is used to list changes made to this software.
|
||||||
|
|
||||||
|
_Current development release: 1.1.0-alpha.1_
|
||||||
|
|
||||||
|
## V1.1.0 [`Unreleased`]
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- If a channel gets deleted and the responsible user has been detected, a message will be sent to that user informing him of the deletion
|
||||||
|
|
||||||
|
## V1.0.0 [2022-11-29]
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- /info
|
||||||
|
- /logchannel
|
||||||
|
- /blocklist get
|
||||||
|
- /blocklist add
|
||||||
|
- /blocklist remove
|
||||||
|
- /preservesettings
|
||||||
|
- /showblocklist
|
||||||
|
- /showsettings
|
||||||
|
- Data will be deleted by default when the bot leaves the server
|
||||||
|
- Server admins can change the behaviour of the bot when it leaves the server to keep the data persistent
|
||||||
|
- Scans for blocked words in channel names and deletes the channel if found
|
||||||
|
- Gets the user creating or renaming a channel to a blocked word
|
||||||
|
- When settings are changed or channels are deleted, notifications to a logchannel can be enabled
|
||||||
|
- CLI to change settings and get information during runtime by attaching to the apps docker container
|
||||||
|
- API for automated uptime checks to prevent the bot from going offline unnoticed
|
||||||
|
- Bot notifies admins via /showsettings when it lacks permissions needed for its functionality
|
40
README.md
40
README.md
@ -1,28 +1,53 @@
|
|||||||
# eu.astrogd.white-leopard
|
# eu.astrogd.white-leopard
|
||||||
|
|
||||||
A Discord bot that checks Discord channel names for banned words and prevents renaming of them
|
A Discord bot that checks Discord channel names for banned words and prevents renaming of them
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
### /logchanel [channel?]
|
|
||||||
|
### /logchanel [channel?] `Permission: MANAGE_GUILD`
|
||||||
|
|
||||||
Sets the channel where the bot will log if a channel meets the banned word criteria. If channel is omitted, the log channel will be disabled.
|
Sets the channel where the bot will log if a channel meets the banned word criteria. If channel is omitted, the log channel will be disabled.
|
||||||
|
|
||||||
### /blocklist
|
### /blocklist `Permission: MANAGE_GUILD`
|
||||||
|
|
||||||
#### /blocklist get
|
#### /blocklist get
|
||||||
Gets the global and server specific banned word list and returns it
|
|
||||||
|
Returns the global and server specific banned word list and returns it (Same behaviour as /showblocklist)
|
||||||
|
|
||||||
#### /blocklist add [word]
|
#### /blocklist add [word]
|
||||||
|
|
||||||
Adds the word to the server specific blocklist
|
Adds the word to the server specific blocklist
|
||||||
|
|
||||||
#### /blocklist remove [word]
|
#### /blocklist remove [word]
|
||||||
|
|
||||||
Removes the word from the server specific blocklist
|
Removes the word from the server specific blocklist
|
||||||
|
|
||||||
### /info
|
### /info `Permission: EVERYONE`
|
||||||
|
|
||||||
Returns general information about the bot and the servers stats
|
Returns general information about the bot and the servers stats
|
||||||
|
|
||||||
|
### /preservesettings `Permission: ADMINISTRATOR`
|
||||||
|
|
||||||
|
Changes the behaviour when the bot leaves the server.
|
||||||
|
Options are:
|
||||||
|
|
||||||
|
- Keep settings persistent even if the bot leaves
|
||||||
|
- Delete setting when the bot leaves the server [default]
|
||||||
|
|
||||||
|
### /showblocklist `Permission: MANAGE_CHANNELS`
|
||||||
|
|
||||||
|
Returns the global and server specific banned word list and returns it
|
||||||
|
|
||||||
|
### /showsettings `Permission: MANAGE_GUILD`
|
||||||
|
|
||||||
|
Returns the current settings for the server
|
||||||
|
|
||||||
## Environment variables
|
## Environment variables
|
||||||
|
|
||||||
| Name | Description | Required | Example |
|
| Name | Description | Required | Example |
|
||||||
| :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ |
|
| :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ |
|
||||||
| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... |
|
| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... |
|
||||||
| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1:3546 |
|
| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1 |
|
||||||
| DB_USERNAME | Username of the database | ▶️ | root |
|
| DB_USERNAME | Username of the database | ▶️ | root |
|
||||||
| DB_PASSWORD | Password of the database | ▶️ | abc123 |
|
| DB_PASSWORD | Password of the database | ▶️ | abc123 |
|
||||||
| DB_DATABASE | Database name | ▶️ | white-leopard |
|
| DB_DATABASE | Database name | ▶️ | white-leopard |
|
||||||
@ -30,6 +55,7 @@ Returns general information about the bot and the servers stats
|
|||||||
| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... |
|
| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... |
|
||||||
| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 |
|
| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 |
|
||||||
|
|
||||||
### Icon explanation:
|
### Icon explanation
|
||||||
|
|
||||||
- ▶️ = Required in runtime
|
- ▶️ = Required in runtime
|
||||||
- 🚀 = Required during CI/CD
|
- 🚀 = Required during CI/CD
|
||||||
|
181
package-lock.json
generated
181
package-lock.json
generated
@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "eu.astrogd.white-leopard",
|
"name": "eu.astrogd.white-leopard",
|
||||||
"version": "1.0.0-beta.1",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "eu.astrogd.white-leopard",
|
"name": "eu.astrogd.white-leopard",
|
||||||
"version": "1.0.0-beta.1",
|
"version": "1.0.0",
|
||||||
"license": "CC-BY-NC-ND-4.0",
|
"license": "CC-BY-NC-ND-4.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.6.0",
|
"discord.js": "^14.6.0",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^11.0.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"pg": "^8.8.0",
|
"pg": "^8.8.0",
|
||||||
"typeorm": "^0.3.10"
|
"typeorm": "^0.3.10"
|
||||||
@ -40,42 +40,42 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@discordjs/builders": {
|
"node_modules/@discordjs/builders": {
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.4.0.tgz",
|
||||||
"integrity": "sha512-Pvca6Nw8Hp+n3N+Wp17xjygXmMvggbh5ywUsOYE2Et4xkwwVRwgzxDJiMUuYapPtnYt4w/8aKlf5khc8ipLvhg==",
|
"integrity": "sha512-nEeTCheTTDw5kO93faM1j8ZJPonAX86qpq/QVoznnSa8WWcCgJpjlu6GylfINTDW6o7zZY0my2SYdxx2mfNwGA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/util": "^0.1.0",
|
"@discordjs/util": "^0.1.0",
|
||||||
"@sapphire/shapeshift": "^3.7.0",
|
"@sapphire/shapeshift": "^3.7.1",
|
||||||
"discord-api-types": "^0.37.12",
|
"discord-api-types": "^0.37.20",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"ts-mixer": "^6.0.1",
|
"ts-mixer": "^6.0.2",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@discordjs/collection": {
|
"node_modules/@discordjs/collection": {
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.3.0.tgz",
|
||||||
"integrity": "sha512-VvrrtGb7vbfPHzbhGq9qZB5o8FOB+kfazrxdt0OtxzSkoBuw9dURMkCwWizZ00+rDpiK2HmLHBZX+y6JsG9khw==",
|
"integrity": "sha512-ylt2NyZ77bJbRij4h9u/wVy7qYw/aDqQLWnadjvDqW/WoWCxrsX6M3CIw9GVP5xcGCDxsrKj5e0r5evuFYwrKg==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@discordjs/rest": {
|
"node_modules/@discordjs/rest": {
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-1.4.0.tgz",
|
||||||
"integrity": "sha512-U6X5J+r/MxYpPTlHFuPxXEf92aKsBaD2teBC7sWkKILIr30O8c9+XshfL7KFBCavnAqS/qE+PF9fgRilO3N44g==",
|
"integrity": "sha512-k3Ip7ffFSAfp7Mu4H/3BEXFvFz+JsbXRrRtpeBMnSp1LefhtlZWJE6xdXzNlblktKNQltnRwY+z0NZrGQdxAMw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/collection": "^1.2.0",
|
"@discordjs/collection": "^1.3.0",
|
||||||
"@discordjs/util": "^0.1.0",
|
"@discordjs/util": "^0.1.0",
|
||||||
"@sapphire/async-queue": "^1.5.0",
|
"@sapphire/async-queue": "^1.5.0",
|
||||||
"@sapphire/snowflake": "^3.2.2",
|
"@sapphire/snowflake": "^3.2.2",
|
||||||
"discord-api-types": "^0.37.12",
|
"discord-api-types": "^0.37.20",
|
||||||
"file-type": "^18.0.0",
|
"file-type": "^18.0.0",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.1",
|
||||||
"undici": "^5.11.0"
|
"undici": "^5.13.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
@ -124,9 +124,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sapphire/shapeshift": {
|
"node_modules/@sapphire/shapeshift": {
|
||||||
"version": "3.7.0",
|
"version": "3.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.7.1.tgz",
|
||||||
"integrity": "sha512-A6vI1zJoxhjWo4grsxpBRBgk96SqSdjLX5WlzKp9H+bJbkM07mvwcbtbVAmUZHbi/OG3HLfiZ1rlw4BhH6tsBQ==",
|
"integrity": "sha512-JmYN/0GW49Vl8Hi4PwrsDBNjcuCylH78vWYolVys74LRIzilAAMINxx4RHQOdvYoz+ceJKVp4+zBbQ5kuIFOLw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"lodash.uniqwith": "^4.5.0"
|
"lodash.uniqwith": "^4.5.0"
|
||||||
@ -402,19 +402,6 @@
|
|||||||
"npm": "1.2.8000 || >= 1.4.16"
|
"npm": "1.2.8000 || >= 1.4.16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/body-parser/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/body-parser/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@ -641,19 +628,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "2.1.2"
|
"ms": "2.0.0"
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"supports-color": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/depd": {
|
"node_modules/depd": {
|
||||||
@ -683,27 +662,27 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/discord-api-types": {
|
"node_modules/discord-api-types": {
|
||||||
"version": "0.37.19",
|
"version": "0.37.20",
|
||||||
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.19.tgz",
|
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.20.tgz",
|
||||||
"integrity": "sha512-5dVUYJfxCh/RU/S4D7osG3H+Ntl0GBkANO6oVRl35Eo+cd/peoNUAmcSzLzQ9Fqu2RJ9+2vd7DVcqNqYjX38wQ=="
|
"integrity": "sha512-uAO+55E11rMkYR36/paE1vKN8c2bZa1mgrIaiQIBgIZRKZTDIGOZB+8I5eMRPFJcGxrg16riUu+0aTu2JQEPew=="
|
||||||
},
|
},
|
||||||
"node_modules/discord.js": {
|
"node_modules/discord.js": {
|
||||||
"version": "14.6.0",
|
"version": "14.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.7.0.tgz",
|
||||||
"integrity": "sha512-On1K7xpJZRe0KsziIaDih2ksYPhgxym/ZqV45i1f3yig4vUotikqs7qp5oXiTzQ/UTiNRCixUWFTh7vA1YBCqw==",
|
"integrity": "sha512-CR2JAoqR+82D7mfMZ7toPAqdIk2sMF8wgTc8yDGPPMHzJknIKtkEPtzWFhBYGMZUkK+M4POw08ngBWqK2A4RMg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^1.3.0",
|
"@discordjs/builders": "^1.4.0",
|
||||||
"@discordjs/collection": "^1.2.0",
|
"@discordjs/collection": "^1.3.0",
|
||||||
"@discordjs/rest": "^1.3.0",
|
"@discordjs/rest": "^1.4.0",
|
||||||
"@discordjs/util": "^0.1.0",
|
"@discordjs/util": "^0.1.0",
|
||||||
"@sapphire/snowflake": "^3.2.2",
|
"@sapphire/snowflake": "^3.2.2",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
"discord-api-types": "^0.37.12",
|
"discord-api-types": "^0.37.20",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"lodash.snakecase": "^4.1.1",
|
"lodash.snakecase": "^4.1.1",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.1",
|
||||||
"undici": "^5.11.0",
|
"undici": "^5.13.0",
|
||||||
"ws": "^8.9.0"
|
"ws": "^8.11.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
@ -797,19 +776,6 @@
|
|||||||
"node": ">= 0.10.0"
|
"node": ">= 0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/fast-deep-equal": {
|
"node_modules/fast-deep-equal": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||||
@ -848,19 +814,6 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/finalhandler/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/finalhandler/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/forwarded": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
@ -878,16 +831,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fs-extra": {
|
"node_modules/fs-extra": {
|
||||||
"version": "10.1.0",
|
"version": "11.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.0.0.tgz",
|
||||||
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
|
"integrity": "sha512-4YxRvMi4P5C3WQTvdRfrv5UVqbISpqjORFQAW5QPiKAauaxNCwrEdIi6pG3tDFhKKpMen+enEhHIzB/tvIO+/w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graceful-fs": "^4.2.0",
|
"graceful-fs": "^4.2.0",
|
||||||
"jsonfile": "^6.0.1",
|
"jsonfile": "^6.0.1",
|
||||||
"universalify": "^2.0.0"
|
"universalify": "^2.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=14.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fs.realpath": {
|
"node_modules/fs.realpath": {
|
||||||
@ -1208,9 +1161,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
},
|
},
|
||||||
"node_modules/mz": {
|
"node_modules/mz": {
|
||||||
"version": "2.7.0",
|
"version": "2.7.0",
|
||||||
@ -1621,19 +1574,6 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/send/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/send/node_modules/debug/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/send/node_modules/ms": {
|
"node_modules/send/node_modules/ms": {
|
||||||
"version": "2.1.3",
|
"version": "2.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||||
@ -2026,6 +1966,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/typeorm/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typeorm/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "4.9.3",
|
"version": "4.9.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
||||||
@ -2040,9 +2001,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
"node_modules/undici": {
|
||||||
"version": "5.12.0",
|
"version": "5.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-5.13.0.tgz",
|
||||||
"integrity": "sha512-zMLamCG62PGjd9HHMpo05bSLvvwWOZgGeiWlN/vlqu3+lRo3elxktVGEyLMX+IO7c2eflLjcW74AlkhEZm15mg==",
|
"integrity": "sha512-UDZKtwb2k7KRsK4SdXWG7ErXiL7yTGgLWvk2AXO1JMjgjh404nFo6tWSCM2xMpJwMPx3J8i/vfqEh1zOqvj82Q==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"busboy": "^1.6.0"
|
"busboy": "^1.6.0"
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "eu.astrogd.white-leopard",
|
"name": "eu.astrogd.white-leopard",
|
||||||
"version": "1.0.0-beta.2",
|
"version": "1.1.0-alpha.2",
|
||||||
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
|
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "tsc && shx cp package-lock.json build/package-lock.json",
|
"build": "tsc && shx cp package-lock.json build/package-lock.json",
|
||||||
|
"start:rebuild": "npm run build && node --enable-source-maps .",
|
||||||
"deploy-commands:dev": "ts-node ci/devDeploy.ts",
|
"deploy-commands:dev": "ts-node ci/devDeploy.ts",
|
||||||
"deploy-commands:prod": "ts-node ci/deploy.ts",
|
"deploy-commands:prod": "ts-node ci/deploy.ts",
|
||||||
"deploy:dev": "npm run build && npm run deploy-commands:dev && docker compose build && docker compose up -d",
|
"deploy:dev": "npm run build && npm run deploy-commands:dev && docker compose build && docker compose up -d",
|
||||||
@ -40,7 +41,7 @@
|
|||||||
"discord.js": "^14.6.0",
|
"discord.js": "^14.6.0",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^11.0.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"pg": "^8.8.0",
|
"pg": "^8.8.0",
|
||||||
"typeorm": "^0.3.10"
|
"typeorm": "^0.3.10"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
import { getGuildSetting } from "../tools/data";
|
||||||
import moment from "moment";
|
|
||||||
import { Badword, database, GuildSetting } from "../data";
|
import { Badword, database, GuildSetting } from "../data";
|
||||||
import { Console } from "console";
|
import { Console } from "console";
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ export default async function execute(args: string[]) {
|
|||||||
case "info": {
|
case "info": {
|
||||||
if (!args[1]) return printHelp();
|
if (!args[1]) return printHelp();
|
||||||
const settings = await getGuildSetting(args[1]);
|
const settings = await getGuildSetting(args[1]);
|
||||||
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
|
||||||
const wordCount = await database.getRepository(Badword).count({
|
const wordCount = await database.getRepository(Badword).count({
|
||||||
where: {
|
where: {
|
||||||
guildID: args[1]
|
guildID: args[1]
|
||||||
@ -21,35 +19,12 @@ export default async function execute(args: string[]) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Guild ${args[1]}:
|
console.log(`Guild ${args[1]}:
|
||||||
- Premium: ${isPremium ? `ACTIVE for ${moment(settings.isPremiumUntil).fromNow(true)}` : "INACTIVE"}
|
- Preserve Settings: ${settings.preserveDataOnGuildLeave ? "ENABLED" : "DISABLED"}
|
||||||
- Logchannel: ${settings.notificationChannelID ? `ENABLED (${settings.notificationChannelID})` : "DISABLED"}
|
- Logchannel: ${settings.notificationChannelID ? `ENABLED (${settings.notificationChannelID})` : "DISABLED"}
|
||||||
- blocked Words: ${wordCount}`);
|
- blocked Words: ${wordCount}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "setpremium": {
|
|
||||||
if (!args[1] || !args[2]) return printHelp();
|
|
||||||
const settings = await getGuildSetting(args[1]);
|
|
||||||
|
|
||||||
if (args[2].toLowerCase() === "null") {
|
|
||||||
settings.isPremiumUntil = null;
|
|
||||||
await database.getRepository(GuildSetting).save(settings);
|
|
||||||
console.log("Premium status removed for guild " + args[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const date = new Date(args[2]);
|
|
||||||
if (isNaN(Number(date))) return printHelp();
|
|
||||||
|
|
||||||
const now = new Date();
|
|
||||||
if (now > date) return console.log("Date lies in the past");
|
|
||||||
|
|
||||||
settings.isPremiumUntil = date;
|
|
||||||
await database.getRepository(GuildSetting).save(settings);
|
|
||||||
console.log(`Premium status for guild ${args[1]} is now active for ${moment(date).fromNow(true)}`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "words": {
|
case "words": {
|
||||||
if (!args[1] || !args[2]) return printWordHelp();
|
if (!args[1] || !args[2]) return printWordHelp();
|
||||||
|
|
||||||
@ -124,6 +99,21 @@ export default async function execute(args: string[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "delete": {
|
||||||
|
if (!args[1]) return printHelp();
|
||||||
|
|
||||||
|
await database.getRepository(GuildSetting).delete({
|
||||||
|
id: args[1]
|
||||||
|
});
|
||||||
|
|
||||||
|
await database.getRepository(Badword).delete({
|
||||||
|
guildID: args[1]
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Deleted all data for guild ${args[1]}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
printHelp();
|
printHelp();
|
||||||
break;
|
break;
|
||||||
@ -136,8 +126,8 @@ function printHelp() {
|
|||||||
console.log(`Usage "guild":
|
console.log(`Usage "guild":
|
||||||
|
|
||||||
guild info [GUILDID]
|
guild info [GUILDID]
|
||||||
guild setPremium [GUILDID] [YYYY-MM-DD or NULL]
|
guild words [get|add|remove|clear]
|
||||||
guild words [get|add|remove|clear]`);
|
guild delete [GUILDID]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printWordHelp() {
|
function printWordHelp() {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { runCleanup } from "../service";
|
||||||
import client from "./index";
|
import client from "./index";
|
||||||
|
|
||||||
const token = process.env["TOKEN"];
|
const token = process.env["TOKEN"];
|
||||||
@ -7,4 +8,6 @@ client.login(token);
|
|||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
console.log(`Connected to Discord API. Bot account is ${client.user?.tag} (${client.user?.id})`);
|
console.log(`Connected to Discord API. Bot account is ${client.user?.tag} (${client.user?.id})`);
|
||||||
|
|
||||||
|
runCleanup();
|
||||||
});
|
});
|
@ -1,10 +1,11 @@
|
|||||||
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
|
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
|
||||||
import { database, Badword } from "../data";
|
import { database, Badword } from "../data";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
import { getGuildSetting } from "../tools/data";
|
||||||
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
|
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
|
||||||
import { getGuildChannel } from "../tools/discord";
|
import { getGuildChannel } from "../tools/discord";
|
||||||
import { Color, Emoji } from "../tools/design";
|
import { Color, Emoji } from "../tools/design";
|
||||||
|
import { execute as showBlocklistRunner } from "./showblocklist";
|
||||||
|
|
||||||
const builder = new SlashCommandBuilder();
|
const builder = new SlashCommandBuilder();
|
||||||
builder.setName("blocklist");
|
builder.setName("blocklist");
|
||||||
@ -45,30 +46,12 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
if (!interaction.guildId) throw new Error("Command was executed in DM context");
|
if (!interaction.guildId) throw new Error("Command was executed in DM context");
|
||||||
|
|
||||||
const settings = await getGuildSetting(interaction.guildId);
|
const settings = await getGuildSetting(interaction.guildId);
|
||||||
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
|
||||||
|
|
||||||
const logChannel = settings.notificationChannelID ? await getGuildChannel(interaction.guildId, settings.notificationChannelID) : null;
|
const logChannel = settings.notificationChannelID ? await getGuildChannel(interaction.guildId, settings.notificationChannelID) : null;
|
||||||
|
|
||||||
switch (interaction.options.getSubcommand(true)) {
|
switch (interaction.options.getSubcommand(true)) {
|
||||||
case "get": {
|
case "get": {
|
||||||
const guildBadWords = await database.getRepository(Badword).find({
|
await showBlocklistRunner(interaction);
|
||||||
select: {
|
|
||||||
value: true
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
guildID: interaction.guildId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const globalBadWords = await database.getRepository(Badword).find({
|
|
||||||
where: {
|
|
||||||
guildID: IsNull()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interaction.reply({
|
|
||||||
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
|
|
||||||
ephemeral: true
|
|
||||||
}).catch();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,14 +62,14 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const limit = isPremium ? 100 : 10;
|
const limit = 100;
|
||||||
if (count >= limit) {
|
if (count >= limit) {
|
||||||
const embed = getFailedEmbed();
|
const embed = getFailedEmbed();
|
||||||
embed.setDescription(`You reached the word limit for your guild. Please delete a word before adding a new one`);
|
embed.setDescription(`You reached the word limit for your guild. Please delete a word before adding a new one`);
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +88,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +116,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
if (logChannel && logChannel.isTextBased()) {
|
if (logChannel && logChannel.isTextBased()) {
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
embeds: [logMessage]
|
embeds: [logMessage]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -154,7 +137,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +150,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
|
|
||||||
const logMessage = getDefaultEmbed();
|
const logMessage = getDefaultEmbed();
|
||||||
logMessage.setTitle(`${Emoji.SETTINGS} Word removed`);
|
logMessage.setTitle(`${Emoji.SETTINGS} Word removed`);
|
||||||
@ -180,7 +163,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
if (logChannel && logChannel.isTextBased()) {
|
if (logChannel && logChannel.isTextBased()) {
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
embeds: [logMessage]
|
embeds: [logMessage]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
import * as notification from "./notification";
|
import * as notification from "./logchannel";
|
||||||
import * as blocklist from "./blocklist";
|
import * as blocklist from "./blocklist";
|
||||||
import * as info from "./info";
|
import * as info from "./info";
|
||||||
|
import * as preserveSettings from "./preserveSettings";
|
||||||
|
import * as showBlocklist from "./showblocklist";
|
||||||
|
import * as showSettings from "./showSettings";
|
||||||
|
|
||||||
const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON()];
|
const commands = [];
|
||||||
|
commands.push(notification);
|
||||||
|
commands.push(blocklist);
|
||||||
|
commands.push(info);
|
||||||
|
commands.push(preserveSettings);
|
||||||
|
commands.push(showBlocklist);
|
||||||
|
commands.push(showSettings);
|
||||||
|
|
||||||
|
const array = commands.map((command) => command.builder.toJSON());
|
||||||
|
|
||||||
export {
|
export {
|
||||||
array
|
array
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js";
|
import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js";
|
||||||
import * as notification from "./notification";
|
import * as notification from "./logchannel";
|
||||||
import * as blocklist from "./blocklist";
|
import * as blocklist from "./blocklist";
|
||||||
import * as info from "./info";
|
import * as info from "./info";
|
||||||
|
import * as preserveSettings from "./preserveSettings";
|
||||||
|
import * as showBlocklist from "./showblocklist";
|
||||||
|
import * as showSettings from "./showSettings";
|
||||||
import client from "../client";
|
import client from "../client";
|
||||||
import getDefaultEmbed from "../tools/defaultEmbeds";
|
import getDefaultEmbed from "../tools/defaultEmbeds";
|
||||||
|
|
||||||
@ -9,6 +12,9 @@ const commands = new Collection<string, { builder: SlashCommandBuilder, execute:
|
|||||||
commands.set(notification.builder.name, notification);
|
commands.set(notification.builder.name, notification);
|
||||||
commands.set(blocklist.builder.name, blocklist);
|
commands.set(blocklist.builder.name, blocklist);
|
||||||
commands.set(info.builder.name, info);
|
commands.set(info.builder.name, info);
|
||||||
|
commands.set(preserveSettings.builder.name, preserveSettings);
|
||||||
|
commands.set(showBlocklist.builder.name, showBlocklist);
|
||||||
|
commands.set(showSettings.builder.name, showSettings);
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async (interaction) => {
|
client.on(Events.InteractionCreate, async (interaction) => {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
@ -38,6 +44,6 @@ client.on(Events.InteractionCreate, async (interaction) => {
|
|||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -1,7 +1,6 @@
|
|||||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { Badword, database } from "../data";
|
import { Badword, database } from "../data";
|
||||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
|
||||||
import getDefaultEmbed from "../tools/defaultEmbeds";
|
import getDefaultEmbed from "../tools/defaultEmbeds";
|
||||||
import pack from "../../package.json";
|
import pack from "../../package.json";
|
||||||
import { Color, Emoji } from "../tools/design";
|
import { Color, Emoji } from "../tools/design";
|
||||||
@ -14,8 +13,6 @@ builder.setDMPermission(false);
|
|||||||
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
|
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
|
||||||
|
|
||||||
const settings = await getGuildSetting(interaction.guildId);
|
|
||||||
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
|
||||||
const globalBlockedWordsCount = await database.getRepository(Badword).count({
|
const globalBlockedWordsCount = await database.getRepository(Badword).count({
|
||||||
where: {
|
where: {
|
||||||
guildID: IsNull()
|
guildID: IsNull()
|
||||||
@ -30,17 +27,13 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
embed.setTitle(`${Emoji.SECURITY_CHALLENGE} Channel filter V${pack.version} by AstroGD®`);
|
embed.setTitle(`${Emoji.SECURITY_CHALLENGE} Channel filter V${pack.version} by AstroGD®`);
|
||||||
embed.setDescription(`Codename eu.astrogd.white-leopard`);
|
embed.setDescription(`Codename eu.astrogd.white-leopard`);
|
||||||
embed.setColor(isPremium ? Color.PREMIUM_ORANGE : Color.INFORMING_BLUE);
|
embed.setColor(Color.INFORMING_BLUE);
|
||||||
embed.addFields({
|
embed.addFields({
|
||||||
name: "What does this bot do?",
|
name: "What does this bot do?",
|
||||||
value: "This bot checks for blocked words contained in channel names and reverts the changes if found."
|
value: "This bot checks for blocked words contained in channel names and reverts the changes if found."
|
||||||
},{
|
},{
|
||||||
name: "Author",
|
name: "Author",
|
||||||
value: `This bot was created by AstroGD#0001 ${Emoji.ASTROGD} mainly for the official r/Overwatch2 Subreddit Discord server`
|
value: `This bot was created by AstroGD#0001 ${Emoji.ASTROGD} mainly for the official r/Overwatch2 Subreddit Discord server`
|
||||||
},{
|
|
||||||
name: "Server status",
|
|
||||||
value: `${isPremium ? Emoji.PREMIUM : Emoji.SWITCH_OFF} Premium features are ${isPremium ? "enabled" : "disabled"} on this server`,
|
|
||||||
inline: true
|
|
||||||
},{
|
},{
|
||||||
name: "Global word count",
|
name: "Global word count",
|
||||||
value: globalBlockedWordsCount.toString(),
|
value: globalBlockedWordsCount.toString(),
|
||||||
@ -57,7 +50,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
|||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
|
||||||
import getDefaultEmbed, { getSuccessEmbed } from "../tools/defaultEmbeds";
|
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
|
||||||
import { database, GuildSetting } from "../data";
|
import { database, GuildSetting } from "../data";
|
||||||
import { getGuildSetting } from "../tools/data";
|
import { getGuildSetting } from "../tools/data";
|
||||||
import { getGuildChannel } from "../tools/discord";
|
import { getGuildChannel, getChannelPermission } from "../tools/discord";
|
||||||
import { Emoji } from "../tools/design";
|
import { Emoji } from "../tools/design";
|
||||||
|
|
||||||
const builder = new SlashCommandBuilder();
|
const builder = new SlashCommandBuilder();
|
||||||
builder.setName("logchannel");
|
builder.setName("logchannel");
|
||||||
builder.setDescription("Configures the log channel");
|
builder.setDescription("Configures the log channel");
|
||||||
builder.setDMPermission(false);
|
builder.setDMPermission(false);
|
||||||
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
|
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);
|
||||||
builder.addChannelOption((option) => {
|
builder.addChannelOption((option) => {
|
||||||
option.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement);
|
option.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement);
|
||||||
option.setName("channel");
|
option.setName("channel");
|
||||||
@ -20,7 +20,7 @@ builder.addChannelOption((option) => {
|
|||||||
|
|
||||||
async function resetNotificationChannel(guildSetting: GuildSetting, interaction: ChatInputCommandInteraction): Promise<void> {
|
async function resetNotificationChannel(guildSetting: GuildSetting, interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
const logChannel = guildSetting.notificationChannelID ? await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID) : null;
|
const logChannel = guildSetting.notificationChannelID ? await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID) : null;
|
||||||
|
|
||||||
guildSetting.notificationChannelID = null;
|
guildSetting.notificationChannelID = null;
|
||||||
await database.getRepository(GuildSetting).save(guildSetting);
|
await database.getRepository(GuildSetting).save(guildSetting);
|
||||||
|
|
||||||
@ -31,11 +31,11 @@ async function resetNotificationChannel(guildSetting: GuildSetting, interaction:
|
|||||||
name: "This action was performed by",
|
name: "This action was performed by",
|
||||||
value: `${interaction.user.tag} (${interaction.user.id})`
|
value: `${interaction.user.tag} (${interaction.user.id})`
|
||||||
});
|
});
|
||||||
|
|
||||||
if (logChannel && logChannel.isTextBased()) {
|
if (logChannel && logChannel.isTextBased()) {
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
embeds: [logEmbed]
|
embeds: [logEmbed]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = getSuccessEmbed();
|
const embed = getSuccessEmbed();
|
||||||
@ -43,7 +43,7 @@ async function resetNotificationChannel(guildSetting: GuildSetting, interaction:
|
|||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const execute = async (interaction: ChatInputCommandInteraction) => {
|
const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
@ -55,6 +55,20 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||||||
if (!optionVal) return await resetNotificationChannel(guildSetting, interaction);
|
if (!optionVal) return await resetNotificationChannel(guildSetting, interaction);
|
||||||
|
|
||||||
const channel = getTextBasedChannel(optionVal);
|
const channel = getTextBasedChannel(optionVal);
|
||||||
|
if (channel.isDMBased()) return;
|
||||||
|
|
||||||
|
const permissions = await getChannelPermission(channel);
|
||||||
|
if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) {
|
||||||
|
const embed = getFailedEmbed();
|
||||||
|
embed.setDescription(`Bot doesn't have permission to view and/or write in channel <#${channel.id}>`);
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [ embed ],
|
||||||
|
ephemeral: true
|
||||||
|
}).catch(() => {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (guildSetting.notificationChannelID) {
|
if (guildSetting.notificationChannelID) {
|
||||||
const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID);
|
const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID);
|
||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
@ -68,7 +82,7 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||||||
if (oldLogChannel && oldLogChannel.isTextBased()) {
|
if (oldLogChannel && oldLogChannel.isTextBased()) {
|
||||||
oldLogChannel.send({
|
oldLogChannel.send({
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,16 +98,16 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
channel.send({
|
channel.send({
|
||||||
embeds: [ embed ]
|
embeds: [embed]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
|
|
||||||
const reply = getSuccessEmbed();
|
const reply = getSuccessEmbed();
|
||||||
reply.setDescription(`Log channel was set to <#${channel.id}>`);
|
reply.setDescription(`Log channel was set to <#${channel.id}>`);
|
||||||
|
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [ reply ],
|
embeds: [reply],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
66
src/commands/preserveSettings.ts
Normal file
66
src/commands/preserveSettings.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
|
||||||
|
import { database, GuildSetting } from "../data";
|
||||||
|
import { getGuildSetting } from "../tools/data";
|
||||||
|
import getDefaultEmbed, { getSuccessEmbed } from "../tools/defaultEmbeds";
|
||||||
|
import { Emoji } from "../tools/design";
|
||||||
|
import { getGuildChannel } from "../tools/discord";
|
||||||
|
|
||||||
|
const builder = new SlashCommandBuilder();
|
||||||
|
builder.setName("preservesettings");
|
||||||
|
builder.setDescription("Sets if the bot should save the server settings and blocklist if it leaves the server or delete it");
|
||||||
|
builder.addStringOption((option) => {
|
||||||
|
option.addChoices({
|
||||||
|
name: "Keep data when bot leaves the server",
|
||||||
|
value: "keep"
|
||||||
|
}, {
|
||||||
|
name: "Delete data when bot leaves the server",
|
||||||
|
value: "delete"
|
||||||
|
});
|
||||||
|
option.setName("behaviour");
|
||||||
|
option.setDescription("How the bot behaves when leaving the server");
|
||||||
|
option.setRequired(true);
|
||||||
|
return option;
|
||||||
|
});
|
||||||
|
builder.setDMPermission(false);
|
||||||
|
builder.setDefaultMemberPermissions(PermissionFlagsBits.Administrator);
|
||||||
|
|
||||||
|
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
|
||||||
|
|
||||||
|
const settings = await getGuildSetting(interaction.guildId);
|
||||||
|
const option = interaction.options.getString("behaviour", true).toLowerCase();
|
||||||
|
|
||||||
|
if (option !== "keep" && option !== "delete") throw new TypeError(`option "behaviour" expected to be of type "keep" | "delete" but was "${option}"`);
|
||||||
|
|
||||||
|
settings.preserveDataOnGuildLeave = option === "keep";
|
||||||
|
|
||||||
|
await database.getRepository(GuildSetting).save(settings);
|
||||||
|
|
||||||
|
const embed = getSuccessEmbed();
|
||||||
|
embed.setDescription(`Preserve settings on server leave is now ${settings.preserveDataOnGuildLeave ? "ENABLED" : "DISABLED"}`);
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
|
if (!settings.notificationChannelID) return;
|
||||||
|
const logChannel = await getGuildChannel(interaction.guildId, settings.notificationChannelID);
|
||||||
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
|
const logEmbed = getDefaultEmbed();
|
||||||
|
logEmbed.setTitle(`${Emoji.SETTINGS} Settings changed`);
|
||||||
|
logEmbed.setDescription(`Preserve settings on server leave is now ${settings.preserveDataOnGuildLeave ? "ENABLED" : "DISABLED"}`);
|
||||||
|
logEmbed.addFields({
|
||||||
|
name: "This action was performed by",
|
||||||
|
value: `${interaction.user.tag} (${interaction.user.id})`
|
||||||
|
});
|
||||||
|
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [logEmbed]
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
builder,
|
||||||
|
execute
|
||||||
|
}
|
110
src/commands/showSettings.ts
Normal file
110
src/commands/showSettings.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { ChatInputCommandInteraction, Guild, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
|
||||||
|
import client from "../client";
|
||||||
|
import { Badword, database } from "../data";
|
||||||
|
import { getGuildSetting } from "../tools/data";
|
||||||
|
import getDefaultEmbed from "../tools/defaultEmbeds";
|
||||||
|
import { Color, Emoji } from "../tools/design";
|
||||||
|
import { getGuildChannel, getChannelPermission } from "../tools/discord";
|
||||||
|
|
||||||
|
const builder = new SlashCommandBuilder();
|
||||||
|
builder.setName("showsettings");
|
||||||
|
builder.setDescription("Show the current settings of this guild");
|
||||||
|
builder.setDMPermission(false);
|
||||||
|
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);
|
||||||
|
|
||||||
|
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) throw new Error("Interaction was performed outside guild context");
|
||||||
|
|
||||||
|
const guild = await new Promise<null | Guild>((resolve) => {
|
||||||
|
client.guilds.fetch(interaction.guildId).catch(() => {resolve(null)}).then((guild) => {resolve(guild || null)});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!guild) throw new Error("Guild is unavailable");
|
||||||
|
|
||||||
|
const settings = await getGuildSetting(interaction.guildId);
|
||||||
|
const wordCount = await database.getRepository(Badword).count({
|
||||||
|
where: {
|
||||||
|
guildID: interaction.guildId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const logChannel = settings.notificationChannelID ? await getGuildChannel(interaction.guildId, settings.notificationChannelID) : null;
|
||||||
|
|
||||||
|
const embed = getDefaultEmbed();
|
||||||
|
embed.setTitle(`Settings from guild ${interaction.guild?.name || ""} (${interaction.guildId})`);
|
||||||
|
embed.setDescription("Thanks for using this bot");
|
||||||
|
embed.setColor(Color.INFORMING_BLUE);
|
||||||
|
embed.addFields({
|
||||||
|
name: "Logchannel",
|
||||||
|
value: settings.notificationChannelID ? `<#${settings.notificationChannelID}>` : "Not configured",
|
||||||
|
inline: true
|
||||||
|
}, {
|
||||||
|
name: "Words in Blocklist",
|
||||||
|
value: `${wordCount}/100`,
|
||||||
|
inline: true
|
||||||
|
}, {
|
||||||
|
name: `Preserve data on server leave is ${settings.preserveDataOnGuildLeave ? "active" : "inactive"}`,
|
||||||
|
value: settings.preserveDataOnGuildLeave ? "Your settings will be saved even if the bot gets kicked" : "Your settings will be deleted as soon as the bot leaves this server"
|
||||||
|
}, {
|
||||||
|
name: `${Emoji.WAVING} Found a bug? Want to request a feature? Say hello?`,
|
||||||
|
value: "Join the support server at https://go.astrogd.eu/discord"
|
||||||
|
});
|
||||||
|
|
||||||
|
const embeds = [];
|
||||||
|
embeds.push(embed);
|
||||||
|
|
||||||
|
const invalidLogChannelEmbed = getDefaultEmbed();
|
||||||
|
invalidLogChannelEmbed.setColor(Color.WARNING_YELLOW);
|
||||||
|
invalidLogChannelEmbed.setTitle(`${Emoji.CHAT_DENY} Logchannel is misconfigured!`);
|
||||||
|
invalidLogChannelEmbed.setDescription("The bot is unable to read and/or write in the configured logChannel. Please adjust your permissions.");
|
||||||
|
|
||||||
|
const missingPermissionEmbed = getDefaultEmbed();
|
||||||
|
missingPermissionEmbed.setColor(Color.WARNING_YELLOW);
|
||||||
|
missingPermissionEmbed.setTitle(`${Emoji.CHAT_DENY} Bot is missing permissions to function properly!`);
|
||||||
|
missingPermissionEmbed.setDescription("Without these missing Permissions, the bot won't work properly and might lead to unexpected behavior");
|
||||||
|
|
||||||
|
if (logChannel && logChannel.isTextBased()) {
|
||||||
|
const permissions = await getChannelPermission(logChannel);
|
||||||
|
if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) {
|
||||||
|
embeds.push(invalidLogChannelEmbed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!logChannel || !logChannel.isTextBased()) && settings.notificationChannelID) {
|
||||||
|
embeds.push(invalidLogChannelEmbed);
|
||||||
|
}
|
||||||
|
|
||||||
|
const member = await guild.members.fetchMe();
|
||||||
|
if (!member.permissions.has(PermissionFlagsBits.ViewAuditLog)) {
|
||||||
|
missingPermissionEmbed.addFields({
|
||||||
|
name: "View Audit Logs",
|
||||||
|
value: "With this permission the bot can determine who created or updated a channel with a blocked word"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!member.permissions.has(PermissionFlagsBits.ViewChannel)) {
|
||||||
|
missingPermissionEmbed.addFields({
|
||||||
|
name: "View Channels",
|
||||||
|
value: "If the bot can't see a channel, it won't be able to detect blocked words in it"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!member.permissions.has(PermissionFlagsBits.ManageChannels)) {
|
||||||
|
missingPermissionEmbed.addFields({
|
||||||
|
name: "Manage Channels",
|
||||||
|
value: "If the bot can't delete a channel, it can't protect your server from channels with blocked words"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missingPermissionEmbed.data.fields?.length || 0 > 0) embeds.push(missingPermissionEmbed);
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: embeds,
|
||||||
|
ephemeral: true
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
builder,
|
||||||
|
execute
|
||||||
|
}
|
37
src/commands/showblocklist.ts
Normal file
37
src/commands/showblocklist.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
import { Badword, database } from "../data";
|
||||||
|
|
||||||
|
const builder = new SlashCommandBuilder();
|
||||||
|
builder.setName("showblocklist");
|
||||||
|
builder.setDescription("Shows the blocklist of this server");
|
||||||
|
builder.setDMPermission(false);
|
||||||
|
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
|
||||||
|
|
||||||
|
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
|
||||||
|
|
||||||
|
const guildBadWords = await database.getRepository(Badword).find({
|
||||||
|
select: {
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
guildID: interaction.guildId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const globalBadWords = await database.getRepository(Badword).find({
|
||||||
|
where: {
|
||||||
|
guildID: IsNull()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/100)\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
|
||||||
|
ephemeral: true
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
builder,
|
||||||
|
execute
|
||||||
|
}
|
19
src/data/migrations/1669392941776-data.ts
Normal file
19
src/data/migrations/1669392941776-data.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class data1669392941776 implements MigrationInterface {
|
||||||
|
name = 'data1669392941776'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "guild_setting"
|
||||||
|
ADD "preserveDataOnGuildLeave" boolean NOT NULL DEFAULT false
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "guild_setting" DROP COLUMN "preserveDataOnGuildLeave"
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/data/migrations/1669686263307-data.ts
Normal file
19
src/data/migrations/1669686263307-data.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class data1669686263307 implements MigrationInterface {
|
||||||
|
name = 'data1669686263307'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "guild_setting" DROP COLUMN "isPremiumUntil"
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "guild_setting"
|
||||||
|
ADD "isPremiumUntil" TIMESTAMP
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,6 @@ export class GuildSetting {
|
|||||||
@Column("varchar", { nullable: true, default: null })
|
@Column("varchar", { nullable: true, default: null })
|
||||||
notificationChannelID!: string | null;
|
notificationChannelID!: string | null;
|
||||||
|
|
||||||
@Column("timestamp", { nullable: true, default: null })
|
@Column("boolean", { default: false })
|
||||||
isPremiumUntil!: Date | null;
|
preserveDataOnGuildLeave!: boolean
|
||||||
}
|
}
|
116
src/events/channelCreate.ts
Normal file
116
src/events/channelCreate.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import client from "../client";
|
||||||
|
import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User } from "discord.js";
|
||||||
|
import { getGuildSetting } from "../tools/data";
|
||||||
|
import { Badword, database } from "../data";
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds";
|
||||||
|
import { getGuildChannel } from "../tools/discord";
|
||||||
|
import { Color, Emoji } from "../tools/design";
|
||||||
|
|
||||||
|
client.on(Events.ChannelCreate, async (newChannel) => {
|
||||||
|
if (newChannel.isDMBased()) return;
|
||||||
|
const name = newChannel.name.toLowerCase();
|
||||||
|
|
||||||
|
const guild = newChannel.guild;
|
||||||
|
const settings = await getGuildSetting(guild.id);
|
||||||
|
|
||||||
|
const globalBlocklist = await database.getRepository(Badword).find({
|
||||||
|
where: {
|
||||||
|
guildID: IsNull()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const localBlocklist = await database.getRepository(Badword).find({
|
||||||
|
where: {
|
||||||
|
guildID: guild.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const blocklist = [...globalBlocklist, ...localBlocklist];
|
||||||
|
let found: string | null = null;
|
||||||
|
|
||||||
|
for (let i = 0; i < blocklist.length; i++) {
|
||||||
|
const word = blocklist[i];
|
||||||
|
if (!word) continue;
|
||||||
|
|
||||||
|
if (!name.includes(word.value)) continue;
|
||||||
|
found = word.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found === null) return;
|
||||||
|
|
||||||
|
let responsibleUser: User | null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const clientMember = await guild.members.fetchMe();
|
||||||
|
const canSeeAuditLog = clientMember.permissions.has(PermissionFlagsBits.ViewAuditLog);
|
||||||
|
const auditLogs = canSeeAuditLog ? await guild.fetchAuditLogs({
|
||||||
|
type: AuditLogEvent.ChannelCreate,
|
||||||
|
limit: 50
|
||||||
|
}) : undefined;
|
||||||
|
|
||||||
|
const change = auditLogs?.entries.filter((entry) => {
|
||||||
|
if (entry.target.id !== newChannel.id) return false;
|
||||||
|
|
||||||
|
return entry.changes.filter((change) => {
|
||||||
|
return change.key === "name" && change.new === newChannel.name;
|
||||||
|
}).length > 0;
|
||||||
|
}).reduce<null | GuildAuditLogsEntry<AuditLogEvent.ChannelCreate, "Create", "Channel", AuditLogEvent.ChannelCreate>>((unknown, curr) => {
|
||||||
|
if (!unknown) return curr;
|
||||||
|
const prev = unknown as GuildAuditLogsEntry<AuditLogEvent.ChannelCreate, "Create", "Channel", AuditLogEvent.ChannelCreate>
|
||||||
|
return curr.createdTimestamp > prev.createdTimestamp ? curr : prev;
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
responsibleUser = change?.executor || null;
|
||||||
|
} catch (error) {
|
||||||
|
responsibleUser = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!newChannel.deletable) throw new Error("Missing permissions to delete channel");
|
||||||
|
await newChannel.delete("[Automated] Detected blocked word in channel name");
|
||||||
|
} catch (error) {
|
||||||
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
|
const embed = getFailedEmbed();
|
||||||
|
embed.setDescription(`Couldn't delete <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
|
||||||
|
embed.addFields({
|
||||||
|
name: "Detected banned word:",
|
||||||
|
value: `||${found}||`
|
||||||
|
}, {
|
||||||
|
name: "Channel created by:",
|
||||||
|
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
|
||||||
|
});
|
||||||
|
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch(() => {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responsibleUser) {
|
||||||
|
const embed = getUserReportEmbed(guild.name, newChannel.name);
|
||||||
|
responsibleUser.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
|
const embed = getDefaultEmbed();
|
||||||
|
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
|
||||||
|
embed.setDescription(`||#${newChannel.name}|| (${newChannel.id}) has been deleted because its name contained a blocked word.`);
|
||||||
|
embed.setColor(Color.WARNING_YELLOW);
|
||||||
|
embed.addFields({
|
||||||
|
name: "Detected banned word:",
|
||||||
|
value: `||${found}||`,
|
||||||
|
inline: true
|
||||||
|
}, {
|
||||||
|
name: "Channel created by:",
|
||||||
|
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
|
||||||
|
});
|
||||||
|
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch(() => {});
|
||||||
|
});
|
@ -1,20 +1,18 @@
|
|||||||
import client from "../client";
|
import client from "../client";
|
||||||
import { Events } from "discord.js";
|
import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User } from "discord.js";
|
||||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
import { getGuildSetting } from "../tools/data";
|
||||||
import { Badword, database } from "../data";
|
import { Badword, database } from "../data";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds";
|
import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds";
|
||||||
import { getGuildChannel } from "../tools/discord";
|
import { getGuildChannel } from "../tools/discord";
|
||||||
import { Color, Emoji } from "../tools/design";
|
import { Color, Emoji } from "../tools/design";
|
||||||
|
|
||||||
client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
||||||
if (oldChannel.isDMBased() || newChannel.isDMBased()) return;
|
if (oldChannel.isDMBased() || newChannel.isDMBased()) return;
|
||||||
const name = newChannel.name.toLowerCase();
|
const name = newChannel.name.toLowerCase();
|
||||||
if (name === "censored") return;
|
|
||||||
|
|
||||||
const guild = oldChannel.guild;
|
const guild = oldChannel.guild;
|
||||||
const settings = await getGuildSetting(guild.id);
|
const settings = await getGuildSetting(guild.id);
|
||||||
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
|
||||||
|
|
||||||
const globalBlocklist = await database.getRepository(Badword).find({
|
const globalBlocklist = await database.getRepository(Badword).find({
|
||||||
where: {
|
where: {
|
||||||
@ -29,7 +27,7 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
|||||||
|
|
||||||
const blocklist = [...globalBlocklist, ...localBlocklist];
|
const blocklist = [...globalBlocklist, ...localBlocklist];
|
||||||
let found: string | null = null;
|
let found: string | null = null;
|
||||||
|
|
||||||
for (let i = 0; i < blocklist.length; i++) {
|
for (let i = 0; i < blocklist.length; i++) {
|
||||||
const word = blocklist[i];
|
const word = blocklist[i];
|
||||||
if (!word) continue;
|
if (!word) continue;
|
||||||
@ -41,45 +39,78 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
|||||||
|
|
||||||
if (found === null) return;
|
if (found === null) return;
|
||||||
|
|
||||||
|
let responsibleUser: User | null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const clientMember = await guild.members.fetchMe();
|
||||||
|
const canSeeAuditLog = clientMember.permissions.has(PermissionFlagsBits.ViewAuditLog);
|
||||||
|
const auditLogs = canSeeAuditLog ? await guild.fetchAuditLogs({
|
||||||
|
type: AuditLogEvent.ChannelUpdate,
|
||||||
|
limit: 50
|
||||||
|
}) : undefined;
|
||||||
|
|
||||||
|
const change = auditLogs?.entries.filter((entry) => {
|
||||||
|
if (entry.target.id !== newChannel.id) return false;
|
||||||
|
|
||||||
|
return entry.changes.filter((change) => {
|
||||||
|
return change.key === "name" && change.new === newChannel.name;
|
||||||
|
}).length > 0;
|
||||||
|
}).reduce<null | GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate, "Update", "Channel", AuditLogEvent.ChannelUpdate>>((unknown, curr) => {
|
||||||
|
if (!unknown) return curr;
|
||||||
|
const prev = unknown as GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate, "Update", "Channel", AuditLogEvent.ChannelUpdate>
|
||||||
|
return curr.createdTimestamp > prev.createdTimestamp ? curr : prev;
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
responsibleUser = change?.executor || null;
|
||||||
|
} catch (error) {
|
||||||
|
responsibleUser = null;
|
||||||
|
}
|
||||||
|
|
||||||
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
|
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await newChannel.setName("CENSORED", `[Automated] Detected blocked word in channel name. Name has been censored`);
|
if (!newChannel.deletable) throw new Error("Missing permissions to delete channel");
|
||||||
|
await newChannel.delete("[Automated] Detected blocked word in channel name");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!logChannel || !logChannel.isTextBased()) return;
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
const embed = getFailedEmbed();
|
const embed = getFailedEmbed();
|
||||||
embed.setDescription(`Couldn't censor <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
|
embed.setDescription(`Couldn't delete <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
|
||||||
if (isPremium) embed.addFields({
|
embed.addFields({
|
||||||
name: "Detected banned word:",
|
name: "Detected banned word:",
|
||||||
value: `||${found}||`
|
value: `||${found}||`
|
||||||
},{
|
}, {
|
||||||
name: "Old channel name:",
|
name: "Channel renamed by:",
|
||||||
value: `||${name}||`,
|
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
|
||||||
inline: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (responsibleUser) {
|
||||||
|
const embed = getUserReportEmbed(guild.name, newChannel.name);
|
||||||
|
responsibleUser.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
if (!logChannel || !logChannel.isTextBased()) return;
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
|
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
|
||||||
embed.setDescription(`<#${newChannel.id}> (${newChannel.id}) has been renamed because its name contained a blocked word.`);
|
embed.setDescription(`||#${newChannel.name}|| (${newChannel.id}) has been deleted because its name contained a blocked word.`);
|
||||||
embed.setColor(Color.WARNING_YELLOW);
|
embed.setColor(Color.WARNING_YELLOW);
|
||||||
if (isPremium) embed.addFields({
|
embed.addFields({
|
||||||
name: "Detected banned word:",
|
name: "Detected banned word:",
|
||||||
value: `||${found}||`,
|
value: `||${found}||`,
|
||||||
inline: true
|
inline: true
|
||||||
},{
|
}, {
|
||||||
name: "Old channel name:",
|
name: "Channel renamed by:",
|
||||||
value: `||${name}||`,
|
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
|
||||||
inline: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
}).catch();
|
}).catch(() => {});
|
||||||
});
|
});
|
17
src/events/guildDelete.ts
Normal file
17
src/events/guildDelete.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import client from "../client";
|
||||||
|
import { Events } from "discord.js";
|
||||||
|
import { getGuildSetting } from "../tools/data";
|
||||||
|
import { Badword, database, GuildSetting } from "../data";
|
||||||
|
|
||||||
|
client.on(Events.GuildDelete, async (guild) => {
|
||||||
|
const settings = await getGuildSetting(guild.id);
|
||||||
|
if (settings.preserveDataOnGuildLeave) return;
|
||||||
|
|
||||||
|
await database.getRepository(GuildSetting).delete({
|
||||||
|
id: guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
await database.getRepository(Badword).delete({
|
||||||
|
guildID: guild.id
|
||||||
|
});
|
||||||
|
});
|
@ -1 +1,3 @@
|
|||||||
import "./channelUpdate";
|
import "./channelUpdate";
|
||||||
|
import "./guildDelete";
|
||||||
|
import "./channelCreate";
|
39
src/service/cleanup.ts
Normal file
39
src/service/cleanup.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Badword, database, GuildSetting } from "../data";
|
||||||
|
import client from "../client";
|
||||||
|
import { DiscordAPIError } from "discord.js";
|
||||||
|
|
||||||
|
export default async function execute(): Promise<void> {
|
||||||
|
const guilds = await database.getRepository(GuildSetting).find({
|
||||||
|
where: {
|
||||||
|
preserveDataOnGuildLeave: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const guild of guilds) {
|
||||||
|
try {
|
||||||
|
await client.guilds.fetch(guild.id);
|
||||||
|
} catch (error) {
|
||||||
|
if (!(error instanceof DiscordAPIError)) {
|
||||||
|
console.error(`service.cleanup failed: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = guild.id;
|
||||||
|
|
||||||
|
// 5001 = Missing access
|
||||||
|
if (error.code.toString() !== "50001") {
|
||||||
|
console.warn(`Guild ${guild.id} is unavailable but not because of error 5001:\n${error}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await database.getRepository(Badword).delete({
|
||||||
|
guildID: guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
await database.getRepository(GuildSetting).remove(guild);
|
||||||
|
console.log(`Removed data for guild ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Cleanup completed");
|
||||||
|
}
|
@ -1 +1,6 @@
|
|||||||
import "./uptime";
|
import "./uptime";
|
||||||
|
import runCleanup from "./cleanup";
|
||||||
|
|
||||||
|
export {
|
||||||
|
runCleanup
|
||||||
|
}
|
@ -10,17 +10,9 @@ export async function getGuildSetting(guildID: string): Promise<GuildSetting> {
|
|||||||
if (!guildSetting) {
|
if (!guildSetting) {
|
||||||
guildSetting = new GuildSetting();
|
guildSetting = new GuildSetting();
|
||||||
guildSetting.id = guildID;
|
guildSetting.id = guildID;
|
||||||
guildSetting.isPremiumUntil = null;
|
|
||||||
guildSetting.notificationChannelID = null;
|
guildSetting.notificationChannelID = null;
|
||||||
|
guildSetting.preserveDataOnGuildLeave = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return guildSetting;
|
return guildSetting;
|
||||||
}
|
|
||||||
|
|
||||||
export function isPremiumActive(timestamp: Date | null): boolean {
|
|
||||||
if (timestamp === null) return false;
|
|
||||||
const now = Number(new Date());
|
|
||||||
const activeUntil = Number(timestamp);
|
|
||||||
|
|
||||||
return now < activeUntil;
|
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ import { Color, Emoji } from "./design";
|
|||||||
export default function getDefaultEmbed(): EmbedBuilder {
|
export default function getDefaultEmbed(): EmbedBuilder {
|
||||||
const embed = new EmbedBuilder();
|
const embed = new EmbedBuilder();
|
||||||
embed.setFooter({
|
embed.setFooter({
|
||||||
text: `Channel filter V${pack.version} by AstroGD®`,
|
text: `Channel filter V${pack.version}`,
|
||||||
iconURL: client.user?.avatarURL() || undefined,
|
iconURL: client.user?.avatarURL() || undefined,
|
||||||
});
|
});
|
||||||
embed.setTimestamp(new Date());
|
embed.setTimestamp(new Date());
|
||||||
@ -28,5 +28,16 @@ export function getFailedEmbed(): EmbedBuilder {
|
|||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
embed.setTitle(`${Emoji.CHAT_DENY} Failed`);
|
embed.setTitle(`${Emoji.CHAT_DENY} Failed`);
|
||||||
embed.setColor(Color.STOPSIGN_RED);
|
embed.setColor(Color.STOPSIGN_RED);
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserReportEmbed(guildName: string, channelName: string): EmbedBuilder {
|
||||||
|
const embed = getDefaultEmbed();
|
||||||
|
embed.setColor(Color.STOPSIGN_RED);
|
||||||
|
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} A channel you modified has been deleted`);
|
||||||
|
embed.setDescription(`Hey there ${Emoji.WAVING}
|
||||||
|
Your channel (#${channelName}) on the "${guildName}" server contained a blacklisted word and was deleted automatically.
|
||||||
|
Please make sure to keep channel names friendly for everyone!`);
|
||||||
|
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
@ -1,10 +1,25 @@
|
|||||||
import { GuildBasedChannel } from "discord.js";
|
import { GuildBasedChannel, GuildTextBasedChannel, PermissionsBitField } from "discord.js";
|
||||||
import client from "../client";
|
import client from "../client";
|
||||||
|
|
||||||
export async function getGuildChannel(guildID: string, channelID: string): Promise<GuildBasedChannel | null> {
|
export async function getGuildChannel(guildID: string, channelID: string): Promise<GuildBasedChannel | null> {
|
||||||
const guild = await client.guilds.fetch(guildID);
|
try {
|
||||||
if (!guild) return null;
|
const guild = await client.guilds.fetch(guildID);
|
||||||
|
if (!guild) return null;
|
||||||
|
|
||||||
const channel = await guild.channels.fetch(channelID);
|
const channel = await guild.channels.fetch(channelID);
|
||||||
return channel;
|
return channel;
|
||||||
|
} catch (_error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getChannelPermission(channel: GuildTextBasedChannel): Promise<Readonly<PermissionsBitField> | null> {
|
||||||
|
try {
|
||||||
|
const guildMember = await channel.guild.members.fetchMe();
|
||||||
|
if (!guildMember) return null;
|
||||||
|
|
||||||
|
return channel.permissionsFor(guildMember);
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user