mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 15:03:37 +00:00
Compare commits
452 Commits
Author | SHA1 | Date | |
---|---|---|---|
0945c7c26c | |||
871cb475f9 | |||
57aaf92947 | |||
dc7b14b11a | |||
0f5022df15 | |||
8f256d9bc3 | |||
b686afba98 | |||
f08eeb435c | |||
7a8c10c6d4 | |||
b38dfa039d | |||
b07f0d4942 | |||
788216c373 | |||
ead52decf2 | |||
7757788f99 | |||
ddff397fe4 | |||
8fc441c1b3 | |||
0ee3ca5e08 | |||
214dff29d5 | |||
cc3b2a50cf | |||
ee08232128 | |||
f9d5be189e | |||
a8513ce514 | |||
9ecdbc2bee | |||
5ee30b1782 | |||
4bf74f15a2 | |||
ccb386e3b3 | |||
dbedb83104 | |||
b34120e688 | |||
90c7c667e4 | |||
062a163a11 | |||
1f4c3a08d0 | |||
acc7ab1727 | |||
c7ddc6ec5b | |||
6d22dda0ae | |||
bfba8304e4 | |||
7d38170ba6 | |||
348b540c06 | |||
330c33b3d7 | |||
dfa9548b59 | |||
b351bbebed | |||
469374f25e | |||
72c1609503 | |||
8d5291cbb0 | |||
ebf1d0759e | |||
c829f70418 | |||
341bddd4cd | |||
460a5415e5 | |||
a4d984f19c | |||
09ae458ff1 | |||
00f6ee71e0 | |||
126d5e9ba2 | |||
d64b0ac0cb | |||
bfb27e7359 | |||
48445afdd5 | |||
4854e622b3 | |||
9d9c8a6a07 | |||
7040300b3e | |||
24478b6320 | |||
a43a788e15 | |||
2892913caa | |||
930d481fcf | |||
81a9d7be7c | |||
45e5019b28 | |||
b76b7a107c | |||
87295d10c1 | |||
d03b8cdb1d | |||
fd8c1ec31b | |||
720d356d1f | |||
4b0efe7491 | |||
a20e7a1c8e | |||
88fdad4ab9 | |||
3ed49f88ab | |||
752bd07c5d | |||
b08de94c64 | |||
892c5f9902 | |||
3029a8a653 | |||
86510a8871 | |||
e85b864170 | |||
727f8f5177 | |||
ad9a2f8f19 | |||
803bc20fb7 | |||
7d479b4c5f | |||
ffa9c8abb0 | |||
49475212a7 | |||
824d4042c1 | |||
0c76c137b9 | |||
accff3fa60 | |||
1cfa62802f | |||
9019741146 | |||
095b6ad775 | |||
a043cde46e | |||
bfec178de7 | |||
12f3948e40 | |||
0bc26f8895 | |||
b66a60ebe9 | |||
b4a24de8cd | |||
9517ba1fa9 | |||
73d330d1e2 | |||
13ae6c2716 | |||
645ea3e197 | |||
fcf6f15be9 | |||
3d066435b4 | |||
26eda76b23 | |||
05905e6e6d | |||
1533ae46a4 | |||
2b72f87256 | |||
8bf79c2744 | |||
45923319a6 | |||
d8daacf80e | |||
24eaf3a7e2 | |||
57f63c3838 | |||
b9e1945719 | |||
0b8fb4977c | |||
a5eec44b8e | |||
e2ebe6a36e | |||
5132e40d2c | |||
1d6361871c | |||
3978f19b2e | |||
26cdef50b2 | |||
fee833d231 | |||
6541287dec | |||
44d81b6fd7 | |||
200f16eac0 | |||
8c9fe03629 | |||
24071eb5df | |||
3b5c241872 | |||
44a708548f | |||
5c1a8f0ef1 | |||
526bb7736a | |||
22c0544d09 | |||
9c3748ad7c | |||
3807ae89a0 | |||
9e2be295c3 | |||
fb257d1c30 | |||
17a075cd29 | |||
93b5663ebe | |||
8399fd5bb1 | |||
364b5d9b3c | |||
e08c20aa3d | |||
65bebb7b13 | |||
13814afebc | |||
b44bc679e5 | |||
c83b90aa20 | |||
1bb8d8d801 | |||
0b1cb03305 | |||
90a93d35f7 | |||
24716dd497 | |||
259b58aa1a | |||
52ec0845a7 | |||
ddbe950a19 | |||
46790b12ff | |||
488d0a6d12 | |||
7699871779 | |||
ac323a5410 | |||
9408d0d66b | |||
5cd3912ff5 | |||
33e674f7c7 | |||
d0c10018f3 | |||
523c94aafb | |||
ac42502883 | |||
704596c371 | |||
4de241ecab | |||
f70818c9f3 | |||
6ad412000d | |||
2804f942b7 | |||
561b365e44 | |||
9475c68682 | |||
34abb66086 | |||
890df2c27c | |||
cb1d2ca6b9 | |||
f31ad5ceca | |||
8b5933749d | |||
ab950352fa | |||
984e8aab76 | |||
cc8b44db9b | |||
1371a83e90 | |||
33e4a416a9 | |||
5bf4bd9a1c | |||
4edfe6848c | |||
884233a938 | |||
3ac284e237 | |||
d1fe9177af | |||
8316723a6a | |||
f9ce2bfaf9 | |||
a9857cb34b | |||
894a1d82f5 | |||
fa4f5e1e09 | |||
12c8b8558f | |||
bb8a36ad5c | |||
ebeeadd5c3 | |||
6e0b2f5092 | |||
2286815485 | |||
2e402de6bf | |||
45d68ff4ab | |||
370701a4b9 | |||
956f1f7b6d | |||
115a2e7589 | |||
f9d195788c | |||
c673ae27f6 | |||
c5d04aed3c | |||
e39a24de2a | |||
aa715aaafa | |||
9303dd1c19 | |||
9a5075f27e | |||
60ef1cd138 | |||
235a02ca60 | |||
05852b99d4 | |||
01730cd08b | |||
6335a4617f | |||
552d3c81f9 | |||
2d9b0ce732 | |||
3b0f8068c1 | |||
c142fc61b4 | |||
dcfde4131f | |||
a1cb21d98e | |||
4c731c1942 | |||
d2a6d70cf6 | |||
f5ef44b12a | |||
a86cf0c769 | |||
7a0a3e0d50 | |||
479c0ee13d | |||
b280981e1c | |||
933140502d | |||
dfada15b00 | |||
8fdcdd0116 | |||
11573a5113 | |||
7e3a83743d | |||
38af503626 | |||
534bc74936 | |||
ea2be5d5fb | |||
38a8571ddc | |||
2d41c7a76b | |||
16bc2aab52 | |||
17132cd51a | |||
ec6ea7e839 | |||
c81dbddab1 | |||
e0226c5cfe | |||
3f12bafee0 | |||
3fc28a79cb | |||
72d0054d25 | |||
25356be323 | |||
e8d90f8a3c | |||
c724ae502f | |||
a3efdbf3cb | |||
2857b6886f | |||
1e24e89568 | |||
3609e6af10 | |||
d5fefcdbbc | |||
8860952c07 | |||
55905e3841 | |||
d27cdf6ee5 | |||
0d4c46cfd4 | |||
190852bc16 | |||
9ef6b3f36f | |||
1a5caf244f | |||
73857c9fc5 | |||
853661ff52 | |||
9040b84050 | |||
1518ff7809 | |||
ba5b142bbe | |||
4ccace9450 | |||
711e6d48fb | |||
83cfec4678 | |||
90f47825b6 | |||
b0270e651e | |||
238a67c267 | |||
2e5f0a781a | |||
d9e57a47e9 | |||
13a085b9de | |||
fddc57d90e | |||
9d9ae80dbe | |||
314c744527 | |||
555b4d14f0 | |||
41fb87fab6 | |||
0f4e0b952b | |||
3ec1892a09 | |||
7d4fb50351 | |||
179914a2f2 | |||
a8fc38ffca | |||
329986be53 | |||
5ec4ea6aae | |||
e546001be8 | |||
f2158ba8ae | |||
a1f85a0d19 | |||
430e0f9e51 | |||
45b23722fa | |||
66ace838c6 | |||
8e9546097f | |||
61981a5b0b | |||
65f83bc522 | |||
74239f71a7 | |||
46237fd91e | |||
bf0811945a | |||
706e65bc06 | |||
12337f499b | |||
da71137f68 | |||
45bd690c05 | |||
eba7551329 | |||
fea24ec1aa | |||
1fd6c2c691 | |||
492df398ff | |||
a1d4e356a6 | |||
c4fb1d5147 | |||
b6c47d7c6f | |||
5208a3feb1 | |||
8a10697edd | |||
f786abebe4 | |||
5e53a908e7 | |||
65bd82054a | |||
0d795a6efb | |||
01514454bf | |||
3dd5b9d36e | |||
40879c85bb | |||
0858f9e49e | |||
a1aa96fc2f | |||
6ed91fe43b | |||
0f184a9fc6 | |||
ec651a681c | |||
fe165f03c6 | |||
73e2427a21 | |||
47ed5b7e04 | |||
34b7bf8f19 | |||
18a03d50ee | |||
6c89770d16 | |||
79acdc9687 | |||
0c93814013 | |||
1c9ad75b8e | |||
277b67e3df | |||
b5d5ca1fe6 | |||
5df88494b0 | |||
7a93cd001f | |||
bdc76b73a7 | |||
25e9ebbd4e | |||
c4c2461175 | |||
e2d74c10ea | |||
f0dcd76033 | |||
5f5b164e0d | |||
1358787793 | |||
42591791c3 | |||
c539a63011 | |||
33c41233da | |||
32ac31a8af | |||
0b7da1937b | |||
ee13f11f71 | |||
a6d1f68191 | |||
0ac8491a96 | |||
a36f3bf90d | |||
c08d5650ec | |||
3488d8e737 | |||
96e1ce82ae | |||
4498efcdcd | |||
294aa28849 | |||
f0887514af | |||
8d15567f85 | |||
fbbd901cbd | |||
fcb5f4f6e6 | |||
bd70f2bedc | |||
4ba582295b | |||
d524649ad5 | |||
ca494df400 | |||
6ec4a068f9 | |||
b8c1816b1c | |||
c5f269c0a7 | |||
b979d26425 | |||
f18776ce1a | |||
8168650f69 | |||
dd37b3447f | |||
b03c6fd3b0 | |||
7810f6fff8 | |||
2fec81e84d | |||
606dcc0ab3 | |||
727cae13b4 | |||
dc5a9d4e71 | |||
e479e5a82a | |||
6afe6c30f9 | |||
17161b72b9 | |||
3cb54c9470 | |||
9533748f0f | |||
42b8f52834 | |||
8785d0c715 | |||
1706007088 | |||
7ccd72cc6d | |||
751f9989eb | |||
6c860b6b23 | |||
0bfb34c1dd | |||
0a269aac94 | |||
4b10736508 | |||
97317449f9 | |||
0b7c04d242 | |||
63e99dd2b3 | |||
d5b8d67064 | |||
ce5351c3f4 | |||
2d68eb1ffd | |||
cecadb2bef | |||
c5d5d28475 | |||
9e6d60bde8 | |||
76fe1aaae9 | |||
684a87c398 | |||
8c35d71818 | |||
03248bcfa8 | |||
9a84a3c938 | |||
510f2c5b50 | |||
e571194eac | |||
ca02f95500 | |||
28e7476f70 | |||
95e8b17ddd | |||
6a11482110 | |||
202674cb53 | |||
64f97b990a | |||
7dc0a6d3b9 | |||
8f685a0676 | |||
ce7d3d633b | |||
177a405f08 | |||
40490d80dc | |||
ef18a08cc6 | |||
378fe97ea3 | |||
39d7acaa9e | |||
0ef9cad101 | |||
07e45ae54d | |||
f437797bed | |||
e267b06cf1 | |||
a5ffaadf31 | |||
251eb7f5a1 | |||
b2ae9ef6f0 | |||
db409ac6d2 | |||
fb2c18b9b0 | |||
5efb68b717 | |||
f543cd3267 | |||
0515f0f5e3 | |||
59796ff002 | |||
bf70276d7f | |||
7db92969af | |||
3520e86f0b | |||
bb07884ab4 | |||
2de365770d | |||
0c5fdcd651 | |||
b01ee3b380 | |||
308afd9f96 | |||
31baeeab45 | |||
c17900b618 | |||
10c6a8c589 | |||
284f0e9f0c | |||
1f259d95ac | |||
9b67506558 | |||
f9ba5a3117 | |||
f1f16c4f9a | |||
5147c6455f | |||
3b8ae4fd4b | |||
471f345026 | |||
0d63c1920e | |||
3cb07107d5 | |||
acef9404b2 |
5
.env_example
Normal file
5
.env_example
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
DISCORD_TOKEN=
|
||||||
|
RADIOX_STATIONSLISTURL=https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json
|
||||||
|
DEV_MODE=false
|
||||||
|
DEBUG_MODE=false
|
||||||
|
STREAMER_MODE=manual
|
13
.eslintrc
Normal file
13
.eslintrc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"extends": [
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"prettier/@typescript-eslint",
|
||||||
|
"plugin:prettier/recommended"
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2019,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {}
|
||||||
|
}
|
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
|
||||||
|
# npm
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
9
.github/labeler.yml
vendored
Normal file
9
.github/labeler.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
dependencies:
|
||||||
|
- package-lock.json
|
||||||
|
|
||||||
|
documentation:
|
||||||
|
- README.md
|
||||||
|
- SECURITY.md
|
||||||
|
- CONTRIBUTING.md
|
||||||
|
- LICENSE
|
||||||
|
- .env_example
|
71
.github/workflows/codeql-analyze.yml
vendored
Normal file
71
.github/workflows/codeql-analyze.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL Analyze"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, stable ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '24 20 * * 6'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: CodeQL Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'javascript' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
19
.github/workflows/docker-build.yml
vendored
Normal file
19
.github/workflows/docker-build.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: Docker Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
buildx:
|
||||||
|
name: Docker Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1.6.0
|
||||||
|
id: buildx
|
||||||
|
with:
|
||||||
|
install: true
|
||||||
|
- name: Build
|
||||||
|
run: docker build . # will run buildx
|
17
.github/workflows/labeler.yml
vendored
Normal file
17
.github/workflows/labeler.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
name: Labeler
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
label:
|
||||||
|
name: Labeler
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ github.actor != 'dependabot[bot]' }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/labeler@v3
|
||||||
|
with:
|
||||||
|
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
sync-labels: true
|
19
.github/workflows/typescript-build.yml
vendored
Normal file
19
.github/workflows/typescript-build.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: TypeScript Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tsc:
|
||||||
|
name: TypeScript Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: install node v16
|
||||||
|
uses: actions/setup-node@v2.4.0
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
- name: npm install
|
||||||
|
run: npm install
|
||||||
|
- name: tsc
|
||||||
|
uses: icrawl/action-tsc@v1
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
datastore/
|
datastore/
|
||||||
node_modules/
|
node_modules/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
.vscode/
|
|
||||||
.env
|
.env
|
||||||
|
build/
|
||||||
|
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 100,
|
||||||
|
"tabWidth": 4,
|
||||||
|
"semi": true
|
||||||
|
}
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.trimTrailingWhitespace": true,
|
||||||
|
"files.insertFinalNewline": true,
|
||||||
|
"files.trimFinalNewlines": true,
|
||||||
|
"editor.renderFinalNewline": false
|
||||||
|
}
|
27
CONTRIBUTING.md
Normal file
27
CONTRIBUTING.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||||
|
|
||||||
|
If you haven't already, come find us in [Discord](https://waren.io/r/eximiabots-discord). We want you working on things you're excited about.
|
||||||
|
|
||||||
|
Here are some important resources:
|
||||||
|
|
||||||
|
* [Discord](https://waren.io/r/eximiabots-discord) Join our Discord guild.
|
||||||
|
|
||||||
|
## Coding
|
||||||
|
|
||||||
|
### Pull Requests
|
||||||
|
* Open a new PR from your fork's new branch into develop branch.
|
||||||
|
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
||||||
|
* Try to fix all merge conflicts.
|
||||||
|
|
||||||
|
### Coding conventions
|
||||||
|
* We indent using four spaces (soft tabs)
|
||||||
|
* We ALWAYS put spaces after list items and method parameters (`[1, 2, 3]`, not `[1,2,3]`), around operators (`x += 1`, not `x+=1`), and around hash arrows.
|
||||||
|
* This is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
We have currently automated testing in Github Workflows, you can suggest new Github Workflows to us by making PR.
|
||||||
|
|
||||||
|
Every release is manually tested by [cwchristerw](https://github.com/cwchristerw) or [MatteZ02](https://github.com/MatteZ02).
|
10
Dockerfile
10
Dockerfile
@ -1,10 +1,10 @@
|
|||||||
FROM node:14.15.4-alpine
|
FROM node:16-alpine
|
||||||
|
|
||||||
#Dependencies
|
#Dependencies
|
||||||
RUN apk add --virtual .build-deps python make g++ gcc
|
RUN apk add --virtual .build-deps python3 make g++ gcc git
|
||||||
|
|
||||||
#Dependencies for RadioX Bot
|
#Code Dependencies
|
||||||
RUN apk add --virtual .radiox-deps ffmpeg
|
RUN apk add --virtual .code-deps ffmpeg
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
@ -12,4 +12,6 @@ COPY / /usr/src/app/
|
|||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
CMD [ "npm", "start" ]
|
CMD [ "npm", "start" ]
|
||||||
|
@ -4,12 +4,9 @@ Internet Radio to your Discord guild
|
|||||||
## [Radio Stations List](https://gitea.cwinfo.org/cwchristerw/radio)
|
## [Radio Stations List](https://gitea.cwinfo.org/cwchristerw/radio)
|
||||||
This bot is using Gitea repo to get radio stations from [playlist.json](https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json) file. List is currently maintained by Christer Warén. You can use alternative list with same format when using RADIOX_STATIONSLISTURL environment variable.
|
This bot is using Gitea repo to get radio stations from [playlist.json](https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json) file. List is currently maintained by Christer Warén. You can use alternative list with same format when using RADIOX_STATIONSLISTURL environment variable.
|
||||||
|
|
||||||
## PREFIX
|
|
||||||
Default prefix is "rx-" and you can change it with using RADIOX_PREFIX environment variable.
|
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
1. `docker build -t warengroup/eximiabots-radiox .`
|
1. `docker build -t warengroup/eximiabots-radiox . --pull`
|
||||||
2. `docker run --name radiox-dev -d --net host -e DISCORD_TOKEN= -e RADIOX_PREFIX="rx-" -v "$PWD/datastore":/usr/src/app/datastore/ warengroup/eximiabots-radiox`
|
2. `docker run --name radiox-dev -d --net host -e DISCORD_TOKEN= -v "$PWD/datastore":/usr/src/app/datastore/ warengroup/eximiabots-radiox`
|
||||||
|
|
||||||
## Join our Discord Server
|
## Join our Discord Server
|
||||||
https://discord.gg/rRA65Mn
|
https://discord.gg/rRA65Mn
|
||||||
|
17
SECURITY.md
Normal file
17
SECURITY.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 0.3.x | :white_check_mark: |
|
||||||
|
| 0.2.x | :x: |
|
||||||
|
| 0.1.x | :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Use this section to tell people how to report a vulnerability.
|
||||||
|
|
||||||
|
Tell them where to go, how often they can expect to get an update on a
|
||||||
|
reported vulnerability, what to expect if the vulnerability is accepted or
|
||||||
|
declined, etc.
|
@ -1,62 +0,0 @@
|
|||||||
const { Client, Collection } = require('discord.js');
|
|
||||||
const Discord = require('discord.js');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const events = './events/';
|
|
||||||
const Datastore = require('./datastore.js');
|
|
||||||
|
|
||||||
const GatewayIntents = new Discord.Intents();
|
|
||||||
GatewayIntents.add(
|
|
||||||
1 << 0, // GUILDS
|
|
||||||
1 << 7, // GUILD_VOICE_STATES
|
|
||||||
1 << 9 // GUILD_MESSAGES
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = class extends Client {
|
|
||||||
constructor() {
|
|
||||||
super({
|
|
||||||
disableEveryone: true,
|
|
||||||
disabledEvents: ['TYPING_START'],
|
|
||||||
ws: {
|
|
||||||
intents: GatewayIntents
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.commands = new Collection();
|
|
||||||
this.commandAliases = new Collection();
|
|
||||||
this.radio = new Map();
|
|
||||||
|
|
||||||
this.funcs = {};
|
|
||||||
this.funcs.check = require('./funcs/check.js');
|
|
||||||
this.funcs.checkFetchStatus = require('./funcs/checkFetchStatus.js');
|
|
||||||
this.funcs.isDev = require('./funcs/isDev.js');
|
|
||||||
this.funcs.msToTime = require('./funcs/msToTime.js');
|
|
||||||
this.funcs.statisticsUpdate = require('./funcs/statisticsUpdate.js');
|
|
||||||
|
|
||||||
this.config = require('../config.js');
|
|
||||||
this.messages = require('./messages.js');
|
|
||||||
|
|
||||||
const commandFiles = fs.readdirSync('./client/commands/').filter(f => f.endsWith('.js'));
|
|
||||||
for (const file of commandFiles) {
|
|
||||||
const command = require(`./commands/${file}`);
|
|
||||||
command.uses = 0;
|
|
||||||
this.commands.set(command.name, command);
|
|
||||||
this.commandAliases.set(command.alias, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.on('ready', () => {
|
|
||||||
require(`${events}ready`).execute(this, Discord);
|
|
||||||
this.datastore = new Datastore();
|
|
||||||
});
|
|
||||||
this.on('message', (msg) => {
|
|
||||||
require(`${events}msg`).execute(this, msg, Discord);
|
|
||||||
});
|
|
||||||
this.on('voiceStateUpdate', (oldState, newState) => {
|
|
||||||
require(`${events}voiceStateUpdate`).execute(this, oldState, newState);
|
|
||||||
});
|
|
||||||
this.on('error', (error) => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,51 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'help',
|
|
||||||
alias: 'h',
|
|
||||||
usage: '<command(opt)>',
|
|
||||||
description: 'Get help using bot',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
|
|
||||||
if (args[1]) {
|
|
||||||
if (!client.commands.has(args[1]) || (client.commands.has(args[1]) && client.commands.get(args[1]).omitFromHelp === true)) return msg.channel.send('That command does not exist');
|
|
||||||
const command = client.commands.get(args[1]);
|
|
||||||
|
|
||||||
message.helpCommandTitle = client.messages.helpCommandTitle.replace("%client.config.prefix%", client.config.prefix);
|
|
||||||
message.helpCommandTitle = message.helpCommandTitle.replace("%command.name%", command.name);
|
|
||||||
message.helpCommandTitle = message.helpCommandTitle.replace("%command.usage%", command.usage);
|
|
||||||
message.helpCommandDescription = client.messages.helpCommandDescription.replace("%command.description%", command.description);
|
|
||||||
message.helpCommandDescription = message.helpCommandDescription.replace("%command.alias%", command.alias);
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(message.helpCommandTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(message.helpCommandDescription)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
msg.channel.send(embed);
|
|
||||||
} else {
|
|
||||||
const categories = [];
|
|
||||||
for (let i = 0; i < client.commands.size; i++) {
|
|
||||||
if (!categories.includes(client.commands.array()[i].category)) categories.push(client.commands.array()[i].category);
|
|
||||||
}
|
|
||||||
let commands = '';
|
|
||||||
for (let i = 0; i < categories.length; i++) {
|
|
||||||
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username);
|
|
||||||
message.helpDescription = client.messages.helpDescription.replace("%commands%", commands);
|
|
||||||
message.helpDescription = message.helpDescription.replace("%client.config.prefix%", client.config.prefix);
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(message.helpTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(message.helpDescription)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,18 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'invite',
|
|
||||||
alias: 'i',
|
|
||||||
usage: '',
|
|
||||||
description: 'Invite Bot',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(message.inviteTitle)
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setURL(client.config.invite)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
return msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,28 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'list',
|
|
||||||
alias: 'l',
|
|
||||||
usage: '',
|
|
||||||
description: 'List radio stations.',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'radio',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
if(!client.stations) {
|
|
||||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
|
||||||
}
|
|
||||||
let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}`
|
|
||||||
const hashs = stations.split('**#**').length;
|
|
||||||
for (let i = 0; i < hashs; i++) {
|
|
||||||
stations = stations.replace('**#**', `**${i + 1}**`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(client.messages.listTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(stations)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
return msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,53 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'maintenance',
|
|
||||||
alias: 'm',
|
|
||||||
usage: '',
|
|
||||||
description: 'Bot Maintenance',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
|
|
||||||
if(!client.funcs.isDev(client.config.devId, msg.author.id)) return msg.channel.send(client.messageEmojis["error"] + client.messages.notAllowed);
|
|
||||||
|
|
||||||
if(!client.stations) {
|
|
||||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentRadios = client.radio.keys();
|
|
||||||
let radio = currentRadios.next();
|
|
||||||
let stoppedRadios = "";
|
|
||||||
|
|
||||||
client.user.setStatus('dnd');
|
|
||||||
|
|
||||||
while (!radio.done) {
|
|
||||||
let currentRadio = client.radio.get(radio.value);
|
|
||||||
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
|
|
||||||
|
|
||||||
if(currentRadio){
|
|
||||||
client.funcs.statisticsUpdate(client, currentRadio.currentGuild.guild, currentRadio);
|
|
||||||
currentRadio.connection.dispatcher?.destroy();
|
|
||||||
currentRadio.voiceChannel.leave();
|
|
||||||
const cembed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(client.messages.maintenanceTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(client.messages.sendedMaintenanceMessage)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
currentRadio.textChannel.send(cembed);
|
|
||||||
client.radio.delete(radio.value);
|
|
||||||
stoppedRadios += "-" + radio.value + ": " + currentRadio.currentGuild.guild.name + "\n";
|
|
||||||
}
|
|
||||||
radio = currentRadios.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(client.messages.maintenanceTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription("Stopped all radios" + "\n" + stoppedRadios)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
return msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,30 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'nowplaying',
|
|
||||||
alias: 'np',
|
|
||||||
usage: '',
|
|
||||||
description: 'Current Radio Station',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'radio',
|
|
||||||
async execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
const radio = client.radio.get(msg.guild.id);
|
|
||||||
if (!radio) return msg.channel.send('There is nothing playing.');
|
|
||||||
if(!client.stations) {
|
|
||||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
|
||||||
}
|
|
||||||
const completed = (radio.connection.dispatcher.streamTime.toFixed(0));
|
|
||||||
|
|
||||||
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
|
|
||||||
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
|
|
||||||
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed, \"hh:mm:ss\")%", client.funcs.msToTime(completed, "hh:mm:ss"));
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(client.messages.nowplayingTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(message.nowplayingDescription)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
return msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,158 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'play',
|
|
||||||
alias: 'p',
|
|
||||||
usage: '<song name>',
|
|
||||||
description: 'Play some music.',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'radio',
|
|
||||||
async execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
let url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
|
||||||
const radio = client.radio.get(msg.guild.id);
|
|
||||||
const voiceChannel = msg.member.voice.channel;
|
|
||||||
if (!radio) {
|
|
||||||
if (!msg.member.voice.channel) return msg.channel.send(client.messageEmojis["error"] + client.messages.noVoiceChannel);
|
|
||||||
} else {
|
|
||||||
if (voiceChannel !== radio.voiceChannel) return msg.channel.send(client.messageEmojis["error"] + client.messages.wrongVoiceChannel);
|
|
||||||
}
|
|
||||||
if(!client.stations) {
|
|
||||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
|
||||||
}
|
|
||||||
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
|
||||||
const permissions = voiceChannel.permissionsFor(msg.client.user);
|
|
||||||
if (!permissions.has('CONNECT')) {
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + client.messages.noPermsConnect);
|
|
||||||
}
|
|
||||||
if (!permissions.has('SPEAK')) {
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + client.messages.noPermsSpeak);
|
|
||||||
}
|
|
||||||
let station;
|
|
||||||
const number = parseInt(args[1] - 1);
|
|
||||||
if (url.startsWith('http')) {
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + client.messages.errorStationURL);
|
|
||||||
} else if (!isNaN(number)) {
|
|
||||||
if (number > client.stations.length - 1) {
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + client.messages.wrongStationNumber);
|
|
||||||
} else {
|
|
||||||
url = client.stations[number].stream[client.stations[number].stream.default];
|
|
||||||
station = client.stations[number];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (args[1].length < 3) return msg.channel.send(client.messageEmojis["error"] + client.messages.tooShortSearch);
|
|
||||||
const sstation = await searchStation(args.slice(1).join(' '), client);
|
|
||||||
if (!sstation) return msg.channel.send(client.messageEmojis["error"] + client.messages.noSearchResults);
|
|
||||||
url = sstation.stream[sstation.stream.default];
|
|
||||||
station = sstation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radio) {
|
|
||||||
|
|
||||||
client.funcs.statisticsUpdate(client, msg.guild, radio);
|
|
||||||
|
|
||||||
radio.connection.dispatcher.destroy();
|
|
||||||
radio.station = station;
|
|
||||||
radio.textChannel = msg.channel;
|
|
||||||
play(msg.guild, client, url);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const construct = {
|
|
||||||
textChannel: msg.channel,
|
|
||||||
voiceChannel: voiceChannel,
|
|
||||||
connection: null,
|
|
||||||
station: station,
|
|
||||||
volume: 5,
|
|
||||||
};
|
|
||||||
client.radio.set(msg.guild.id, construct);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const connection = await voiceChannel.join();
|
|
||||||
construct.connection = connection;
|
|
||||||
let date = new Date();
|
|
||||||
construct.startTime = date.getTime();
|
|
||||||
play(msg.guild, client, url);
|
|
||||||
|
|
||||||
client.datastore.checkEntry(msg.guild.id);
|
|
||||||
construct.currentGuild = client.datastore.getEntry(msg.guild.id);
|
|
||||||
|
|
||||||
if(!construct.currentGuild.statistics[construct.station.name]){
|
|
||||||
construct.currentGuild.statistics[construct.station.name] = {};
|
|
||||||
construct.currentGuild.statistics[construct.station.name].time = 0;
|
|
||||||
construct.currentGuild.statistics[construct.station.name].used = 0;
|
|
||||||
client.datastore.updateEntry(msg.guild, construct.currentGuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
client.radio.delete(msg.guild.id);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + `An error occured: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function play(guild, client, url) {
|
|
||||||
let message = {};
|
|
||||||
const radio = client.radio.get(guild.id);
|
|
||||||
|
|
||||||
const dispatcher = radio.connection
|
|
||||||
.play(url, { bitrate: "auto", volume: 1 })
|
|
||||||
.on("finish", () => {
|
|
||||||
console.log("Stream finished");
|
|
||||||
client.funcs.statisticsUpdate(client, guild, radio);
|
|
||||||
radio.voiceChannel.leave();
|
|
||||||
client.radio.delete(guild.id);
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.on('error', error => {
|
|
||||||
console.error(error);
|
|
||||||
radio.voiceChannel.leave();
|
|
||||||
client.radio.delete(guild.id);
|
|
||||||
return radio.textChannel.send(client.messages.errorPlaying);
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.setVolume(radio.volume / 10);
|
|
||||||
|
|
||||||
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
|
|
||||||
radio.textChannel.send(client.messageEmojis["play"] + message.play);
|
|
||||||
};
|
|
||||||
|
|
||||||
function searchStation(key, client) {
|
|
||||||
if (client.stations === null) return false;
|
|
||||||
let foundStations = [];
|
|
||||||
if (!key) return false;
|
|
||||||
if (key == 'radio') return false;
|
|
||||||
if (key.startsWith("radio ")) key = key.slice(6);
|
|
||||||
const probabilityIncrement = 100 / key.split(' ').length / 2;
|
|
||||||
for (let i = 0; i < key.split(' ').length; i++) {
|
|
||||||
client.stations.filter(x => x.name.toUpperCase().includes(key.split(' ')[i].toUpperCase()) || x === key).forEach(x => foundStations.push({ station: x, name: x.name, probability: probabilityIncrement }));
|
|
||||||
}
|
|
||||||
if (foundStations.length === 0) return false;
|
|
||||||
for (let i = 0; i < foundStations.length; i++) {
|
|
||||||
for (let j = 0; j < foundStations.length; j++) {
|
|
||||||
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let i = 0; i < foundStations.length; i++) {
|
|
||||||
if (foundStations[i].name.length > key.length) {
|
|
||||||
foundStations[i].probability -= (foundStations[i].name.split(' ').length - key.split(' ').length) * (probabilityIncrement * 0.5);
|
|
||||||
} else if (foundStations[i].name.length === key.length) {
|
|
||||||
foundStations[i].probability += (probabilityIncrement * 0.9);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let j = 0; j < key.split(' ').length; j++) {
|
|
||||||
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(' ')[j])) {
|
|
||||||
foundStations[i].probability -= (probabilityIncrement * 0.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let highestProbabilityStation;
|
|
||||||
for (let i = 0; i < foundStations.length; i++) {
|
|
||||||
if (!highestProbabilityStation || highestProbabilityStation.probability < foundStations[i].probability) highestProbabilityStation = foundStations[i];
|
|
||||||
if (highestProbabilityStation && highestProbabilityStation.probability === foundStations[i].probability) {
|
|
||||||
highestProbabilityStation = foundStations[i].station;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return highestProbabilityStation;
|
|
||||||
};
|
|
@ -1,39 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'statistics',
|
|
||||||
alias: 'stats',
|
|
||||||
usage: '',
|
|
||||||
description: 'Show usage statistics.',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
let stations = client.stations;
|
|
||||||
let currentGuild = client.datastore.getEntry(msg.guild.id);
|
|
||||||
let statistics = "";
|
|
||||||
|
|
||||||
if(!client.stations) {
|
|
||||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
|
||||||
return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!currentGuild || currentGuild && !currentGuild.statistics){
|
|
||||||
statistics = "You have not listened any radio station";
|
|
||||||
} else {
|
|
||||||
Object.keys(stations).forEach(function(station) {
|
|
||||||
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) > 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) > 0){
|
|
||||||
statistics += `**${parseInt(station) + 1}** ` + stations[station].name + " \n";
|
|
||||||
statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time, "dd:hh:mm:ss") + "\n";
|
|
||||||
statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
|
||||||
.setTitle(client.messages.statisticsTitle)
|
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["statistics"].replace(/[^0-9]+/g, ''))
|
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.setDescription(statistics)
|
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
|
||||||
return msg.channel.send(embed);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,18 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'stop',
|
|
||||||
description: 'Stop command.',
|
|
||||||
alias: 's',
|
|
||||||
usage: '',
|
|
||||||
permission: 'none',
|
|
||||||
category: 'radio',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
const radio = client.radio.get(msg.guild.id);
|
|
||||||
if (client.funcs.check(client, msg, command)) {
|
|
||||||
client.funcs.statisticsUpdate(client, msg.guild, radio);
|
|
||||||
radio.connection.dispatcher.destroy();
|
|
||||||
radio.voiceChannel.leave();
|
|
||||||
client.radio.delete(msg.guild.id);
|
|
||||||
msg.channel.send(client.messageEmojis["stop"] + client.messages.stop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,27 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'volume',
|
|
||||||
description: 'Volume command.',
|
|
||||||
alias: 'none',
|
|
||||||
usage: '<volume>',
|
|
||||||
permission: 'MANAGE_MESSAGES',
|
|
||||||
category: 'radio',
|
|
||||||
execute(msg, args, client, Discord, command) {
|
|
||||||
let message = {};
|
|
||||||
const radio = client.radio.get(msg.guild.id);
|
|
||||||
|
|
||||||
if (!args[1] && radio) {
|
|
||||||
message.currentVolume = client.messages.currentVolume.replace("%radio.volume%", radio.volume)
|
|
||||||
return msg.channel.send(message.currentVolume);
|
|
||||||
}
|
|
||||||
const volume = parseFloat(args[1]);
|
|
||||||
if (client.funcs.check(client, msg, command)) {
|
|
||||||
if (isNaN(volume)) return msg.channel.send(client.messages.invalidVolume);
|
|
||||||
if (volume > 100) return msg.channel.send(client.messages.maxVolume);
|
|
||||||
if (volume < 0) return msg.channel.send(client.messages.negativeVolume);
|
|
||||||
radio.volume = volume;
|
|
||||||
radio.connection.dispatcher.setVolume(volume / 5);
|
|
||||||
message.newVolume = client.messages.newVolume.replace("%volume%", volume);
|
|
||||||
return msg.channel.send(message.newVolume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,124 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = class {
|
|
||||||
constructor() {
|
|
||||||
this.map = new Map();
|
|
||||||
this.loadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
loadData() {
|
|
||||||
//console.log("");
|
|
||||||
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'datastore')).filter(f => f.endsWith('.json'));
|
|
||||||
for (const file of dataFiles) {
|
|
||||||
try {
|
|
||||||
const json = require(`../datastore/${file}`);
|
|
||||||
this.map.set(json.guild.id, json);
|
|
||||||
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
|
||||||
//console.log(JSON.stringify(json, null, 4));
|
|
||||||
} catch (error) {
|
|
||||||
//console.log('[ERROR] Loading ' + file + ' failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log("");
|
|
||||||
}
|
|
||||||
|
|
||||||
calculateGlobal(client){
|
|
||||||
let guilds = this.map.keys();
|
|
||||||
let stations = client.stations;
|
|
||||||
var statistics = {};
|
|
||||||
|
|
||||||
if(!client.stations) return;
|
|
||||||
|
|
||||||
let calculation = guilds.next();
|
|
||||||
|
|
||||||
while (!calculation.done) {
|
|
||||||
let currentGuild = this.getEntry(calculation.value);
|
|
||||||
if(calculation.value != 'global'){
|
|
||||||
if(stations){
|
|
||||||
Object.keys(stations).forEach(function(station) {
|
|
||||||
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) != 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) != 0){
|
|
||||||
if(!statistics[stations[station].name]){
|
|
||||||
statistics[stations[station].name] = {};
|
|
||||||
statistics[stations[station].name].time = 0;
|
|
||||||
statistics[stations[station].name].used = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
|
||||||
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calculation = guilds.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
let newData = {};
|
|
||||||
newData.guild = {};
|
|
||||||
newData.guild.id = "global";
|
|
||||||
newData.guild.name = "global";
|
|
||||||
newData.statistics = statistics;
|
|
||||||
this.updateEntry(newData.guild, newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
checkEntry(id){
|
|
||||||
if(!this.map.has(id)){
|
|
||||||
this.createEntry(id);
|
|
||||||
//this.showEntry(this.getEntry(id));
|
|
||||||
} else {
|
|
||||||
//this.showEntry(this.getEntry(id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createEntry(id){
|
|
||||||
let newData = {};
|
|
||||||
newData.guild = {};
|
|
||||||
newData.guild.id = id;
|
|
||||||
newData.statistics = {};
|
|
||||||
this.map.set(id, newData);
|
|
||||||
this.saveEntry(id, newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
getEntry(id){
|
|
||||||
return this.map.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateEntry(guild, newData) {
|
|
||||||
newData.guild.name = guild.name;
|
|
||||||
this.map.set(guild.id, newData);
|
|
||||||
this.saveEntry(guild.id, newData);
|
|
||||||
//this.showEntry(this.getEntry(guild.id));
|
|
||||||
}
|
|
||||||
|
|
||||||
showEntry(data){
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
createTestFile () {
|
|
||||||
let newData = {
|
|
||||||
"guild": {
|
|
||||||
"id": "test",
|
|
||||||
"name": "Test"
|
|
||||||
},
|
|
||||||
"statistics": {
|
|
||||||
"test": {
|
|
||||||
"time": 0,
|
|
||||||
"used": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateEntry(newData.guild, newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveEntry(file, data) {
|
|
||||||
data = JSON.stringify(data, null, 4);
|
|
||||||
|
|
||||||
fs.writeFile(path.join(path.dirname(__dirname), 'datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
|
||||||
if (err) {
|
|
||||||
//console.log(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,27 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'message',
|
|
||||||
async execute(client, msg, Discord) {
|
|
||||||
if (msg.author.bot || !msg.guild) return;
|
|
||||||
let prefix = client.config.prefix;
|
|
||||||
if(msg.mentions.members.first()){
|
|
||||||
if(msg.mentions.members.first().user.id === client.user.id){
|
|
||||||
prefix = "<@!" + client.user.id + "> ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const args = msg.content.slice(prefix.length).split(' ');
|
|
||||||
if (!msg.content.startsWith(prefix)) return;
|
|
||||||
if (!args[0]) return;
|
|
||||||
const commandName = args[0].toLowerCase();
|
|
||||||
if (commandName === 'none') return;
|
|
||||||
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName);
|
|
||||||
if (!command && msg.content !== `${prefix}`) return;
|
|
||||||
const permissions = msg.channel.permissionsFor(msg.client.user);
|
|
||||||
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
|
|
||||||
try {
|
|
||||||
command.execute(msg, args, client, Discord, command);
|
|
||||||
} catch (error) {
|
|
||||||
msg.reply(client.messages.runningCommandFailed);
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
const fetch = require('node-fetch');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'ready',
|
|
||||||
async execute(client, Discord) {
|
|
||||||
|
|
||||||
console.log('RadioX');
|
|
||||||
console.log('Internet Radio to your Discord guild');
|
|
||||||
console.log('(c)2020-2021 EximiaBots by Warén Group');
|
|
||||||
|
|
||||||
client.developers = "";
|
|
||||||
let user = "";
|
|
||||||
for (i = 0; i < client.config.devId.length; i++) {
|
|
||||||
user = await client.users.fetch(client.config.devId[i]);
|
|
||||||
if (i == client.config.devId.length - 1) {
|
|
||||||
client.developers += user.tag;
|
|
||||||
} else {
|
|
||||||
client.developers += user.tag + " & ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
client.stations = await fetch(client.config.stationslistUrl)
|
|
||||||
.then(client.funcs.checkFetchStatus)
|
|
||||||
.then(response => response.json());
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
setInterval(async () => {
|
|
||||||
try {
|
|
||||||
client.stations = await fetch(client.config.stationslistUrl)
|
|
||||||
.then(client.funcs.checkFetchStatus)
|
|
||||||
.then(response => response.json());
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}, 3600000);
|
|
||||||
|
|
||||||
if(!client.stations) {
|
|
||||||
client.user.setStatus('dnd');
|
|
||||||
}
|
|
||||||
|
|
||||||
client.datastore.calculateGlobal(client);
|
|
||||||
require(`../emojis.js`).execute(client);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: "voiceStateUpdate",
|
|
||||||
async execute(client, oldState, newState) {
|
|
||||||
if (oldState.channel === null) return;
|
|
||||||
let change = false;
|
|
||||||
const radio = client.radio.get(newState.guild.id);
|
|
||||||
if (!radio) return;
|
|
||||||
|
|
||||||
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
|
||||||
if (newState.channel === null) {
|
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
|
||||||
return client.radio.delete(newState.guild.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const newPermissions = newState.channel.permissionsFor(newState.client.user);
|
|
||||||
if (!newPermissions.has("CONNECT") || !newPermissions.has("SPEAK") || !newPermissions.has("VIEW_CHANNEL")) {
|
|
||||||
try {
|
|
||||||
setTimeout(
|
|
||||||
async () => (radio.connection = await oldState.channel.join()),
|
|
||||||
1000
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
|
||||||
radio.connection.dispatcher.destroy();
|
|
||||||
radio.voiceChannel.leave();
|
|
||||||
client.radio.delete(oldState.guild.id);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (newState.channel !== radio.voiceChannel) {
|
|
||||||
change = true;
|
|
||||||
radio.voiceChannel = newState.channel;
|
|
||||||
radio.connection = await newState.channel.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel) || change) {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!radio || !radio.connection.dispatcher || !radio.connection.dispatcher === null) return;
|
|
||||||
if (radio.voiceChannel.members.size === 1) {
|
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
|
||||||
radio.connection.dispatcher.destroy();
|
|
||||||
radio.voiceChannel.leave();
|
|
||||||
client.radio.delete(newState.guild.id);
|
|
||||||
}
|
|
||||||
}, 120000);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,20 +0,0 @@
|
|||||||
module.exports = function (client, msg, command) {
|
|
||||||
let message = {};
|
|
||||||
const radio = client.radio.get(msg.guild.id);
|
|
||||||
const permissions = msg.channel.permissionsFor(msg.author);
|
|
||||||
if (!radio) {
|
|
||||||
msg.channel.send(client.messageEmojis["error"] + client.messages.notPlaying);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (msg.member.voice.channel !== radio.voiceChannel) {
|
|
||||||
msg.channel.send(client.messageEmojis["error"] + client.messages.wrongVoiceChannel);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!command.permission == 'none'){
|
|
||||||
if (!permissions.has(command.permission)) {
|
|
||||||
message.noPerms = client.messages.noPerms.replace("%command.permission%", command.permission);
|
|
||||||
msg.channel.send(client.messageEmojis["error"] + message.noPerms);
|
|
||||||
return false;
|
|
||||||
} else return true;
|
|
||||||
} else return true;
|
|
||||||
};
|
|
@ -1,7 +0,0 @@
|
|||||||
module.exports = function (response) {
|
|
||||||
if (response.ok) { // res.status >= 200 && res.status < 300
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
throw new Error(response.status + " " + response.statusText);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
module.exports = function msToTime(duration, format) {
|
|
||||||
var seconds = Math.floor((duration / 1000) % 60),
|
|
||||||
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
|
||||||
hours = Math.floor((duration / (1000 * 60 * 60)) % 24),
|
|
||||||
days = Math.floor((duration / (1000 * 60 * 60 * 24)));
|
|
||||||
|
|
||||||
days = (days < 10) ? "0" + days : days;
|
|
||||||
hours = (hours < 10) ? "0" + hours : hours;
|
|
||||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
||||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
|
||||||
|
|
||||||
if (format === "hh:mm:ss") {
|
|
||||||
return `${hours}:${minutes}:${seconds}`;
|
|
||||||
} else if (format === "dd:hh:mm:ss") {
|
|
||||||
return `${days}:${hours}:${minutes}:${seconds}`;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
module.exports = function statisticsUpdate(client, guild, radio) {
|
|
||||||
|
|
||||||
client.datastore.checkEntry(guild.id);
|
|
||||||
|
|
||||||
radio.currentGuild = client.datastore.getEntry(guild.id);
|
|
||||||
|
|
||||||
if(!radio.currentGuild.statistics[radio.station.name]){
|
|
||||||
radio.currentGuild.statistics[radio.station.name] = {};
|
|
||||||
radio.currentGuild.statistics[radio.station.name].time = 0;
|
|
||||||
radio.currentGuild.statistics[radio.station.name].used = 0;
|
|
||||||
client.datastore.updateEntry(guild, radio.currentGuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!radio.connection.dispatcher){
|
|
||||||
let date = new Date();
|
|
||||||
radio.currentTime = date.getTime();
|
|
||||||
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
|
||||||
radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.playTime);
|
|
||||||
} else {
|
|
||||||
radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.connection.dispatcher.streamTime.toFixed(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
radio.currentGuild.statistics[radio.station.name].used = parseInt(radio.currentGuild.statistics[radio.station.name].used)+1;
|
|
||||||
client.datastore.updateEntry(guild, radio.currentGuild);
|
|
||||||
client.datastore.calculateGlobal(client);
|
|
||||||
}
|
|
2
index.js
2
index.js
@ -1,2 +0,0 @@
|
|||||||
const radioClient = require("./client/class.js");
|
|
||||||
const client = new radioClient();
|
|
6837
package-lock.json
generated
6837
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "eximiabots-radiox",
|
"name": "eximiabots-radiox",
|
||||||
"version": "0.1.0",
|
"version": "0.3.10",
|
||||||
"description": "Internet Radio to your Discord guild",
|
"description": "Internet Radio to your Discord guild",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ."
|
"build": "rimraf ./build && tsc",
|
||||||
|
"start": "node --no-warnings build/index.js",
|
||||||
|
"start:dev": "npm run build && node --no-warnings build/index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -16,10 +18,34 @@
|
|||||||
"url": "https://github.com/warengroup/eximiabots-radiox/issues"
|
"url": "https://github.com/warengroup/eximiabots-radiox/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "^0.3.3",
|
"@discordjs/builders": "^0.6.0",
|
||||||
"discord.js": "^12.5.3",
|
"@discordjs/opus": "^0.6.0",
|
||||||
"dotenv": "^8.2.0",
|
"@discordjs/rest": "^0.1.1-canary.0",
|
||||||
"node-fetch": "^2.6.1",
|
"@discordjs/voice": "^0.6.0",
|
||||||
|
"discord-api-types": "^0.23.1",
|
||||||
|
"discord.js": "^13.1.0",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
|
"libsodium-wrappers": "^0.7.9",
|
||||||
|
"node-fetch": "^3.0.0",
|
||||||
"path": "^0.12.7"
|
"path": "^0.12.7"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^16.9.1",
|
||||||
|
"@types/ws": "^7.4.7",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
||||||
|
"@typescript-eslint/parser": "^4.31.1",
|
||||||
|
"eslint": "^7.32.0",
|
||||||
|
"eslint-config-prettier": "^8.3.0",
|
||||||
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
|
"nodemon": "^2.0.12",
|
||||||
|
"prettier": "^2.4.1",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"ts-node": "^10.2.1",
|
||||||
|
"tsc-watch": "^4.5.0",
|
||||||
|
"typescript": "^4.4.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.9.1",
|
||||||
|
"npm": ">=7.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
117
src/Client.ts
Normal file
117
src/Client.ts
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import Discord, { Client, Collection } from "discord.js";
|
||||||
|
import Datastore from "./client/classes/Datastore.js";
|
||||||
|
import Radio from "./client/classes/Radio.js";
|
||||||
|
import Stations from "./client/classes/Stations.js";
|
||||||
|
import Streamer from "./client/classes/Streamer.js";
|
||||||
|
import Statistics from "./client/classes/Statistics.js";
|
||||||
|
import fs from "fs";
|
||||||
|
import { command, radio } from "./client/utils/typings.js";
|
||||||
|
import config from "./config.js";
|
||||||
|
import messages from "./client/messages.js";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const events = "./client/events/";
|
||||||
|
|
||||||
|
const GatewayIntents = new Discord.Intents();
|
||||||
|
GatewayIntents.add(
|
||||||
|
1 << 0, // GUILDS
|
||||||
|
1 << 7, // GUILD_VOICE_STATES
|
||||||
|
1 << 9 // GUILD_MESSAGES
|
||||||
|
);
|
||||||
|
|
||||||
|
class RadioClient extends Client {
|
||||||
|
readonly commands: Collection<string, command>;
|
||||||
|
public funcs: any;
|
||||||
|
readonly config = config;
|
||||||
|
readonly messages = messages;
|
||||||
|
public datastore: Datastore | null;
|
||||||
|
public stations: Stations | null;
|
||||||
|
public streamer: Streamer | null;
|
||||||
|
public statistics: Statistics | null;
|
||||||
|
public radio: Radio | null;
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
intents: GatewayIntents
|
||||||
|
});
|
||||||
|
this.commands = new Collection();
|
||||||
|
this.datastore = null;
|
||||||
|
this.stations = null;
|
||||||
|
this.streamer = null;
|
||||||
|
this.statistics = null;
|
||||||
|
this.radio = null;
|
||||||
|
|
||||||
|
this.funcs = {};
|
||||||
|
this.funcs.check = require("./client/funcs/check.js");
|
||||||
|
this.funcs.isDev = require("./client/funcs/isDev.js");
|
||||||
|
this.funcs.logger = require("./client/funcs/logger.js");
|
||||||
|
this.funcs.msToTime = require("./client/funcs/msToTime.js");
|
||||||
|
this.funcs.saveState = require("./client/funcs/saveState.js");
|
||||||
|
this.funcs.loadState = require("./client/funcs/loadState.js");
|
||||||
|
this.funcs.play = require("./client/funcs/play.js");
|
||||||
|
this.funcs.listStations = require("./client/funcs/listStations.js");
|
||||||
|
|
||||||
|
console.log('RadioX ' + this.config.version);
|
||||||
|
console.log('Internet Radio to your Discord guild');
|
||||||
|
console.log('(c)2020-2021 EximiaBots by Warén Group');
|
||||||
|
console.log('');
|
||||||
|
|
||||||
|
this.funcs.logger("Bot", "Starting");
|
||||||
|
|
||||||
|
this.funcs.logger("Maintenance Mode", "Enabled");
|
||||||
|
this.config.maintenanceMode = true;
|
||||||
|
|
||||||
|
this.on("ready", () => {
|
||||||
|
require(`${events}ready`).execute(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("messageCreate", msg => {
|
||||||
|
require(`${events}messageCreate`).execute(this, msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("messageDelete", msg => {
|
||||||
|
require(`${events}messageDelete`).execute(this, msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("interactionCreate", interaction => {
|
||||||
|
require(`${events}interactionCreate`).execute(this, interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("voiceStateUpdate", (oldState, newState) => {
|
||||||
|
require(`${events}voiceStateUpdate`).execute(this, oldState, newState);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("error", error => {
|
||||||
|
this.funcs.logger("Discord Client / Error");
|
||||||
|
console.error(error);
|
||||||
|
console.log('');
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGINT', () => {
|
||||||
|
require(`${events}SIGINT`).execute(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGTERM', () => {
|
||||||
|
require(`${events}SIGTERM`).execute(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
require(`${events}uncaughtException`).execute(this, error);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('exit', () => {
|
||||||
|
this.funcs.logger("Bot", "Stopping");
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('warning', (warning) => {
|
||||||
|
require(`${events}warning`).execute(this, warning);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.login(this.config.token).catch((err) => {
|
||||||
|
this.funcs.logger("Discord Client / Error");
|
||||||
|
console.log(err);
|
||||||
|
console.log('');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RadioClient
|
103
src/client/classes/Datastore.js
Normal file
103
src/client/classes/Datastore.js
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = class {
|
||||||
|
constructor() {
|
||||||
|
this.map = new Map();
|
||||||
|
this.loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadData() {
|
||||||
|
const dir = path.join(path.dirname(__dirname), '../../datastore');
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
fs.mkdirSync(dir);
|
||||||
|
}
|
||||||
|
//console.log("");
|
||||||
|
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), '../../datastore')).filter(f => f.endsWith('.json'));
|
||||||
|
for (const file of dataFiles) {
|
||||||
|
try {
|
||||||
|
const json = require(`../../../datastore/${file}`);
|
||||||
|
this.map.set(json.guild.id, json);
|
||||||
|
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
||||||
|
//console.log(JSON.stringify(json, null, 4));
|
||||||
|
} catch (error) {
|
||||||
|
//console.log('[ERROR] Loading ' + file + ' failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.log("");
|
||||||
|
}
|
||||||
|
|
||||||
|
checkEntry(id){
|
||||||
|
this.loadEntry(id);
|
||||||
|
if(!this.map.has(id)){
|
||||||
|
this.createEntry(id);
|
||||||
|
//this.showEntry(this.getEntry(id));
|
||||||
|
} else {
|
||||||
|
//this.showEntry(this.getEntry(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createEntry(id){
|
||||||
|
let newData = {};
|
||||||
|
newData.guild = {};
|
||||||
|
newData.guild.id = id;
|
||||||
|
newData.statistics = {};
|
||||||
|
newData.state = {};
|
||||||
|
this.map.set(id, newData);
|
||||||
|
this.saveEntry(id, newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadEntry(id){
|
||||||
|
const json = require(`../../../datastore/` + id + '.json');
|
||||||
|
this.map.set(id, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
getEntry(id){
|
||||||
|
return this.map.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateEntry(guild, newData) {
|
||||||
|
newData.guild.name = guild.name;
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
newData.updated = date.toISOString().substring(0, 10)
|
||||||
|
|
||||||
|
this.map.set(guild.id, newData);
|
||||||
|
this.saveEntry(guild.id, newData);
|
||||||
|
//this.showEntry(this.getEntry(guild.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
showEntry(data){
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
createTestFile () {
|
||||||
|
let newData = {
|
||||||
|
"guild": {
|
||||||
|
"id": "test",
|
||||||
|
"name": "Test"
|
||||||
|
},
|
||||||
|
"statistics": {
|
||||||
|
"test": {
|
||||||
|
"time": 0,
|
||||||
|
"used": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateEntry(newData.guild, newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveEntry(file, data) {
|
||||||
|
data = JSON.stringify(data, null, 4);
|
||||||
|
|
||||||
|
fs.writeFile(path.join(path.dirname(__dirname), '../../datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
||||||
|
if (err) {
|
||||||
|
//console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
76
src/client/classes/Radio.js
Normal file
76
src/client/classes/Radio.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
const {
|
||||||
|
getVoiceConnection,
|
||||||
|
joinVoiceChannel
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = class Radio extends Map {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
save(client) {
|
||||||
|
let currentRadios = this.keys();
|
||||||
|
let radio = currentRadios.next();
|
||||||
|
|
||||||
|
while (!radio.done) {
|
||||||
|
let currentRadio = this.get(radio.value);
|
||||||
|
|
||||||
|
if (currentRadio) {
|
||||||
|
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
|
||||||
|
|
||||||
|
client.statistics.update(client, currentRadio.guild, currentRadio);
|
||||||
|
client.funcs.saveState(client, currentRadio.guild, currentRadio);
|
||||||
|
currentRadio.connection?.destroy();
|
||||||
|
currentRadio.message?.delete();
|
||||||
|
this.delete(radio.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
radio = currentRadios.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
restore(client, guilds) {
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
guilds.forEach(async guild => {
|
||||||
|
let state = client.funcs.loadState(client, guild);
|
||||||
|
if(!state) return;
|
||||||
|
if(!state.station || !state.channels.voice || !state.channels.text) return;
|
||||||
|
let voiceChannel = client.channels.cache.get(state.channels.voice);
|
||||||
|
if(!voiceChannel) return;
|
||||||
|
if(voiceChannel.members.filter(member => !member.user.bot).size === 0) return;
|
||||||
|
|
||||||
|
|
||||||
|
const sstation = await client.stations.search(state.station.name);
|
||||||
|
let station = sstation;
|
||||||
|
|
||||||
|
const construct = {
|
||||||
|
textChannel: client.channels.cache.get(state.channels.text),
|
||||||
|
voiceChannel: client.channels.cache.get(state.channels.voice),
|
||||||
|
connection: null,
|
||||||
|
message: null,
|
||||||
|
station: station
|
||||||
|
};
|
||||||
|
this.set(guild.id, construct);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const connection =
|
||||||
|
getVoiceConnection(guild.id) ??
|
||||||
|
joinVoiceChannel({
|
||||||
|
channelId: voiceChannel.id,
|
||||||
|
guildId: voiceChannel.guild.id,
|
||||||
|
adapterCreator: voiceChannel.guild.voiceAdapterCreator
|
||||||
|
});
|
||||||
|
|
||||||
|
construct.connection = connection;
|
||||||
|
let date = new Date();
|
||||||
|
construct.startTime = date.getTime();
|
||||||
|
client.datastore.checkEntry(guild.id);
|
||||||
|
client.funcs.play(client, null, guild, station);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
111
src/client/classes/Stations.js
Normal file
111
src/client/classes/Stations.js
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||||
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||||
|
|
||||||
|
module.exports = class Stations extends Array {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.logger = require("../funcs/logger.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetch(options){
|
||||||
|
try {
|
||||||
|
this.logger('Stations', 'Started fetching list – ' + options.url);
|
||||||
|
let list = await fetch(options.url)
|
||||||
|
.then(this.checkFetchStatus)
|
||||||
|
.then(response => response.json());
|
||||||
|
|
||||||
|
if(list){
|
||||||
|
this.length = 0;
|
||||||
|
list.forEach(station => {
|
||||||
|
this.push(station);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(options.show){
|
||||||
|
this.logger('Stations');
|
||||||
|
list.forEach(station => {
|
||||||
|
console.log("- " + station.name);
|
||||||
|
});
|
||||||
|
console.log("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger('Stations', 'Successfully fetched list');
|
||||||
|
} catch (error) {
|
||||||
|
this.logger('Stations', 'Fetching list failed');
|
||||||
|
console.error(error + "\n");
|
||||||
|
|
||||||
|
this.fetch(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFetchStatus(response) {
|
||||||
|
if (response.ok) { // res.status >= 200 && res.status < 300
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw new Error(response.status + " " + response.statusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
search(key) {
|
||||||
|
if (this === null) return false;
|
||||||
|
let foundStations = [];
|
||||||
|
if (!key) return false;
|
||||||
|
if (key == "radio") return false;
|
||||||
|
|
||||||
|
this
|
||||||
|
.filter(
|
||||||
|
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
|
||||||
|
)
|
||||||
|
.forEach(x =>
|
||||||
|
foundStations.push({ station: x, name: x.name, probability: 100 })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (key.startsWith("radio ")) key = key.slice(6);
|
||||||
|
const probabilityIncrement = 100 / key.split(" ").length / 2;
|
||||||
|
for (let i = 0; i < key.split(" ").length; i++) {
|
||||||
|
this
|
||||||
|
.filter(
|
||||||
|
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
|
||||||
|
)
|
||||||
|
.forEach(x =>
|
||||||
|
foundStations.push({ station: x, name: x.name, probability: probabilityIncrement })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (foundStations.length === 0) return false;
|
||||||
|
for (let i = 0; i < foundStations.length; i++) {
|
||||||
|
for (let j = 0; j < foundStations.length; j++) {
|
||||||
|
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < foundStations.length; i++) {
|
||||||
|
if (foundStations[i].name.length > key.length) {
|
||||||
|
foundStations[i].probability -=
|
||||||
|
(foundStations[i].name.split(" ").length - key.split(" ").length) *
|
||||||
|
(probabilityIncrement * 0.5);
|
||||||
|
} else if (foundStations[i].name.length === key.length) {
|
||||||
|
foundStations[i].probability += probabilityIncrement * 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = 0; j < key.split(" ").length; j++) {
|
||||||
|
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) {
|
||||||
|
foundStations[i].probability -= probabilityIncrement * 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let highestProbabilityStation;
|
||||||
|
for (let i = 0; i < foundStations.length; i++) {
|
||||||
|
if (
|
||||||
|
!highestProbabilityStation ||
|
||||||
|
highestProbabilityStation.probability < foundStations[i].probability
|
||||||
|
)
|
||||||
|
highestProbabilityStation = foundStations[i];
|
||||||
|
if (
|
||||||
|
highestProbabilityStation &&
|
||||||
|
highestProbabilityStation.probability === foundStations[i].probability
|
||||||
|
) {
|
||||||
|
highestProbabilityStation = foundStations[i].station;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highestProbabilityStation;
|
||||||
|
}
|
||||||
|
};
|
70
src/client/classes/Statistics.js
Normal file
70
src/client/classes/Statistics.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
module.exports = class {
|
||||||
|
constructor() {
|
||||||
|
this.map = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
update(client, guild, radio) {
|
||||||
|
|
||||||
|
client.datastore.checkEntry(guild.id);
|
||||||
|
|
||||||
|
radio.datastore = client.datastore.getEntry(guild.id);
|
||||||
|
|
||||||
|
if(!radio.datastore.statistics[radio.station.name]){
|
||||||
|
radio.datastore.statistics[radio.station.name] = {};
|
||||||
|
radio.datastore.statistics[radio.station.name].time = 0;
|
||||||
|
radio.datastore.statistics[radio.station.name].used = 0;
|
||||||
|
client.datastore.updateEntry(guild, radio.datastore);
|
||||||
|
}
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.currentTime = date.getTime();
|
||||||
|
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
||||||
|
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime);
|
||||||
|
|
||||||
|
radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1;
|
||||||
|
client.datastore.updateEntry(guild, radio.datastore);
|
||||||
|
this.calculateGlobal(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateGlobal(client){
|
||||||
|
if(!client.stations) return;
|
||||||
|
if(!client.datastore.map) return;
|
||||||
|
|
||||||
|
let guilds = client.datastore.map.keys();
|
||||||
|
let stations = client.stations;
|
||||||
|
let statistics = {};
|
||||||
|
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
let calculation = guilds.next();
|
||||||
|
|
||||||
|
while (!calculation.done) {
|
||||||
|
let currentGuild = client.datastore.getEntry(calculation.value);
|
||||||
|
if(calculation.value != 'global'){
|
||||||
|
if(stations){
|
||||||
|
Object.keys(stations).forEach(function(station) {
|
||||||
|
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) != 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) != 0){
|
||||||
|
if(!statistics[stations[station].name]){
|
||||||
|
statistics[stations[station].name] = {};
|
||||||
|
statistics[stations[station].name].time = 0;
|
||||||
|
statistics[stations[station].name].used = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
||||||
|
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
calculation = guilds.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
let newData = {};
|
||||||
|
newData.guild = {};
|
||||||
|
newData.guild.id = "global";
|
||||||
|
newData.guild.name = "global";
|
||||||
|
newData.statistics = statistics;
|
||||||
|
client.datastore.updateEntry(newData.guild, newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
128
src/client/classes/Streamer.js
Normal file
128
src/client/classes/Streamer.js
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
const {
|
||||||
|
createAudioPlayer,
|
||||||
|
createAudioResource,
|
||||||
|
AudioPlayerStatus,
|
||||||
|
NoSubscriberBehavior
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = class {
|
||||||
|
constructor() {
|
||||||
|
this.map = new Map();
|
||||||
|
this.mode = null;
|
||||||
|
this.logger = require("../funcs/logger.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
init(client){
|
||||||
|
if(!client.config.streamerMode) return;
|
||||||
|
|
||||||
|
switch(client.config.streamerMode){
|
||||||
|
case "manual":
|
||||||
|
this.mode = "manual";
|
||||||
|
break;
|
||||||
|
case "auto":
|
||||||
|
this.mode = "auto";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.mode = "manual";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mode == "auto"){
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
client.stations.forEach(station => {
|
||||||
|
this.play(station);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh(client){
|
||||||
|
this.init(client);
|
||||||
|
|
||||||
|
let streamers = this.map.keys();
|
||||||
|
streamers.forEach(streamer => {
|
||||||
|
if(client.stations.findIndex(station => station.name == streamer)) return;
|
||||||
|
this.stop(streamer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
play(station) {
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(!audioPlayer) {
|
||||||
|
audioPlayer = createAudioPlayer({
|
||||||
|
behaviors: {
|
||||||
|
noSubscriber: NoSubscriberBehavior.Play,
|
||||||
|
maxMissedFrames: Math.round(5000 / 20),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.map.set(station.name, audioPlayer);
|
||||||
|
}
|
||||||
|
const url = station.stream[station.stream.default];
|
||||||
|
const resource = createAudioResource(url);
|
||||||
|
audioPlayer.play(resource);
|
||||||
|
resource.playStream
|
||||||
|
.on("readable", () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Readable");
|
||||||
|
this.map.set(station.name, audioPlayer);
|
||||||
|
})
|
||||||
|
.on("finish", () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Finished");
|
||||||
|
this.play(station);
|
||||||
|
})
|
||||||
|
.on("error", error => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Error");
|
||||||
|
this.play(station);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
audioPlayer
|
||||||
|
.on('playing', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Playing");
|
||||||
|
})
|
||||||
|
.on('idle', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Idle");
|
||||||
|
this.play(station);
|
||||||
|
})
|
||||||
|
.on('paused', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Paused");
|
||||||
|
this.play(station);
|
||||||
|
})
|
||||||
|
.on('buffering', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Buffering");
|
||||||
|
})
|
||||||
|
.on('autopaused', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "AutoPaused");
|
||||||
|
this.play(station);
|
||||||
|
})
|
||||||
|
.on('error', error => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
|
||||||
|
this.play(station);
|
||||||
|
});
|
||||||
|
return audioPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(station){
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(audioPlayer){
|
||||||
|
this.logger('Streamer', station.name + " / " + "Stop");
|
||||||
|
audioPlayer.stop();
|
||||||
|
}
|
||||||
|
this.map.delete(station.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
listen(station) {
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(!audioPlayer){
|
||||||
|
audioPlayer = this.play(station);
|
||||||
|
}
|
||||||
|
return audioPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
leave(client) {
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
client.stations.forEach(station => {
|
||||||
|
this.stop(station);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
72
src/client/commands.js
Normal file
72
src/client/commands.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const { Routes } = require('discord-api-types/v9');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require ('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async execute(client) {
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`./commands/${file}`);
|
||||||
|
client.commands.set(command.name, command);
|
||||||
|
|
||||||
|
command.data = new SlashCommandBuilder()
|
||||||
|
.setName(command.name)
|
||||||
|
.setDescription(command.description);
|
||||||
|
|
||||||
|
command.data = command.data.toJSON();
|
||||||
|
if(command.options) {
|
||||||
|
command.options.forEach(function(option) {
|
||||||
|
if(option.type == "STRING") option.type = 3;
|
||||||
|
if(option.type == "NUMBER") option.type = 10;
|
||||||
|
command.data.options.push(option);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.push(command.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rest = new REST({ version: '9' }).setToken(client.config.token);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
client.funcs.logger('Slash Commands', 'Started refreshing application (/) commands.');
|
||||||
|
|
||||||
|
if(client.config.devMode){
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationCommands(client.user.id),
|
||||||
|
{ body: [] },
|
||||||
|
);
|
||||||
|
|
||||||
|
let guilds = await client.guilds.fetch();
|
||||||
|
guilds.forEach(async guild => {
|
||||||
|
try {
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationGuildCommands(client.user.id, guild.id),
|
||||||
|
{ body: commands }
|
||||||
|
);
|
||||||
|
client.funcs.logger('Slash Commands', 'Guild Applications – Successful' + "\n" + guild.id + " / " + guild.name);
|
||||||
|
} catch (DiscordAPIError) {
|
||||||
|
client.funcs.logger('Slash Commands', 'Guild Applications – Failed' + "\n" + guild.id + " / " + guild.name);
|
||||||
|
if(DiscordAPIError.name != "DiscordAPIError[50001]") console.error(DiscordAPIError.message + "\n\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationCommands(client.user.id),
|
||||||
|
{ body: commands }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.funcs.logger('Slash Commands', 'Successfully reloaded application (/) commands.' + "\n");
|
||||||
|
} catch (error) {
|
||||||
|
client.funcs.logger('Slash Commands', 'Reloading application (/) commands failed.' + "\n");
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +1,26 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'bug',
|
name: 'bug',
|
||||||
alias: 'none',
|
|
||||||
usage: '',
|
|
||||||
description: 'Report a bug',
|
description: 'Report a bug',
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
category: 'info',
|
||||||
async execute(msg, args, client, Discord, command) {
|
async execute(interaction, client) {
|
||||||
let message = {};
|
let message = {};
|
||||||
|
|
||||||
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);
|
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);
|
||||||
message.bugDescription = message.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);
|
message.bugDescription = client.messages.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
.setTitle(message.bugTitle)
|
.setTitle(message.bugTitle)
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
||||||
.setColor(client.config.embedColor)
|
.setColor(client.config.embedColor)
|
||||||
.setDescription(message.bugDescription)
|
.setDescription(message.bugDescription)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
msg.channel.send(embed);
|
|
||||||
|
|
||||||
},
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
35
src/client/commands/help.js
Normal file
35
src/client/commands/help.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'help',
|
||||||
|
description: 'Get help using bot',
|
||||||
|
category: 'info',
|
||||||
|
execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
|
||||||
|
const categories = [];
|
||||||
|
for (let i = 0; i < client.commands.size; i++) {
|
||||||
|
if (!categories.includes([...client.commands.values()][i].category)) categories.push([...client.commands.values()][i].category);
|
||||||
|
}
|
||||||
|
let commands = '';
|
||||||
|
for (let i = 0; i < categories.length; i++) {
|
||||||
|
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username);
|
||||||
|
message.helpDescription = client.messages.helpDescription.replace("%commands%", commands);
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(message.helpTitle)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(message.helpDescription)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
22
src/client/commands/invite.js
Normal file
22
src/client/commands/invite.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'invite',
|
||||||
|
description: 'Invite Bot',
|
||||||
|
category: 'info',
|
||||||
|
execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(message.inviteTitle)
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setURL("https://discord.com/api/oauth2/authorize?client_id=" + client.user.id + "&permissions=2184465408&scope=applications.commands%20bot") //View Channels, Send Messages, Embed Links, Use External Emojis, Use Slash Commands, Connect, Speak, Use Voice Activity
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
43
src/client/commands/list.js
Normal file
43
src/client/commands/list.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'list',
|
||||||
|
description: 'List radio stations',
|
||||||
|
category: 'radio',
|
||||||
|
execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
|
||||||
|
if(!client.stations) {
|
||||||
|
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
|
||||||
|
if(radio && !client.config.maintenanceMode){
|
||||||
|
client.funcs.listStations(client, interaction);
|
||||||
|
} else {
|
||||||
|
let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}`
|
||||||
|
const hashs = stations.split('**#**').length;
|
||||||
|
for (let i = 0; i < hashs; i++) {
|
||||||
|
stations = stations.replace('**#**', `**${i + 1}.**`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.messages.listTitle)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, ''))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(stations)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
206
src/client/commands/maintenance.js
Normal file
206
src/client/commands/maintenance.js
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
import Streamer from "../classes/Streamer.js";
|
||||||
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||||
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'maintenance',
|
||||||
|
description: 'Bot Maintenance',
|
||||||
|
category: 'info',
|
||||||
|
async execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
|
||||||
|
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.notAllowed,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
|
||||||
|
const options = new Array(
|
||||||
|
{
|
||||||
|
emoji: "🌀",
|
||||||
|
label: "Restart Bot",
|
||||||
|
description: "",
|
||||||
|
value: "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "<:RadioXStop:688541155377414168>",
|
||||||
|
label: "Save Radios",
|
||||||
|
description: "",
|
||||||
|
value: "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "<:RadioXPlay:688541155712827458>",
|
||||||
|
label: "Restore Radios",
|
||||||
|
description: "",
|
||||||
|
value: "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "#️⃣",
|
||||||
|
label: "Reload Commands",
|
||||||
|
description: "",
|
||||||
|
value: "6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "<:RadioXList:688541155519889482>",
|
||||||
|
label: "Reload Stations",
|
||||||
|
description: "",
|
||||||
|
value: "7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "<:dnd:746069698139127831>",
|
||||||
|
label: "Enable Maintenance Mode",
|
||||||
|
description: "",
|
||||||
|
value: "8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "<:online:746069731836035098>",
|
||||||
|
label: "Disable Maintenance Mode",
|
||||||
|
description: "",
|
||||||
|
value: "9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "💤",
|
||||||
|
label: "Streamer Mode – Manual",
|
||||||
|
description: "",
|
||||||
|
value: "10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "📡",
|
||||||
|
label: "Streamer Mode – Auto",
|
||||||
|
description: "",
|
||||||
|
value: "11"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const menu = new Discord.MessageActionRow()
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageSelectMenu()
|
||||||
|
.setCustomId('maintenance')
|
||||||
|
.setPlaceholder('Select action')
|
||||||
|
.addOptions(options)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!action){
|
||||||
|
return interaction.reply({
|
||||||
|
content: "**" + client.messages.maintenanceTitle + "**",
|
||||||
|
components: [menu],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
client.funcs.logger('Maintenance', options.find(option => option.value == action).label);
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.messages.maintenanceTitle)
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(options.find(option => option.value == action).label)
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
|
let guilds = await client.guilds.fetch();
|
||||||
|
|
||||||
|
switch(action){
|
||||||
|
case "0":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
process.emit('SIGINT');
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.radio.save(client);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
break;
|
||||||
|
case "6":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
require(`../commands.js`).execute(client);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
break;
|
||||||
|
case "7":
|
||||||
|
try {
|
||||||
|
client.stations.fetch({
|
||||||
|
url: client.config.stationslistUrl
|
||||||
|
});
|
||||||
|
client.streamer.refresh(client);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "8":
|
||||||
|
client.user.setStatus('dnd');
|
||||||
|
client.funcs.logger("Maintenance Mode", "Enabled");
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
break;
|
||||||
|
case "9":
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.funcs.logger("Maintenance Mode", "Disabled");
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
break;
|
||||||
|
case "10":
|
||||||
|
client.config.streamerMode = "manual";
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.funcs.saveRadios(client);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if(client.radio.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){
|
||||||
|
client.streamer.leave(client);
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!client.config.maintenanceMode){
|
||||||
|
clearInterval();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "11":
|
||||||
|
client.config.streamerMode = "auto";
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.funcs.save(client);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if(client.radio.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){
|
||||||
|
client.streamer.leave(client);
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!client.config.maintenanceMode){
|
||||||
|
clearInterval();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
35
src/client/commands/next.js
Normal file
35
src/client/commands/next.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'next',
|
||||||
|
description: 'Next Station',
|
||||||
|
category: 'radio',
|
||||||
|
async execute(interaction, client, command) {
|
||||||
|
if (client.funcs.check(client, interaction, command)) {
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
|
||||||
|
let index = client.stations.findIndex(station => station.name == radio.station.name) + 1;
|
||||||
|
if(index == client.stations.length) index = 0;
|
||||||
|
|
||||||
|
let station = client.stations[index];
|
||||||
|
|
||||||
|
if(!station) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noSearchResults,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.station = station;
|
||||||
|
radio.textChannel = interaction.channel;
|
||||||
|
radio.startTime = date.getTime();
|
||||||
|
|
||||||
|
if(interaction.isCommand()) {
|
||||||
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
}
|
||||||
|
if(interaction.isButton()) {
|
||||||
|
interaction.deferUpdate();
|
||||||
|
client.funcs.play(client, null, interaction.guild, station);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
src/client/commands/nowplaying.js
Normal file
35
src/client/commands/nowplaying.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'nowplaying',
|
||||||
|
description: 'Current Radio Station',
|
||||||
|
category: 'radio',
|
||||||
|
async execute(interaction, client, command) {
|
||||||
|
if (client.funcs.check(client, interaction, command)) {
|
||||||
|
let message = {};
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.currentTime = date.getTime();
|
||||||
|
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
||||||
|
const completed = (radio.playTime);
|
||||||
|
|
||||||
|
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%" + "\n", radio.station.name != radio.station.owner ? radio.station.owner + "\n" : "");
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed));
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.messages.nowplayingTitle)
|
||||||
|
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(message.nowplayingDescription)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
138
src/client/commands/play.js
Normal file
138
src/client/commands/play.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
const {
|
||||||
|
getVoiceConnection,
|
||||||
|
joinVoiceChannel
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "play",
|
||||||
|
usage: "<song name>",
|
||||||
|
description: "Play radio",
|
||||||
|
options: [
|
||||||
|
{ type: "STRING", name: "query", description: "Select station", required: false}
|
||||||
|
],
|
||||||
|
category: "radio",
|
||||||
|
async execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
|
||||||
|
if(client.config.maintenanceMode){
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.maintenance,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!client.stations) {
|
||||||
|
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let query = interaction.options?.getString("query") ?? interaction.values?.[0];
|
||||||
|
if(!query){
|
||||||
|
return client.funcs.listStations(client, interaction);
|
||||||
|
}
|
||||||
|
let url = query ? query.replace(/<(.+)>/g, "$1") : "";
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
const voiceChannel = interaction.member.voice.channel;
|
||||||
|
if (!voiceChannel) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
if (radio) {
|
||||||
|
if (voiceChannel !== radio.voiceChannel) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!query) return interaction.reply({
|
||||||
|
content: client.messages.noQuery,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
const permissions = voiceChannel.permissionsFor(interaction.client.user);
|
||||||
|
if (!permissions.has("CONNECT")) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noPermsConnect,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!permissions.has("SPEAK")) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noPermsSpeak,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let station;
|
||||||
|
const number = parseInt(query - 1);
|
||||||
|
if (url.startsWith("http")) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.errorStationURL,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
} else if (!isNaN(number)) {
|
||||||
|
if (number > client.stations.length - 1) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.wrongStationNumber,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
station = client.stations[number];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (query.length < 3) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.tooShortSearch,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
const sstation = await client.stations.search(query, client);
|
||||||
|
if (!sstation) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noSearchResults,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
station = sstation;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radio) {
|
||||||
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.station = station;
|
||||||
|
radio.textChannel = interaction.channel;
|
||||||
|
radio.startTime = date.getTime();
|
||||||
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const construct = {
|
||||||
|
textChannel: interaction.channel,
|
||||||
|
voiceChannel: voiceChannel,
|
||||||
|
connection: null,
|
||||||
|
message: null,
|
||||||
|
station: station
|
||||||
|
};
|
||||||
|
client.radio.set(interaction.guild.id, construct);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const connection =
|
||||||
|
getVoiceConnection(voiceChannel.guild.id) ??
|
||||||
|
joinVoiceChannel({
|
||||||
|
channelId: voiceChannel.id,
|
||||||
|
guildId: voiceChannel.guild.id,
|
||||||
|
adapterCreator: voiceChannel.guild.voiceAdapterCreator
|
||||||
|
});
|
||||||
|
construct.connection = connection;
|
||||||
|
let date = new Date();
|
||||||
|
construct.startTime = date.getTime();
|
||||||
|
client.datastore.checkEntry(interaction.guild.id);
|
||||||
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
client.radio.delete(interaction.guild.id);
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + `An error occured: ${error}`,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
36
src/client/commands/prev.js
Normal file
36
src/client/commands/prev.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'prev',
|
||||||
|
description: 'Previous Station',
|
||||||
|
category: 'radio',
|
||||||
|
async execute(interaction, client, command) {
|
||||||
|
if (client.funcs.check(client, interaction, command)) {
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
|
||||||
|
let index = client.stations.findIndex(station => station.name == radio.station.name) - 1;
|
||||||
|
if(index == -1) index = client.stations.length - 1;
|
||||||
|
|
||||||
|
let station = client.stations[index];
|
||||||
|
|
||||||
|
if(!station) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noSearchResults,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.station = station;
|
||||||
|
radio.textChannel = interaction.channel;
|
||||||
|
radio.startTime = date.getTime();
|
||||||
|
|
||||||
|
if(interaction.isCommand()) {
|
||||||
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
}
|
||||||
|
if(interaction.isButton()) {
|
||||||
|
interaction.deferUpdate();
|
||||||
|
client.funcs.play(client, null, interaction.guild, station);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
src/client/commands/statistics.js
Normal file
52
src/client/commands/statistics.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'statistics',
|
||||||
|
description: 'Show statistics',
|
||||||
|
category: 'info',
|
||||||
|
execute(interaction, client) {
|
||||||
|
let message = {};
|
||||||
|
let stations = client.stations;
|
||||||
|
let currentGuild = client.datastore.getEntry(interaction.guild.id);
|
||||||
|
let global = client.datastore.getEntry("global");
|
||||||
|
let statistics = "";
|
||||||
|
|
||||||
|
if(!client.stations) {
|
||||||
|
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||||
|
return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!currentGuild || currentGuild && !currentGuild.statistics){
|
||||||
|
statistics = "You have not listened any radio stations";
|
||||||
|
} else {
|
||||||
|
Object.keys(stations).forEach(function(station) {
|
||||||
|
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) > 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) > 0){
|
||||||
|
statistics += `**${parseInt(station) + 1}. ` + stations[station].name + "** \n";
|
||||||
|
if(global && global.statistics[stations[station].name] && global.statistics[stations[station].name].time && parseInt(global.statistics[stations[station].name].time) > 0 && global.statistics[stations[station].name].used && parseInt(global.statistics[stations[station].name].used) > 0){
|
||||||
|
statistics += "Guild – Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " (" + ((currentGuild.statistics[stations[station].name].time / global.statistics[stations[station].name].time) * 100).toFixed(0) + "%" + ")" + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + " (" + ((currentGuild.statistics[stations[station].name].used / global.statistics[stations[station].name].used) * 100).toFixed(0) + "%" + ")" + "\n";
|
||||||
|
statistics += "Global – Time: " + client.funcs.msToTime(global.statistics[stations[station].name].time) + " / " + "Used: " + global.statistics[stations[station].name].used + "\n\n";
|
||||||
|
} else {
|
||||||
|
statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + "\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.messages.statisticsTitle)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["statistics"].replace(/[^0-9]+/g, ''))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(statistics)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -1,27 +1,31 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'status',
|
name: 'status',
|
||||||
alias: 'none',
|
|
||||||
usage: '',
|
|
||||||
description: 'Bot Status',
|
description: 'Bot Status',
|
||||||
permission: 'none',
|
|
||||||
category: 'info',
|
category: 'info',
|
||||||
async execute(msg, args, client, Discord, command) {
|
async execute(interaction, client) {
|
||||||
let message = {};
|
let message = {};
|
||||||
|
|
||||||
message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username);
|
message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username);
|
||||||
let uptime = client.funcs.msToTime(client.uptime, "dd:hh:mm:ss");
|
let uptime = client.funcs.msToTime(client.uptime);
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
.setTitle(message.statusTitle)
|
.setTitle(message.statusTitle)
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
||||||
.setColor(client.config.embedColor)
|
.setColor(client.config.embedColor)
|
||||||
.addField(client.messages.statusField1, Date.now() - msg.createdTimestamp + "ms", true)
|
.addField(client.messages.statusField1, uptime, false)
|
||||||
.addField(client.messages.statusField2, client.ws.ping + "ms", true)
|
.addField(client.messages.statusField2, client.config.version, false)
|
||||||
.addField(client.messages.statusField3, uptime, true)
|
.addField(client.messages.statusField3, Date.now() - interaction.createdTimestamp + "ms", false)
|
||||||
.addField(client.messages.statusField4, client.config.version, true)
|
.addField(client.messages.statusField4, client.ws.ping + "ms", false)
|
||||||
.addField(client.messages.statusField5, client.config.hostedBy, true)
|
.addField(client.messages.statusField5, client.config.hostedBy, false)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
msg.channel.send(embed);
|
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
44
src/client/commands/stop.js
Normal file
44
src/client/commands/stop.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'stop',
|
||||||
|
description: 'Stop radio',
|
||||||
|
category: 'radio',
|
||||||
|
async execute(interaction, client, command) {
|
||||||
|
if (client.funcs.check(client, interaction, command)) {
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
radio.connection?.destroy();
|
||||||
|
client.funcs.logger('Radio', interaction.guild.id + " / " + 'Stop');
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.user.username)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["stop"].replace(/[^0-9]+/g, ''))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.addField(client.messages.nowplayingTitle, "-", true)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
if(!radio.message){
|
||||||
|
radio.message = radio.textChannel.send({ embeds: [embed], components: [] });
|
||||||
|
} else {
|
||||||
|
if(radio.textChannel.id == radio.message.channel.id){
|
||||||
|
radio.message.edit({ embeds: [embed], components: [] });
|
||||||
|
} else {
|
||||||
|
radio.message?.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(async function() {
|
||||||
|
await radio.message?.delete();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
client.radio.delete(interaction.guild.id);
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["stop"] + client.messages.stop,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -9,7 +9,9 @@ module.exports = {
|
|||||||
stop: "<:RadioXStop:688541155377414168>",
|
stop: "<:RadioXStop:688541155377414168>",
|
||||||
statistics: "<:RadioXStatistics:694954485507686421>",
|
statistics: "<:RadioXStatistics:694954485507686421>",
|
||||||
maintenance: "<:RadioXMaintenance:695043843057254493>",
|
maintenance: "<:RadioXMaintenance:695043843057254493>",
|
||||||
error: "<:RadioXError:688541155792781320>"
|
error: "<:RadioXError:688541155792781320>",
|
||||||
|
prev: "<:RadioXPrev:882153637370023957>",
|
||||||
|
next: "<:RadioXNext:882153637474893834>"
|
||||||
};
|
};
|
||||||
|
|
||||||
let fallbackEmojis = {
|
let fallbackEmojis = {
|
||||||
@ -20,14 +22,16 @@ module.exports = {
|
|||||||
stop: "⏹️",
|
stop: "⏹️",
|
||||||
statistics: "📊",
|
statistics: "📊",
|
||||||
maintenance: "🛠️",
|
maintenance: "🛠️",
|
||||||
error: "❌"
|
error: "❌",
|
||||||
|
prev: "⏪",
|
||||||
|
next: "⏩"
|
||||||
};
|
};
|
||||||
|
|
||||||
client.messageEmojis = {};
|
client.messageEmojis = {};
|
||||||
|
|
||||||
for (customEmojiName in customEmojis) {
|
for (const customEmojiName in customEmojis) {
|
||||||
customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, '');
|
const customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, '');
|
||||||
customEmoji = client.emojis.cache.get(customEmojiID);
|
const customEmoji = client.emojis.cache.get(customEmojiID);
|
||||||
if (customEmoji) {
|
if (customEmoji) {
|
||||||
client.messageEmojis[customEmojiName] = customEmojis[customEmojiName];
|
client.messageEmojis[customEmojiName] = customEmojis[customEmojiName];
|
||||||
} else {
|
} else {
|
15
src/client/events/SIGINT.js
Normal file
15
src/client/events/SIGINT.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'SIGINT',
|
||||||
|
execute(client) {
|
||||||
|
client.user.setStatus('dnd');
|
||||||
|
|
||||||
|
client.streamer.leave(client);
|
||||||
|
client.radio.save(client);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if(client.radio.size == 0){
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
6
src/client/events/SIGTERM.js
Normal file
6
src/client/events/SIGTERM.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'SIGTERM',
|
||||||
|
execute(client) {
|
||||||
|
process.emit('SIGINT');
|
||||||
|
}
|
||||||
|
}
|
43
src/client/events/interactionCreate.js
Normal file
43
src/client/events/interactionCreate.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'interactionCreate',
|
||||||
|
async execute(client, interaction) {
|
||||||
|
|
||||||
|
const permissions = interaction.channel.permissionsFor(interaction.client.user);
|
||||||
|
if (!permissions.has('VIEW_CHANNEL')) return;
|
||||||
|
|
||||||
|
if (!permissions.has('EMBED_LINKS')) return interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.noPermsEmbed,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if(interaction.isCommand()){
|
||||||
|
const commandName = interaction.commandName;
|
||||||
|
const command = client.commands.get(commandName);
|
||||||
|
if (!command) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
command.execute(interaction, client);
|
||||||
|
} catch (error) {
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.runningCommandFailed,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
} else if (interaction.isSelectMenu() || interaction.isButton()){
|
||||||
|
const commandName = interaction.customId;
|
||||||
|
const command = client.commands.get(commandName);
|
||||||
|
if (!command) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
command.execute(interaction, client, command);
|
||||||
|
} catch (error) {
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.runningCommandFailed,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
src/client/events/messageCreate.js
Normal file
58
src/client/events/messageCreate.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
module.exports = {
|
||||||
|
name: 'messageCreate',
|
||||||
|
async execute(client, message) {
|
||||||
|
|
||||||
|
if (message.author.bot || !message.guild) return;
|
||||||
|
let prefix = "rx$";
|
||||||
|
if(client.user.username == "RadioX"){
|
||||||
|
prefix = "rx>";
|
||||||
|
} else if (client.user.username == "RadioX Beta"){
|
||||||
|
prefix = "rx-";
|
||||||
|
} else if (client.user.username == "RadioX Dev"){
|
||||||
|
prefix = "rx$";
|
||||||
|
} else if(message.mentions.members.first() && message.mentions.members.first().user.id === client.user.id){
|
||||||
|
prefix = "<@!" + client.user.id + "> ";
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = message.content.slice(prefix.length).split(' ');
|
||||||
|
if (!message.content.startsWith(prefix)) return;
|
||||||
|
if (!args[0]) return;
|
||||||
|
const commandName = args[0].toLowerCase();
|
||||||
|
if (commandName === 'none') return;
|
||||||
|
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
|
||||||
|
if (!command && message.content !== `${prefix}`) return;
|
||||||
|
const permissions = message.channel.permissionsFor(message.client.user);
|
||||||
|
if (!permissions.has('EMBED_LINKS')) return message.channel.send(client.messages.noPermsEmbed);
|
||||||
|
try {
|
||||||
|
let newMessage = {};
|
||||||
|
|
||||||
|
newMessage.messageCommandsDeprecatedTitle = client.messages.messageCommandsDeprecatedTitle.replace("%client.user.username%", client.user.username);
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(newMessage.messageCommandsDeprecatedTitle)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.setDescription(client.messages.messageCommandsDeprecatedDescription)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
let msg = await message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
|
setTimeout(async function() {
|
||||||
|
try {
|
||||||
|
await msg.delete();
|
||||||
|
} catch (DiscordAPIError) {
|
||||||
|
}
|
||||||
|
}, 30000);
|
||||||
|
} catch (error) {
|
||||||
|
message.reply({
|
||||||
|
content: client.messages.runningCommandFailed,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/client/events/messageDelete.js
Normal file
10
src/client/events/messageDelete.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'messageDelete',
|
||||||
|
async execute(client, msg) {
|
||||||
|
if (!msg.author.bot || !msg.guild) return;
|
||||||
|
const radio = client.radio.get(msg.guild.id);
|
||||||
|
if (!radio) return;
|
||||||
|
if(msg.id != radio.message.id) return;
|
||||||
|
radio.message = null;
|
||||||
|
}
|
||||||
|
}
|
102
src/client/events/ready.js
Normal file
102
src/client/events/ready.js
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import Datastore from "../classes/Datastore.js";
|
||||||
|
import Radio from "../classes/Radio.js";
|
||||||
|
import Stations from "../classes/Stations.js";
|
||||||
|
import Streamer from "../classes/Streamer.js";
|
||||||
|
import Statistics from "../classes/Statistics.js";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'ready',
|
||||||
|
async execute(client) {
|
||||||
|
|
||||||
|
client.funcs.logger("Bot", "Ready");
|
||||||
|
|
||||||
|
/*DATASTORE*/
|
||||||
|
client.funcs.logger('Datastore', 'Initialize');
|
||||||
|
client.datastore = new Datastore();
|
||||||
|
|
||||||
|
client.funcs.logger('Datastore');
|
||||||
|
client.datastore.map.forEach(datastore => {
|
||||||
|
console.log("- " + datastore.guild.id + " / " + datastore.guild.name);
|
||||||
|
});
|
||||||
|
console.log("\n");
|
||||||
|
|
||||||
|
client.funcs.logger('Datastore', 'Ready');
|
||||||
|
|
||||||
|
/*DEVELOPERS*/
|
||||||
|
client.funcs.logger('Developers');
|
||||||
|
|
||||||
|
client.developers = "";
|
||||||
|
let user = "";
|
||||||
|
for (let i = 0; i < client.config.devId.length; i++) {
|
||||||
|
user = await client.users.fetch(client.config.devId[i]);
|
||||||
|
console.log("- " + user.tag);
|
||||||
|
if (i == client.config.devId.length - 1) {
|
||||||
|
client.developers += user.tag;
|
||||||
|
} else {
|
||||||
|
client.developers += user.tag + " & ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("\n");
|
||||||
|
|
||||||
|
/*STATIONS*/
|
||||||
|
client.stations = new Stations();
|
||||||
|
|
||||||
|
await client.stations.fetch({
|
||||||
|
url: client.config.stationslistUrl,
|
||||||
|
show: true
|
||||||
|
});
|
||||||
|
|
||||||
|
setInterval(async () => {
|
||||||
|
await client.stations.fetch({
|
||||||
|
url: client.config.stationslistUrl,
|
||||||
|
show: false
|
||||||
|
});
|
||||||
|
}, 3600000);
|
||||||
|
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
|
if(!client.stations) {
|
||||||
|
client.user.setStatus('dnd');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*GUILDS*/
|
||||||
|
client.funcs.logger('Guilds', 'Started fetching list');
|
||||||
|
|
||||||
|
client.funcs.logger('Guilds');
|
||||||
|
let guilds = await client.guilds.fetch();
|
||||||
|
guilds.forEach(guild => {
|
||||||
|
console.log("- " + guild.id + " / " + guild.name);
|
||||||
|
});
|
||||||
|
console.log("\n");
|
||||||
|
|
||||||
|
client.funcs.logger('Guilds', 'Successfully fetched list');
|
||||||
|
|
||||||
|
/*STATISTICS*/
|
||||||
|
client.statistics = new Statistics();
|
||||||
|
client.statistics.calculateGlobal(client);
|
||||||
|
|
||||||
|
/*EMOJIS*/
|
||||||
|
require(`../emojis.js`).execute(client);
|
||||||
|
|
||||||
|
/*COMMANDS*/
|
||||||
|
require(`../commands.js`).execute(client);
|
||||||
|
|
||||||
|
/*RADIO*/
|
||||||
|
client.radio = new Radio();
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
/*RESTORE RADIOS*/
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
if(client.stations) {
|
||||||
|
/*MAINTENANCE MODE*/
|
||||||
|
client.funcs.logger("Maintenance Mode", "Disabled");
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
10
src/client/events/uncaughtException.js
Normal file
10
src/client/events/uncaughtException.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'uncaughtException',
|
||||||
|
execute(client, error) {
|
||||||
|
client.funcs.logger("Error");
|
||||||
|
console.log(error.stack);
|
||||||
|
console.log('');
|
||||||
|
|
||||||
|
process.emit('SIGINT');
|
||||||
|
}
|
||||||
|
}
|
67
src/client/events/voiceStateUpdate.js
Normal file
67
src/client/events/voiceStateUpdate.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const {
|
||||||
|
getVoiceConnection,
|
||||||
|
joinVoiceChannel
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "voiceStateUpdate",
|
||||||
|
async execute(client, oldState, newState) {
|
||||||
|
if (oldState.channel === null) return;
|
||||||
|
let change = false;
|
||||||
|
const radio = client.radio.get(newState.guild.id);
|
||||||
|
if (!radio) return;
|
||||||
|
|
||||||
|
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
||||||
|
|
||||||
|
if (newState.channel === null) {
|
||||||
|
client.statistics.update(client, newState.guild, radio);
|
||||||
|
radio.connection?.destroy();
|
||||||
|
radio.message?.delete();
|
||||||
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
|
return client.radio.delete(newState.guild.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newPermissions = newState.channel.permissionsFor(newState.client.user);
|
||||||
|
if (!newPermissions.has("CONNECT") || !newPermissions.has("SPEAK") || !newPermissions.has("VIEW_CHANNEL")) {
|
||||||
|
try {
|
||||||
|
setTimeout(
|
||||||
|
async () => (
|
||||||
|
radio.connection = joinVoiceChannel({
|
||||||
|
channelId: oldState.channel.id,
|
||||||
|
guildId: oldState.channel.guild.id,
|
||||||
|
adapterCreator: oldState.channel.guild.voiceAdapterCreator
|
||||||
|
})
|
||||||
|
//radio.connection = await oldState.channel.join()
|
||||||
|
),
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
client.statistics.update(client, newState.guild, radio);
|
||||||
|
radio.connection?.destroy();
|
||||||
|
radio.message?.delete();
|
||||||
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
|
client.radio.delete(oldState.guild.id);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newState.channel !== radio.voiceChannel) {
|
||||||
|
change = true;
|
||||||
|
radio.voiceChannel = newState.channel;
|
||||||
|
radio.connection = getVoiceConnection(newState.channel.guild.id);
|
||||||
|
//radio.connection = await newState.channel.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && oldState.channel === radio.voiceChannel) || change) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!radio || !radio.connection || !radio.connection === null) return;
|
||||||
|
if (radio.voiceChannel.members.filter(member => !member.user.bot).size === 0) {
|
||||||
|
client.statistics.update(client, newState.guild, radio);
|
||||||
|
radio.connection?.destroy();
|
||||||
|
radio.message?.delete();
|
||||||
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
|
client.radio.delete(newState.guild.id);
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
12
src/client/events/warning.js
Normal file
12
src/client/events/warning.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'warning',
|
||||||
|
execute(client, warning) {
|
||||||
|
if(warning.name == "ExperimentalWarning" && warning.message.startsWith("stream/web")) return;
|
||||||
|
|
||||||
|
client.funcs.logger("Warning");
|
||||||
|
console.warn(warning.name);
|
||||||
|
console.warn(warning.message);
|
||||||
|
console.warn(warning.stack);
|
||||||
|
console.log('');
|
||||||
|
}
|
||||||
|
}
|
36
src/client/funcs/check.js
Normal file
36
src/client/funcs/check.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
module.exports = function check(client, interaction, command) {
|
||||||
|
let message = {};
|
||||||
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
const permissions = interaction.channel.permissionsFor(interaction.user);
|
||||||
|
if(client.config.maintenanceMode){
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.maintenance,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!client.stations) {
|
||||||
|
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!radio) {
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.notPlaying,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (interaction.member.voice.channel !== radio.voiceChannel) {
|
||||||
|
interaction.reply({
|
||||||
|
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
@ -1,7 +1,7 @@
|
|||||||
module.exports = function (devList, authorID){
|
module.exports = function isDev(devList, authorID){
|
||||||
let response = false;
|
let response = false;
|
||||||
Object.keys(devList).forEach(function(oneDev) {
|
Object.keys(devList).forEach(function(oneDev) {
|
||||||
devID = devList[oneDev];
|
let devID = devList[oneDev];
|
||||||
if(authorID == devID){
|
if(authorID == devID){
|
||||||
response = true;
|
response = true;
|
||||||
}
|
}
|
33
src/client/funcs/listStations.js
Normal file
33
src/client/funcs/listStations.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = function listStations(client, interaction){
|
||||||
|
let stations = new Array();
|
||||||
|
let options = new Array();
|
||||||
|
|
||||||
|
stations = client.stations.forEach(station => {
|
||||||
|
if(station.name == "GrooveFM") return;
|
||||||
|
station = {
|
||||||
|
label: station.name,
|
||||||
|
description: station.owner,
|
||||||
|
value: station.name
|
||||||
|
};
|
||||||
|
options.push(station);
|
||||||
|
});
|
||||||
|
|
||||||
|
const menu = new Discord.MessageActionRow()
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageSelectMenu()
|
||||||
|
.setCustomId('play')
|
||||||
|
.setPlaceholder('Nothing selected')
|
||||||
|
.addOptions(options)
|
||||||
|
);
|
||||||
|
|
||||||
|
stations = null;
|
||||||
|
options = null;
|
||||||
|
|
||||||
|
return interaction.reply({
|
||||||
|
content: '**Select station:**',
|
||||||
|
components: [menu],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
12
src/client/funcs/loadState.js
Normal file
12
src/client/funcs/loadState.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module.exports = function loadState(client, guild){
|
||||||
|
let data = client.datastore.getEntry(guild.id);
|
||||||
|
if(!data) return;
|
||||||
|
let state;
|
||||||
|
|
||||||
|
state = data.state;
|
||||||
|
if(!state) return;
|
||||||
|
|
||||||
|
data.state = {};
|
||||||
|
client.datastore.updateEntry(guild, data);
|
||||||
|
return state;
|
||||||
|
}
|
5
src/client/funcs/logger.js
Normal file
5
src/client/funcs/logger.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = function logger(area, text){
|
||||||
|
let date = new Date();
|
||||||
|
console.log('[' + area + '] – ' + date.toISOString());
|
||||||
|
if(text) console.log(text + '\n');
|
||||||
|
}
|
12
src/client/funcs/msToTime.js
Normal file
12
src/client/funcs/msToTime.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module.exports = function msToTime(duration) {
|
||||||
|
let seconds = Math.floor((duration / 1000) % 60),
|
||||||
|
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
||||||
|
hours = Math.floor((duration / (1000 * 60 * 60)) % 24),
|
||||||
|
days = Math.floor((duration / (1000 * 60 * 60 * 24)));
|
||||||
|
|
||||||
|
return +days > 0
|
||||||
|
? `${days}:${+hours < 10 ? `0${hours}` : hours}:${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}`
|
||||||
|
: +hours > 0
|
||||||
|
? `${+hours < 10 ? `0${hours}` : hours}:${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}`
|
||||||
|
: `${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}`;
|
||||||
|
}
|
74
src/client/funcs/play.js
Normal file
74
src/client/funcs/play.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import Discord from "discord.js";
|
||||||
|
|
||||||
|
module.exports = async function play(client, interaction, guild, station) {
|
||||||
|
let message = {};
|
||||||
|
const radio = client.radio.get(guild.id);
|
||||||
|
const audioPlayer = client.streamer.listen(station);
|
||||||
|
radio.connection.subscribe(audioPlayer);
|
||||||
|
client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name);
|
||||||
|
|
||||||
|
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.name != radio.station.owner ? radio.station.owner + "\n" : "");
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", "");
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
|
||||||
|
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
|
||||||
|
|
||||||
|
const embed = new Discord.MessageEmbed()
|
||||||
|
.setTitle(client.user.username)
|
||||||
|
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')))
|
||||||
|
.setColor(client.config.embedColor)
|
||||||
|
.addField(client.messages.nowplayingTitle, message.nowplayingDescription, true)
|
||||||
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
const buttons = new Discord.MessageActionRow()
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageButton()
|
||||||
|
.setCustomId('list')
|
||||||
|
.setEmoji(client.messageEmojis["list"])
|
||||||
|
.setStyle('SECONDARY')
|
||||||
|
)
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageButton()
|
||||||
|
.setCustomId('prev')
|
||||||
|
.setEmoji(client.messageEmojis["prev"])
|
||||||
|
.setStyle('SECONDARY')
|
||||||
|
)
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageButton()
|
||||||
|
.setCustomId('stop')
|
||||||
|
.setEmoji(client.messageEmojis["stop"])
|
||||||
|
.setStyle('SECONDARY')
|
||||||
|
)
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageButton()
|
||||||
|
.setCustomId('next')
|
||||||
|
.setEmoji(client.messageEmojis["next"])
|
||||||
|
.setStyle('SECONDARY')
|
||||||
|
)
|
||||||
|
.addComponents(
|
||||||
|
new Discord.MessageButton()
|
||||||
|
.setCustomId('statistics')
|
||||||
|
.setEmoji(client.messageEmojis["statistics"])
|
||||||
|
.setStyle('SECONDARY')
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!radio.message){
|
||||||
|
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
|
||||||
|
} else {
|
||||||
|
if(radio.textChannel.id == radio.message.channel.id){
|
||||||
|
radio.message.edit({ embeds: [embed], components: [buttons] });
|
||||||
|
} else {
|
||||||
|
radio.message?.delete();
|
||||||
|
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
|
||||||
|
|
||||||
|
interaction?.reply({
|
||||||
|
content: client.messageEmojis["play"] + message.play,
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
18
src/client/funcs/saveState.js
Normal file
18
src/client/funcs/saveState.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module.exports = function saveState(client, guild, radio){
|
||||||
|
client.datastore.checkEntry(guild.id);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
|
||||||
|
let data = client.datastore.getEntry(guild.id);
|
||||||
|
|
||||||
|
data.state = {};
|
||||||
|
data.state.channels = {};
|
||||||
|
data.state.channels.text = radio.textChannel.id;
|
||||||
|
data.state.channels.voice = radio.voiceChannel.id;
|
||||||
|
data.state.date = date.toISOString();
|
||||||
|
data.state.station = {};
|
||||||
|
data.state.station.name = radio.station.name;
|
||||||
|
data.state.station.owner = radio.station.owner;
|
||||||
|
|
||||||
|
client.datastore.updateEntry(guild, data);
|
||||||
|
}
|
@ -5,15 +5,13 @@ module.exports = {
|
|||||||
runningCommandFailed: "Running this command failed!",
|
runningCommandFailed: "Running this command failed!",
|
||||||
noPermsEmbed: "I cannot send embeds (Embed links).",
|
noPermsEmbed: "I cannot send embeds (Embed links).",
|
||||||
bugTitle: "Found a bug with %client.user.username%?",
|
bugTitle: "Found a bug with %client.user.username%?",
|
||||||
bugDescription: "Join the support server \n %client.config.supportGuild%",
|
bugDescription: "Join the support server" + "\n" + "%client.config.supportGuild%",
|
||||||
helpTitle: "%client.user.username% help:",
|
helpTitle: "%client.user.username% help:",
|
||||||
helpDescription: "%commands% \n %client.config.prefix%help <command> to see more information about a command.",
|
helpDescription: "%commands%",
|
||||||
helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%",
|
|
||||||
helpCommandDescription: "%command.description% \n Command Alias: %command.alias%",
|
|
||||||
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
||||||
listTitle: "Radio Stations",
|
listTitle: "Radio Stations",
|
||||||
nowplayingTitle: "Now Playing",
|
nowplayingTitle: "Now Playing",
|
||||||
nowplayingDescription: "**%radio.station.name%** \n Owner: %radio.station.owner% \n %client.funcs.msToTime(completed, \"hh:mm:ss\")%",
|
nowplayingDescription: "**%radio.station.name%**" + "\n" + "%radio.station.owner%" + "\n" + "%client.funcs.msToTime(completed)%",
|
||||||
noVoiceChannel: "You need to be in a voice channel to play radio!",
|
noVoiceChannel: "You need to be in a voice channel to play radio!",
|
||||||
noQuery: "You need to use a number or search for a supported station!",
|
noQuery: "You need to use a number or search for a supported station!",
|
||||||
noPermsConnect: "I cannot connect to your voice channel.",
|
noPermsConnect: "I cannot connect to your voice channel.",
|
||||||
@ -24,11 +22,6 @@ module.exports = {
|
|||||||
errorPlaying: "An error has occured while playing radio!",
|
errorPlaying: "An error has occured while playing radio!",
|
||||||
play: "Start playing: %radio.station.name%",
|
play: "Start playing: %radio.station.name%",
|
||||||
stop: "Stopped playback!",
|
stop: "Stopped playback!",
|
||||||
currentVolume: "Current volume: **%radio.volume%**",
|
|
||||||
maxVolume: "The max volume is `100`!",
|
|
||||||
invalidVolume: "You need to enter a valid __number__.",
|
|
||||||
negativeVolume: "The volume needs to be a positive number!",
|
|
||||||
newVolume: "Volume is now: **%volume%**",
|
|
||||||
statisticsTitle: "Statistics",
|
statisticsTitle: "Statistics",
|
||||||
maintenanceTitle: "Maintenance",
|
maintenanceTitle: "Maintenance",
|
||||||
errorToGetPlaylist: "You can't use this bot because it has no playlist available. Check more information in our Discord support server %client.config.supportGuild% !",
|
errorToGetPlaylist: "You can't use this bot because it has no playlist available. Check more information in our Discord support server %client.config.supportGuild% !",
|
||||||
@ -36,10 +29,13 @@ module.exports = {
|
|||||||
sendedMaintenanceMessage: "This bot is going to be under maintenance!",
|
sendedMaintenanceMessage: "This bot is going to be under maintenance!",
|
||||||
footerText: "EximiaBots by Warén Group",
|
footerText: "EximiaBots by Warén Group",
|
||||||
statusTitle: "%client.user.username% Status",
|
statusTitle: "%client.user.username% Status",
|
||||||
statusField1: "Bot Latency",
|
statusField1: ":clock1: Bot Uptime",
|
||||||
statusField2: "API Latency",
|
statusField2: ":floppy_disk: Bot Version",
|
||||||
statusField3: "Uptime",
|
statusField3: ":heartbeat: WebSocket Ping",
|
||||||
statusField4: "Version",
|
statusField4: ":hourglass: Latency",
|
||||||
statusField5: "Hosted by",
|
statusField5: ":globe_with_meridians: Hosted by",
|
||||||
errorStationURL: "Station can't be URL"
|
errorStationURL: "Station can't be URL",
|
||||||
|
messageCommandsDeprecatedTitle: "%client.user.username%",
|
||||||
|
messageCommandsDeprecatedDescription: "We recommend you to reauthorize our bot by clicking the invite link down below, because Discord is planning to remove message content from verified bots [Read More](https://support-dev.discord.com/hc/en-us/articles/4404772028055)" + "\n\n" + "**Invite Bot**" + "\n" + "https://wgi.fi/radiox_invite" + "\n\n" + "This bot now supports slash commands, you should start using them instead. Type / into the message box and select the bot you wish to use. Remember to be careful as there are a few bugs here and there on Discord." + "\n\n" + "We will remove this deprecation message in March of 2022 when RadioX 1.0.0 is released.",
|
||||||
|
maintenance: "Shhhh... We are now sleeping and dreaming about new features to implement. Will be back soon."
|
||||||
};
|
};
|
3
src/client/utils/typings.ts
Normal file
3
src/client/utils/typings.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export interface command { }
|
||||||
|
|
||||||
|
export interface radio {}
|
@ -17,11 +17,12 @@ module.exports = {
|
|||||||
|
|
||||||
//misc
|
//misc
|
||||||
embedColor: "#88aa00",
|
embedColor: "#88aa00",
|
||||||
invite: "https://discordapp.com/api/oauth2/authorize?client_id=684109535312609409&permissions=3427328&scope=bot",
|
|
||||||
hostedBy: "[Warén Group](https://waren.io)",
|
hostedBy: "[Warén Group](https://waren.io)",
|
||||||
|
|
||||||
//Settings
|
//Settings
|
||||||
prefix: process.env.RADIOX_PREFIX || "rx-",
|
version: process.env.DEV_MODE ? process.env.npm_package_version + "-dev" : process.env.npm_package_version,
|
||||||
version: process.env.RADIOX_VERSION || process.env.npm_package_version
|
debug: process.env.DEBUG_MODE || false,
|
||||||
|
devMode: process.env.DEV_MODE || false,
|
||||||
|
maintenanceMode: false,
|
||||||
|
streamerMode: process.env.STREAMER_MODE || "manual"
|
||||||
}
|
}
|
3
src/index.js
Normal file
3
src/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const { default: RadioClient } = require("./Client");
|
||||||
|
|
||||||
|
const client = new RadioClient();
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": ["esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"outDir": "build",
|
||||||
|
"rootDir": "src",
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"exclude": ["build", "node_modules", "datastore"]
|
||||||
|
}
|
Reference in New Issue
Block a user