Compare commits
77 commits
39999dfbba
...
c36b2fa7d8
Author | SHA1 | Date | |
---|---|---|---|
c36b2fa7d8 | |||
995564cb5b | |||
400b4de304 | |||
eb774aa280 | |||
9749f9c9c9 | |||
e84f871329 | |||
a23028b40c | |||
915efc226e | |||
a56076e118 | |||
4f2c186244 | |||
46226d37a7 | |||
3f34ff15dd | |||
6c334cea81 | |||
e6c845e3b2 | |||
c2418381ea | |||
61633277ef | |||
40182c8777 | |||
14a1981b94 | |||
6fb448fc28 | |||
c12644d537 | |||
efd213d085 | |||
c02dbb30d7 | |||
ec1763be26 | |||
1c00fdae5c | |||
580fd497a2 | |||
fabbd84f2a | |||
fc7c9ef02c | |||
b9fdd51897 | |||
1908f7505c | |||
b64ddacb41 | |||
f5f87a52dc | |||
1c3ba40b56 | |||
45a92a7b48 | |||
19b6cb033c | |||
ae5f9df366 | |||
3f09a2367c | |||
8e5ac6d01e | |||
6d7dc26e09 | |||
4c1726f5c8 | |||
27afb3dd22 | |||
c3d65b5579 | |||
4bc6280a1c | |||
de5d0bab79 | |||
fdcedbd640 | |||
568fa315bb | |||
feaf17ff81 | |||
2b63400684 | |||
b3b2186a61 | |||
17ae4079e5 | |||
e808bbe6a5 | |||
e02e58e280 | |||
2164b9603d | |||
31a600c74e | |||
a001e63857 | |||
a3e062a1ff | |||
29a4a596f7 | |||
39967068bb | |||
d688d292c3 | |||
0b498eb023 | |||
0d63bd120d | |||
ed8f5927c8 | |||
0465697b87 | |||
d4716e69d5 | |||
e2988d39b5 | |||
6238a20002 | |||
7decd28dc9 | |||
cd666d24fd | |||
2da5e1aa75 | |||
4d01f0b34a | |||
a01a43788e | |||
4621cec9d5 | |||
ac6be6bf5a | |||
d7576f1863 | |||
514be692fd | |||
6522bee37b | |||
861676ed0b | |||
b4cec6778d |
112 changed files with 4421 additions and 3222 deletions
|
@ -7,7 +7,19 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.0.7
|
BOT_VER=3.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_DATE=08 May 2023
|
BOT_DATE=08 May 2023
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=682942374040961060
|
||||||
|
|
||||||
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3101
|
||||||
|
DB_NAME=vylbot
|
||||||
|
DB_AUTH_USER=dev
|
||||||
|
DB_AUTH_PASS=dev
|
||||||
|
DB_SYNC=true
|
||||||
|
DB_LOGGING=true
|
72
.drone.yml
Normal file
72
.drone.yml
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
kind: pipeline
|
||||||
|
name: deployment
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: deploy
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: 192.168.68.121
|
||||||
|
username: vylpes
|
||||||
|
password:
|
||||||
|
from_secret: ssh_password
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- sh /home/vylpes/scripts/vylbot/deploy_prod.sh
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
kind: pipeline
|
||||||
|
name: staging
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: stage
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: 192.168.68.121
|
||||||
|
username: vylpes
|
||||||
|
password:
|
||||||
|
from_secret: ssh_password
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- sh /home/vylpes/scripts/vylbot/deploy_stage.sh
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- develop
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
kind: pipeline
|
||||||
|
name: integration
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: node
|
||||||
|
commands:
|
||||||
|
- yarn install --frozen-lockfile
|
||||||
|
- yarn build
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: node
|
||||||
|
commands:
|
||||||
|
- yarn install --frozen-lockfile
|
||||||
|
- yarn test
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
- hotfix/*
|
||||||
|
- feature/*
|
||||||
|
- renovate/*
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- pull_request
|
18
.gitea/ISSUE_TEMPLATE.md
Normal file
18
.gitea/ISSUE_TEMPLATE.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
Epic: \
|
||||||
|
Story Points:
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*No description*
|
||||||
|
|
||||||
|
## Acceptance Criteria
|
||||||
|
|
||||||
|
*No acceptance criteria*
|
||||||
|
|
||||||
|
## Subtasks
|
||||||
|
|
||||||
|
*No subtasks*
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
*No notes*
|
29
.gitea/PULL_REQUEST_TEMPLATE.md
Normal file
29
.gitea/PULL_REQUEST_TEMPLATE.md
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# Description
|
||||||
|
|
||||||
|
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
|
||||||
|
|
||||||
|
Fixes # (issue)
|
||||||
|
|
||||||
|
## Type of change
|
||||||
|
|
||||||
|
Please delete options that are not relevant.
|
||||||
|
|
||||||
|
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||||
|
- [ ] New feature (non-breaking change which adds functionality)
|
||||||
|
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||||
|
- [ ] This change requires a documentation update
|
||||||
|
|
||||||
|
# How Has This Been Tested?
|
||||||
|
|
||||||
|
Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.
|
||||||
|
|
||||||
|
# Checklist
|
||||||
|
|
||||||
|
- [ ] My code follows the style guidelines of this project
|
||||||
|
- [ ] I have performed a self-review of my own code
|
||||||
|
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||||
|
- [ ] I have made corresponding changes to the documentation
|
||||||
|
- [ ] My changes generate no new warnings
|
||||||
|
- [ ] I have added tests that provde my fix is effective or that my feature works
|
||||||
|
- [ ] New and existing unit tests pass locally with my changes
|
||||||
|
- [ ] Any dependent changes have been merged and published in downstream modules
|
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
16
.github/ISSUE_TEMPLATE/epic.md
vendored
Normal file
16
.github/ISSUE_TEMPLATE/epic.md
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
---
|
||||||
|
name: Epic
|
||||||
|
about: Agile Epic
|
||||||
|
title: ''
|
||||||
|
labels: epic
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Description here*
|
||||||
|
|
||||||
|
## Stories
|
||||||
|
*Stories linked to this epic*
|
||||||
|
|
||||||
|
## Bugs
|
||||||
|
*Bugs linked to this epic*
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
24
.github/ISSUE_TEMPLATE/user-story.md
vendored
Normal file
24
.github/ISSUE_TEMPLATE/user-story.md
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
name: User Story
|
||||||
|
about: Agile User Story
|
||||||
|
title: ''
|
||||||
|
labels: needs criteria, story
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Epic Link: N/A
|
||||||
|
Story Points: N/A
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Description here*
|
||||||
|
|
||||||
|
## Acceptance Criteria
|
||||||
|
*Add your ACs here*
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
*Any extra information*
|
||||||
|
|
||||||
|
## Subtasks
|
||||||
|
*Add technical subtasks here*
|
30
.github/pull_request_template.md
vendored
Normal file
30
.github/pull_request_template.md
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Description
|
||||||
|
|
||||||
|
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
|
||||||
|
|
||||||
|
Fixes # (issue)
|
||||||
|
|
||||||
|
## Type of change
|
||||||
|
|
||||||
|
Please delete options that are not relevant.
|
||||||
|
|
||||||
|
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||||
|
- [ ] New feature (non-breaking change which adds functionality)
|
||||||
|
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||||
|
- [ ] This change requires a documentation update
|
||||||
|
|
||||||
|
# How Has This Been Tested?
|
||||||
|
|
||||||
|
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
|
||||||
|
|
||||||
|
|
||||||
|
# Checklist:
|
||||||
|
|
||||||
|
- [ ] My code follows the style guidelines of this project
|
||||||
|
- [ ] I have performed a self-review of my own code
|
||||||
|
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||||
|
- [ ] I have made corresponding changes to the documentation
|
||||||
|
- [ ] My changes generate no new warnings
|
||||||
|
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||||
|
- [ ] New and existing unit tests pass locally with my changes
|
||||||
|
- [ ] Any dependent changes have been merged and published in downstream modules
|
27
.github/workflows/testing.yml
vendored
27
.github/workflows/testing.yml
vendored
|
@ -1,27 +0,0 @@
|
||||||
name: Testing
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- develop
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [16.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- run: yarn install
|
|
||||||
- run: yarn build
|
|
||||||
- run: yarn test
|
|
||||||
|
|
24
.prod.env
Normal file
24
.prod.env
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Security Warning! Do not commit this file to any VCS!
|
||||||
|
# This is a local file to speed up development process,
|
||||||
|
# so you don't have to change your environment variables.
|
||||||
|
#
|
||||||
|
# This is not applied to `.env.template`!
|
||||||
|
# Template files must be committed to the VCS, but must not contain
|
||||||
|
# any secret values.
|
||||||
|
|
||||||
|
BOT_TOKEN=
|
||||||
|
BOT_VER=3.1
|
||||||
|
BOT_AUTHOR=Vylpes
|
||||||
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=680083120896081954
|
||||||
|
|
||||||
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3121
|
||||||
|
DB_NAME=vylbot
|
||||||
|
DB_AUTH_USER=prod
|
||||||
|
DB_AUTH_PASS=prod
|
||||||
|
DB_SYNC=false
|
||||||
|
DB_LOGGING=false
|
24
.stage.env
Normal file
24
.stage.env
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Security Warning! Do not commit this file to any VCS!
|
||||||
|
# This is a local file to speed up development process,
|
||||||
|
# so you don't have to change your environment variables.
|
||||||
|
#
|
||||||
|
# This is not applied to `.env.template`!
|
||||||
|
# Template files must be committed to the VCS, but must not contain
|
||||||
|
# any secret values.
|
||||||
|
|
||||||
|
BOT_TOKEN=
|
||||||
|
BOT_VER=3.1
|
||||||
|
BOT_AUTHOR=Vylpes
|
||||||
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=1016767908740857949
|
||||||
|
|
||||||
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3111
|
||||||
|
DB_NAME=vylbot
|
||||||
|
DB_AUTH_USER=stage
|
||||||
|
DB_AUTH_PASS=stage
|
||||||
|
DB_SYNC=false
|
||||||
|
DB_LOGGING=false
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Vylpes
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -6,7 +6,7 @@
|
||||||
"title": "Vylpes' Den",
|
"title": "Vylpes' Den",
|
||||||
"description": [
|
"description": [
|
||||||
"Welcome to Vylpes' Den! Make sure to say hi!",
|
"Welcome to Vylpes' Den! Make sure to say hi!",
|
||||||
"Invite link: https://discord.gg/UyAhAVp"
|
"Invite link: https://go.vylpes.xyz/A6HcA"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -70,19 +70,17 @@
|
||||||
"description": [
|
"description": [
|
||||||
"This server uses a bot made by me, VylBot, to help moderate the server.",
|
"This server uses a bot made by me, VylBot, to help moderate the server.",
|
||||||
"For more information on it, see the GitHub repositories:",
|
"For more information on it, see the GitHub repositories:",
|
||||||
"https://github.com/Vylpes/vylbot-core",
|
"https://gitea.vylpes.xyz/rabbitlabs/vylbot-app"
|
||||||
"https://github.com/Vylpes/vylbot-app"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Links",
|
"title": "Links",
|
||||||
"description": [
|
"description": [
|
||||||
"YouTube: https://www.youtube.com/channel/UCwPlzKwCmP5Q9bCX3fHk2BA",
|
"YouTube: https://www.youtube.com/@vylpes",
|
||||||
"Patreon: https://www.patreon.com/vylpes",
|
"Patreon: https://www.patreon.com/vylpes",
|
||||||
"Twitch: https://www.twitch.tv/vylpes_",
|
"Twitch: https://www.twitch.tv/vylpes_",
|
||||||
"Twitter: https://twitter.com/vylpes",
|
"Twitter: https://twitter.com/vylpes"
|
||||||
"Blog: https://vylpes.xyz"
|
|
||||||
],
|
],
|
||||||
"footer": "Last updated 01/02/2022"
|
"footer": "Last updated 20/06/2023"
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -1,88 +1,12 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"image": "https://i.imgur.com/bjH1gza.png"
|
"title": "Welcome to Mankalor's Discord Server!",
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Bot Testing Ground",
|
|
||||||
"description": [
|
"description": [
|
||||||
"Welcome to Vylpes' Den! Make sure to say hi!",
|
"*You must follow Discord's TOS, including the rule where", "you must be 13 years or older.",
|
||||||
"Invite link: https://discord.gg/UyAhAVp"
|
"If moderators know you're under 13, we will have to ban you!*",
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Discord TOS",
|
|
||||||
"description": [
|
|
||||||
"All servers are required to follow the Discord Terms of Service. This includes minimum age requirements (13+). If the moderation team discover a breach of TOS we are required by discord to ban. Make sure you know them!",
|
|
||||||
"https://discord.com/terms"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Rules",
|
|
||||||
"description": [
|
|
||||||
"**English Only**",
|
|
||||||
"In order for everyone to understand each other we would like to ask everyone to speak in English only.",
|
|
||||||
"",
|
"",
|
||||||
"**No NSFW or Obscene Content**",
|
"You need to input a code in *#entry* which is somewhere in this message before you can start chatting, so read the server rules and info below.",
|
||||||
"This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.",
|
"If you still don't see the other channels after writing this code, message a moderator. For any issues with this bot, message <@147392775707426816>."
|
||||||
"",
|
|
||||||
"**Treat Everyone with Respect**",
|
|
||||||
"Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.",
|
|
||||||
"",
|
|
||||||
"**No spam or self promotion**",
|
|
||||||
"Outside of #self-promo. This includes DMing fellow members.",
|
|
||||||
"",
|
|
||||||
"**Keep Politics to #general**",
|
|
||||||
"And make sure it doesn't become too heated. Debate don't argue.",
|
|
||||||
"",
|
|
||||||
"**Drama From Other Servers**",
|
|
||||||
"Please don't bring up drama from other servers, keep that to DMs",
|
|
||||||
"",
|
|
||||||
"**Bot Abuse**",
|
|
||||||
"Don't abuse the bots or you will be blocked from using them",
|
|
||||||
"",
|
|
||||||
"**Event Spoilers**",
|
|
||||||
"Contents of events and keynotes, such as the Nintendo Direct, must be spoken about in events, this rule applies for up to 24 hours after the event ends. Even though we will only enforce talking there for a set time, please be considerate of those who haven't watched the event yet."
|
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Moderators Discretion",
|
|
||||||
"description": [
|
|
||||||
"Don't argue with a mod's decision. A moderator's choice is final. If you have an issue with a member of the mod team DM me (Vylpes#0001)."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Supporters",
|
|
||||||
"description": [
|
|
||||||
"If you are a Twitch Subscriber or a Patreon Member and have linked your profiles to your discord account you will get exclusive access to the Vylpes Plus channels, including early access to videos!"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Self-Assignable Roles",
|
|
||||||
"description": [
|
|
||||||
"If you want to assign yourself roles, go to #bot-stuff and type v!role <role>. The current roles you can get are:",
|
|
||||||
"Notify: Get pinged when a new stream or video releases.",
|
|
||||||
"VotePings: Get pinged when I start a new poll",
|
|
||||||
"ProjectUpdates: Get pinged when I update my projects as well as new for them"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "VylBot",
|
|
||||||
"description": [
|
|
||||||
"This server uses a bot made by me, VylBot, to help moderate the server.",
|
|
||||||
"For more information on it, see the GitHub repositories:",
|
|
||||||
"https://github.com/Vylpes/vylbot-core",
|
|
||||||
"https://github.com/Vylpes/vylbot-app"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Links",
|
|
||||||
"description": [
|
|
||||||
"YouTube: https://www.youtube.com/channel/UCwPlzKwCmP5Q9bCX3fHk2BA",
|
|
||||||
"Patreon: https://www.patreon.com/vylpes",
|
|
||||||
"Twitch: https://www.twitch.tv/vylpes_",
|
|
||||||
"Twitter: https://twitter.com/vylpes",
|
|
||||||
"Blog: https://vylpes.xyz"
|
|
||||||
],
|
|
||||||
"footer": "Last updated 01/02/2022"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -6,7 +6,7 @@
|
||||||
"If moderators know you're under 13, we will have to ban you!*",
|
"If moderators know you're under 13, we will have to ban you!*",
|
||||||
"",
|
"",
|
||||||
"You need to input a code in *#entry* which is somewhere in this message before you can start chatting, so read the server rules and info below.",
|
"You need to input a code in *#entry* which is somewhere in this message before you can start chatting, so read the server rules and info below.",
|
||||||
"If you still don't see the other channels after writing this code, message a moderator. For any issues with this bot, message Vylpes#5725."
|
"If you still don't see the other channels after writing this code, message a moderator. For any issues with this bot, message <@147392775707426816>."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
11
database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql
Normal file
11
database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
CREATE TABLE `audit` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL,
|
||||||
|
`AuditId` varchar(255) NOT NULL,
|
||||||
|
`UserId` varchar(255) NOT NULL,
|
||||||
|
`AuditType` int NOT NULL,
|
||||||
|
`Reason` varchar(255) NOT NULL,
|
||||||
|
`ModeratorId` varchar(255) NOT NULL,
|
||||||
|
`ServerId` varchar(255) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -0,0 +1,5 @@
|
||||||
|
CREATE TABLE `ignored_channel` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
10
database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql
Normal file
10
database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
CREATE TABLE `lobby` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL,
|
||||||
|
`ChannelId` varchar(255) NOT NULL,
|
||||||
|
`RoleId` varchar(255) NOT NULL,
|
||||||
|
`Cooldown` int NOT NULL,
|
||||||
|
`LastUsed` datetime NOT NULL,
|
||||||
|
`Name` varchar(255) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -0,0 +1,7 @@
|
||||||
|
CREATE TABLE `role` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL,
|
||||||
|
`RoleId` varchar(255) NOT NULL,
|
||||||
|
`serverId` varchar(255) DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -0,0 +1,5 @@
|
||||||
|
CREATE TABLE `server` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -0,0 +1,8 @@
|
||||||
|
CREATE TABLE `setting` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL,
|
||||||
|
`Key` varchar(255) NOT NULL,
|
||||||
|
`Value` varchar(255) NOT NULL,
|
||||||
|
`serverId` varchar(255) DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `audit`
|
||||||
|
ADD PRIMARY KEY (`Id`);
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `ignored_channel`
|
||||||
|
ADD PRIMARY KEY (`Id`);
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `lobby`
|
||||||
|
ADD PRIMARY KEY (`Id`);
|
3
database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql
Normal file
3
database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `role`
|
||||||
|
ADD PRIMARY KEY (`Id`),
|
||||||
|
ADD KEY `FK_d9e438d88cfb64f7f8e1ae593c3` (`serverId`);
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `server`
|
||||||
|
ADD PRIMARY KEY (`Id`);
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `setting`
|
||||||
|
ADD PRIMARY KEY (`Id`),
|
||||||
|
ADD KEY `FK_a3623ec541bdb12fa0f58bdfde7` (`serverId`);
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `role`
|
||||||
|
ADD CONSTRAINT `FK_d9e438d88cfb64f7f8e1ae593c3` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`);
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `setting`
|
||||||
|
ADD CONSTRAINT `FK_a3623ec541bdb12fa0f58bdfde7` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`);
|
31
docker-compose.prod.yml
Normal file
31
docker-compose.prod.yml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
prod_database_data:
|
||||||
|
|
||||||
|
services:
|
||||||
|
# discord:
|
||||||
|
# build: .
|
||||||
|
|
||||||
|
database:
|
||||||
|
image: mysql/mysql-server
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- MYSQL_DATABASE=vylbot
|
||||||
|
- MYSQL_USER=prod
|
||||||
|
- MYSQL_PASSWORD=prod
|
||||||
|
- MYSQL_ROOT_PASSWORD=root
|
||||||
|
- MYSQL_ROOT_HOST=0.0.0.0
|
||||||
|
ports:
|
||||||
|
- "3121:3306"
|
||||||
|
volumes:
|
||||||
|
- prod_database_data:/var/lib/mysql
|
||||||
|
|
||||||
|
phpmyadmin:
|
||||||
|
image: phpmyadmin
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "3122:80"
|
||||||
|
environment:
|
||||||
|
- PMA_ARBITRARY=1
|
31
docker-compose.stage.yml
Normal file
31
docker-compose.stage.yml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
stage_database_data:
|
||||||
|
|
||||||
|
services:
|
||||||
|
# discord:
|
||||||
|
# build: .
|
||||||
|
|
||||||
|
database:
|
||||||
|
image: mysql/mysql-server
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- MYSQL_DATABASE=vylbot
|
||||||
|
- MYSQL_USER=stage
|
||||||
|
- MYSQL_PASSWORD=stage
|
||||||
|
- MYSQL_ROOT_PASSWORD=root
|
||||||
|
- MYSQL_ROOT_HOST=0.0.0.0
|
||||||
|
ports:
|
||||||
|
- "3111:3306"
|
||||||
|
volumes:
|
||||||
|
- stage_database_data:/var/lib/mysql
|
||||||
|
|
||||||
|
phpmyadmin:
|
||||||
|
image: phpmyadmin
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "3112:80"
|
||||||
|
environment:
|
||||||
|
- PMA_ARBITRARY=1
|
|
@ -1,4 +1,8 @@
|
||||||
version: "3.9"
|
version: "3.9"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
dev_database_data:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# discord:
|
# discord:
|
||||||
# build: .
|
# build: .
|
||||||
|
@ -12,13 +16,16 @@ services:
|
||||||
- MYSQL_USER=dev
|
- MYSQL_USER=dev
|
||||||
- MYSQL_PASSWORD=dev
|
- MYSQL_PASSWORD=dev
|
||||||
- MYSQL_ROOT_PASSWORD=root
|
- MYSQL_ROOT_PASSWORD=root
|
||||||
|
- MYSQL_ROOT_HOST=0.0.0.0
|
||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- "3101:3306"
|
||||||
|
volumes:
|
||||||
|
- dev_database_data:/var/lib/mysql
|
||||||
|
|
||||||
phpmyadmin:
|
phpmyadmin:
|
||||||
image: phpmyadmin
|
image: phpmyadmin
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 8080:80
|
- "3102:80"
|
||||||
environment:
|
environment:
|
||||||
- PMA_ARBITRARY=1
|
- PMA_ARBITRARY=1
|
43
package.json
43
package.json
|
@ -1,41 +1,46 @@
|
||||||
{
|
{
|
||||||
"name": "vylbot-app",
|
"name": "vylbot-app",
|
||||||
"version": "3.0.7",
|
"version": "3.1.0",
|
||||||
"description": "A discord bot made for Vylpes' Den",
|
"description": "A discord bot made for Vylpes' Den",
|
||||||
"main": "./dist/vylbot",
|
"main": "./dist/vylbot",
|
||||||
"typings": "./dist",
|
"typings": "./dist",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"clean": "rm -rf node_modules/ dist/",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node ./dist/vylbot",
|
"start": "node ./dist/vylbot",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"db:up": "typeorm migration:run",
|
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
||||||
"db:down": "typeorm migration:revert"
|
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Vylpes/vylbot-app.git"
|
"url": "https://github.com/Vylpes/vylbot-app"
|
||||||
},
|
},
|
||||||
"author": "Vylpes",
|
"author": "Vylpes",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": "https://github.com/Vylpes/vylbot-app/issues",
|
"bugs": {
|
||||||
|
"url": "https://github.com/Vylpes/vylbot-app/issues",
|
||||||
|
"email": "helpdesk@vylpes.com"
|
||||||
|
},
|
||||||
"homepage": "https://github.com/Vylpes/vylbot-app",
|
"homepage": "https://github.com/Vylpes/vylbot-app",
|
||||||
|
"funding": "https://ko-fi.com/vylpes",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/jest": "^27.0.3",
|
"@discordjs/rest": "^1.1.0",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/jest": "^29.0.0",
|
||||||
"discord.js": "^13.6.0",
|
"@types/uuid": "^9.0.0",
|
||||||
"dotenv": "^10.0.0",
|
"discord.js": "^14.3.0",
|
||||||
"emoji-regex": "^9.2.0",
|
"dotenv": "^16.0.0",
|
||||||
"jest": "^27.4.5",
|
"emoji-regex": "^10.0.0",
|
||||||
"jest-mock-extended": "^2.0.4",
|
"jest": "^29.0.0",
|
||||||
"minimatch": "3.1.2",
|
"jest-mock-extended": "^3.0.0",
|
||||||
|
"minimatch": "9.0.2",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"random-bunny": "^2.0.0",
|
"random-bunny": "^2.0.5",
|
||||||
"ts-jest": "^27.1.2",
|
"ts-jest": "^29.0.0",
|
||||||
"typeorm": "0.3.14",
|
"typeorm": "0.3.17"
|
||||||
"uuid": "^8.3.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.10",
|
"@types/node": "^20.0.0",
|
||||||
"typescript": "^4.5.2"
|
"typescript": "^5.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
scripts/deploy_prod.sh
Normal file
23
scripts/deploy_prod.sh
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
export PATH="$HOME/.yarn/bin:$PATH"
|
||||||
|
export PATH="$HOME/.nodeuse/bin:$PATH"
|
||||||
|
|
||||||
|
export BOT_TOKEN=$(cat $HOME/scripts/vylbot/prod_key.txt)
|
||||||
|
|
||||||
|
cd ~/apps/vylbot/vylbot_prod \
|
||||||
|
&& git checkout main \
|
||||||
|
&& git fetch \
|
||||||
|
&& git pull \
|
||||||
|
&& docker compose --file docker-compose.prod.yml down \
|
||||||
|
&& (pm2 stop vylbot_prod || true) \
|
||||||
|
&& (pm2 delete vylbot_prod || true) \
|
||||||
|
&& cp .prod.env .env \
|
||||||
|
&& yarn clean \
|
||||||
|
&& yarn install --frozen-lockfile \
|
||||||
|
&& yarn build \
|
||||||
|
&& docker compose --file docker-compose.prod.yml up -d \
|
||||||
|
&& echo "Sleeping for 10 seconds to let database load..." \
|
||||||
|
&& sleep 10 \
|
||||||
|
&& yarn run db:up \
|
||||||
|
&& NODE_ENV=production pm2 start --name vylbot_prod dist/vylbot.js
|
23
scripts/deploy_stage.sh
Normal file
23
scripts/deploy_stage.sh
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
export PATH="$HOME/.yarn/bin:$PATH"
|
||||||
|
export PATH="$HOME/.nodeuse/bin:$PATH"
|
||||||
|
|
||||||
|
export BOT_TOKEN=$(cat $HOME/scripts/vylbot/stage_key.txt)
|
||||||
|
|
||||||
|
cd ~/apps/vylbot/vylbot_stage \
|
||||||
|
&& git checkout develop \
|
||||||
|
&& git fetch \
|
||||||
|
&& git pull \
|
||||||
|
&& docker compose --file docker-compose.stage.yml down \
|
||||||
|
&& (pm2 stop vylbot_stage || true) \
|
||||||
|
&& (pm2 delete vylbot_stage || true) \
|
||||||
|
&& cp .stage.env .env \
|
||||||
|
&& yarn clean \
|
||||||
|
&& yarn install --frozen-lockfile \
|
||||||
|
&& yarn build \
|
||||||
|
&& docker compose --file docker-compose.stage.yml up -d \
|
||||||
|
&& echo "Sleeping for 10 seconds to let database load..." \
|
||||||
|
&& sleep 10 \
|
||||||
|
&& yarn run db:up \
|
||||||
|
&& NODE_ENV=production pm2 start --name vylbot_stage dist/vylbot.js
|
|
@ -1,14 +1,14 @@
|
||||||
import { Client } from "discord.js";
|
import { Client } from "discord.js";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
import { createConnection } from "typeorm";
|
import { createConnection } from "typeorm";
|
||||||
import DefaultValues from "../constants/DefaultValues";
|
import { EventType } from "../constants/EventType";
|
||||||
import ICommandItem from "../contracts/ICommandItem";
|
import ICommandItem from "../contracts/ICommandItem";
|
||||||
import IEventItem from "../contracts/IEventItem";
|
import IEventItem from "../contracts/IEventItem";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { Event } from "../type/event";
|
|
||||||
|
|
||||||
import { Events } from "./events";
|
import { Events } from "./events";
|
||||||
import { Util } from "./util";
|
import { Util } from "./util";
|
||||||
|
import AppDataSource from "../database/dataSources/appDataSource";
|
||||||
|
|
||||||
export class CoreClient extends Client {
|
export class CoreClient extends Client {
|
||||||
private static _commandItems: ICommandItem[];
|
private static _commandItems: ICommandItem[];
|
||||||
|
@ -25,12 +25,10 @@ export class CoreClient extends Client {
|
||||||
return this._eventItems;
|
return this._eventItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(intents: number[], devmode: boolean = false) {
|
constructor(intents: number[]) {
|
||||||
super({ intents: intents });
|
super({ intents: intents });
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
DefaultValues.useDevPrefix = devmode;
|
|
||||||
|
|
||||||
CoreClient._commandItems = [];
|
CoreClient._commandItems = [];
|
||||||
CoreClient._eventItems = [];
|
CoreClient._eventItems = [];
|
||||||
|
|
||||||
|
@ -44,19 +42,17 @@ export class CoreClient extends Client {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await createConnection().catch(e => {
|
await AppDataSource.initialize()
|
||||||
console.error(e);
|
.then(() => console.log("Data Source Initialized"))
|
||||||
return;
|
.catch((err) => console.error("Error Initialising Data Source", err));
|
||||||
});
|
|
||||||
|
|
||||||
super.on("messageCreate", (message) => {
|
super.on("interactionCreate", this._events.onInteractionCreate);
|
||||||
this._events.onMessageCreate(message, CoreClient._commandItems)
|
|
||||||
});
|
|
||||||
super.on("ready", this._events.onReady);
|
super.on("ready", this._events.onReady);
|
||||||
|
|
||||||
super.login(process.env.BOT_TOKEN);
|
await super.login(process.env.BOT_TOKEN);
|
||||||
|
|
||||||
this._util.loadEvents(this, CoreClient._eventItems);
|
this._util.loadEvents(this, CoreClient._eventItems);
|
||||||
|
this._util.loadSlashCommands(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterCommand(name: string, command: Command, serverId?: string) {
|
public static RegisterCommand(name: string, command: Command, serverId?: string) {
|
||||||
|
@ -69,9 +65,10 @@ export class CoreClient extends Client {
|
||||||
CoreClient._commandItems.push(item);
|
CoreClient._commandItems.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterEvent(event: Event) {
|
public static RegisterEvent(eventType: EventType, func: Function) {
|
||||||
const item: IEventItem = {
|
const item: IEventItem = {
|
||||||
Event: event,
|
EventType: eventType,
|
||||||
|
ExecutionFunction: func,
|
||||||
};
|
};
|
||||||
|
|
||||||
CoreClient._eventItems.push(item);
|
CoreClient._eventItems.push(item);
|
||||||
|
|
|
@ -1,33 +1,40 @@
|
||||||
import { Message } from "discord.js";
|
import { Interaction } from "discord.js";
|
||||||
import ICommandItem from "../contracts/ICommandItem";
|
import ICommandItem from "../contracts/ICommandItem";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import { Util } from "./util";
|
import { CoreClient } from "./client";
|
||||||
|
|
||||||
export class Events {
|
export class Events {
|
||||||
private _util: Util;
|
public async onInteractionCreate(interaction: Interaction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
constructor() {
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||||
this._util = new Util();
|
const disabledCommands = disabledCommandsString?.split(",");
|
||||||
|
|
||||||
|
const disabledCommandsMessage = await SettingsHelper.GetSetting("commands.disabled.message", interaction.guildId);
|
||||||
|
|
||||||
|
if (disabledCommands?.find(x => x == interaction.commandName)) {
|
||||||
|
await interaction.reply(disabledCommandsMessage || "This command is disabled.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when a message is sent
|
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
|
||||||
// Used to check for commands
|
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
|
||||||
public async onMessageCreate(message: Message, commands: ICommandItem[]) {
|
|
||||||
if (!message.guild) return;
|
|
||||||
if (message.author.bot) return;
|
|
||||||
|
|
||||||
const prefix = await SettingsHelper.GetSetting("bot.prefix", message.guild.id);
|
let itemToUse: ICommandItem;
|
||||||
|
|
||||||
if (!prefix) return;
|
if (!itemForServer) {
|
||||||
|
if (!item) {
|
||||||
if (message.content.substring(0, prefix.length).toLowerCase() == prefix.toLowerCase()) {
|
await interaction.reply('Command not found');
|
||||||
const args = message.content.substring(prefix.length).split(" ");
|
return;
|
||||||
const name = args.shift();
|
|
||||||
|
|
||||||
if (!name) return;
|
|
||||||
|
|
||||||
await this._util.loadCommand(name, args, message, commands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemToUse = item;
|
||||||
|
} else {
|
||||||
|
itemToUse = itemForServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemToUse.Command.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when bot is logged in and ready to use
|
// Emit when bot is logged in and ready to use
|
||||||
|
|
|
@ -1,101 +1,95 @@
|
||||||
// Required Components
|
import { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
|
||||||
import { Client, Message } from "discord.js";
|
import { EventType } from "../constants/EventType";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ICommandItem from "../contracts/ICommandItem";
|
|
||||||
import IEventItem from "../contracts/IEventItem";
|
import IEventItem from "../contracts/IEventItem";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import { CoreClient } from "./client";
|
||||||
import StringTools from "../helpers/StringTools";
|
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
|
||||||
|
|
||||||
// Util Class
|
|
||||||
export class Util {
|
export class Util {
|
||||||
public async loadCommand(name: string, args: string[], message: Message, commands: ICommandItem[]) {
|
public loadSlashCommands(client: Client) {
|
||||||
if (!message.member) return;
|
const registeredCommands = CoreClient.commandItems;
|
||||||
if (!message.guild) return;
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", message.guild?.id);
|
const globalCommands = registeredCommands.filter(x => !x.ServerId);
|
||||||
const disabledCommands = disabledCommandsString?.split(",");
|
const guildCommands = registeredCommands.filter(x => x.ServerId);
|
||||||
|
|
||||||
if (disabledCommands?.find(x => x == name)) {
|
const globalCommandData: SlashCommandBuilder[] = globalCommands
|
||||||
message.reply(process.env.COMMANDS_DISABLED_MESSAGE || "This command is disabled.");
|
.filter(x => x.Command.CommandBuilder)
|
||||||
return;
|
.flatMap(x => x.Command.CommandBuilder);
|
||||||
}
|
|
||||||
|
|
||||||
const item = commands.find(x => x.Name == name && !x.ServerId);
|
const guildIds: string[] = [];
|
||||||
const itemForServer = commands.find(x => x.Name == name && x.ServerId == message.guild?.id);
|
|
||||||
|
|
||||||
let itemToUse: ICommandItem;
|
for (let command of guildCommands) {
|
||||||
|
if (!guildIds.find(x => x == command.ServerId)) {
|
||||||
if (!itemForServer) {
|
guildIds.push(command.ServerId!);
|
||||||
if (!item) {
|
|
||||||
message.reply('Command not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToUse = item;
|
|
||||||
} else {
|
|
||||||
itemToUse = itemForServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requiredRoles = itemToUse.Command.Roles;
|
|
||||||
|
|
||||||
if (message.author.id != process.env.BOT_OWNERID && message.author.id != message.guild.ownerId) {
|
|
||||||
for (const i in requiredRoles) {
|
|
||||||
if (message.guild) {
|
|
||||||
const setting = await SettingsHelper.GetSetting(`role.${requiredRoles[i]}`, message.guild?.id);
|
|
||||||
|
|
||||||
if (!setting) {
|
|
||||||
message.reply("Unable to verify if you have this role, please contact your bot administrator");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!message.member.roles.cache.find(role => role.name == setting)) {
|
|
||||||
message.reply(`You require the \`${StringTools.Capitalise(setting)}\` role to run this command`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const context: ICommandContext = {
|
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!);
|
||||||
name: name,
|
|
||||||
args: args,
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const precheckResponse = itemToUse.Command.precheck(context);
|
rest.put(
|
||||||
const precheckAsyncResponse = await itemToUse.Command.precheckAsync(context);
|
Routes.applicationCommands(process.env.BOT_CLIENTID!),
|
||||||
|
{
|
||||||
if (precheckResponse != CommandResponse.Ok) {
|
body: globalCommandData
|
||||||
message.reply(ErrorMessages.GetErrorMessage(precheckResponse));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (precheckAsyncResponse != CommandResponse.Ok) {
|
for (let guild of guildIds) {
|
||||||
message.reply(ErrorMessages.GetErrorMessage(precheckAsyncResponse));
|
const guildCommandData = guildCommands.filter(x => x.ServerId == guild)
|
||||||
return;
|
.filter(x => x.Command.CommandBuilder)
|
||||||
|
.flatMap(x => x.Command.CommandBuilder);
|
||||||
|
|
||||||
|
if (!client.guilds.cache.has(guild)) continue;
|
||||||
|
|
||||||
|
rest.put(
|
||||||
|
Routes.applicationGuildCommands(process.env.BOT_CLIENTID!, guild),
|
||||||
|
{
|
||||||
|
body: guildCommandData
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
itemToUse.Command.execute(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the events
|
// Load the events
|
||||||
loadEvents(client: Client, events: IEventItem[]) {
|
loadEvents(client: Client, events: IEventItem[]) {
|
||||||
events.forEach((e) => {
|
events.forEach((e) => {
|
||||||
client.on('channelCreate', e.Event.channelCreate);
|
switch(e.EventType) {
|
||||||
client.on('channelDelete', e.Event.channelDelete);
|
case EventType.ChannelCreate:
|
||||||
client.on('channelUpdate', e.Event.channelUpdate);
|
client.on('channelCreate', (channel) => e.ExecutionFunction(channel));
|
||||||
client.on('guildBanAdd', e.Event.guildBanAdd);
|
break;
|
||||||
client.on('guildBanRemove', e.Event.guildBanRemove);
|
case EventType.ChannelDelete:
|
||||||
client.on('guildCreate', e.Event.guildCreate);
|
client.on('channelDelete', (channel) => e.ExecutionFunction(channel));
|
||||||
client.on('guildMemberAdd', e.Event.guildMemberAdd);
|
break;
|
||||||
client.on('guildMemberRemove', e.Event.guildMemberRemove);
|
case EventType.ChannelUpdate:
|
||||||
client.on('guildMemberUpdate', e.Event.guildMemberUpdate);
|
client.on('channelUpdate', (channel) => e.ExecutionFunction(channel));
|
||||||
client.on('messageCreate', e.Event.messageCreate);
|
break;
|
||||||
client.on('messageDelete', e.Event.messageDelete);
|
case EventType.GuildBanAdd:
|
||||||
client.on('messageUpdate', e.Event.messageUpdate);
|
client.on('guildBanAdd', (ban) => e.ExecutionFunction(ban));
|
||||||
client.on('ready', e.Event.ready);
|
break;
|
||||||
|
case EventType.GuildBanRemove:
|
||||||
|
client.on('guildBanRemove', (ban) => e.ExecutionFunction(ban));
|
||||||
|
break;
|
||||||
|
case EventType.GuildCreate:
|
||||||
|
client.on('guildCreate', (guild) => e.ExecutionFunction(guild));
|
||||||
|
break;
|
||||||
|
case EventType.GuildMemberAdd:
|
||||||
|
client.on('guildMemberAdd', (member) => e.ExecutionFunction(member));
|
||||||
|
break;
|
||||||
|
case EventType.GuildMemberRemove:
|
||||||
|
client.on('guildMemberRemove', (member) => e.ExecutionFunction(member));
|
||||||
|
break;
|
||||||
|
case EventType.GuildMemberUpdate:
|
||||||
|
client.on('guildMemberUpdate', (oldMember, newMember) => e.ExecutionFunction(oldMember, newMember));
|
||||||
|
break;
|
||||||
|
case EventType.MessageCreate:
|
||||||
|
client.on('messageCreate', (message) => e.ExecutionFunction(message));
|
||||||
|
break;
|
||||||
|
case EventType.MessageDelete:
|
||||||
|
client.on('messageDelete', (message) => e.ExecutionFunction(message));
|
||||||
|
break;
|
||||||
|
case EventType.MessageUpdate:
|
||||||
|
client.on('messageUpdate', (oldMessage, newMessage) => e.ExecutionFunction(oldMessage, newMessage));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error('Event not implemented.');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
58
src/commands/501231711271780357/Lobby/add.ts
Normal file
58
src/commands/501231711271780357/Lobby/add.ts
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../../type/command";
|
||||||
|
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
||||||
|
|
||||||
|
export default class AddRole extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('addlobby')
|
||||||
|
.setDescription('Add lobby channel')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addChannelOption(option =>
|
||||||
|
option
|
||||||
|
.setName('channel')
|
||||||
|
.setDescription('The channel')
|
||||||
|
.setRequired(true))
|
||||||
|
.addRoleOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role to ping on request')
|
||||||
|
.setRequired(true))
|
||||||
|
.addNumberOption(option =>
|
||||||
|
option
|
||||||
|
.setName('cooldown')
|
||||||
|
.setDescription('The cooldown in minutes')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The game name')
|
||||||
|
.setRequired(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
const channel = interaction.options.get('channel');
|
||||||
|
const role = interaction.options.get('role');
|
||||||
|
const cooldown = interaction.options.get('cooldown');
|
||||||
|
const gameName = interaction.options.get('name');
|
||||||
|
|
||||||
|
if (!channel || !channel.channel || !role || !role.role || !cooldown || !cooldown.value || !gameName || !gameName.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lobby = await eLobby.FetchOneByChannelId(channel.channel.id);
|
||||||
|
|
||||||
|
if (lobby) {
|
||||||
|
await interaction.reply('This channel has already been setup.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entity = new eLobby(channel.channel.id, role.role.id, cooldown.value as number, gameName.value as string);
|
||||||
|
await entity.Save(eLobby, entity);
|
||||||
|
|
||||||
|
await interaction.reply(`Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown.value} minutes \` and will ping \`${role.name}\` on use`);
|
||||||
|
}
|
||||||
|
}
|
48
src/commands/501231711271780357/Lobby/list.ts
Normal file
48
src/commands/501231711271780357/Lobby/list.ts
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../../type/command";
|
||||||
|
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
||||||
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
|
||||||
|
export default class ListLobby extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('listlobby')
|
||||||
|
.setDescription('Lists all channels set up as lobbies')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||||
|
if (!interaction.guild) {
|
||||||
|
await interaction.reply('Guild not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const channels: eLobby[] = [];
|
||||||
|
|
||||||
|
for (let channel of interaction.guild.channels.cache.map(x => x)) {
|
||||||
|
const lobby = await eLobby.FetchOneByChannelId(channel.id);
|
||||||
|
|
||||||
|
if (lobby) {
|
||||||
|
channels.push(lobby);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Lobbies")
|
||||||
|
.setDescription(`Channels: ${channels.length}`);
|
||||||
|
|
||||||
|
for (let lobby of channels) {
|
||||||
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: `# ${lobby.Name}`,
|
||||||
|
value: `Last Used: ${lobby.LastUsed}`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
|
}
|
||||||
|
}
|
41
src/commands/501231711271780357/Lobby/lobby.ts
Normal file
41
src/commands/501231711271780357/Lobby/lobby.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../../type/command";
|
||||||
|
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
||||||
|
|
||||||
|
export default class Lobby extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('lobby')
|
||||||
|
.setDescription('Attempt to organise a lobby');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.channelId) return;
|
||||||
|
|
||||||
|
const lobby = await eLobby.FetchOneByChannelId(interaction.channelId);
|
||||||
|
|
||||||
|
if (!lobby) {
|
||||||
|
await interaction.reply('This channel is disabled from using the lobby command.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeNow = Date.now();
|
||||||
|
const timeLength = lobby.Cooldown * 60 * 1000; // x minutes in ms
|
||||||
|
const timeAgo = timeNow - timeLength;
|
||||||
|
|
||||||
|
// If it was less than x minutes ago
|
||||||
|
if (lobby.LastUsed.getTime() > timeAgo) {
|
||||||
|
const timeLeft = Math.ceil((timeLength - (timeNow - lobby.LastUsed.getTime())) / 1000 / 60);
|
||||||
|
|
||||||
|
await interaction.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lobby.MarkAsUsed();
|
||||||
|
await lobby.Save(eLobby, lobby);
|
||||||
|
|
||||||
|
await interaction.reply(`${interaction.user} would like to organise a lobby of **${lobby.Name}**! <@&${lobby.RoleId}>`);
|
||||||
|
}
|
||||||
|
}
|
40
src/commands/501231711271780357/Lobby/remove.ts
Normal file
40
src/commands/501231711271780357/Lobby/remove.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../../type/command";
|
||||||
|
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
||||||
|
import BaseEntity from "../../../contracts/BaseEntity";
|
||||||
|
|
||||||
|
export default class RemoveLobby extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('removelobby')
|
||||||
|
.setDescription('Remove a lobby channel')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addChannelOption(option =>
|
||||||
|
option
|
||||||
|
.setName('channel')
|
||||||
|
.setDescription('The channel')
|
||||||
|
.setRequired(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
const channel = interaction.options.get('channel');
|
||||||
|
|
||||||
|
if (!channel || !channel.channel) {
|
||||||
|
await interaction.reply('Channel is required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entity = await eLobby.FetchOneByChannelId(channel.channel.id);
|
||||||
|
|
||||||
|
if (!entity) {
|
||||||
|
await interaction.reply('Channel not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await BaseEntity.Remove<eLobby>(eLobby, entity);
|
||||||
|
|
||||||
|
await interaction.reply(`Removed <#${channel.channel.id}> from the list of lobby channels`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
import { Command } from "../../type/command";
|
import { Command } from "../../type/command";
|
||||||
|
|
||||||
|
@ -7,19 +7,23 @@ export default class Entry extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName('entry')
|
||||||
"moderator"
|
.setDescription('Sends the entry embed')
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.channel) return;
|
||||||
|
|
||||||
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", context.message.guild.id) || "rules";
|
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", interaction.guildId) || "rules";
|
||||||
|
|
||||||
const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Welcome")
|
||||||
|
.setDescription(`Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
|
||||||
|
|
||||||
await embedInfo.SendToCurrentChannel();
|
await interaction.channel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,159 +0,0 @@
|
||||||
import { TextChannel } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
|
||||||
import { Command } from "../../type/command";
|
|
||||||
import { default as eLobby } from "../../entity/501231711271780357/Lobby";
|
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
|
||||||
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import ErrorEmbed from "../../helpers/embeds/ErrorEmbed";
|
|
||||||
import BaseEntity from "../../contracts/BaseEntity";
|
|
||||||
|
|
||||||
export default class Lobby extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
if (!context.message.guild) return;
|
|
||||||
|
|
||||||
switch (context.args[0]) {
|
|
||||||
case "config":
|
|
||||||
await this.UseConfig(context);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
await this.UseDefault(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======
|
|
||||||
// Default
|
|
||||||
// =======
|
|
||||||
|
|
||||||
private async UseDefault(context: ICommandContext) {
|
|
||||||
const channel = context.message.channel as TextChannel;
|
|
||||||
const channelId = channel.id;
|
|
||||||
|
|
||||||
const lobby = await eLobby.FetchOneByChannelId(channelId);
|
|
||||||
|
|
||||||
if (!lobby) {
|
|
||||||
this.SendDisabled(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeNow = Date.now();
|
|
||||||
const timeLength = lobby.Cooldown * 60 * 1000; // x minutes in ms
|
|
||||||
const timeAgo = timeNow - timeLength;
|
|
||||||
|
|
||||||
// If it was less than x minutes ago
|
|
||||||
if (lobby.LastUsed.getTime() > timeAgo) {
|
|
||||||
this.SendOnCooldown(context, timeLength, new Date(timeNow), lobby.LastUsed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.RequestLobby(context, lobby);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async RequestLobby(context: ICommandContext, lobby: eLobby) {
|
|
||||||
lobby.MarkAsUsed();
|
|
||||||
await lobby.Save(eLobby, lobby);
|
|
||||||
|
|
||||||
context.message.channel.send(`${context.message.author} would like to organise a lobby of **${lobby.Name}**! <@&${lobby.RoleId}>`);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SendOnCooldown(context: ICommandContext, timeLength: number, timeNow: Date, timeUsed: Date) {
|
|
||||||
const timeLeft = Math.ceil((timeLength - (timeNow.getTime() - timeUsed.getTime())) / 1000 / 60);
|
|
||||||
|
|
||||||
context.message.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SendDisabled(context: ICommandContext) {
|
|
||||||
context.message.reply("This channel hasn't been setup for lobbies.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======
|
|
||||||
// Config
|
|
||||||
// ======
|
|
||||||
private async UseConfig(context: ICommandContext) {
|
|
||||||
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
|
|
||||||
|
|
||||||
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (context.args[1]) {
|
|
||||||
case "add":
|
|
||||||
await this.AddLobbyConfig(context);
|
|
||||||
break;
|
|
||||||
case "remove":
|
|
||||||
await this.RemoveLobbyConfig(context);
|
|
||||||
break;
|
|
||||||
case "help":
|
|
||||||
default:
|
|
||||||
await this.SendConfigHelp(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async SendConfigHelp(context: ICommandContext) {
|
|
||||||
const helpText = readFileSync(`${process.cwd()}/data/usage/lobby.txt`).toString();
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Configure Lobby Command", helpText);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async AddLobbyConfig(context: ICommandContext) {
|
|
||||||
const channel = context.message.guild!.channels.cache.find(x => x.id == context.args[2]);
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[3]);
|
|
||||||
const cooldown = Number(context.args[4]) || 30;
|
|
||||||
const gameName = context.args.splice(5).join(" ");
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "The channel id you provided is invalid or channel does not exist.");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "The role id you provided is invalid or role does not exist.");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const lobby = await eLobby.FetchOneByChannelId(channel.id);
|
|
||||||
|
|
||||||
if (lobby) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "This channel has already been setup.");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const entity = new eLobby(channel.id, role.id, cooldown, gameName);
|
|
||||||
await entity.Save(eLobby, entity);
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes\` and will ping \`${role.name}\` on use`);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async RemoveLobbyConfig(context: ICommandContext) {
|
|
||||||
const entity = await eLobby.FetchOneByChannelId(context.args[2]);
|
|
||||||
|
|
||||||
if (!entity) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "The channel id you provided has not been setup as a lobby, unable to remove.");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await BaseEntity.Remove<eLobby>(eLobby, entity);
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed <#${context.args[2]}> from the list of lobby channels`);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
}
|
|
54
src/commands/Role/config.ts
Normal file
54
src/commands/Role/config.ts
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../type/command";
|
||||||
|
import { default as eRole } from "../../database/entities/Role";
|
||||||
|
import Server from "../../database/entities/Server";
|
||||||
|
|
||||||
|
export default class ConfigRole extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('configrole')
|
||||||
|
.setDescription('Toggle your roles')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
|
||||||
|
.addRoleOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role name')
|
||||||
|
.setRequired(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId || !interaction.guild) return;
|
||||||
|
if (!interaction.member) return;
|
||||||
|
|
||||||
|
const role = interaction.options.get('role');
|
||||||
|
|
||||||
|
if (!role || !role.role) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingRole = await eRole.FetchOneByRoleId(role.role.id);
|
||||||
|
|
||||||
|
if (existingRole) {
|
||||||
|
await eRole.Remove(eRole, existingRole);
|
||||||
|
|
||||||
|
await interaction.reply('Removed role from configuration.');
|
||||||
|
} else {
|
||||||
|
const server = await Server.FetchOneById(Server, interaction.guildId);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('This server has not been setup.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRole = new eRole(role.role.id);
|
||||||
|
newRole.SetServer(server);
|
||||||
|
|
||||||
|
await newRole.Save(eRole, newRole);
|
||||||
|
|
||||||
|
await interaction.reply('Added role to configuration.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
src/commands/Role/role.ts
Normal file
109
src/commands/Role/role.ts
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../type/command";
|
||||||
|
import { default as eRole } from "../../database/entities/Role";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
|
||||||
|
export default class Role extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('Toggle your roles')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('toggle')
|
||||||
|
.setDescription('Toggle your role')
|
||||||
|
.addRoleOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role name')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('list')
|
||||||
|
.setDescription('List togglable roles'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
switch (interaction.options.getSubcommand()) {
|
||||||
|
case 'toggle':
|
||||||
|
await this.ToggleRole(interaction);
|
||||||
|
break;
|
||||||
|
case 'list':
|
||||||
|
await this.SendRolesList(interaction);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await interaction.reply('Subcommand not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async SendRolesList(interaction: CommandInteraction) {
|
||||||
|
const roles = await this.GetRolesList(interaction);
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Roles")
|
||||||
|
.setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ToggleRole(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guild) return;
|
||||||
|
if (!interaction.member) return;
|
||||||
|
|
||||||
|
const roles = await this.GetRolesList(interaction);
|
||||||
|
const requestedRole = interaction.options.get('role');
|
||||||
|
|
||||||
|
if (!requestedRole || !requestedRole.role) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!roles.includes(requestedRole.role.name)) {
|
||||||
|
await interaction.reply('This role isn\'t marked as assignable.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleManager = interaction.member.roles as GuildMemberRoleManager;
|
||||||
|
|
||||||
|
const userRole = roleManager.cache.find(x => x.name == requestedRole.role!.name);
|
||||||
|
const assignRole = interaction.guild.roles.cache.find(x => x.id == requestedRole.role!.id);
|
||||||
|
|
||||||
|
if (!assignRole) return;
|
||||||
|
|
||||||
|
if (!assignRole.editable) {
|
||||||
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userRole) {
|
||||||
|
await roleManager.add(assignRole);
|
||||||
|
await interaction.reply(`Gave role: \`${assignRole.name}\``);
|
||||||
|
} else {
|
||||||
|
await roleManager.remove(assignRole);
|
||||||
|
await interaction.reply(`Removed role: \`${assignRole.name}\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async GetRolesList(interaction: CommandInteraction): Promise<string[]> {
|
||||||
|
if (!interaction.guildId || !interaction.guild) return [];
|
||||||
|
|
||||||
|
const rolesArray = await eRole.FetchAllByServerId(interaction.guildId);
|
||||||
|
|
||||||
|
const roles: string[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < rolesArray.length; i++) {
|
||||||
|
const serverRole = interaction.guild.roles.cache.find(x => x.id == rolesArray[i].RoleId);
|
||||||
|
|
||||||
|
if (serverRole) {
|
||||||
|
roles.push(serverRole.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,56 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class About extends Command {
|
export default class About extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
super.Category = "General";
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('about')
|
||||||
|
.setDescription('About VylBot');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const embed = new PublicEmbed(context, "About", "")
|
const fundingLink = process.env.ABOUT_FUNDING;
|
||||||
.addField("Version", process.env.BOT_VER!)
|
const repoLink = process.env.ABOUT_REPO;
|
||||||
.addField("Author", process.env.BOT_AUTHOR!)
|
|
||||||
.addField("Date", process.env.BOT_DATE!);
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("About")
|
||||||
|
.setDescription("Discord Bot made by Vylpes");
|
||||||
|
|
||||||
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: "Version",
|
||||||
|
value: process.env.BOT_VER!,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Author",
|
||||||
|
value: process.env.BOT_AUTHOR!,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||||
|
|
||||||
|
if (repoLink) {
|
||||||
|
row.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setURL(repoLink)
|
||||||
|
.setLabel("Repo")
|
||||||
|
.setStyle(ButtonStyle.Link));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fundingLink) {
|
||||||
|
row.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setURL(fundingLink)
|
||||||
|
.setLabel("Funding")
|
||||||
|
.setStyle(ButtonStyle.Link));
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ], components: row.components.length > 0 ? [ row ] : [] });
|
||||||
}
|
}
|
||||||
}
|
}
|
212
src/commands/audits.ts
Normal file
212
src/commands/audits.ts
Normal file
|
@ -0,0 +1,212 @@
|
||||||
|
import Audit from "../database/entities/Audit";
|
||||||
|
import AuditTools from "../helpers/AuditTools";
|
||||||
|
import { Command } from "../type/command";
|
||||||
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
|
export default class Audits extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("audits")
|
||||||
|
.setDescription("View audits of a particular user in the server")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('user')
|
||||||
|
.setDescription('View all audits done against a user')
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('view')
|
||||||
|
.setDescription('View a particular audit')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('auditid')
|
||||||
|
.setDescription('The audit id in caps')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('clear')
|
||||||
|
.setDescription('Clears an audit from a user')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('auditid')
|
||||||
|
.setDescription('The audit id in caps')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('add')
|
||||||
|
.setDescription('Manually add an audit')
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('type')
|
||||||
|
.setDescription('The type of audit')
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'General', value: AuditType.General.toString() },
|
||||||
|
{ name: 'Warn', value: AuditType.Warn.toString() },
|
||||||
|
{ name: 'Mute', value: AuditType.Mute.toString() },
|
||||||
|
{ name: 'Kick', value: AuditType.Kick.toString() },
|
||||||
|
{ name: 'Ban', value: AuditType.Ban.toString() },
|
||||||
|
)
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason')));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
switch (interaction.options.getSubcommand()) {
|
||||||
|
case "user":
|
||||||
|
await this.SendAuditForUser(interaction);
|
||||||
|
break;
|
||||||
|
case "view":
|
||||||
|
await this.SendAudit(interaction);
|
||||||
|
break;
|
||||||
|
case "clear":
|
||||||
|
await this.ClearAudit(interaction);
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
await this.AddAudit(interaction);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await interaction.reply("Subcommand doesn't exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async SendAuditForUser(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const user = interaction.options.getUser('target');
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
await interaction.reply("User not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audits = await Audit.FetchAuditsByUserId(user.id, interaction.guildId);
|
||||||
|
|
||||||
|
if (!audits || audits.length == 0) {
|
||||||
|
await interaction.reply("There are no audits for this user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Audits")
|
||||||
|
.setDescription(`Audits: ${audits.length}`);
|
||||||
|
|
||||||
|
for (let audit of audits) {
|
||||||
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: `${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`,
|
||||||
|
value: audit.WhenCreated.toString(),
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async SendAudit(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const auditId = interaction.options.get('auditid');
|
||||||
|
|
||||||
|
if (!auditId || !auditId.value) {
|
||||||
|
await interaction.reply("AuditId not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
|
||||||
|
|
||||||
|
if (!audit) {
|
||||||
|
await interaction.reply("Audit not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Audit")
|
||||||
|
.setDescription(audit.AuditId.toUpperCase())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: audit.Reason || "*none*",
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Type",
|
||||||
|
value: AuditTools.TypeToFriendlyText(audit.AuditType),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${audit.ModeratorId}>`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ClearAudit(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const auditId = interaction.options.get('auditid');
|
||||||
|
|
||||||
|
if (!auditId || !auditId.value) {
|
||||||
|
await interaction.reply("AuditId not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
|
||||||
|
|
||||||
|
if (!audit) {
|
||||||
|
await interaction.reply("Audit not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Audit.Remove(Audit, audit);
|
||||||
|
|
||||||
|
await interaction.reply("Audit cleared.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async AddAudit(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const user = interaction.options.getUser('target');
|
||||||
|
const auditType = interaction.options.get('type');
|
||||||
|
const reasonInput = interaction.options.get('reason');
|
||||||
|
|
||||||
|
if (!user || !auditType || !auditType.value) {
|
||||||
|
await interaction.reply("Invalid input.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const type = auditType.value as AuditType;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "";
|
||||||
|
|
||||||
|
const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId);
|
||||||
|
|
||||||
|
await audit.Save(Audit, audit);
|
||||||
|
|
||||||
|
await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,83 +1,79 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import Audit from "../database/entities/Audit";
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
|
||||||
export default class Ban extends Command {
|
export default class Ban extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("ban")
|
||||||
"moderator"
|
.setDescription("Ban a member from the server with an optional reason")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.guild) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
commandContext: context,
|
await interaction.reply("User not found.");
|
||||||
embeds: [embed],
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const member = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Banned")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
if (!member.bannable) {
|
||||||
commandContext: context,
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
embeds: [embed],
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
await member.ban();
|
||||||
reasonArgs.splice(0, 1)
|
await interaction.reply(`\`${targetUser.user.tag}\` has been banned.`);
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
if (!context.message.guild?.available) {
|
if (!channelName) return;
|
||||||
return {
|
|
||||||
commandContext: context,
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
embeds: [],
|
|
||||||
};
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetMember.bannable) {
|
const audit = new Audit(targetUser.user.id, AuditType.Ban, reason, interaction.user.id, interaction.guildId);
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
await audit.Save(Audit, audit);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Banned");
|
|
||||||
logEmbed.AddUser("User", targetUser, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been banned`);
|
|
||||||
|
|
||||||
await targetMember.ban({ reason: `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}` });
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [logEmbed, publicEmbed],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,29 +1,45 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import randomBunny from "random-bunny";
|
import randomBunny from "random-bunny";
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class Bunny extends Command {
|
export default class Bunny extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Fun";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("bunny")
|
||||||
|
.setDescription("Get a random picture of a rabbit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const result = await randomBunny('rabbits', 'hot');
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const subreddits = [
|
||||||
|
'rabbits',
|
||||||
|
'bunnieswithhats',
|
||||||
|
'buncomfortable',
|
||||||
|
'bunnytongues',
|
||||||
|
'dutchbunnymafia',
|
||||||
|
];
|
||||||
|
|
||||||
|
const random = Math.floor(Math.random() * subreddits.length);
|
||||||
|
const selectedSubreddit = subreddits[random];
|
||||||
|
|
||||||
|
const result = await randomBunny(selectedSubreddit, 'hot');
|
||||||
|
|
||||||
if (result.IsSuccess) {
|
if (result.IsSuccess) {
|
||||||
const embed = new PublicEmbed(context, result.Result!.Title, "")
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle(result.Result!.Title)
|
||||||
|
.setDescription(result.Result!.Permalink)
|
||||||
.setImage(result.Result!.Url)
|
.setImage(result.Result!.Url)
|
||||||
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
||||||
.setFooter({ text: `r/Rabbits · ${result.Result!.Ups} upvotes` });
|
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`});
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
} else {
|
} else {
|
||||||
const errorEmbed = new ErrorEmbed(context, "There was an error using this command.");
|
await interaction.reply("There was an error running this command.");
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,50 +1,43 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { TextChannel } from "discord.js";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
|
||||||
|
|
||||||
export default class Clear extends Command {
|
export default class Clear extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("clear")
|
||||||
"moderator"
|
.setDescription("Clears the channel of messages")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
|
||||||
|
.addNumberOption(option =>
|
||||||
|
option
|
||||||
|
.setName('count')
|
||||||
|
.setDescription('The amount to delete')
|
||||||
|
.setRequired(true)
|
||||||
|
.setMinValue(1)
|
||||||
|
.setMaxValue(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (context.args.length == 0) {
|
if (!interaction.isChatInputCommand()) return;
|
||||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
if (!interaction.channel) return;
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
const totalToClear = interaction.options.getNumber('count');
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const totalToClear = Number.parseInt(context.args[0]);
|
|
||||||
|
|
||||||
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
await interaction.reply('Please specify an amount between 1 and 100.');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
return;
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
|
const channel = interaction.channel as TextChannel;
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
|
if (!channel.manageable) {
|
||||||
await embed.SendToCurrentChannel();
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
await channel.bulkDelete(totalToClear);
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
await interaction.reply(`${totalToClear} message(s) were removed.`);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,4 @@
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import StringTools from "../helpers/StringTools";
|
import StringTools from "../helpers/StringTools";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
@ -10,85 +7,58 @@ export default class Code extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName('code')
|
||||||
"moderator"
|
.setDescription('Manage the verification code of the server')
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('randomise')
|
||||||
|
.setDescription('Regenerates the verification code for this server'))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('embed')
|
||||||
|
.setDescription('Sends the embed with the current code to the current channel'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild){
|
if (!interaction.isChatInputCommand()) return;
|
||||||
return CommandResponse.NotInServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isEnabled = await SettingsHelper.GetSetting("verification.enabled", context.message.guild?.id);
|
switch (interaction.options.getSubcommand()) {
|
||||||
|
|
||||||
if (!isEnabled) {
|
|
||||||
return CommandResponse.FeatureDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEnabled.toLocaleLowerCase() != 'true') {
|
|
||||||
return CommandResponse.FeatureDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommandResponse.Ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
const action = context.args[0];
|
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case "randomise":
|
case "randomise":
|
||||||
await this.Randomise(context);
|
await this.Randomise(interaction);
|
||||||
break;
|
break;
|
||||||
case "embed":
|
case "embed":
|
||||||
await this.SendEmbed(context);
|
await this.SendEmbed(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
await this.SendUsage(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendUsage(context: ICommandContext) {
|
private async Randomise(interaction: CommandInteraction) {
|
||||||
const description = [
|
if (!interaction.guildId) return;
|
||||||
"USAGE: <randomise|embed>",
|
|
||||||
"",
|
|
||||||
"randomise: Sets the server's entry code to a random code",
|
|
||||||
"embed: Sends an embed with the server's entry code"
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", description);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Randomise(context: ICommandContext) {
|
|
||||||
if (!context.message.guild) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const randomCode = StringTools.RandomString(5);
|
const randomCode = StringTools.RandomString(5);
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("verification.code", context.message.guild.id, randomCode);
|
await SettingsHelper.SetSetting("verification.code", interaction.guildId, randomCode);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``);
|
await interaction.reply(`Entry code has been set to \`${randomCode}\``);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendEmbed(context: ICommandContext) {
|
private async SendEmbed(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
return;
|
if (!interaction.channel) return;
|
||||||
}
|
|
||||||
|
|
||||||
const code = await SettingsHelper.GetSetting("verification.code", context.message.guild.id);
|
const code = await SettingsHelper.GetSetting("verification.code", interaction.guildId);
|
||||||
|
|
||||||
if (!code || code == "") {
|
if (!code || code == "") {
|
||||||
const errorEmbed = new ErrorEmbed(context, "There is no code for this server setup.");
|
await interaction.reply("There is no code for this server setup.");
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Entry Code", code!);
|
const embed = new EmbedBuilder()
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Entry Code")
|
||||||
|
.setDescription(code);
|
||||||
|
|
||||||
|
await interaction.channel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,126 +1,186 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
|
||||||
import DefaultValues from "../constants/DefaultValues";
|
import DefaultValues from "../constants/DefaultValues";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import Server from "../entity/Server";
|
import Server from "../database/entities/Server";
|
||||||
import Setting from "../entity/Setting";
|
import Setting from "../database/entities/Setting";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Config extends Command {
|
export default class Config extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
super.Category = "Administration";
|
|
||||||
super.Roles = [
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
"administrator"
|
.setName('config')
|
||||||
]
|
.setDescription('Configure the current server')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('reset')
|
||||||
|
.setDescription('Reset a setting to the default')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('get')
|
||||||
|
.setDescription('Gets a setting for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('set')
|
||||||
|
.setDescription('Sets a setting to a specified value')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('value')
|
||||||
|
.setDescription('The value')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('list')
|
||||||
|
.setDescription('Lists all settings'))
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.isChatInputCommand()) return;
|
||||||
return CommandResponse.ServerNotSetup;
|
if (!interaction.guildId) return;
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
"Settings",
|
"Settings",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!server) {
|
if (!server) {
|
||||||
return CommandResponse.ServerNotSetup;
|
await interaction.reply('Server not setup. Please use the setup command,');
|
||||||
}
|
|
||||||
|
|
||||||
return CommandResponse.Ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
if (!context.message.guild) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
|
switch (interaction.options.getSubcommand()) {
|
||||||
"Settings",
|
case 'list':
|
||||||
]);
|
await this.SendHelpText(interaction);
|
||||||
|
break;
|
||||||
if (!server) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = context.args[0];
|
|
||||||
const action = context.args[1];
|
|
||||||
const value = context.args.splice(2).join(" ");
|
|
||||||
|
|
||||||
if (!key) {
|
|
||||||
this.SendHelpText(context);
|
|
||||||
} else if (!action) {
|
|
||||||
this.GetValue(context, server, key);
|
|
||||||
} else {
|
|
||||||
switch(action) {
|
|
||||||
case 'reset':
|
case 'reset':
|
||||||
this.ResetValue(context, server, key);
|
await this.ResetValue(interaction);
|
||||||
|
break;
|
||||||
|
case 'get':
|
||||||
|
await this.GetValue(interaction);
|
||||||
break;
|
break;
|
||||||
case 'set':
|
case 'set':
|
||||||
if (!value) {
|
await this.SetValue(interaction);
|
||||||
const errorEmbed = new ErrorEmbed(context, "Value is required when setting");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SetValue(context, server, key, value);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
const errorEmbed = new ErrorEmbed(context, "Action must be either set or reset");
|
await interaction.reply('Subcommand not found.');
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendHelpText(context: ICommandContext) {
|
private async SendHelpText(interaction: CommandInteraction) {
|
||||||
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
|
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Config", description);
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Config")
|
||||||
|
.setDescription(description);
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async GetValue(context: ICommandContext, server: Server, key: string) {
|
private async GetValue(interaction: CommandInteraction) {
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
|
||||||
|
if (!key || !key.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
|
"Settings",
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
|
|
||||||
if (setting) {
|
if (setting) {
|
||||||
const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`);
|
await interaction.reply(`\`${key}\`: \`${setting.Value}\``);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
} else {
|
||||||
const embed = new PublicEmbed(context, "", `${key}: ${DefaultValues.GetValue(key)} <DEFAULT>`);
|
await interaction.reply(`\`${key}\`: \`${DefaultValues.GetValue(key.value.toString())}\` <DEFAULT>`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ResetValue(context: ICommandContext, server: Server, key: string) {
|
private async ResetValue(interaction: CommandInteraction) {
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
|
||||||
|
if (!key || !key.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
|
"Settings",
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
|
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been reset");
|
await interaction.reply('Setting not found.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Setting.Remove(Setting, setting);
|
await Setting.Remove(Setting, setting);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been reset");
|
await interaction.reply('The setting has been reset to the default.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SetValue(context: ICommandContext, server: Server, key: string, value: string) {
|
private async SetValue(interaction: CommandInteraction) {
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
const value = interaction.options.get('value');
|
||||||
|
|
||||||
|
if (!key || !key.value || !value || !value.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
|
"Settings",
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
|
|
||||||
if (setting) {
|
if (setting) {
|
||||||
setting.UpdateBasicDetails(key, value);
|
setting.UpdateBasicDetails(key.value.toString(), value.value.toString());
|
||||||
|
|
||||||
await setting.Save(Setting, setting);
|
await setting.Save(Setting, setting);
|
||||||
} else {
|
} else {
|
||||||
const newSetting = new Setting(key, value);
|
const newSetting = new Setting(key.value.toString(), value.value.toString());
|
||||||
|
|
||||||
await newSetting.Save(Setting, newSetting);
|
await newSetting.Save(Setting, newSetting);
|
||||||
|
|
||||||
|
@ -129,7 +189,6 @@ export default class Config extends Command {
|
||||||
await server.Save(Server, server);
|
await server.Save(Server, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been set");
|
await interaction.reply('Setting has been set.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
|
@ -7,87 +6,86 @@ export default class Disable extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName('disable')
|
||||||
"moderator"
|
.setDescription('Disables a command')
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('add')
|
||||||
|
.setDescription('Disables a command for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The name of the command')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('remove')
|
||||||
|
.setDescription('Enables a command for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The name of the command')
|
||||||
|
.setRequired(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const action = context.args[0];
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "add":
|
case "add":
|
||||||
await this.Add(context);
|
await this.Add(interaction);
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
await this.Remove(context);
|
await this.Remove(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await this.SendUsage(context);
|
await interaction.reply('Subcommand not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendUsage(context: ICommandContext) {
|
private async Add(interaction: CommandInteraction) {
|
||||||
const description = [
|
if (!interaction.guildId) return;
|
||||||
"USAGE: <add|remove> <name>",
|
|
||||||
"",
|
|
||||||
"add: Adds the command name to the server's disabled command string",
|
|
||||||
"remove: Removes the command name from the server's disabled command string",
|
|
||||||
"name: The name of the command to enable/disable"
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", description);
|
const commandName = interaction.options.get('name');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Add(context: ICommandContext) {
|
if (!commandName || !commandName.value) {
|
||||||
if (!context.message.guild) {
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandName = context.args[1];
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||||
|
|
||||||
if (!commandName) {
|
|
||||||
this.SendUsage(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
|
|
||||||
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
||||||
|
|
||||||
disabledCommands?.push(commandName);
|
disabledCommands?.push(commandName.value.toString());
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`);
|
await interaction.reply(`Disabled command ${commandName.value}`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Remove(context: ICommandContext) {
|
private async Remove(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const commandName = interaction.options.get('name');
|
||||||
|
|
||||||
|
if (!commandName || !commandName.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandName = context.args[1];
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||||
|
|
||||||
if (!commandName) {
|
|
||||||
this.SendUsage(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
|
|
||||||
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
||||||
|
|
||||||
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName);
|
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName.value!.toString());
|
||||||
|
|
||||||
if (disabledCommandsInstance! > -1) {
|
if (disabledCommandsInstance! > -1) {
|
||||||
disabledCommands?.splice(disabledCommandsInstance!, 1);
|
disabledCommands?.splice(disabledCommandsInstance!, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`);
|
await interaction.reply(`Enabled command ${commandName.value}`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,68 +0,0 @@
|
||||||
import { existsSync, readdirSync } from "fs";
|
|
||||||
import { CoreClient } from "../client/client";
|
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import StringTools from "../helpers/StringTools";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
|
|
||||||
export interface ICommandData {
|
|
||||||
Exists: boolean;
|
|
||||||
Name?: string;
|
|
||||||
Category?: string;
|
|
||||||
Roles?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Help extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
if (context.args.length == 0) {
|
|
||||||
await this.SendAll(context);
|
|
||||||
} else {
|
|
||||||
await this.SendSingle(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendAll(context: ICommandContext) {
|
|
||||||
const allCommands = CoreClient.commandItems
|
|
||||||
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
|
|
||||||
const cateogries = [...new Set(allCommands.map(x => x.Command.Category))];
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Commands", "");
|
|
||||||
|
|
||||||
cateogries.forEach(category => {
|
|
||||||
let filtered = allCommands.filter(x => x.Command.Category == category);
|
|
||||||
|
|
||||||
embed.addField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", "));
|
|
||||||
});
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendSingle(context: ICommandContext) {
|
|
||||||
const command = CoreClient.commandItems.find(x => x.Name == context.args[0] && !x.ServerId);
|
|
||||||
const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id);
|
|
||||||
|
|
||||||
if (exclusiveCommand) {
|
|
||||||
const embed = new PublicEmbed(context, StringTools.Capitalise(exclusiveCommand.Name), "");
|
|
||||||
embed.addField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
|
|
||||||
embed.addField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else if (command) {
|
|
||||||
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), "");
|
|
||||||
embed.addField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised"));
|
|
||||||
embed.addField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone");
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Command does not exist");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
39
src/commands/ignore.ts
Normal file
39
src/commands/ignore.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import IgnoredChannel from "../database/entities/IgnoredChannel";
|
||||||
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
|
export default class Ignore extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('ignore')
|
||||||
|
.setDescription('Ignore events in this channel')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const isChannelIgnored = await IgnoredChannel.IsChannelIgnored(interaction.guildId);
|
||||||
|
|
||||||
|
if (isChannelIgnored) {
|
||||||
|
const entity = await IgnoredChannel.FetchOneById(IgnoredChannel, interaction.guildId);
|
||||||
|
|
||||||
|
if (!entity) {
|
||||||
|
await interaction.reply('Unable to find channel.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await IgnoredChannel.Remove(IgnoredChannel, entity);
|
||||||
|
|
||||||
|
await interaction.reply('This channel will start being logged again.');
|
||||||
|
} else {
|
||||||
|
const entity = new IgnoredChannel(interaction.guildId);
|
||||||
|
|
||||||
|
await entity.Save(IgnoredChannel, entity);
|
||||||
|
|
||||||
|
await interaction.reply('This channel will now be ignored from logging.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,83 +1,79 @@
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
import Audit from "../database/entities/Audit";
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
|
||||||
export default class Kick extends Command {
|
export default class Kick extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("kick")
|
||||||
"moderator"
|
.setDescription("Kick a member from the server with an optional reason")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.guild) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
commandContext: context,
|
await interaction.reply("User not found.");
|
||||||
embeds: [embed]
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const member = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Kicked")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
if (!member.kickable) {
|
||||||
commandContext: context,
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
embeds: [embed]
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
await member.kick();
|
||||||
reasonArgs.splice(0, 1)
|
await interaction.reply(`\`${targetUser.user.tag}\` has been kicked.`);
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
if (!context.message.guild?.available) {
|
if (!channelName) return;
|
||||||
return {
|
|
||||||
commandContext: context,
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
embeds: []
|
|
||||||
};
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetMember.kickable) {
|
const audit = new Audit(targetUser.user.id, AuditType.Kick, reason, interaction.user.id, interaction.guildId);
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
await audit.Save(Audit, audit);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Kicked");
|
|
||||||
logEmbed.AddUser("User", targetUser, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been kicked`);
|
|
||||||
|
|
||||||
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [logEmbed, publicEmbed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,96 +1,85 @@
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { AuditType } from "../constants/AuditType";
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import Audit from "../database/entities/Audit";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Mute extends Command {
|
export default class Mute extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("mute")
|
||||||
"moderator"
|
.setDescription("(DEPRECATED) Mute a member in the server with an optional reason")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
commandContext: context,
|
await interaction.reply('Fields are required.');
|
||||||
embeds: [embed]
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Muted")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
if (!mutedRole) {
|
||||||
reasonArgs.splice(0, 1);
|
await interaction.reply('Muted role not found.');
|
||||||
|
return;
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) {
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetMember.manageable) {
|
if (!targetMember.manageable) {
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
await embed.SendToCurrentChannel();
|
return;
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Muted");
|
await targetMember.roles.add(mutedRole);
|
||||||
logEmbed.AddUser("User", targetUser, true)
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been muted`);
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
if (!channelName) return;
|
||||||
|
|
||||||
if (!mutedRole) {
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (channel) {
|
||||||
commandContext: context,
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
const audit = new Audit(targetUser.user.id, AuditType.Mute, reason, interaction.user.id, interaction.guildId);
|
||||||
|
await audit.Save(Audit, audit);
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
await interaction.reply("Please note the mute and unmute commands have been deprecated and will be removed in a future update. Please use timeout instead");
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [logEmbed, publicEmbed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,67 +0,0 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
|
|
||||||
export default class Poll extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
|
||||||
const argsJoined = context.args.join(" ");
|
|
||||||
const argsSplit = argsJoined.split(";");
|
|
||||||
|
|
||||||
if (argsSplit.length < 3 || argsSplit.length > 10) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = argsSplit[0];
|
|
||||||
|
|
||||||
const arrayOfNumbers = [
|
|
||||||
':one:',
|
|
||||||
':two:',
|
|
||||||
':three:',
|
|
||||||
':four:',
|
|
||||||
':five:',
|
|
||||||
':six:',
|
|
||||||
':seven:',
|
|
||||||
':eight:',
|
|
||||||
':nine:'
|
|
||||||
];
|
|
||||||
|
|
||||||
const reactionEmojis = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"];
|
|
||||||
|
|
||||||
const description = arrayOfNumbers.splice(0, argsSplit.length - 1);
|
|
||||||
|
|
||||||
description.forEach((value, index) => {
|
|
||||||
description[index] = `${value} ${argsSplit[index + 1]}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, title, description.join("\n"));
|
|
||||||
|
|
||||||
const message = await context.message.channel.send({ embeds: [ embed ]});
|
|
||||||
|
|
||||||
description.forEach(async (value, index) => {
|
|
||||||
await message.react(reactionEmojis[index]);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (context.message.deletable) {
|
|
||||||
await context.message.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,232 +0,0 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Role as DiscordRole } from "discord.js";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import { default as eRole } from "../entity/Role";
|
|
||||||
import Server from "../entity/Server";
|
|
||||||
|
|
||||||
export default class Role extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
if (!context.message.guild) return;
|
|
||||||
|
|
||||||
switch (context.args[0]) {
|
|
||||||
case "config":
|
|
||||||
await this.UseConfig(context);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
await this.UseDefault(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======
|
|
||||||
// Default
|
|
||||||
// =======
|
|
||||||
|
|
||||||
private async UseDefault(context: ICommandContext) {
|
|
||||||
if (context.args.length == 0) {
|
|
||||||
await this.SendRolesList(context, context.message.guild!.id);
|
|
||||||
} else {
|
|
||||||
await this.ToggleRole(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async GetRolesList(context: ICommandContext): Promise<string[]> {
|
|
||||||
const rolesArray = await eRole.FetchAllByServerId(context.message.guild!.id);
|
|
||||||
|
|
||||||
const stringArray: string[] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < rolesArray.length; i++) {
|
|
||||||
const serverRole = context.message.guild!.roles.cache.find(x => x.id == rolesArray[i].RoleId);
|
|
||||||
|
|
||||||
if (serverRole) {
|
|
||||||
stringArray.push(serverRole.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendRolesList(context: ICommandContext, serverId: string): Promise<ICommandReturnContext> {
|
|
||||||
const roles = await this.GetRolesList(context);
|
|
||||||
|
|
||||||
const botPrefix = await SettingsHelper.GetServerPrefix(serverId);
|
|
||||||
const description = roles.length == 0 ? "*no roles*" : `Do ${botPrefix}role <role> to get the role!\n\n${roles.join('\n')}`;
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Roles", description);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ToggleRole(context: ICommandContext): Promise<ICommandReturnContext> {
|
|
||||||
const roles = await this.GetRolesList(context);
|
|
||||||
const requestedRole = context.args.join(" ");
|
|
||||||
|
|
||||||
if (!roles.includes(requestedRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const assignRole = context.message.guild?.roles.cache.find(x => x.name == requestedRole);
|
|
||||||
|
|
||||||
if (!assignRole) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const role = context.message.member?.roles.cache.find(x => x.name == requestedRole)
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
await this.AddRole(context, assignRole);
|
|
||||||
} else {
|
|
||||||
await this.RemoveRole(context, assignRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async AddRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
|
|
||||||
await context.message.member?.roles.add(role, "Toggled with role command");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async RemoveRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
|
|
||||||
await context.message.member?.roles.remove(role, "Toggled with role command");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======
|
|
||||||
// Config
|
|
||||||
// ======
|
|
||||||
|
|
||||||
private async UseConfig(context: ICommandContext) {
|
|
||||||
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
|
|
||||||
|
|
||||||
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (context.args[1]) {
|
|
||||||
case "add":
|
|
||||||
await this.AddRoleConfig(context);
|
|
||||||
break;
|
|
||||||
case "remove":
|
|
||||||
await this.RemoveRoleConfig(context);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
await this.SendConfigHelp(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async SendConfigHelp(context: ICommandContext) {
|
|
||||||
const helpText = readFileSync(`${process.cwd()}/data/usage/role.txt`).toString();
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Configure Role Command", helpText);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async AddRoleConfig(context: ICommandContext) {
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
this.SendConfigHelp(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingRole = await eRole.FetchOneByRoleId(role.id);
|
|
||||||
|
|
||||||
if (existingRole) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "This role has already been setup");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById(Server, context.message.guild!.id, [
|
|
||||||
"Roles",
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!server) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Server not setup, please request the server owner runs the setup command.");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const roleSetting = new eRole(role.id);
|
|
||||||
|
|
||||||
await roleSetting.Save(eRole, roleSetting);
|
|
||||||
|
|
||||||
server.AddRoleToServer(roleSetting);
|
|
||||||
await server.Save(Server, server);
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async RemoveRoleConfig(context: ICommandContext) {
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
this.SendConfigHelp(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingRole = await eRole.FetchOneByRoleId(role.id);
|
|
||||||
|
|
||||||
if (!existingRole) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Unable to find this role");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await eRole.Remove(eRole, existingRole);
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import { existsSync, readFileSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
interface IRules {
|
interface IRules {
|
||||||
|
@ -15,38 +14,61 @@ export default class Rules extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Admin";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("rules")
|
||||||
"administrator"
|
.setDescription("Send the rules embeds for this server")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!existsSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`)) {
|
if (!interaction.guildId) return;
|
||||||
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) {
|
||||||
|
await interaction.reply('Rules file doesn\'t exist.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`).toString();
|
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`).toString();
|
||||||
const rules = JSON.parse(rulesFile) as IRules[];
|
const rules = JSON.parse(rulesFile) as IRules[];
|
||||||
|
|
||||||
const embeds: PublicEmbed[] = [];
|
const embeds: EmbedBuilder[] = [];
|
||||||
|
|
||||||
|
if (rules.length == 0) {
|
||||||
|
await interaction.reply({ content: "No rules have been supplied within code base for this server.", ephemeral: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rules.forEach(rule => {
|
rules.forEach(rule => {
|
||||||
const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || "");
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle(rule.title || "Rules")
|
||||||
|
.setDescription(rule.description ? rule.description.join("\n") : "*none*");
|
||||||
|
|
||||||
embed.setImage(rule.image || "");
|
if (rule.image) {
|
||||||
embed.setFooter({ text: rule.footer || "" });
|
embed.setImage(rule.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.footer) {
|
||||||
|
embed.setFooter({ text: rule.footer });
|
||||||
|
}
|
||||||
|
|
||||||
embeds.push(embed);
|
embeds.push(embed);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < embeds.length; i++) {
|
const channel = interaction.channel;
|
||||||
const embed = embeds[i];
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
if (!channel) {
|
||||||
}
|
await interaction.reply({ content: "Channel not found.", ephemeral: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await channel.send({ embeds: embeds });
|
||||||
|
|
||||||
|
const successEmbed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Success")
|
||||||
|
.setDescription("The rules have sent to this channel successfully");
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ successEmbed ], ephemeral: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,37 +1,31 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import Server from "../entity/Server";
|
import Server from "../database/entities/Server";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Setup extends Command {
|
export default class Setup extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
super.Category = "Administration";
|
|
||||||
super.Roles = [
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
"moderator"
|
.setName('setup')
|
||||||
]
|
.setDescription('Makes the server ready to be configured')
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById(Server, context.message.guild?.id);
|
const server = await Server.FetchOneById(Server, interaction.guildId);
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command");
|
await interaction.reply('This server has already been setup, please configure using the config command.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newServer = new Server(context.message.guild?.id);
|
const newServer = new Server(interaction.guildId);
|
||||||
|
|
||||||
await newServer.Save(Server, newServer);
|
await newServer.Save(Server, newServer);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Success", "Please configure using the config command");
|
await interaction.reply('Success, please configure using the configure command.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
156
src/commands/timeout.ts
Normal file
156
src/commands/timeout.ts
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
import { CacheType, CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
import Audit from "../database/entities/Audit";
|
||||||
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
import TimeLengthInput from "../helpers/TimeLengthInput";
|
||||||
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
|
export default class Timeout extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("timeout")
|
||||||
|
.setDescription("Timeouts a user out, sending them a DM with the reason if possible")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName("length")
|
||||||
|
.setDescription("How long to timeout for? (Example: 24h, 60m)")
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||||
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
|
// Interaction Inputs
|
||||||
|
const targetUser = interaction.options.get('target');
|
||||||
|
const lengthInput = interaction.options.get('length');
|
||||||
|
const reasonInput = interaction.options.get('reason');
|
||||||
|
|
||||||
|
// Validation
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lengthInput || !lengthInput.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetUser.user.bot) {
|
||||||
|
await interaction.reply('Cannot timeout bots.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// General Variables
|
||||||
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : null;
|
||||||
|
|
||||||
|
const timeLength = new TimeLengthInput(lengthInput.value.toString());
|
||||||
|
|
||||||
|
const logEmbed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Member Timed Out")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason || "*none*",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Length",
|
||||||
|
value: timeLength.GetLengthShort(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Until",
|
||||||
|
value: timeLength.GetDateFromNow().toString(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Bot Permissions Check
|
||||||
|
if (!targetMember.manageable) {
|
||||||
|
await interaction.reply('Insufficient bot permissions. Please contact a moderator.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute Timeout
|
||||||
|
await targetMember.timeout(timeLength.GetMilliseconds(), reason || "");
|
||||||
|
|
||||||
|
// Log Embed To Channel
|
||||||
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
|
if (!channelName) return;
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Audit
|
||||||
|
const audit = new Audit(targetUser.user.id, AuditType.Timeout, reason || "*none*", interaction.user.id, interaction.guildId);
|
||||||
|
await audit.Save(Audit, audit);
|
||||||
|
|
||||||
|
// DM User, if possible
|
||||||
|
const resultEmbed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setDescription(`<@${targetUser.user.id}> has been timed out`);
|
||||||
|
|
||||||
|
const dmEmbed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setDescription(`You have been timed out in ${interaction.guild.name}`)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason || "*none*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Length",
|
||||||
|
value: timeLength.GetLengthShort(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Until",
|
||||||
|
value: timeLength.GetDateFromNow().toString(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dmChannel = await targetUser.user.createDM();
|
||||||
|
|
||||||
|
await dmChannel.send({ embeds: [ dmEmbed ]});
|
||||||
|
|
||||||
|
resultEmbed.addFields([
|
||||||
|
{
|
||||||
|
name: "DM Sent",
|
||||||
|
value: "true",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} catch {
|
||||||
|
resultEmbed.addFields([
|
||||||
|
{
|
||||||
|
name: "DM Sent",
|
||||||
|
value: "false",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success Reply
|
||||||
|
await interaction.reply({ embeds: [ resultEmbed ]});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,96 +1,80 @@
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Unmute extends Command {
|
export default class Unmute extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("unmute")
|
||||||
"moderator"
|
.setDescription("(DEPRECATED) Unmute a member in the server with an optional reason")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
commandContext: context,
|
await interaction.reply('Fields are required.');
|
||||||
embeds: [embed]
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Unmuted")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
if (!mutedRole) {
|
||||||
reasonArgs.splice(0, 1);
|
await interaction.reply('Muted role not found.');
|
||||||
|
return;
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) {
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetMember.manageable) {
|
if (!targetMember.manageable) {
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
||||||
await embed.SendToCurrentChannel();
|
return;
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Unmuted");
|
await targetMember.roles.remove(mutedRole);
|
||||||
logEmbed.AddUser("User", targetUser, true)
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been unmuted`);
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
if (!channelName) return;
|
||||||
|
|
||||||
if (!mutedRole) {
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (channel) {
|
||||||
commandContext: context,
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
await interaction.reply("Please note the mute and unmute commands have been deprecated and will be removed in a future update. Please use timeout instead");
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [logEmbed, publicEmbed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,71 +1,70 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
import { AuditType } from "../constants/AuditType";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
import Audit from "../database/entities/Audit";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Warn extends Command {
|
export default class Warn extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Moderation";
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
super.Roles = [
|
.setName("warn")
|
||||||
"moderator"
|
.setDescription("Warns a member in the server with an optional reason")
|
||||||
];
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const user = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!user) {
|
const targetUser = interaction.options.get('target');
|
||||||
const errorEmbed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
commandContext: context,
|
await interaction.reply('Fields are required.');
|
||||||
embeds: [errorEmbed]
|
return;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = context.message.guild?.members.cache.find(x => x.user.id == user.id);
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!member) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const errorEmbed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await errorEmbed.SendToCurrentChannel();
|
.setTitle("Member Warned")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
if (!channelName) return;
|
||||||
};
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
const audit = new Audit(targetUser.user.id, AuditType.Warn, reason, interaction.user.id, interaction.guildId);
|
||||||
reasonArgs.splice(0, 1);
|
await audit.Save(Audit, audit);
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
await interaction.reply('Successfully warned user.');
|
||||||
|
|
||||||
if (!context.message.guild?.available) {
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Warned");
|
|
||||||
logEmbed.AddUser("User", user, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${user} has been warned`);
|
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [logEmbed, publicEmbed]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
8
src/constants/AuditType.ts
Normal file
8
src/constants/AuditType.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export enum AuditType {
|
||||||
|
General,
|
||||||
|
Warn,
|
||||||
|
Mute,
|
||||||
|
Kick,
|
||||||
|
Ban,
|
||||||
|
Timeout,
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
export enum CommandResponse {
|
|
||||||
Ok,
|
|
||||||
Unauthorised,
|
|
||||||
ServerNotSetup,
|
|
||||||
NotInServer,
|
|
||||||
FeatureDisabled,
|
|
||||||
}
|
|
|
@ -17,11 +17,7 @@ export default class DefaultValues {
|
||||||
private static SetValues() {
|
private static SetValues() {
|
||||||
if (this.values.length == 0) {
|
if (this.values.length == 0) {
|
||||||
// Bot
|
// Bot
|
||||||
if (this.useDevPrefix) {
|
this.values.push({ Key: "bot.prefix", Value: process.env.BOT_PREFIX || "v!" })
|
||||||
this.values.push({ Key: "bot.prefix", Value: "d!" });
|
|
||||||
} else {
|
|
||||||
this.values.push({ Key: "bot.prefix", Value: "v!" });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
this.values.push({ Key: "commands.disabled", Value: "" });
|
this.values.push({ Key: "commands.disabled", Value: "" });
|
||||||
|
|
3
src/constants/EmbedColours.ts
Normal file
3
src/constants/EmbedColours.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default class EmbedColours {
|
||||||
|
public static readonly Ok = 0x3050ba;
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
import { CommandResponse } from "./CommandResponse";
|
|
||||||
|
|
||||||
export default class ErrorMessages {
|
|
||||||
public static readonly InsufficientBotPermissions = "Unable to do this action, am I missing permissions?";
|
|
||||||
public static readonly ChannelNotFound = "Unable to find channel";
|
|
||||||
public static readonly RoleNotFound = "Unable to find role";
|
|
||||||
|
|
||||||
public static readonly UserUnauthorised = "You are not authorised to use this command";
|
|
||||||
public static readonly ServerNotSetup = "This server hasn't been setup yet, please run the setup command";
|
|
||||||
public static readonly NotInServer = "This command requires to be ran inside of a server";
|
|
||||||
public static readonly FeatureDisabled = "This feature is currently disabled by a server moderator";
|
|
||||||
|
|
||||||
public static GetErrorMessage(response: CommandResponse): string {
|
|
||||||
switch (response) {
|
|
||||||
case CommandResponse.Unauthorised:
|
|
||||||
return this.UserUnauthorised;
|
|
||||||
case CommandResponse.ServerNotSetup:
|
|
||||||
return this.ServerNotSetup;
|
|
||||||
case CommandResponse.NotInServer:
|
|
||||||
return this.NotInServer;
|
|
||||||
case CommandResponse.FeatureDisabled:
|
|
||||||
return this.FeatureDisabled;
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
15
src/constants/EventType.ts
Normal file
15
src/constants/EventType.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
export enum EventType {
|
||||||
|
ChannelCreate,
|
||||||
|
ChannelDelete,
|
||||||
|
ChannelUpdate,
|
||||||
|
GuildBanAdd,
|
||||||
|
GuildBanRemove,
|
||||||
|
GuildCreate,
|
||||||
|
GuildMemberAdd,
|
||||||
|
GuildMemberRemove,
|
||||||
|
GuildMemberUpdate,
|
||||||
|
MessageCreate,
|
||||||
|
MessageDelete,
|
||||||
|
MessageUpdate,
|
||||||
|
Ready,
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import { Column, DeepPartial, EntityTarget, getConnection, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm";
|
import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
import AppDataSource from "../database/dataSources/appDataSource";
|
||||||
|
|
||||||
export default class BaseEntity {
|
export default class BaseEntity {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -21,25 +22,19 @@ export default class BaseEntity {
|
||||||
public async Save<T extends BaseEntity>(target: EntityTarget<T>, entity: DeepPartial<T>): Promise<void> {
|
public async Save<T extends BaseEntity>(target: EntityTarget<T>, entity: DeepPartial<T>): Promise<void> {
|
||||||
this.WhenUpdated = new Date();
|
this.WhenUpdated = new Date();
|
||||||
|
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository<T>(target);
|
||||||
|
|
||||||
const repository = connection.getRepository<T>(target);
|
|
||||||
|
|
||||||
await repository.save(entity);
|
await repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Remove<T extends BaseEntity>(target: EntityTarget<T>, entity: T): Promise<void> {
|
public static async Remove<T extends BaseEntity>(target: EntityTarget<T>, entity: T): Promise<void> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository<T>(target);
|
||||||
|
|
||||||
const repository = connection.getRepository<T>(target);
|
|
||||||
|
|
||||||
await repository.remove(entity);
|
await repository.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchAll<T extends BaseEntity>(target: EntityTarget<T>, relations?: string[]): Promise<T[]> {
|
public static async FetchAll<T extends BaseEntity>(target: EntityTarget<T>, relations?: string[]): Promise<T[]> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository<T>(target);
|
||||||
|
|
||||||
const repository = connection.getRepository<T>(target);
|
|
||||||
|
|
||||||
const all = await repository.find({ relations: relations || [] });
|
const all = await repository.find({ relations: relations || [] });
|
||||||
|
|
||||||
|
@ -47,9 +42,7 @@ export default class BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchOneById<T extends BaseEntity>(target: EntityTarget<T>, id: string, relations?: string[]): Promise<T | null> {
|
public static async FetchOneById<T extends BaseEntity>(target: EntityTarget<T>, id: string, relations?: string[]): Promise<T | null> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository<T>(target);
|
||||||
|
|
||||||
const repository = connection.getRepository<T>(target);
|
|
||||||
|
|
||||||
const single = await repository.findOne({ where: ({ Id: id } as FindOptionsWhere<T>), relations: relations || {} });
|
const single = await repository.findOne({ where: ({ Id: id } as FindOptionsWhere<T>), relations: relations || {} });
|
||||||
|
|
||||||
|
@ -57,9 +50,7 @@ export default class BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Any<T extends ObjectLiteral>(target: EntityTarget<T>): Promise<boolean> {
|
public static async Any<T extends ObjectLiteral>(target: EntityTarget<T>): Promise<boolean> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository<T>(target);
|
||||||
|
|
||||||
const repository = connection.getRepository<T>(target);
|
|
||||||
|
|
||||||
const any = await repository.find();
|
const any = await repository.find();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
|
|
||||||
export interface ICommandContext {
|
|
||||||
name: string;
|
|
||||||
args: string[];
|
|
||||||
message: Message;
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { MessageEmbed } from "discord.js";
|
|
||||||
import { ICommandContext } from "./ICommandContext";
|
|
||||||
|
|
||||||
export default interface ICommandReturnContext {
|
|
||||||
commandContext: ICommandContext,
|
|
||||||
embeds: MessageEmbed[]
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
import { Event } from "../type/event";
|
import { EventType } from "../constants/EventType";
|
||||||
|
|
||||||
export default interface IEventItem {
|
export default interface IEventItem {
|
||||||
Event: Event,
|
EventType: EventType,
|
||||||
|
ExecutionFunction: Function,
|
||||||
}
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
import { MessageEmbed } from "discord.js";
|
|
||||||
import { ICommandContext } from "./ICommandContext";
|
|
||||||
|
|
||||||
export default interface ICommandReturnContext {
|
|
||||||
embeds: MessageEmbed[]
|
|
||||||
}
|
|
26
src/database/dataSources/appDataSource.ts
Normal file
26
src/database/dataSources/appDataSource.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { DataSource } from "typeorm";
|
||||||
|
import * as dotenv from "dotenv";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const AppDataSource = new DataSource({
|
||||||
|
type: "mysql",
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: Number(process.env.DB_PORT),
|
||||||
|
username: process.env.DB_AUTH_USER,
|
||||||
|
password: process.env.DB_AUTH_PASS,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
synchronize: process.env.DB_SYNC == "true",
|
||||||
|
logging: process.env.DB_LOGGING == "true",
|
||||||
|
entities: [
|
||||||
|
"dist/database/entities/**/*.js",
|
||||||
|
],
|
||||||
|
migrations: [
|
||||||
|
"dist/database/migrations/**/*.js",
|
||||||
|
],
|
||||||
|
subscribers: [
|
||||||
|
"dist/database/subscribers/**/*.js",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
export default AppDataSource;
|
|
@ -1,5 +1,6 @@
|
||||||
import { Column, Entity, getConnection } from "typeorm";
|
import { Column, Entity } from "typeorm";
|
||||||
import BaseEntity from "../../contracts/BaseEntity";
|
import BaseEntity from "../../../contracts/BaseEntity";
|
||||||
|
import AppDataSource from "../../dataSources/appDataSource";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export default class Lobby extends BaseEntity {
|
export default class Lobby extends BaseEntity {
|
||||||
|
@ -34,9 +35,7 @@ export default class Lobby extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchOneByChannelId(channelId: string, relations?: string[]): Promise<Lobby | null> {
|
public static async FetchOneByChannelId(channelId: string, relations?: string[]): Promise<Lobby | null> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository(Lobby);
|
||||||
|
|
||||||
const repository = connection.getRepository(Lobby);
|
|
||||||
|
|
||||||
const single = await repository.findOne({ where: { ChannelId: channelId }, relations: relations || [] });
|
const single = await repository.findOne({ where: { ChannelId: channelId }, relations: relations || [] });
|
||||||
|
|
53
src/database/entities/Audit.ts
Normal file
53
src/database/entities/Audit.ts
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
import { Column, Entity } from "typeorm";
|
||||||
|
import { AuditType } from "../../constants/AuditType";
|
||||||
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
|
import StringTools from "../../helpers/StringTools";
|
||||||
|
import AppDataSource from "../dataSources/appDataSource";
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export default class Audit extends BaseEntity {
|
||||||
|
constructor(userId: string, auditType: AuditType, reason: string, moderatorId: string, serverId: string) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.AuditId = StringTools.RandomString(5).toUpperCase();
|
||||||
|
this.UserId = userId;
|
||||||
|
this.AuditType = auditType;
|
||||||
|
this.Reason = reason;
|
||||||
|
this.ModeratorId = moderatorId;
|
||||||
|
this.ServerId = serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
AuditId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
UserId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
AuditType: AuditType;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
Reason: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
ModeratorId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
ServerId: string;
|
||||||
|
|
||||||
|
public static async FetchAuditsByUserId(userId: string, serverId: string): Promise<Audit[] | null> {
|
||||||
|
const repository = AppDataSource.getRepository(Audit);
|
||||||
|
|
||||||
|
const all = await repository.find({ where: { UserId: userId, ServerId: serverId } });
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async FetchAuditByAuditId(auditId: string, serverId: string): Promise<Audit | null> {
|
||||||
|
const repository = AppDataSource.getRepository(Audit);
|
||||||
|
|
||||||
|
const single = await repository.findOne({ where: { AuditId: auditId, ServerId: serverId } });
|
||||||
|
|
||||||
|
return single;
|
||||||
|
}
|
||||||
|
}
|
20
src/database/entities/IgnoredChannel.ts
Normal file
20
src/database/entities/IgnoredChannel.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { Entity } from "typeorm";
|
||||||
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
|
import AppDataSource from "../dataSources/appDataSource";
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export default class IgnoredChannel extends BaseEntity {
|
||||||
|
constructor(channelId: string) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.Id = channelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async IsChannelIgnored(channelId: string): Promise<boolean> {
|
||||||
|
const repository = AppDataSource.getRepository(IgnoredChannel);
|
||||||
|
|
||||||
|
const single = await repository.findOne({ where: { Id: channelId } });
|
||||||
|
|
||||||
|
return single != undefined;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import { Column, Entity, EntityTarget, getConnection, ManyToOne } from "typeorm";
|
import { Column, Entity, ManyToOne } from "typeorm";
|
||||||
import BaseEntity from "../contracts/BaseEntity"
|
import BaseEntity from "../../contracts/BaseEntity"
|
||||||
import Server from "./Server";
|
import Server from "./Server";
|
||||||
|
import AppDataSource from "../dataSources/appDataSource";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export default class Role extends BaseEntity {
|
export default class Role extends BaseEntity {
|
||||||
|
@ -16,10 +17,12 @@ export default class Role extends BaseEntity {
|
||||||
@ManyToOne(() => Server, x => x.Roles)
|
@ManyToOne(() => Server, x => x.Roles)
|
||||||
Server: Server;
|
Server: Server;
|
||||||
|
|
||||||
public static async FetchOneByRoleId(roleId: string, relations?: string[]): Promise<Role | null> {
|
public SetServer(server: Server) {
|
||||||
const connection = getConnection();
|
this.Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
const repository = connection.getRepository(Role);
|
public static async FetchOneByRoleId(roleId: string, relations?: string[]): Promise<Role | null> {
|
||||||
|
const repository = AppDataSource.getRepository(Role);
|
||||||
|
|
||||||
const single = await repository.findOne({ where: { RoleId: roleId }, relations: relations || []});
|
const single = await repository.findOne({ where: { RoleId: roleId }, relations: relations || []});
|
||||||
|
|
||||||
|
@ -27,9 +30,7 @@ export default class Role extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchAllByServerId(serverId: string): Promise<Role[]> {
|
public static async FetchAllByServerId(serverId: string): Promise<Role[]> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository(Server);
|
||||||
|
|
||||||
const repository = connection.getRepository(Server);
|
|
||||||
|
|
||||||
const all = await repository.findOne({ where: { Id: serverId }, relations: [
|
const all = await repository.findOne({ where: { Id: serverId }, relations: [
|
||||||
"Roles",
|
"Roles",
|
|
@ -1,5 +1,5 @@
|
||||||
import { Entity, OneToMany } from "typeorm";
|
import { Entity, OneToMany } from "typeorm";
|
||||||
import BaseEntity from "../contracts/BaseEntity";
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
import Role from "./Role";
|
import Role from "./Role";
|
||||||
import Setting from "./Setting";
|
import Setting from "./Setting";
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Column, Entity, getConnection, ManyToOne } from "typeorm";
|
import { Column, Entity, ManyToOne } from "typeorm";
|
||||||
import BaseEntity from "../contracts/BaseEntity";
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
import Server from "./Server";
|
import Server from "./Server";
|
||||||
|
import AppDataSource from "../dataSources/appDataSource";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export default class Setting extends BaseEntity {
|
export default class Setting extends BaseEntity {
|
||||||
|
@ -26,9 +27,7 @@ export default class Setting extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchOneByKey(key: string, relations?: string[]): Promise<Setting | null> {
|
public static async FetchOneByKey(key: string, relations?: string[]): Promise<Setting | null> {
|
||||||
const connection = getConnection();
|
const repository = AppDataSource.getRepository(Setting);
|
||||||
|
|
||||||
const repository = connection.getRepository(Setting);
|
|
||||||
|
|
||||||
const single = await repository.findOne({ where: { Key: key }, relations: relations || {} });
|
const single = await repository.findOne({ where: { Key: key }, relations: relations || {} });
|
||||||
|
|
30
src/database/migrations/3.1/1662399171315-CreateBase.ts
Normal file
30
src/database/migrations/3.1/1662399171315-CreateBase.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
import MigrationHelper from "../../../helpers/MigrationHelper"
|
||||||
|
|
||||||
|
export class vylbot1662399171315 implements MigrationInterface {
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
MigrationHelper.Up('1662399171315-CreateBase', '3.1', [
|
||||||
|
"01-table/Audit",
|
||||||
|
"01-table/IgnoredChannel",
|
||||||
|
"01-table/Lobby",
|
||||||
|
"01-table/Role",
|
||||||
|
"01-table/Server",
|
||||||
|
"01-table/Setting",
|
||||||
|
|
||||||
|
"02-key/Audit",
|
||||||
|
"02-key/IgnoredChannel",
|
||||||
|
"02-key/Lobby",
|
||||||
|
"02-key/Role",
|
||||||
|
"02-key/Server",
|
||||||
|
"02-key/Setting",
|
||||||
|
|
||||||
|
"03-constraint/Role",
|
||||||
|
"03-constraint/Setting",
|
||||||
|
], queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
import { Event } from "../type/event";
|
|
||||||
import { GuildMember } from "discord.js";
|
|
||||||
import EventEmbed from "../helpers/embeds/EventEmbed";
|
|
||||||
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
|
||||||
|
|
||||||
export default class MemberEvents extends Event {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async guildMemberAdd(member: GuildMember) {
|
|
||||||
if (!member.guild) return;
|
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
const embed = new EventEmbed(member.client, member.guild, "Member Joined");
|
|
||||||
embed.AddUser("User", member.user, true);
|
|
||||||
embed.addField("Created", member.user.createdAt.toISOString());
|
|
||||||
embed.setFooter({ text: `Id: ${member.user.id}` });
|
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
|
||||||
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async guildMemberRemove(member: GuildMember) {
|
|
||||||
if (!member.guild) return;
|
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
const embed = new EventEmbed(member.client, member.guild, "Member Left");
|
|
||||||
embed.AddUser("User", member.user, true);
|
|
||||||
embed.addField("Joined", member.joinedAt?.toISOString() || "n/a");
|
|
||||||
embed.setFooter({ text: `Id: ${member.user.id}` });
|
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
|
||||||
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
|
||||||
const handler = new GuildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
|
||||||
await handler.NicknameChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
35
src/events/MemberEvents/GuildMemberAdd.ts
Normal file
35
src/events/MemberEvents/GuildMemberAdd.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function GuildMemberAdd(member: GuildMember) {
|
||||||
|
if (!member.guild) return;
|
||||||
|
|
||||||
|
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||||
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle('Member Joined')
|
||||||
|
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||||
|
.setFooter({ text: `Id: ${member.user.id}` })
|
||||||
|
.setThumbnail(member.avatarURL())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Created',
|
||||||
|
value: member.user.createdAt.toISOString(),
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const channelSetting = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
||||||
|
|
||||||
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = member.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
|
}
|
35
src/events/MemberEvents/GuildMemberRemove.ts
Normal file
35
src/events/MemberEvents/GuildMemberRemove.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function GuildMemberRemove(member: GuildMember) {
|
||||||
|
if (!member.guild) return;
|
||||||
|
|
||||||
|
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||||
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle('Member Left')
|
||||||
|
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||||
|
.setFooter({ text: `Id: ${member.user.id}` })
|
||||||
|
.setThumbnail(member.avatarURL())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Joined',
|
||||||
|
value: member.joinedAt ? member.joinedAt.toISOString() : "*none*",
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const channelSetting = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
||||||
|
|
||||||
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = member.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
|
}
|
|
@ -1,32 +1,8 @@
|
||||||
import { GuildMember } from "discord.js";
|
import { GuildMember } from "discord.js";
|
||||||
import EventEmbed from "../../helpers/embeds/EventEmbed";
|
import NicknameChanged from "./GuildMemberUpdate/NicknameChanged";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
|
||||||
|
|
||||||
export default class GuildMemberUpdate {
|
export default async function GuildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||||
public oldMember: GuildMember;
|
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
||||||
public newMember: GuildMember;
|
await NicknameChanged(oldMember, newMember);
|
||||||
|
|
||||||
constructor(oldMember: GuildMember, newMember: GuildMember) {
|
|
||||||
this.oldMember = oldMember;
|
|
||||||
this.newMember = newMember;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async NicknameChanged() {
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.update.enabled", this.newMember.guild.id);
|
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
const oldNickname = this.oldMember.nickname || "*none*";
|
|
||||||
const newNickname = this.newMember.nickname || "*none*";
|
|
||||||
|
|
||||||
const embed = new EventEmbed(this.oldMember.client, this.newMember.guild, "Nickname Changed");
|
|
||||||
embed.AddUser("User", this.newMember.user, true);
|
|
||||||
embed.addField("Before", oldNickname, true);
|
|
||||||
embed.addField("After", newNickname, true);
|
|
||||||
embed.setFooter({ text: `Id: ${this.newMember.user.id}` });
|
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
|
|
||||||
if (!channel || channel.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
40
src/events/MemberEvents/GuildMemberUpdate/NicknameChanged.ts
Normal file
40
src/events/MemberEvents/GuildMemberUpdate/NicknameChanged.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function NicknameChanged(oldMember: GuildMember, newMember: GuildMember) {
|
||||||
|
const enabled = await SettingsHelper.GetSetting("event.member.update.enabled", newMember.guild.id);
|
||||||
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
const oldNickname = oldMember.nickname || "*none*";
|
||||||
|
const newNickname = newMember.nickname || "*none*";
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle('Nickname Changed')
|
||||||
|
.setDescription(`${newMember.user} \`${newMember.user.tag}\``)
|
||||||
|
.setFooter({ text: `Id: ${newMember.user.id}` })
|
||||||
|
.setThumbnail(newMember.avatarURL())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Before',
|
||||||
|
value: oldNickname,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'After',
|
||||||
|
value: newNickname,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const channelSetting = await SettingsHelper.GetSetting("event.member.update.channel", newMember.guild.id);
|
||||||
|
|
||||||
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = newMember.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
|
}
|
|
@ -1,64 +0,0 @@
|
||||||
import { Event } from "../type/event";
|
|
||||||
import { Message } from "discord.js";
|
|
||||||
import EventEmbed from "../helpers/embeds/EventEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
|
||||||
import OnMessage from "./MessageEvents/OnMessage";
|
|
||||||
|
|
||||||
export default class MessageEvents extends Event {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async messageDelete(message: Message) {
|
|
||||||
if (!message.guild) return;
|
|
||||||
if (message.author.bot) return;
|
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
const embed = new EventEmbed(message.client, message.guild, "Message Deleted");
|
|
||||||
embed.AddUser("User", message.author, true);
|
|
||||||
embed.addField("Channel", message.channel.toString(), true);
|
|
||||||
embed.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
|
|
||||||
|
|
||||||
if (message.attachments.size > 0) {
|
|
||||||
embed.addField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
|
|
||||||
}
|
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
|
||||||
if (!channel || !message.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async messageUpdate(oldMessage: Message, newMessage: Message) {
|
|
||||||
if (!newMessage.guild) return;
|
|
||||||
if (newMessage.author.bot) return;
|
|
||||||
if (oldMessage.content == newMessage.content) return;
|
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
const embed = new EventEmbed(newMessage.client, newMessage.guild, "Message Edited");
|
|
||||||
embed.AddUser("User", newMessage.author, true);
|
|
||||||
embed.addField("Channel", newMessage.channel.toString(), true);
|
|
||||||
embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
|
|
||||||
embed.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
|
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id);
|
|
||||||
if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async messageCreate(message: Message) {
|
|
||||||
if (!message.guild) return;
|
|
||||||
if (message.author.bot) return;
|
|
||||||
|
|
||||||
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
|
||||||
|
|
||||||
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
|
||||||
await OnMessage.VerificationCheck(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
14
src/events/MessageEvents/MessageCreate.ts
Normal file
14
src/events/MessageEvents/MessageCreate.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { Message } from "discord.js";
|
||||||
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
import VerificationCheck from "./MessageCreate/VerificationCheck";
|
||||||
|
|
||||||
|
export default async function MessageCreate(message: Message) {
|
||||||
|
if (!message.guild) return;
|
||||||
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
||||||
|
|
||||||
|
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
||||||
|
await VerificationCheck(message);
|
||||||
|
}
|
||||||
|
}
|
57
src/events/MessageEvents/MessageCreate/VerificationCheck.ts
Normal file
57
src/events/MessageEvents/MessageCreate/VerificationCheck.ts
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { Message } from "discord.js";
|
||||||
|
import SettingsHelper from "../../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function VerificationCheck(message: Message) {
|
||||||
|
if (!message.guild) return;
|
||||||
|
|
||||||
|
const verificationChannel = await SettingsHelper.GetSetting("verification.channel", message.guild.id);
|
||||||
|
|
||||||
|
if (!verificationChannel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const channel = message.guild.channels.cache.find(x => x.name == verificationChannel);
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentChannel = message.guild.channels.cache.find(x => x == message.channel);
|
||||||
|
|
||||||
|
if (!currentChannel || currentChannel.name != verificationChannel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const verificationCode = await SettingsHelper.GetSetting("verification.code", message.guild.id);
|
||||||
|
|
||||||
|
if (!verificationCode || verificationCode == "") {
|
||||||
|
await message.reply("`verification.code` is not set inside of the server's config. Please contact the server's mod team.");
|
||||||
|
await message.delete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const verificationRoleName = await SettingsHelper.GetSetting("verification.role", message.guild.id);
|
||||||
|
|
||||||
|
if (!verificationRoleName) {
|
||||||
|
await message.reply("`verification.role` is not set inside of the server's config. Please contact the server's mod team.");
|
||||||
|
await message.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const role = message.guild.roles.cache.find(x => x.name == verificationRoleName);
|
||||||
|
|
||||||
|
if (!role) {
|
||||||
|
await message.reply("The entry role configured for this server does not exist. Please contact the server's mod team.");
|
||||||
|
await message.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.content.toLocaleLowerCase() != verificationCode.toLocaleLowerCase()) {
|
||||||
|
await message.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await message.member?.roles.add(role);
|
||||||
|
await message.delete();
|
||||||
|
}
|
53
src/events/MessageEvents/MessageDelete.ts
Normal file
53
src/events/MessageEvents/MessageDelete.ts
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
||||||
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function MessageDelete(message: Message) {
|
||||||
|
if (!message.guild) return;
|
||||||
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
||||||
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
const ignored = await IgnoredChannel.IsChannelIgnored(message.channel.id);
|
||||||
|
if (ignored) return;
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Message Deleted")
|
||||||
|
.setDescription(`${message.author} \`${message.author.tag}\``)
|
||||||
|
.setThumbnail(message.author.avatarURL())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Channel",
|
||||||
|
value: message.channel.toString(),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Content",
|
||||||
|
value: `\`\`\`${message.content || "*none*"}\`\`\``,
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (message.attachments.size > 0) {
|
||||||
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: "Attachments",
|
||||||
|
value: `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
||||||
|
|
||||||
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = message.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [ embed ]});
|
||||||
|
}
|
49
src/events/MessageEvents/MessageUpdate.ts
Normal file
49
src/events/MessageEvents/MessageUpdate.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
||||||
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
|
||||||
|
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {
|
||||||
|
if (!newMessage.guild) return;
|
||||||
|
if (newMessage.author.bot) return;
|
||||||
|
if (oldMessage.content == newMessage.content) return;
|
||||||
|
|
||||||
|
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
||||||
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
|
||||||
|
if (ignored) return;
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Message Edited")
|
||||||
|
.setDescription(`${newMessage.author} \`${newMessage.author.tag}\``)
|
||||||
|
.setThumbnail(newMessage.author.avatarURL())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Channel",
|
||||||
|
value: newMessage.channel.toString(),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Before",
|
||||||
|
value: `\`\`\`${oldMessage.content || "*none*"}\`\`\``,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "After",
|
||||||
|
value: `\`\`\`${newMessage.content || "*none*"}\`\`\``,
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", newMessage.guild.id);
|
||||||
|
|
||||||
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = newMessage.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [ embed ]});
|
||||||
|
}
|
|
@ -1,59 +0,0 @@
|
||||||
import { Message as Message } from "discord.js";
|
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
|
||||||
|
|
||||||
export default class OnMessage {
|
|
||||||
public static async VerificationCheck(message: Message) {
|
|
||||||
if (!message.guild) return;
|
|
||||||
|
|
||||||
const verificationChannel = await SettingsHelper.GetSetting("verification.channel", message.guild.id);
|
|
||||||
|
|
||||||
if (!verificationChannel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const channel = message.guild.channels.cache.find(x => x.name == verificationChannel);
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentChannel = message.guild.channels.cache.find(x => x == message.channel);
|
|
||||||
|
|
||||||
if (!currentChannel || currentChannel.name != verificationChannel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const verificationCode = await SettingsHelper.GetSetting("verification.code", message.guild.id);
|
|
||||||
|
|
||||||
if (!verificationCode || verificationCode == "") {
|
|
||||||
await message.reply("`verification.code` is not set inside of the server's config. Please contact the server's mod team.");
|
|
||||||
await message.delete();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const verificationRoleName = await SettingsHelper.GetSetting("verification.role", message.guild.id);
|
|
||||||
|
|
||||||
if (!verificationRoleName) {
|
|
||||||
await message.reply("`verification.role` is not set inside of the server's config. Please contact the server's mod team.");
|
|
||||||
await message.delete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const role = message.guild.roles.cache.find(x => x.name == verificationRoleName);
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
await message.reply("The entry role configured for this server does not exist. Please contact the server's mod team.");
|
|
||||||
await message.delete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.content.toLocaleLowerCase() != verificationCode.toLocaleLowerCase()) {
|
|
||||||
await message.delete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await message.member?.roles.add(role);
|
|
||||||
await message.delete();
|
|
||||||
}
|
|
||||||
}
|
|
41
src/helpers/AuditTools.ts
Normal file
41
src/helpers/AuditTools.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
|
||||||
|
export default class AuditTools {
|
||||||
|
public static TypeToFriendlyText(auditType: AuditType): string {
|
||||||
|
switch (auditType) {
|
||||||
|
case AuditType.General:
|
||||||
|
return "General";
|
||||||
|
case AuditType.Warn:
|
||||||
|
return "Warn";
|
||||||
|
case AuditType.Mute:
|
||||||
|
return "Mute";
|
||||||
|
case AuditType.Kick:
|
||||||
|
return "Kick";
|
||||||
|
case AuditType.Ban:
|
||||||
|
return "Ban";
|
||||||
|
case AuditType.Timeout:
|
||||||
|
return "Timeout";
|
||||||
|
default:
|
||||||
|
return "Other";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringToType(str: string): AuditType {
|
||||||
|
switch (str.toLowerCase()) {
|
||||||
|
case "general":
|
||||||
|
return AuditType.General;
|
||||||
|
case "warn":
|
||||||
|
return AuditType.Warn;
|
||||||
|
case "mute":
|
||||||
|
return AuditType.Mute;
|
||||||
|
case "kick":
|
||||||
|
return AuditType.Kick;
|
||||||
|
case "ban":
|
||||||
|
return AuditType.Ban;
|
||||||
|
case "timeout":
|
||||||
|
return AuditType.Timeout;
|
||||||
|
default:
|
||||||
|
return AuditType.General;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
src/helpers/MigrationHelper.ts
Normal file
20
src/helpers/MigrationHelper.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
import { QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export default class MigrationHelper {
|
||||||
|
public static Up(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) {
|
||||||
|
for (let path of queryFiles) {
|
||||||
|
const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Up/${path}.sql`).toString();
|
||||||
|
|
||||||
|
queryRunner.query(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Down(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) {
|
||||||
|
for (let path of queryFiles) {
|
||||||
|
const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Down/${path}.sql`).toString();
|
||||||
|
|
||||||
|
queryRunner.query(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import DefaultValues from "../constants/DefaultValues";
|
import DefaultValues from "../constants/DefaultValues";
|
||||||
import Server from "../entity/Server";
|
import Server from "../database/entities/Server";
|
||||||
import Setting from "../entity/Setting";
|
import Setting from "../database/entities/Setting";
|
||||||
|
|
||||||
export default class SettingsHelper {
|
export default class SettingsHelper {
|
||||||
public static async GetSetting(key: string, serverId: string): Promise<string | undefined> {
|
public static async GetSetting(key: string, serverId: string): Promise<string | undefined> {
|
||||||
|
|
|
@ -35,4 +35,8 @@ export default class StringTools {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ReplaceAll(str: string, find: string, replace: string) {
|
||||||
|
return str.replace(new RegExp(find, 'g'), replace);
|
||||||
|
}
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue