Compare commits
201
Commits
3.0
..
b0be8007d8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0be8007d8 | ||
|
|
62fc2097c2 | ||
|
|
b96e5b2880 | ||
|
|
b3bd6a45fe | ||
|
|
83e618c6a3 | ||
|
|
078c540327 | ||
|
|
e021a713b2 | ||
|
|
91aaafeb40 | ||
|
|
99457b40fc | ||
|
|
78a359ba09 | ||
|
|
2a4dc09a9e | ||
|
|
c442619531 | ||
|
|
d6fa27923b | ||
|
|
ec8cccf5e5 | ||
|
|
7ca6215f47 | ||
|
|
82f6ea4f4d | ||
|
|
1a0434ffed | ||
|
|
25a5df0743 | ||
|
|
d8bd5ecfdb | ||
|
|
8101a02807 | ||
|
|
d3da68f4d4 | ||
|
|
03a1920ccb | ||
|
|
4d753f3ddf | ||
|
|
71563abaf2 | ||
|
|
2c96f8ce85 | ||
|
|
cecd7baf3f | ||
|
|
e35f739cf9 | ||
|
|
f32968c0b5 | ||
|
|
c13b731cd5 | ||
|
|
4be5be2a47 | ||
|
|
3d0c4a169e | ||
|
|
e8c331fa63 | ||
|
|
303dc594b7 | ||
|
|
3d9c25e637 | ||
|
|
a4eb81d7de | ||
|
|
9c34f3a4f4 | ||
|
|
7ef68cf968 | ||
|
|
0224ba67fe | ||
|
|
1c5afca21c | ||
|
|
8c0062f31f | ||
|
|
2027ae296c | ||
|
|
3c50feb597 | ||
|
|
c3f5807cea | ||
|
|
6e8da65580 | ||
|
|
13b2f61261 | ||
|
|
6271e218cd | ||
|
|
6f4977b466 | ||
|
|
f691fcd2ee | ||
|
|
d03b02c9f9 | ||
|
|
db7be88f13 | ||
|
|
2b3ca9ae18 | ||
|
|
d555a3144d | ||
|
|
60d50d99bc | ||
|
|
a54f20e990 | ||
|
|
fac0aedc5e | ||
|
|
0a693f4bc3 | ||
|
|
8fa6de233e | ||
|
|
6fc3dc9577 | ||
|
|
c19287d580 | ||
|
|
3a678ae859 | ||
|
|
69e9ae982b | ||
|
|
3a846ed846 | ||
|
|
7d6ad97951 | ||
|
|
450444f37b | ||
|
|
b5bbbb7907 | ||
|
|
f830f8468c | ||
|
|
316e5f6b4a | ||
|
|
437cf3a460 | ||
|
|
822c6297a5 | ||
|
|
d459b3b735 | ||
|
|
6b2d64388d | ||
|
|
aad528c5c7 | ||
|
|
47ced9d0f2 | ||
|
|
86c94db9aa | ||
|
|
5171cee268 | ||
|
|
f345505578 | ||
|
|
4f64254e60 | ||
|
|
5678cf52d8 | ||
|
|
c96e0d88b5 | ||
|
|
3791667aac | ||
|
|
813d0dde02 | ||
|
|
b78322e521 | ||
|
|
78002d9299 | ||
|
|
78a149b546 | ||
|
|
178054dd23 | ||
|
|
9c09edc88d | ||
|
|
b5e8aa7bd0 | ||
|
|
230aca1620 | ||
|
|
508e3fb5da | ||
|
|
c195f1f56b | ||
|
|
55f7314b05 | ||
|
|
c3b9a36557 | ||
|
|
4b45f802f7 | ||
|
|
1b80d5aa5a | ||
|
|
83ae5bf657 | ||
|
|
e2a7aa79f6 | ||
|
|
e186c44185 | ||
|
|
de96a679e6 | ||
|
|
9589f484ff | ||
|
|
af7dec9c79 | ||
|
|
a6123b9656 | ||
|
|
e940da94e2 | ||
|
|
dad51621c5 | ||
|
|
7003cfbd39 | ||
|
|
0b057de598 | ||
|
|
ff70af988a | ||
|
|
f3c144d2b1 | ||
|
|
716c6e9d93 | ||
|
|
6172182ed5 | ||
|
|
fc4dd64dff | ||
|
|
c40430fa9b | ||
|
|
40a73fd62d | ||
|
|
39111235f7 | ||
|
|
aee731bebe | ||
|
|
e50730298d | ||
|
|
d26fea7b9c | ||
|
|
f6ba9233be | ||
|
|
1423b6105a | ||
|
|
eb765952e4 | ||
|
|
8e1154319b | ||
|
|
a7f5508c41 | ||
|
|
d2a14637f0 | ||
|
|
539cd723b2 | ||
|
|
c95f461300 | ||
|
|
52fcd8434e | ||
|
|
1d8b9eb873 | ||
|
|
91f8c2b6bb | ||
|
|
60e6453354 | ||
|
|
0120932e59 | ||
|
|
56df16c3d5 | ||
|
|
251ac6e171 | ||
|
|
194a19cec2 | ||
|
|
069002a534 | ||
|
|
7c960ddbdc | ||
|
|
13dabe4bda | ||
|
|
1d099ad67e | ||
|
|
acb11c3d9a | ||
|
|
86f9c6bc77 | ||
|
|
59106ea59e | ||
|
|
d04897d603 | ||
|
|
af8df43295 | ||
|
|
9d9a973201 | ||
|
|
5cc35c463e | ||
|
|
24053bf5a7 | ||
|
|
41d6de7219 | ||
|
|
fae59dd9bb | ||
|
|
c055ac84c6 | ||
|
|
d88c1b380a | ||
|
|
5b11e68f8a | ||
|
|
29be1c987a | ||
|
|
070eeb986f | ||
|
|
f9b385ec86 | ||
|
|
8e4a6841cc | ||
|
|
0d735f3744 | ||
|
|
030d816caf | ||
|
|
50e5e704b7 | ||
|
|
ffd2f05509 | ||
|
|
1efab2eb5b | ||
|
|
ef2cd9769e | ||
|
|
c6666bbbc1 | ||
|
|
85624a974d | ||
|
|
a37e0b47ab | ||
|
|
143e96ec46 | ||
|
|
19f889e885 | ||
|
|
864f92b766 | ||
|
|
6d1af8094e | ||
|
|
c145848c14 | ||
|
|
119c997265 | ||
|
|
b9051a0f74 | ||
|
|
649c1cc8ae | ||
|
|
2e45054ade | ||
|
|
65f17b67ec | ||
|
|
52eed29f27 | ||
|
|
bf4d0d7f6a | ||
|
|
35ee744673 | ||
|
|
ac4b0b52df | ||
|
|
04eb4d4c6e | ||
|
|
6aa5261a03 | ||
|
|
464cbc5fd7 | ||
|
|
ecd4af7dc6 | ||
|
|
6d312b664e | ||
|
|
d2207d4cac | ||
|
|
37d80f53ca | ||
|
|
e6d0354334 | ||
|
|
a209eab8ff | ||
|
|
c2b9f55408 | ||
|
|
3813ce3691 | ||
|
|
1eac4c96f2 | ||
|
|
b4d5ca75e6 | ||
|
|
1be3167cb9 | ||
|
|
61e96746be | ||
|
|
dfd678757b | ||
|
|
093796211c | ||
|
|
178cca5b1b | ||
|
|
970806213d | ||
|
|
0a069157b0 | ||
|
|
ef7282f777 | ||
|
|
eef8886a6d | ||
|
|
138385c895 | ||
|
|
4a14098ade | ||
|
|
1242118b0d |
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
.git
|
||||||
|
.gitea
|
||||||
|
.idea
|
||||||
|
.mvn
|
||||||
|
src
|
||||||
|
classes
|
||||||
|
logs
|
||||||
|
target/*
|
||||||
|
!target/netneutrality.jar
|
||||||
|
*.iml
|
||||||
|
README.md
|
||||||
|
checkstyle.xml
|
||||||
|
mvnw
|
||||||
|
mvnw.cmd
|
||||||
|
pom.xml
|
||||||
+10
-3
@@ -1,17 +1,24 @@
|
|||||||
|
NETNEUTRALITY_TAG=latest
|
||||||
|
|
||||||
NETNEUTRALITY_BOT_ENV=dev
|
NETNEUTRALITY_BOT_ENV=dev
|
||||||
NETNEUTRALITY_BOT_TOKEN=
|
NETNEUTRALITY_BOT_TOKEN=
|
||||||
NETNEUTRALITY_BOT_PREFIX=$
|
NETNEUTRALITY_BOT_PREFIX=$
|
||||||
NETNEUTRALITY_BOT_OWNER=
|
NETNEUTRALITY_BOT_OWNER=
|
||||||
|
NETNEUTRALITY_BOT_INVITE=
|
||||||
NETNEUTRALITY_API_PORT=9000
|
NETNEUTRALITY_API_PORT=9000
|
||||||
|
|
||||||
MYSQL_HOST=127.0.0.1
|
MYSQL_HOST=127.0.0.1
|
||||||
MYSQL_USER=root
|
|
||||||
MYSQL_PASSWORD=
|
|
||||||
MYSQL_DATABASE=
|
|
||||||
MYSQL_PORT=3306
|
MYSQL_PORT=3306
|
||||||
|
MYSQL_USER=java
|
||||||
|
MYSQL_PASSWORD=password
|
||||||
|
MYSQL_DATABASE=netneutrality
|
||||||
|
MYSQL_ROOT_PASSWORD=password
|
||||||
|
MARIADB_AUTO_UPGRADE=1
|
||||||
|
|
||||||
NETNEUTRALITY_PO_TOKEN=
|
NETNEUTRALITY_PO_TOKEN=
|
||||||
NETNEUTRALITY_VISITOR_DATA=
|
NETNEUTRALITY_VISITOR_DATA=
|
||||||
|
NETNEUTRALITY_CIPHER_URL=http://localhost:8001
|
||||||
|
NETNEUTRALITY_CIPHER_PASSWORD=
|
||||||
|
|
||||||
NETNEUTRALITY_SENTRY_DSN=
|
NETNEUTRALITY_SENTRY_DSN=
|
||||||
GITLAB_HOST=
|
GITLAB_HOST=
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "main"
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "main"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
package:
|
||||||
|
name: Package
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
|
- name: Set up JDK
|
||||||
|
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '25'
|
||||||
|
cache: 'maven'
|
||||||
|
|
||||||
|
- name: Build package
|
||||||
|
run: |
|
||||||
|
chmod +x ./mvnw
|
||||||
|
./mvnw --batch-mode --update-snapshots verify
|
||||||
|
|
||||||
|
- name: Upload test reports
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@c6a366c94c3e0affe28c06c8df20a878f24da3cf # v3
|
||||||
|
with:
|
||||||
|
name: junit-reports
|
||||||
|
path: |
|
||||||
|
**/target/*-reports/TEST-*.xml
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
|
- name: Upload Maven artifacts
|
||||||
|
uses: actions/upload-artifact@c6a366c94c3e0affe28c06c8df20a878f24da3cf # v3
|
||||||
|
with:
|
||||||
|
name: maven-artifacts
|
||||||
|
path: |
|
||||||
|
target/netneutrality.jar
|
||||||
|
startup.sh
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
docker-main:
|
||||||
|
name: Docker Build and Push (main)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: package
|
||||||
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@a9bc5e6ef2cb54c177f32aa5726adaa15e7e2d59 # v3
|
||||||
|
with:
|
||||||
|
name: maven-artifacts
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Log in to registry
|
||||||
|
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.REGISTRY_URL }}
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push (main)
|
||||||
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:main"
|
||||||
|
|
||||||
|
docker-release:
|
||||||
|
name: Docker Build and Push (release)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: package
|
||||||
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@a9bc5e6ef2cb54c177f32aa5726adaa15e7e2d59 # v3
|
||||||
|
with:
|
||||||
|
name: maven-artifacts
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Compute release version
|
||||||
|
id: rel
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# Strip leading 'v' if present (e.g., v1.2.3 -> 1.2.3)
|
||||||
|
ver="${GITHUB_REF_NAME#v}"
|
||||||
|
echo "version=$ver" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Log in to registry
|
||||||
|
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.REGISTRY_URL }}
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push (release + latest)
|
||||||
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:${{ steps.rel.outputs.version }}
|
||||||
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:latest
|
||||||
@@ -45,3 +45,4 @@ target/
|
|||||||
logs/
|
logs/
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
docker-compose.override.yml
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
image: eclipse-temurin:17-jdk-alpine
|
|
||||||
|
|
||||||
variables:
|
|
||||||
MAVEN_OPTS: >-
|
|
||||||
-Dhttps.protocols=TLSv1.2
|
|
||||||
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
|
|
||||||
-Dorg.slf4j.simpleLogger.showDateTime=true
|
|
||||||
-Djava.awt.headless=true
|
|
||||||
|
|
||||||
MAVEN_CLI_OPTS: >-
|
|
||||||
--batch-mode
|
|
||||||
--errors
|
|
||||||
--fail-at-end
|
|
||||||
--show-version
|
|
||||||
--no-transfer-progress
|
|
||||||
-DinstallAtEnd=true
|
|
||||||
-DdeployAtEnd=true
|
|
||||||
|
|
||||||
cache:
|
|
||||||
key: "maven-$CI_COMMIT_REF_SLUG"
|
|
||||||
paths:
|
|
||||||
- .m2/repository
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- compile
|
|
||||||
- test
|
|
||||||
- package
|
|
||||||
|
|
||||||
compile:
|
|
||||||
stage: compile
|
|
||||||
script:
|
|
||||||
- "chmod +x ./mvnw"
|
|
||||||
- "./mvnw $MAVEN_CLI_OPTS compile"
|
|
||||||
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- "chmod +x ./mvnw"
|
|
||||||
- "./mvnw $MAVEN_CLI_OPTS test"
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
reports:
|
|
||||||
junit:
|
|
||||||
- "**/target/*-reports/TEST-*.xml"
|
|
||||||
|
|
||||||
package:
|
|
||||||
stage: package
|
|
||||||
script:
|
|
||||||
- "chmod +x ./mvnw"
|
|
||||||
- "./mvnw $MAVEN_CLI_OPTS package -DskipTests=true"
|
|
||||||
artifacts:
|
|
||||||
name: "Maven artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
|
|
||||||
paths:
|
|
||||||
- "**/target"
|
|
||||||
+3
-18
@@ -1,18 +1,3 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
wrapperVersion=3.3.4
|
||||||
# or more contributor license agreements. See the NOTICE file
|
distributionType=only-script
|
||||||
# distributed with this work for additional information
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
|
|
||||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
|
|
||||||
+3
-14
@@ -1,17 +1,6 @@
|
|||||||
FROM eclipse-temurin:17-jdk-alpine AS build
|
FROM eclipse-temurin:25-jre@sha256:ff82c74a630c08b417502c4c18189e62074edbb28eb1f2d31b799ac138c01058
|
||||||
|
|
||||||
COPY .mvn/ .mvn
|
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd curl && rm -rf /var/lib/apt/lists/*
|
||||||
COPY mvnw pom.xml ./
|
|
||||||
COPY src ./src
|
|
||||||
|
|
||||||
RUN ["chmod", "+x", "./mvnw"]
|
|
||||||
RUN ./mvnw install
|
|
||||||
|
|
||||||
|
|
||||||
FROM eclipse-temurin:17-jre-alpine
|
|
||||||
|
|
||||||
RUN apk add netcat-openbsd
|
|
||||||
RUN apk add curl
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -19,7 +8,7 @@ ARG API_PORT=9000
|
|||||||
EXPOSE ${API_PORT}
|
EXPOSE ${API_PORT}
|
||||||
|
|
||||||
COPY startup.sh ./
|
COPY startup.sh ./
|
||||||
COPY --from=build /target/netneutrality-jar-with-dependencies.jar ./
|
COPY target/netneutrality.jar ./
|
||||||
|
|
||||||
RUN ["chmod", "+x", "./startup.sh"]
|
RUN ["chmod", "+x", "./startup.sh"]
|
||||||
CMD ["./startup.sh"]
|
CMD ["./startup.sh"]
|
||||||
+11
-4
@@ -1,17 +1,24 @@
|
|||||||
|
NETNEUTRALITY_TAG=latest
|
||||||
|
|
||||||
NETNEUTRALITY_BOT_ENV=dev
|
NETNEUTRALITY_BOT_ENV=dev
|
||||||
NETNEUTRALITY_BOT_TOKEN=
|
NETNEUTRALITY_BOT_TOKEN=
|
||||||
NETNEUTRALITY_BOT_PREFIX=
|
NETNEUTRALITY_BOT_PREFIX=$
|
||||||
NETNEUTRALITY_BOT_OWNER=
|
NETNEUTRALITY_BOT_OWNER=
|
||||||
|
NETNEUTRALITY_BOT_INVITE=
|
||||||
NETNEUTRALITY_API_PORT=9000
|
NETNEUTRALITY_API_PORT=9000
|
||||||
|
|
||||||
MYSQL_HOST=127.0.0.1
|
MYSQL_HOST=127.0.0.1
|
||||||
MYSQL_USER=root
|
|
||||||
MYSQL_PASSWORD=
|
|
||||||
MYSQL_DATABASE=
|
|
||||||
MYSQL_PORT=3306
|
MYSQL_PORT=3306
|
||||||
|
MYSQL_USER=java
|
||||||
|
MYSQL_PASSWORD=password
|
||||||
|
MYSQL_DATABASE=netneutrality
|
||||||
|
MYSQL_ROOT_PASSWORD=password
|
||||||
|
MARIADB_AUTO_UPGRADE=1
|
||||||
|
|
||||||
NETNEUTRALITY_PO_TOKEN=
|
NETNEUTRALITY_PO_TOKEN=
|
||||||
NETNEUTRALITY_VISITOR_DATA=
|
NETNEUTRALITY_VISITOR_DATA=
|
||||||
|
NETNEUTRALITY_CIPHER_URL=http://localhost:8001
|
||||||
|
NETNEUTRALITY_CIPHER_PASSWORD=
|
||||||
|
|
||||||
NETNEUTRALITY_SENTRY_DSN=
|
NETNEUTRALITY_SENTRY_DSN=
|
||||||
GITLAB_HOST=
|
GITLAB_HOST=
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||||
|
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||||
|
|
||||||
|
<module name="Checker">
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
|
||||||
|
<!-- Allows tab characters -->
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<property name="eachLine" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<!-- Indentation with tabs -->
|
||||||
|
<module name="Indentation">
|
||||||
|
<property name="basicOffset" value="4"/>
|
||||||
|
<property name="tabWidth" value="4"/>
|
||||||
|
<property name="forceStrictCondition" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Common useful checks -->
|
||||||
|
<module name="EmptyBlock">
|
||||||
|
<property name="option" value="text"/>
|
||||||
|
</module>
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
<module name="AvoidStarImport"/>
|
||||||
|
<module name="UnusedImports"/>
|
||||||
|
<module name="EqualsHashCode"/>
|
||||||
|
|
||||||
|
<!-- Relaxed Javadoc rules -->
|
||||||
|
<module name="JavadocMethod">
|
||||||
|
<property name="allowMissingParamTags" value="true"/>
|
||||||
|
<property name="allowMissingReturnTag" value="true"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
services:
|
|
||||||
db:
|
|
||||||
image: mariadb:lts
|
|
||||||
container_name: db
|
|
||||||
restart: unless-stopped
|
|
||||||
volumes:
|
|
||||||
- netneutrality-db:/var/lib/mysql
|
|
||||||
- ./sql:/docker-entrypoint-initdb.d
|
|
||||||
environment:
|
|
||||||
MYSQL_USER: 'java'
|
|
||||||
MYSQL_PASSWORD: 'password'
|
|
||||||
MYSQL_DATABASE: 'netneutrality'
|
|
||||||
MYSQL_ROOT_PASSWORD: 'password'
|
|
||||||
MARIADB_AUTO_UPGRADE: '1'
|
|
||||||
ports:
|
|
||||||
- "3306"
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
|
|
||||||
bot:
|
|
||||||
container_name: bot
|
|
||||||
build: ./
|
|
||||||
restart: unless-stopped
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
volumes:
|
|
||||||
- ./logs:/app/logs
|
|
||||||
environment:
|
|
||||||
MYSQL_HOST: 'db'
|
|
||||||
MYSQL_USER: 'java'
|
|
||||||
MYSQL_PASSWORD: 'password'
|
|
||||||
MYSQL_DATABASE: 'netneutrality'
|
|
||||||
ports:
|
|
||||||
- "9000:9000"
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
|
|
||||||
webapp:
|
|
||||||
image: bot-webapp:dev
|
|
||||||
build: ../netneutrality-webapp
|
|
||||||
restart: always
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
- bot
|
|
||||||
volumes:
|
|
||||||
- ./logs:/app/logs
|
|
||||||
environment:
|
|
||||||
DB_CONNECTION: 'mysql'
|
|
||||||
DB_HOST: 'db'
|
|
||||||
DB_PORT: '3306'
|
|
||||||
DB_DATABASE: 'netneutrality'
|
|
||||||
DB_USERNAME: 'java'
|
|
||||||
DB_PASSWORD: 'password'
|
|
||||||
BOT_URL: 'http://bot:9000'
|
|
||||||
ports:
|
|
||||||
- '8080:80'
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
netneutrality-db:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
internal:
|
|
||||||
+29
-27
@@ -1,44 +1,46 @@
|
|||||||
services:
|
services:
|
||||||
db:
|
netneutrality-db:
|
||||||
image: mariadb:lts
|
image: mariadb:11@sha256:1cac8492bd78b1ec693238dc600be173397efd7b55eabc725abc281dc855b482
|
||||||
container_name: db
|
container_name: db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- netneutrality
|
||||||
volumes:
|
volumes:
|
||||||
- netneutrality-db:/var/lib/mysql
|
- netneutrality-db:/var/lib/mysql
|
||||||
- ./sql:/docker-entrypoint-initdb.d
|
|
||||||
environment:
|
environment:
|
||||||
MYSQL_USER: 'java'
|
- MYSQL_USER=${MYSQL_USER:-java}
|
||||||
MYSQL_PASSWORD: 'password'
|
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-password}
|
||||||
MYSQL_DATABASE: 'netneutrality'
|
- MYSQL_DATABASE=${MYSQL_DATABASE:-netneutrality}
|
||||||
MYSQL_ROOT_PASSWORD: 'password'
|
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-password}
|
||||||
MARIADB_AUTO_UPGRADE: '1'
|
- MARIADB_AUTO_UPGRADE=1
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
|
|
||||||
bot:
|
netneutrality-bot:
|
||||||
|
image: gitea.bobert.me/anthorob/netneutrality:${NETNEUTRALITY_TAG:-latest}
|
||||||
container_name: bot
|
container_name: bot
|
||||||
build: ./
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
env_file: .env
|
||||||
|
networks:
|
||||||
|
- netneutrality
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- netneutrality-db
|
||||||
volumes:
|
volumes:
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
environment:
|
environment:
|
||||||
MYSQL_HOST: 'db'
|
MYSQL_HOST: netneutrality-db
|
||||||
MYSQL_PORT: '3306'
|
MYSQL_PORT: 3306
|
||||||
MYSQL_USER: 'java'
|
MYSQL_USER: java
|
||||||
MYSQL_PASSWORD: 'password'
|
MYSQL_PASSWORD: password
|
||||||
MYSQL_DATABASE: 'netneutrality'
|
MYSQL_DATABASE: netneutrality
|
||||||
env_file: ".env"
|
ejs-api:
|
||||||
ports:
|
image: ghcr.io/kikkia/yt-cipher:master@sha256:996a71e8d78476f5d7e2f2ae04fd3cbd06c7a1ee7c4c0d3e8302303d1cd096af
|
||||||
- "9000:9000"
|
container_name: ejs_signature_api
|
||||||
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- netneutrality
|
||||||
|
# environment: # UNCOMMENT THIS LINE AND API_TOKEN TO ADD A PASSWORD
|
||||||
|
# - API_TOKEN=test
|
||||||
volumes:
|
volumes:
|
||||||
netneutrality-db:
|
netneutrality-db: null
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
internal:
|
netneutrality: null
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
param (
|
||||||
|
[ValidateSet("migrate", "info", "validate", "clean", "baseline", "repair")]
|
||||||
|
[string]$Command = "info"
|
||||||
|
)
|
||||||
|
|
||||||
|
$envFile = ".env"
|
||||||
|
if (-not (Test-Path $envFile)) {
|
||||||
|
Write-Error ".env file not found in the current directory."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-Content $envFile | ForEach-Object {
|
||||||
|
if ($_ -match "^\s*([A-Za-z_][A-Za-z0-9_]*)=(.*)$") {
|
||||||
|
$name = $matches[1]
|
||||||
|
$value = $matches[2]
|
||||||
|
[System.Environment]::SetEnvironmentVariable($name, $value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$MYSQL_HOST = $env:MYSQL_HOST
|
||||||
|
$MYSQL_PORT = $env:MYSQL_PORT
|
||||||
|
$MYSQL_DATABASE = $env:MYSQL_DATABASE
|
||||||
|
|
||||||
|
if (-not $MYSQL_HOST -or -not $MYSQL_PORT -or -not $MYSQL_DATABASE) {
|
||||||
|
Write-Error "MYSQL_HOST, MYSQL_PORT, or MYSQL_DATABASE missing from .env"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$env:FLYWAY_URL = "jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}"
|
||||||
|
$env:FLYWAY_USER = $env:MYSQL_USER
|
||||||
|
$env:FLYWAY_PASSWORD = $env:MYSQL_PASSWORD
|
||||||
|
|
||||||
|
Write-Host "Ensuring database '$MYSQL_DATABASE' exists..."
|
||||||
|
$mysqlCommand = "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
|
& mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$env:MYSQL_USER --password=$env:MYSQL_PASSWORD -e $mysqlCommand
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Error "Failed to create database or connect to MySQL. Check your credentials or server status."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
.\mvnw flyway:$Command
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
COMMAND=${1:-info}
|
||||||
|
ENV_FILE=".env"
|
||||||
|
|
||||||
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
echo ".env file not found in the current directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Export variables from .env
|
||||||
|
export $(grep -E '^[A-Za-z_][A-Za-z0-9_]*=' "$ENV_FILE" | xargs)
|
||||||
|
|
||||||
|
if [[ -z "$MYSQL_HOST" || -z "$MYSQL_PORT" || -z "$MYSQL_DATABASE" ]]; then
|
||||||
|
echo "MYSQL_HOST, MYSQL_PORT, or MYSQL_DATABASE missing from .env"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
export FLYWAY_URL="jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}"
|
||||||
|
export FLYWAY_USER="$MYSQL_USER"
|
||||||
|
export FLYWAY_PASSWORD="$MYSQL_PASSWORD"
|
||||||
|
|
||||||
|
echo "Ensuring database '$MYSQL_DATABASE' exists..."
|
||||||
|
mysql -h"$MYSQL_HOST" -P"$MYSQL_PORT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" \
|
||||||
|
-e "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "Failed to create database or connect to MySQL. Check your credentials or server status."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
./mvnw flyway:"$COMMAND"
|
||||||
@@ -19,290 +19,277 @@
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Apache Maven Wrapper startup batch script, version 3.2.0
|
# Apache Maven Wrapper startup batch script, version 3.3.4
|
||||||
#
|
|
||||||
# Required ENV vars:
|
|
||||||
# ------------------
|
|
||||||
# JAVA_HOME - location of a JDK home dir
|
|
||||||
#
|
#
|
||||||
# Optional ENV vars
|
# Optional ENV vars
|
||||||
# -----------------
|
# -----------------
|
||||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||||
# e.g. to debug Maven itself, use
|
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
set -euf
|
||||||
|
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||||
|
|
||||||
if [ -f /usr/local/etc/mavenrc ] ; then
|
# OS specific support.
|
||||||
. /usr/local/etc/mavenrc
|
native_path() { printf %s\\n "$1"; }
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f /etc/mavenrc ] ; then
|
|
||||||
. /etc/mavenrc
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$HOME/.mavenrc" ] ; then
|
|
||||||
. "$HOME/.mavenrc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# OS specific support. $var _must_ be set to either true or false.
|
|
||||||
cygwin=false;
|
|
||||||
darwin=false;
|
|
||||||
mingw=false
|
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
CYGWIN*) cygwin=true ;;
|
CYGWIN* | MINGW*)
|
||||||
MINGW*) mingw=true;;
|
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||||
Darwin*) darwin=true
|
native_path() { cygpath --path --windows "$1"; }
|
||||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
;;
|
||||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
|
||||||
if [ -x "/usr/libexec/java_home" ]; then
|
|
||||||
JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
|
|
||||||
else
|
|
||||||
JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ] ; then
|
# set JAVACMD and JAVACCMD
|
||||||
if [ -r /etc/gentoo-release ] ; then
|
set_java_home() {
|
||||||
JAVA_HOME=$(java-config --jre-home)
|
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||||
fi
|
if [ -n "${JAVA_HOME-}" ]; then
|
||||||
fi
|
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
||||||
|
|
||||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
|
||||||
if $cygwin ; then
|
|
||||||
[ -n "$JAVA_HOME" ] &&
|
|
||||||
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
|
|
||||||
[ -n "$CLASSPATH" ] &&
|
|
||||||
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
|
||||||
if $mingw ; then
|
|
||||||
[ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
|
|
||||||
JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
|
||||||
javaExecutable="$(which javac)"
|
|
||||||
if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then
|
|
||||||
# readlink(1) is not available as standard on Solaris 10.
|
|
||||||
readLink=$(which readlink)
|
|
||||||
if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
|
|
||||||
if $darwin ; then
|
|
||||||
javaHome="$(dirname "\"$javaExecutable\"")"
|
|
||||||
javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
|
|
||||||
else
|
|
||||||
javaExecutable="$(readlink -f "\"$javaExecutable\"")"
|
|
||||||
fi
|
|
||||||
javaHome="$(dirname "\"$javaExecutable\"")"
|
|
||||||
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
|
|
||||||
JAVA_HOME="$javaHome"
|
|
||||||
export JAVA_HOME
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$JAVACMD" ] ; then
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||||
|
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||||
|
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)"
|
JAVACMD="$(
|
||||||
fi
|
'set' +e
|
||||||
fi
|
'unset' -f command 2>/dev/null
|
||||||
|
'command' -v java
|
||||||
|
)" || :
|
||||||
|
JAVACCMD="$(
|
||||||
|
'set' +e
|
||||||
|
'unset' -f command 2>/dev/null
|
||||||
|
'command' -v javac
|
||||||
|
)" || :
|
||||||
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||||
echo " We cannot execute $JAVACMD" >&2
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ] ; then
|
|
||||||
echo "Warning: JAVA_HOME environment variable is not set."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# traverses directory structure from process work directory to filesystem root
|
|
||||||
# first directory with .mvn subdirectory is considered project base directory
|
|
||||||
find_maven_basedir() {
|
|
||||||
if [ -z "$1" ]
|
|
||||||
then
|
|
||||||
echo "Path not specified to find_maven_basedir"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
basedir="$1"
|
|
||||||
wdir="$1"
|
|
||||||
while [ "$wdir" != '/' ] ; do
|
|
||||||
if [ -d "$wdir"/.mvn ] ; then
|
|
||||||
basedir=$wdir
|
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
fi
|
||||||
if [ -d "${wdir}" ]; then
|
}
|
||||||
wdir=$(cd "$wdir/.." || exit 1; pwd)
|
|
||||||
fi
|
# hash string like Java String::hashCode
|
||||||
# end of workaround
|
hash_string() {
|
||||||
|
str="${1:-}" h=0
|
||||||
|
while [ -n "$str" ]; do
|
||||||
|
char="${str%"${str#?}"}"
|
||||||
|
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||||
|
str="${str#?}"
|
||||||
done
|
done
|
||||||
printf '%s' "$(cd "$basedir" || exit 1; pwd)"
|
printf %x\\n $h
|
||||||
}
|
}
|
||||||
|
|
||||||
# concatenates all lines of a file
|
verbose() { :; }
|
||||||
concat_lines() {
|
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||||
if [ -f "$1" ]; then
|
|
||||||
# Remove \r in case we run on Windows within Git Bash
|
die() {
|
||||||
# and check out the repository with auto CRLF management
|
printf %s\\n "$1" >&2
|
||||||
# enabled. Otherwise, we may read lines that are delimited with
|
exit 1
|
||||||
# \r\n and produce $'-Xarg\r' rather than -Xarg due to word
|
|
||||||
# splitting rules.
|
|
||||||
tr -s '\r\n' ' ' < "$1"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
trim() {
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
# MWRAPPER-139:
|
||||||
printf '%s\n' "$1"
|
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||||
fi
|
# Needed for removing poorly interpreted newline sequences when running in more
|
||||||
|
# exotic environments such as mingw bash on Windows.
|
||||||
|
printf "%s" "${1}" | tr -d '[:space:]'
|
||||||
}
|
}
|
||||||
|
|
||||||
BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
|
scriptDir="$(dirname "$0")"
|
||||||
if [ -z "$BASE_DIR" ]; then
|
scriptName="$(basename "$0")"
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
|
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||||
log "$MAVEN_PROJECTBASEDIR"
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
|
||||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
|
||||||
##########################################################################################
|
|
||||||
wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
|
|
||||||
if [ -r "$wrapperJarPath" ]; then
|
|
||||||
log "Found $wrapperJarPath"
|
|
||||||
else
|
|
||||||
log "Couldn't find $wrapperJarPath, downloading it ..."
|
|
||||||
|
|
||||||
if [ -n "$MVNW_REPOURL" ]; then
|
|
||||||
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
|
||||||
else
|
|
||||||
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
|
||||||
fi
|
|
||||||
while IFS="=" read -r key value; do
|
|
||||||
# Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
|
|
||||||
safeValue=$(echo "$value" | tr -d '\r')
|
|
||||||
case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
|
|
||||||
esac
|
|
||||||
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
|
|
||||||
log "Downloading from: $wrapperUrl"
|
|
||||||
|
|
||||||
if $cygwin; then
|
|
||||||
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v wget > /dev/null; then
|
|
||||||
log "Found wget ... using wget"
|
|
||||||
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
|
|
||||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
|
||||||
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
|
||||||
else
|
|
||||||
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
|
||||||
fi
|
|
||||||
elif command -v curl > /dev/null; then
|
|
||||||
log "Found curl ... using curl"
|
|
||||||
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
|
|
||||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
|
||||||
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
|
|
||||||
else
|
|
||||||
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log "Falling back to using Java to download"
|
|
||||||
javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
|
||||||
javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
|
|
||||||
# For Cygwin, switch paths to Windows format before running javac
|
|
||||||
if $cygwin; then
|
|
||||||
javaSource=$(cygpath --path --windows "$javaSource")
|
|
||||||
javaClass=$(cygpath --path --windows "$javaClass")
|
|
||||||
fi
|
|
||||||
if [ -e "$javaSource" ]; then
|
|
||||||
if [ ! -e "$javaClass" ]; then
|
|
||||||
log " - Compiling MavenWrapperDownloader.java ..."
|
|
||||||
("$JAVA_HOME/bin/javac" "$javaSource")
|
|
||||||
fi
|
|
||||||
if [ -e "$javaClass" ]; then
|
|
||||||
log " - Running MavenWrapperDownloader.java ..."
|
|
||||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
##########################################################################################
|
|
||||||
# End of extension
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
# If specified, validate the SHA-256 sum of the Maven wrapper jar file
|
|
||||||
wrapperSha256Sum=""
|
|
||||||
while IFS="=" read -r key value; do
|
while IFS="=" read -r key value; do
|
||||||
case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
|
case "${key-}" in
|
||||||
|
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||||
|
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||||
esac
|
esac
|
||||||
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
|
done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
if [ -n "$wrapperSha256Sum" ]; then
|
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
wrapperSha256Result=false
|
|
||||||
if command -v sha256sum > /dev/null; then
|
case "${distributionUrl##*/}" in
|
||||||
if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
|
maven-mvnd-*bin.*)
|
||||||
wrapperSha256Result=true
|
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||||
|
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||||
|
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||||
|
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||||
|
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||||
|
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||||
|
*)
|
||||||
|
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||||
|
distributionPlatform=linux-amd64
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||||
|
;;
|
||||||
|
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||||
|
*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||||
|
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||||
|
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||||
|
distributionUrlName="${distributionUrl##*/}"
|
||||||
|
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||||
|
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||||
|
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||||
|
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||||
|
|
||||||
|
exec_maven() {
|
||||||
|
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||||
|
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -d "$MAVEN_HOME" ]; then
|
||||||
|
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||||
|
exec_maven "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${distributionUrl-}" in
|
||||||
|
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||||
|
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# prepare tmp dir
|
||||||
|
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||||
|
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||||
|
trap clean HUP INT TERM EXIT
|
||||||
|
else
|
||||||
|
die "cannot create temp dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||||
|
|
||||||
|
# Download and Install Apache Maven
|
||||||
|
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||||
|
verbose "Downloading from: $distributionUrl"
|
||||||
|
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
|
||||||
|
# select .zip or .tar.gz
|
||||||
|
if ! command -v unzip >/dev/null; then
|
||||||
|
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||||
|
distributionUrlName="${distributionUrl##*/}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# verbose opt
|
||||||
|
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||||
|
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||||
|
|
||||||
|
# normalize http auth
|
||||||
|
case "${MVNW_PASSWORD:+has-password}" in
|
||||||
|
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||||
|
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||||
|
verbose "Found wget ... using wget"
|
||||||
|
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||||
|
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||||
|
verbose "Found curl ... using curl"
|
||||||
|
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||||
|
elif set_java_home; then
|
||||||
|
verbose "Falling back to use Java to download"
|
||||||
|
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||||
|
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
cat >"$javaSource" <<-END
|
||||||
|
public class Downloader extends java.net.Authenticator
|
||||||
|
{
|
||||||
|
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||||
|
{
|
||||||
|
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||||
|
}
|
||||||
|
public static void main( String[] args ) throws Exception
|
||||||
|
{
|
||||||
|
setDefault( new Downloader() );
|
||||||
|
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END
|
||||||
|
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||||
|
verbose " - Compiling Downloader.java ..."
|
||||||
|
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||||
|
verbose " - Running Downloader.java ..."
|
||||||
|
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||||
|
if [ -n "${distributionSha256Sum-}" ]; then
|
||||||
|
distributionSha256Result=false
|
||||||
|
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||||
|
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||||
|
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||||
|
exit 1
|
||||||
|
elif command -v sha256sum >/dev/null; then
|
||||||
|
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
|
||||||
|
distributionSha256Result=true
|
||||||
fi
|
fi
|
||||||
elif command -v shasum > /dev/null; then
|
elif command -v shasum >/dev/null; then
|
||||||
if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
|
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||||
wrapperSha256Result=true
|
distributionSha256Result=true
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
|
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||||
echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
|
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ $wrapperSha256Result = false ]; then
|
if [ $distributionSha256Result = false ]; then
|
||||||
echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
|
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||||
echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
|
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||||
echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
# unzip and move
|
||||||
|
if command -v unzip >/dev/null; then
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||||
if $cygwin; then
|
else
|
||||||
[ -n "$JAVA_HOME" ] &&
|
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||||
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
|
|
||||||
[ -n "$CLASSPATH" ] &&
|
|
||||||
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
|
|
||||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
|
||||||
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Provide a "standardized" way to retrieve the CLI args that will
|
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||||
# work with both Windows and non-Windows executions.
|
actualDistributionDir=""
|
||||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*"
|
|
||||||
export MAVEN_CMD_LINE_ARGS
|
|
||||||
|
|
||||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
# First try the expected directory name (for regular distributions)
|
||||||
|
if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
|
||||||
|
if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
|
||||||
|
actualDistributionDir="$distributionUrlNameMain"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086 # safe args
|
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||||
exec "$JAVACMD" \
|
if [ -z "$actualDistributionDir" ]; then
|
||||||
$MAVEN_OPTS \
|
# enable globbing to iterate over items
|
||||||
$MAVEN_DEBUG_OPTS \
|
set +f
|
||||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
for dir in "$TMP_DOWNLOAD_DIR"/*; do
|
||||||
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
if [ -d "$dir" ]; then
|
||||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
if [ -f "$dir/bin/$MVN_CMD" ]; then
|
||||||
|
actualDistributionDir="$(basename "$dir")"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
set -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$actualDistributionDir" ]; then
|
||||||
|
verbose "Contents of $TMP_DOWNLOAD_DIR:"
|
||||||
|
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
|
||||||
|
die "Could not find Maven distribution directory in extracted archive"
|
||||||
|
fi
|
||||||
|
|
||||||
|
verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||||
|
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
|
||||||
|
mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||||
|
|
||||||
|
clean || :
|
||||||
|
exec_maven "$@"
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<# : batch portion
|
||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||||
@REM or more contributor license agreements. See the NOTICE file
|
@REM or more contributor license agreements. See the NOTICE file
|
||||||
@@ -18,188 +19,171 @@
|
|||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
@REM Apache Maven Wrapper startup batch script, version 3.2.0
|
@REM Apache Maven Wrapper startup batch script, version 3.3.4
|
||||||
@REM
|
|
||||||
@REM Required ENV vars:
|
|
||||||
@REM JAVA_HOME - location of a JDK home dir
|
|
||||||
@REM
|
@REM
|
||||||
@REM Optional ENV vars
|
@REM Optional ENV vars
|
||||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||||
@REM e.g. to debug Maven itself, use
|
|
||||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
|
||||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
|
||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||||
@echo off
|
@SET __MVNW_CMD__=
|
||||||
@REM set title of command window
|
@SET __MVNW_ERROR__=
|
||||||
title %0
|
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
@SET PSModulePath=
|
||||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||||
|
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||||
@REM set %HOME% to equivalent of $HOME
|
|
||||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
|
||||||
|
|
||||||
@REM Execute a user defined script before this one
|
|
||||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
|
||||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
|
||||||
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
|
|
||||||
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
|
|
||||||
:skipRcPre
|
|
||||||
|
|
||||||
@setlocal
|
|
||||||
|
|
||||||
set ERROR_CODE=0
|
|
||||||
|
|
||||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
|
||||||
@setlocal
|
|
||||||
|
|
||||||
@REM ==== START VALIDATION ====
|
|
||||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo Error: JAVA_HOME not found in your environment. >&2
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
|
||||||
echo location of your Java installation. >&2
|
|
||||||
echo.
|
|
||||||
goto error
|
|
||||||
|
|
||||||
:OkJHome
|
|
||||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
|
||||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
|
||||||
echo location of your Java installation. >&2
|
|
||||||
echo.
|
|
||||||
goto error
|
|
||||||
|
|
||||||
@REM ==== END VALIDATION ====
|
|
||||||
|
|
||||||
:init
|
|
||||||
|
|
||||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
|
||||||
@REM Fallback to current working directory if not found.
|
|
||||||
|
|
||||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
|
||||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
|
||||||
|
|
||||||
set EXEC_DIR=%CD%
|
|
||||||
set WDIR=%EXEC_DIR%
|
|
||||||
:findBaseDir
|
|
||||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
|
||||||
cd ..
|
|
||||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
|
||||||
set WDIR=%CD%
|
|
||||||
goto findBaseDir
|
|
||||||
|
|
||||||
:baseDirFound
|
|
||||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
|
||||||
cd "%EXEC_DIR%"
|
|
||||||
goto endDetectBaseDir
|
|
||||||
|
|
||||||
:baseDirNotFound
|
|
||||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
|
||||||
cd "%EXEC_DIR%"
|
|
||||||
|
|
||||||
:endDetectBaseDir
|
|
||||||
|
|
||||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
|
||||||
|
|
||||||
@setlocal EnableExtensions EnableDelayedExpansion
|
|
||||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
|
||||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
|
||||||
|
|
||||||
:endReadAdditionalConfig
|
|
||||||
|
|
||||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
|
||||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
|
||||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
|
||||||
|
|
||||||
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
|
||||||
|
|
||||||
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
|
||||||
IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
|
|
||||||
)
|
)
|
||||||
|
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||||
|
@SET __MVNW_PSMODULEP_SAVE=
|
||||||
|
@SET __MVNW_ARG0_NAME__=
|
||||||
|
@SET MVNW_USERNAME=
|
||||||
|
@SET MVNW_PASSWORD=
|
||||||
|
@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
|
||||||
|
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||||
|
@GOTO :EOF
|
||||||
|
: end batch / begin powershell #>
|
||||||
|
|
||||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
$ErrorActionPreference = "Stop"
|
||||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
if ($env:MVNW_VERBOSE -eq "true") {
|
||||||
if exist %WRAPPER_JAR% (
|
$VerbosePreference = "Continue"
|
||||||
if "%MVNW_VERBOSE%" == "true" (
|
}
|
||||||
echo Found %WRAPPER_JAR%
|
|
||||||
)
|
|
||||||
) else (
|
|
||||||
if not "%MVNW_REPOURL%" == "" (
|
|
||||||
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
|
||||||
)
|
|
||||||
if "%MVNW_VERBOSE%" == "true" (
|
|
||||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
|
||||||
echo Downloading from: %WRAPPER_URL%
|
|
||||||
)
|
|
||||||
|
|
||||||
powershell -Command "&{"^
|
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||||
"$webclient = new-object System.Net.WebClient;"^
|
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
if (!$distributionUrl) {
|
||||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
"}"^
|
}
|
||||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
|
|
||||||
"}"
|
|
||||||
if "%MVNW_VERBOSE%" == "true" (
|
|
||||||
echo Finished downloading %WRAPPER_JAR%
|
|
||||||
)
|
|
||||||
)
|
|
||||||
@REM End of extension
|
|
||||||
|
|
||||||
@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
|
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||||
SET WRAPPER_SHA_256_SUM=""
|
"maven-mvnd-*" {
|
||||||
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
$USE_MVND = $true
|
||||||
IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
|
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||||
)
|
$MVN_CMD = "mvnd.cmd"
|
||||||
IF NOT %WRAPPER_SHA_256_SUM%=="" (
|
break
|
||||||
powershell -Command "&{"^
|
}
|
||||||
"$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
|
default {
|
||||||
"If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
|
$USE_MVND = $false
|
||||||
" Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
|
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||||
" Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
|
break
|
||||||
" Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
|
}
|
||||||
" exit 1;"^
|
}
|
||||||
"}"^
|
|
||||||
"}"
|
|
||||||
if ERRORLEVEL 1 goto error
|
|
||||||
)
|
|
||||||
|
|
||||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||||
@REM work with both Windows and non-Windows executions.
|
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||||
set MAVEN_CMD_LINE_ARGS=%*
|
if ($env:MVNW_REPOURL) {
|
||||||
|
$MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||||
|
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
|
||||||
|
}
|
||||||
|
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||||
|
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||||
|
|
||||||
%MAVEN_JAVA_EXE% ^
|
$MAVEN_M2_PATH = "$HOME/.m2"
|
||||||
%JVM_CONFIG_MAVEN_PROPS% ^
|
if ($env:MAVEN_USER_HOME) {
|
||||||
%MAVEN_OPTS% ^
|
$MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
|
||||||
%MAVEN_DEBUG_OPTS% ^
|
}
|
||||||
-classpath %WRAPPER_JAR% ^
|
|
||||||
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
|
|
||||||
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
|
||||||
if ERRORLEVEL 1 goto error
|
|
||||||
goto end
|
|
||||||
|
|
||||||
:error
|
if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
|
||||||
set ERROR_CODE=1
|
New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
:end
|
$MAVEN_WRAPPER_DISTS = $null
|
||||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
|
||||||
|
$MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
|
||||||
|
} else {
|
||||||
|
$MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
|
||||||
|
}
|
||||||
|
|
||||||
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
|
$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
|
||||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||||
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
|
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||||
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
|
|
||||||
:skipRcPost
|
|
||||||
|
|
||||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||||
if "%MAVEN_BATCH_PAUSE%"=="on" pause
|
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||||
|
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||||
|
exit $?
|
||||||
|
}
|
||||||
|
|
||||||
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
|
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||||
|
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||||
|
}
|
||||||
|
|
||||||
cmd /C exit /B %ERROR_CODE%
|
# prepare tmp dir
|
||||||
|
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||||
|
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||||
|
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||||
|
trap {
|
||||||
|
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||||
|
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||||
|
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||||
|
|
||||||
|
# Download and Install Apache Maven
|
||||||
|
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||||
|
Write-Verbose "Downloading from: $distributionUrl"
|
||||||
|
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
|
||||||
|
$webclient = New-Object System.Net.WebClient
|
||||||
|
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||||
|
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||||
|
}
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||||
|
|
||||||
|
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||||
|
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||||
|
if ($distributionSha256Sum) {
|
||||||
|
if ($USE_MVND) {
|
||||||
|
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||||
|
}
|
||||||
|
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||||
|
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||||
|
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# unzip and move
|
||||||
|
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||||
|
|
||||||
|
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||||
|
$actualDistributionDir = ""
|
||||||
|
|
||||||
|
# First try the expected directory name (for regular distributions)
|
||||||
|
$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
|
||||||
|
$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
|
||||||
|
if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
|
||||||
|
$actualDistributionDir = $distributionUrlNameMain
|
||||||
|
}
|
||||||
|
|
||||||
|
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||||
|
if (!$actualDistributionDir) {
|
||||||
|
Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
|
||||||
|
$testPath = Join-Path $_.FullName "bin/$MVN_CMD"
|
||||||
|
if (Test-Path -Path $testPath -PathType Leaf) {
|
||||||
|
$actualDistributionDir = $_.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$actualDistributionDir) {
|
||||||
|
Write-Error "Could not find Maven distribution directory in extracted archive"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||||
|
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||||
|
try {
|
||||||
|
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||||
|
} catch {
|
||||||
|
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||||
|
Write-Error "fail to move MAVEN_HOME"
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||||
|
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||||
@@ -13,10 +13,11 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<main.class>me.bobert.netneutrality.NetNeutrality</main.class>
|
<main.class>me.bobert.netneutrality.NetNeutrality</main.class>
|
||||||
<java.version>17</java.version>
|
<java.version>25</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
|
<mockito.version>5.20.0</mockito.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -28,52 +29,95 @@
|
|||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.5.5</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>
|
||||||
|
-javaagent:"${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar"
|
||||||
|
</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-maven-plugin</artifactId>
|
<artifactId>flyway-maven-plugin</artifactId>
|
||||||
<version>10.17.0</version>
|
<version>11.14.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<url>jdbc:mysql://localhost:3306/netneutrality</url>
|
<url>${env.FLYWAY_URL}</url>
|
||||||
<user>root</user>
|
<user>${env.FLYWAY_USER}</user>
|
||||||
<password></password>
|
<password>${env.FLYWAY_PASSWORD}</password>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.4.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<propertiesEncoding>UTF-8</propertiesEncoding>
|
<propertiesEncoding>UTF-8</propertiesEncoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.7.1</version>
|
<version>3.5.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifestEntries>
|
|
||||||
<Multi-Release>true</Multi-Release>
|
|
||||||
</manifestEntries>
|
|
||||||
<manifest>
|
<manifest>
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<mainClass>${main.class}</mainClass>
|
<mainClass>${main.class}</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<finalName>netneutrality</finalName>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
<phase>package</phase>
|
||||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>single</goal>
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<finalName>netneutrality</finalName>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>${main.class}</mainClass>
|
||||||
|
</transformer>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Multi-Release>true</Multi-Release>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>checkstyle</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<configLocation>checkstyle.xml</configLocation>
|
||||||
|
<failOnViolation>true</failOnViolation>
|
||||||
|
<linkXRef>false</linkXRef>
|
||||||
|
<outputFile>target/checkstyle-result.xml</outputFile>
|
||||||
|
<outputFormat>xml</outputFormat>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
@@ -100,71 +144,98 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.dv8tion</groupId>
|
<groupId>net.dv8tion</groupId>
|
||||||
<artifactId>JDA</artifactId>
|
<artifactId>JDA</artifactId>
|
||||||
<version>5.1.2</version>
|
<version>6.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.arbjerg</groupId>
|
<groupId>dev.arbjerg</groupId>
|
||||||
<artifactId>lavaplayer</artifactId>
|
<artifactId>lavaplayer</artifactId>
|
||||||
<version>2.2.2</version>
|
<version>2.2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.lavalink.youtube</groupId>
|
<groupId>dev.lavalink.youtube</groupId>
|
||||||
<artifactId>v2</artifactId>
|
<artifactId>v2</artifactId>
|
||||||
<version>1.11.5</version>
|
<version>1.18.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>jdave-api</artifactId>
|
||||||
|
<version>0.1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>jdave-native-linux-x86-64</artifactId>
|
||||||
|
<version>0.1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>jdave-native-win-x86-64</artifactId>
|
||||||
|
<version>0.1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>jdave-native-darwin</artifactId>
|
||||||
|
<version>0.1.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp-jvm</artifactId>
|
||||||
<version>4.12.0</version>
|
<version>5.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.orm</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>6.5.2.Final</version>
|
<version>7.1.9.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.orm</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-hikaricp</artifactId>
|
<artifactId>hibernate-hikaricp</artifactId>
|
||||||
<version>6.5.2.Final</version>
|
<version>7.1.9.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<version>9.0.0</version>
|
<version>9.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
<version>10.17.0</version>
|
<version>11.14.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-mysql</artifactId>
|
<artifactId>flyway-mysql</artifactId>
|
||||||
<version>10.17.0</version>
|
<version>11.14.1</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.sentry</groupId>
|
<groupId>io.sentry</groupId>
|
||||||
<artifactId>sentry</artifactId>
|
<artifactId>sentry</artifactId>
|
||||||
<version>7.12.1</version>
|
<version>8.25.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gitlab4j</groupId>
|
<groupId>org.gitlab4j</groupId>
|
||||||
<artifactId>gitlab4j-api</artifactId>
|
<artifactId>gitlab4j-api</artifactId>
|
||||||
<version>6.0.0-rc.5</version>
|
<version>6.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.fellbaum</groupId>
|
<groupId>net.fellbaum</groupId>
|
||||||
<artifactId>jemoji</artifactId>
|
<artifactId>jemoji</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>1.7.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20240303</version>
|
<version>20250517</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.13.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -176,41 +247,48 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-api</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
<version>2.23.1</version>
|
<version>2.25.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.23.1</version>
|
<version>2.25.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||||
<version>2.23.1</version>
|
<version>2.25.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.15.0</version>
|
<version>3.19.0</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<version>1.17.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.16.1</version>
|
<version>2.21.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>5.11.0</version>
|
<version>6.0.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+31
-1
@@ -1,6 +1,36 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": [
|
"extends": [
|
||||||
"renovate/renovate-config"
|
"local>renovate/renovate-config",
|
||||||
|
"group:monorepos",
|
||||||
|
"group:flyway"
|
||||||
|
],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchPackageNames": [
|
||||||
|
"quay.io/buildah/stable"
|
||||||
|
],
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchPackageNames": [
|
||||||
|
"mariadb"
|
||||||
|
],
|
||||||
|
"automerge": false,
|
||||||
|
"dependencyDashboardApproval": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"groupName": "hibernate orm",
|
||||||
|
"matchPackageNames": [
|
||||||
|
"org.hibernate.orm:**"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"groupName": "apache commons",
|
||||||
|
"matchPackageNames": [
|
||||||
|
"commons-**",
|
||||||
|
"org.apache.commons:**"
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -6,19 +6,22 @@ package me.bobert.netneutrality;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import club.minnced.discord.jdave.interop.JDaveSessionFactory;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import me.bobert.netneutrality.core.LogHandler;
|
import me.bobert.netneutrality.core.LogHandler;
|
||||||
import me.bobert.netneutrality.core.command.CommandManager;
|
import me.bobert.netneutrality.core.command.CommandManager;
|
||||||
|
import me.bobert.netneutrality.core.db.DatabaseMigration;
|
||||||
import me.bobert.netneutrality.core.db.SessionManager;
|
import me.bobert.netneutrality.core.db.SessionManager;
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
|
import me.bobert.netneutrality.core.thread.ScheduledTaskManager;
|
||||||
import me.bobert.netneutrality.core.thread.ThreadManager;
|
import me.bobert.netneutrality.core.thread.ThreadManager;
|
||||||
import me.bobert.netneutrality.hooks.EventsHandler;
|
import me.bobert.netneutrality.hooks.EventsHandler;
|
||||||
import me.bobert.netneutrality.http.server.WebApi;
|
import me.bobert.netneutrality.http.server.WebApi;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.thread.ShutdownThread;
|
|
||||||
import me.bobert.netneutrality.utils.Settings;
|
import me.bobert.netneutrality.utils.Settings;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
|
import net.dv8tion.jda.api.audio.AudioModuleConfig;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
|
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
@@ -33,7 +36,7 @@ public class NetNeutrality {
|
|||||||
private static NetNeutrality instance;
|
private static NetNeutrality instance;
|
||||||
private static JDA jda;
|
private static JDA jda;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
static void main() {
|
||||||
System.out.println("Starting NetNeutrality v" + VERSION);
|
System.out.println("Starting NetNeutrality v" + VERSION);
|
||||||
|
|
||||||
String env = Settings.getInstance().get("NETNEUTRALITY_BOT_ENV", "dev");
|
String env = Settings.getInstance().get("NETNEUTRALITY_BOT_ENV", "dev");
|
||||||
@@ -52,6 +55,8 @@ public class NetNeutrality {
|
|||||||
|
|
||||||
if ("dev".equals(env)) {
|
if ("dev".equals(env)) {
|
||||||
Configurator.setLevel("net.dv8tion.jda", Level.DEBUG);
|
Configurator.setLevel("net.dv8tion.jda", Level.DEBUG);
|
||||||
|
Configurator.setLevel("dev.lavalink.youtube", Level.DEBUG);
|
||||||
|
Configurator.setLevel("com.sedmelluq.discord", Level.DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = new NetNeutrality();
|
instance = new NetNeutrality();
|
||||||
@@ -67,8 +72,8 @@ public class NetNeutrality {
|
|||||||
throw new RuntimeException("No bot token provided, exiting.");
|
throw new RuntimeException("No bot token provided, exiting.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseMigration.migrate();
|
|
||||||
SessionManager.getSessionFactory();
|
SessionManager.getSessionFactory();
|
||||||
|
DatabaseMigration.migrate();
|
||||||
CommandManager.init();
|
CommandManager.init();
|
||||||
MusicManager.initPlayerManager();
|
MusicManager.initPlayerManager();
|
||||||
TaskManager.getInstance().init();
|
TaskManager.getInstance().init();
|
||||||
@@ -78,7 +83,7 @@ public class NetNeutrality {
|
|||||||
new WebApi(Integer.parseInt(Settings.getInstance().get("NETNEUTRALITY_API_PORT", "9000")));
|
new WebApi(Integer.parseInt(Settings.getInstance().get("NETNEUTRALITY_API_PORT", "9000")));
|
||||||
jda.getPresence().setActivity(Activity.watching("you"));
|
jda.getPresence().setActivity(Activity.watching("you"));
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NetNeutrality getInstance() {
|
public static NetNeutrality getInstance() {
|
||||||
@@ -94,10 +99,16 @@ public class NetNeutrality {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jda = JDABuilder
|
jda = JDABuilder
|
||||||
.createDefault(token)
|
.createDefault(token)
|
||||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT)
|
.enableIntents(
|
||||||
.setActivity(Activity.watching("me load..."))
|
GatewayIntent.GUILD_MEMBERS,
|
||||||
.build();
|
GatewayIntent.GUILD_MESSAGE_REACTIONS,
|
||||||
|
GatewayIntent.GUILD_VOICE_STATES,
|
||||||
|
GatewayIntent.MESSAGE_CONTENT)
|
||||||
|
.setAudioModuleConfig(
|
||||||
|
new AudioModuleConfig().withDaveSessionFactory(new JDaveSessionFactory()))
|
||||||
|
.setActivity(Activity.watching("me load..."))
|
||||||
|
.build();
|
||||||
jda.awaitReady();
|
jda.awaitReady();
|
||||||
} catch (InvalidTokenException | IllegalArgumentException | InterruptedException e) {
|
} catch (InvalidTokenException | IllegalArgumentException | InterruptedException e) {
|
||||||
LogHandler.log(e);
|
LogHandler.log(e);
|
||||||
@@ -107,6 +118,7 @@ public class NetNeutrality {
|
|||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
System.out.println("[Net Neutrality] Shutting down...");
|
System.out.println("[Net Neutrality] Shutting down...");
|
||||||
|
ScheduledTaskManager.cancelAll();
|
||||||
MusicManager.disconnectPlayers();
|
MusicManager.disconnectPlayers();
|
||||||
ThreadManager.shutdownExecutor();
|
ThreadManager.shutdownExecutor();
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractAdminCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.db.entities.OBlacklist;
|
import me.bobert.netneutrality.db.entities.OBlacklist;
|
||||||
import me.bobert.netneutrality.db.service.BlacklistService;
|
import me.bobert.netneutrality.db.service.BlacklistService;
|
||||||
@@ -18,7 +18,7 @@ import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BlacklistCommand extends AbstractAdminCommand {
|
public class BlacklistCommand extends AdminCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -43,11 +43,11 @@ public class BlacklistCommand extends AbstractAdminCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addSubcommands(
|
builder.addSubcommands(
|
||||||
new SubcommandData("get", "Get all blacklisted words for this guild"),
|
new SubcommandData("get", "Get all blacklisted words for this guild"),
|
||||||
new SubcommandData("add", "Add a word to the blacklist")
|
new SubcommandData("add", "Add a word to the blacklist")
|
||||||
.addOption(OptionType.STRING, "word", "Word to add", true),
|
.addOption(OptionType.STRING, "word", "Word to add", true),
|
||||||
new SubcommandData("remove", "Remove a word from the blacklist")
|
new SubcommandData("remove", "Remove a word from the blacklist")
|
||||||
.addOption(OptionType.STRING, "word", "Word to remove", true)
|
.addOption(OptionType.STRING, "word", "Word to remove", true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractAdminCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ReactionCommand extends AbstractAdminCommand {
|
public class ReactionCommand extends AdminCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -49,30 +49,30 @@ public class ReactionCommand extends AbstractAdminCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addSubcommandGroups(
|
builder.addSubcommandGroups(
|
||||||
new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands(
|
new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands(
|
||||||
new SubcommandData("list", "Lists all registered tasks for this guild"),
|
new SubcommandData("list", "Lists all registered tasks for this guild"),
|
||||||
new SubcommandData("setup", "Add a role to a message").addOptions(
|
new SubcommandData("setup", "Add a role to a message").addOptions(
|
||||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||||
.setRequiredLength(19, 19),
|
.setRequiredLength(19, 19),
|
||||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||||
),
|
),
|
||||||
new SubcommandData("add", "Add a role to an existing message").addOptions(
|
new SubcommandData("add", "Add a role to an existing message").addOptions(
|
||||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||||
.setRequiredLength(19, 19),
|
.setRequiredLength(19, 19),
|
||||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||||
),
|
),
|
||||||
new SubcommandData("remove", "Remove a role from a message").addOptions(
|
new SubcommandData("remove", "Remove a role from a message").addOptions(
|
||||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||||
.setRequiredLength(19, 19),
|
.setRequiredLength(19, 19),
|
||||||
new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true)
|
new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true)
|
||||||
),
|
),
|
||||||
new SubcommandData("delete", "Remove all roles from a message").addOptions(
|
new SubcommandData("delete", "Remove all roles from a message").addOptions(
|
||||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||||
.setRequiredLength(19, 19)
|
.setRequiredLength(19, 19)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,24 +107,24 @@ public class ReactionCommand extends AbstractAdminCommand {
|
|||||||
|
|
||||||
for (EmojiReactionRoleTask item : tasks) {
|
for (EmojiReactionRoleTask item : tasks) {
|
||||||
Map<String, String> mapping = item.getEmojiMapping().entrySet().stream()
|
Map<String, String> mapping = item.getEmojiMapping().entrySet().stream()
|
||||||
.map(entry -> {
|
.map(entry -> {
|
||||||
Role role = context.getGuild().getRoleById(entry.getValue());
|
Role role = context.getGuild().getRoleById(entry.getValue());
|
||||||
return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null;
|
return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null;
|
||||||
})
|
})
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
builder.append("\n- Task ID: ").append(item.getId()).append("\n")
|
builder.append("\n- Task ID: ").append(item.getId()).append("\n")
|
||||||
.append(" Message: ")
|
.append(" Message: ")
|
||||||
.append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId()))
|
.append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId()))
|
||||||
.append("\n")
|
.append("\n")
|
||||||
.append(" Emoji Mappings:\n");
|
.append(" Emoji Mappings:\n");
|
||||||
|
|
||||||
if (mapping.isEmpty()) {
|
if (mapping.isEmpty()) {
|
||||||
builder.append(" No emoji mappings found\n");
|
builder.append(" No emoji mappings found\n");
|
||||||
} else {
|
} else {
|
||||||
mapping.forEach((emoji, roleMention) ->
|
mapping.forEach((emoji, roleMention) ->
|
||||||
builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n")
|
builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,22 @@ package me.bobert.netneutrality.command.basic;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.*;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandContainer;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandManager;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.tasks.BuiltInTask;
|
import me.bobert.netneutrality.core.tasks.Task;
|
||||||
import me.bobert.netneutrality.tasks.help.BotInfo;
|
import me.bobert.netneutrality.tasks.help.BotInfo;
|
||||||
import me.bobert.netneutrality.tasks.help.CommandHelp;
|
import me.bobert.netneutrality.tasks.help.CommandHelp;
|
||||||
import me.bobert.netneutrality.tasks.help.ReportBug;
|
import me.bobert.netneutrality.tasks.help.ReportBug;
|
||||||
import me.bobert.netneutrality.utils.MessageFunction;
|
import me.bobert.netneutrality.utils.MessageFunction;
|
||||||
|
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.components.buttons.Button;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -61,9 +65,9 @@ public class HelpCommand extends AbstractCommand {
|
|||||||
public CommandExecutionResult execute(CommandContext context) {
|
public CommandExecutionResult execute(CommandContext context) {
|
||||||
String command = context.getOption("command", null, CommandOption::getAsString);
|
String command = context.getOption("command", null, CommandOption::getAsString);
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
Button commands = BuiltInTask.createButton(CommandHelp.class);
|
Button commands = Task.createButton(CommandHelp.class);
|
||||||
Button info = BuiltInTask.createButton(BotInfo.class);
|
Button info = Task.createButton(BotInfo.class);
|
||||||
Button reportbug = BuiltInTask.createButton(ReportBug.class);
|
Button reportbug = Task.createButton(ReportBug.class);
|
||||||
ActionRow row = ActionRow.of(commands, info, reportbug);
|
ActionRow row = ActionRow.of(commands, info, reportbug);
|
||||||
context.replyEphemeral("Thanks for using the Net Neutrality Bot! What do you need help with?", List.of(row));
|
context.replyEphemeral("Thanks for using the Net Neutrality Bot! What do you need help with?", List.of(row));
|
||||||
return CommandExecutionResult.none();
|
return CommandExecutionResult.none();
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.basic;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
|
|
||||||
public class PingCommand extends AbstractCommand {
|
public class PingCommand extends AbstractCommand {
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.bot;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractAdminCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.db.GSettings;
|
import me.bobert.netneutrality.db.GSettings;
|
||||||
import me.bobert.netneutrality.db.service.GuildService;
|
import me.bobert.netneutrality.db.service.GuildService;
|
||||||
@@ -23,7 +23,7 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ConfigureCommand extends AbstractAdminCommand {
|
public class ConfigureCommand extends AdminCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -48,15 +48,15 @@ public class ConfigureCommand extends AbstractAdminCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addSubcommands(
|
builder.addSubcommands(
|
||||||
new SubcommandData("music-volume", "Volume for the music player")
|
new SubcommandData("music-volume", "Volume for the music player")
|
||||||
.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true)
|
.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true)
|
||||||
.setRequiredRange(0, 100)),
|
.setRequiredRange(0, 100)),
|
||||||
new SubcommandData("error-logging", "Send errors to #error and/or #log channel")
|
new SubcommandData("error-logging", "Send errors to #error and/or #log channel")
|
||||||
.addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true),
|
.addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true),
|
||||||
new SubcommandData("music-role", "Role needed to use music commands")
|
new SubcommandData("music-role", "Role needed to use music commands")
|
||||||
.addOption(OptionType.ROLE, "role", "Name of role", true),
|
.addOption(OptionType.ROLE, "role", "Name of role", true),
|
||||||
new SubcommandData("music-channel", "Only allow music commands on this channel")
|
new SubcommandData("music-channel", "Only allow music commands on this channel")
|
||||||
.addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere")
|
.addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ package me.bobert.netneutrality.command.crypto;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.LogHandler;
|
import me.bobert.netneutrality.core.LogHandler;
|
||||||
import me.bobert.netneutrality.core.command.AbstractCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.http.WebModule;
|
import me.bobert.netneutrality.http.WebModule;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
@@ -56,9 +56,9 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addOptions(
|
builder.addOptions(
|
||||||
new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true),
|
new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true),
|
||||||
new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed")
|
new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed")
|
||||||
.setRequiredLength(3, 3)
|
.setRequiredLength(3, 3)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +118,9 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
JSONObject json = http.getAsObject();
|
JSONObject json = http.getAsObject();
|
||||||
|
|
||||||
JSONObject pairs = json.getJSONObject("Data")
|
JSONObject pairs = json.getJSONObject("Data")
|
||||||
.getJSONObject("exchanges")
|
.getJSONObject("exchanges")
|
||||||
.getJSONObject(exchange)
|
.getJSONObject(exchange)
|
||||||
.getJSONObject("pairs");
|
.getJSONObject("pairs");
|
||||||
|
|
||||||
return pairs.has(symbol);
|
return pairs.has(symbol);
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ package me.bobert.netneutrality.command.git;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.command.SlashCommandContext;
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.http.WebModule;
|
import me.bobert.netneutrality.http.WebModule;
|
||||||
import me.bobert.netneutrality.tasks.git.ReportIssueTask;
|
import me.bobert.netneutrality.tasks.git.ReportIssueTask;
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
|
|
||||||
public class BitconnectCommand extends AbstractMusicCommand {
|
public class BitconnectCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class ClearQueueCommand extends AbstractMusicCommand {
|
public class ClearQueueCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needAdmin() {
|
public boolean needAdmin() {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MessageFunction;
|
import me.bobert.netneutrality.utils.MessageFunction;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class CurrentlyPlayingCommand extends AbstractMusicCommand {
|
public class CurrentlyPlayingCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class JoinCommand extends AbstractMusicCommand {
|
public class JoinCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class LeaveCommand extends AbstractMusicCommand {
|
public class LeaveCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
|
||||||
public class PlayCommand extends AbstractMusicCommand {
|
public class PlayCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MessageFunction;
|
import me.bobert.netneutrality.utils.MessageFunction;
|
||||||
@@ -18,7 +18,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
|
||||||
public class QueueCommand extends AbstractMusicCommand {
|
public class QueueCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -43,16 +43,16 @@ public class QueueCommand extends AbstractMusicCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addSubcommands(
|
builder.addSubcommands(
|
||||||
new SubcommandData("clear-all", "Clear all queued tracks"),
|
new SubcommandData("clear-all", "Clear all queued tracks"),
|
||||||
new SubcommandData("delete-track", "Remove a single track from the queue")
|
new SubcommandData("delete-track", "Remove a single track from the queue")
|
||||||
.addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true)
|
.addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true)
|
||||||
.setMinValue(1)),
|
.setMinValue(1)),
|
||||||
new SubcommandData("show-queue", "Display current queue"),
|
new SubcommandData("show-queue", "Display current queue"),
|
||||||
new SubcommandData("shuffle", "Shuffle the queue"),
|
new SubcommandData("shuffle", "Shuffle the queue"),
|
||||||
new SubcommandData("from-user", "View tracks added by a user")
|
new SubcommandData("from-user", "View tracks added by a user")
|
||||||
.addOption(OptionType.USER, "user", "Which user?", true),
|
.addOption(OptionType.USER, "user", "Which user?", true),
|
||||||
new SubcommandData("remove-from-user", "Remove all tracks added by a user")
|
new SubcommandData("remove-from-user", "Remove all tracks added by a user")
|
||||||
.addOption(OptionType.USER, "user", "Which user?", true)
|
.addOption(OptionType.USER, "user", "Which user?", true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ package me.bobert.netneutrality.command.music;/*
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class ResumeCommand extends AbstractMusicCommand {
|
public class ResumeCommand extends MusicCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class ShuffleCommand extends AbstractMusicCommand {
|
public class ShuffleCommand extends MusicCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
@@ -17,7 +17,7 @@ import me.bobert.netneutrality.utils.UserFunction;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
|
||||||
public class SkipCommand extends AbstractMusicCommand {
|
public class SkipCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -37,7 +37,7 @@ public class SkipCommand extends AbstractMusicCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addOptions(new OptionData(OptionType.INTEGER, "skip", "Number of tracks to skip")
|
builder.addOptions(new OptionData(OptionType.INTEGER, "skip", "Number of tracks to skip")
|
||||||
.setMinValue(1));
|
.setMinValue(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
import me.bobert.netneutrality.utils.UserFunction;
|
import me.bobert.netneutrality.utils.UserFunction;
|
||||||
|
|
||||||
public class StopCommand extends AbstractMusicCommand {
|
public class StopCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MessageFunction;
|
import me.bobert.netneutrality.utils.MessageFunction;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class ViewQueueCommand extends AbstractMusicCommand {
|
public class ViewQueueCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
@@ -17,7 +17,7 @@ import me.bobert.netneutrality.utils.UserFunction;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
|
||||||
public class VolumeCommand extends AbstractMusicCommand {
|
public class VolumeCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@@ -37,7 +37,7 @@ public class VolumeCommand extends AbstractMusicCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||||
builder.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for this session", true)
|
builder.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for this session", true)
|
||||||
.setRequiredRange(0, 100));
|
.setRequiredRange(0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ package me.bobert.netneutrality.command.music;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMusicCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.music.MusicManager;
|
import me.bobert.netneutrality.music.MusicManager;
|
||||||
import me.bobert.netneutrality.utils.MusicUtils;
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
|
|
||||||
public class VoteSkipCommand extends AbstractMusicCommand {
|
public class VoteSkipCommand extends MusicCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package me.bobert.netneutrality.command.react;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMessageMenuCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||||
import me.bobert.netneutrality.tasks.reaction.EmojiRoleFirstStep;
|
import me.bobert.netneutrality.tasks.reaction.EmojiRoleFirstStep;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
public class CreateEmojiReaction extends AbstractMessageMenuCommand {
|
public class CreateEmojiReaction extends MessageMenuCommand {
|
||||||
@Override
|
@Override
|
||||||
public CommandExecutionResult execute(Message target, CommandContext context) {
|
public CommandExecutionResult execute(Message target, CommandContext context) {
|
||||||
EmojiReactionRoleTask task = TaskManager.getInstance().findTaskByPartialId(EmojiReactionRoleTask.class, target.getId()).orElse(null);
|
EmojiReactionRoleTask task = TaskManager.getInstance().findTaskByPartialId(EmojiReactionRoleTask.class, target.getId()).orElse(null);
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package me.bobert.netneutrality.command.react;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.AbstractMessageMenuCommand;
|
|
||||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||||
import me.bobert.netneutrality.tasks.reaction.EmojiRoleModify;
|
import me.bobert.netneutrality.tasks.reaction.EmojiRoleModify;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
public class ModifyEmojiReaction extends AbstractMessageMenuCommand {
|
public class ModifyEmojiReaction extends MessageMenuCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandExecutionResult execute(Message target, CommandContext context) {
|
public CommandExecutionResult execute(Message target, CommandContext context) {
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ package me.bobert.netneutrality.context;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.context.AbstractContext;
|
import me.bobert.netneutrality.core.context.AbstractContext;
|
||||||
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
import net.dv8tion.jda.api.modals.Modal;
|
||||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class AsyncContext extends AbstractContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (hook != null) {
|
if (hook != null) {
|
||||||
hook.sendMessage(messageCreateData).queue();
|
hook.sendMessage(messageCreateData).queue();
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ public class AsyncContext extends AbstractContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void edit(MessageEditData messageEditData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
public void edit(MessageEditData messageEditData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (hook != null) {
|
if (hook != null) {
|
||||||
hook.editOriginal(messageEditData).queue();
|
hook.editOriginal(messageEditData).queue();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ package me.bobert.netneutrality.context;
|
|||||||
|
|
||||||
import me.bobert.netneutrality.core.context.AbstractContext;
|
import me.bobert.netneutrality.core.context.AbstractContext;
|
||||||
import me.bobert.netneutrality.core.context.NoMessageContext;
|
import me.bobert.netneutrality.core.context.NoMessageContext;
|
||||||
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,7 +43,7 @@ public class MusicChannelContext extends AbstractContext implements NoMessageCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (getChannel().canTalk()) {
|
if (getChannel().canTalk()) {
|
||||||
getChannel().sendMessage(messageCreateData).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
getChannel().sendMessage(messageCreateData).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import me.bobert.netneutrality.core.command.options.MessageCommandOption;
|
|||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.context.MessageContext;
|
import me.bobert.netneutrality.core.context.MessageContext;
|
||||||
import me.bobert.netneutrality.utils.Settings;
|
import me.bobert.netneutrality.utils.Settings;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Mentions;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
@@ -41,10 +44,10 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return String.format("%s:%s:%s:%s",
|
return String.format("%s:%s:%s:%s",
|
||||||
getGuild() == null ? "PrivateMessage" : getGuild().getId(),
|
getGuild() == null ? "PrivateMessage" : getGuild().getId(),
|
||||||
getChannel().getId(),
|
getChannel().getId(),
|
||||||
getDiscordUser().getId(),
|
getDiscordUser().getId(),
|
||||||
message.getId());
|
message.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,6 +58,7 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
@Override
|
@Override
|
||||||
public List<CommandOption> parseOptions(String[] args, List<OptionData> commandOptions) {
|
public List<CommandOption> parseOptions(String[] args, List<OptionData> commandOptions) {
|
||||||
List<CommandOption> options = new ArrayList<>();
|
List<CommandOption> options = new ArrayList<>();
|
||||||
|
int required = commandOptions.stream().filter(OptionData::isRequired).toList().size();
|
||||||
Mentions mentions = message.getMentions();
|
Mentions mentions = message.getMentions();
|
||||||
int roleMentionIndex = 0;
|
int roleMentionIndex = 0;
|
||||||
int userMentionIndex = 0;
|
int userMentionIndex = 0;
|
||||||
@@ -71,13 +75,59 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
try {
|
try {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case STRING -> {
|
case STRING -> {
|
||||||
String str = args[index];
|
int currentOptionIndex = commandOptions.indexOf(data);
|
||||||
|
boolean nextOptionIsString = false;
|
||||||
|
if (currentOptionIndex + 1 < commandOptions.size()) {
|
||||||
|
OptionData nextOption = commandOptions.get(currentOptionIndex + 1);
|
||||||
|
nextOptionIsString = nextOption.getType() == OptionType.STRING;
|
||||||
|
}
|
||||||
|
|
||||||
if ((str.contains("<@") || str.contains("<#")) && str.contains(">")) {
|
StringBuilder strBuilder = new StringBuilder();
|
||||||
invalidateContext(data, "expected a string at position " + (index + 1) + " but a role/user/channel was provided");
|
if (!nextOptionIsString) {
|
||||||
|
while (index < args.length) {
|
||||||
|
String nextArg = args[index];
|
||||||
|
|
||||||
|
if ((nextArg.contains("<@") || nextArg.contains("<#") || nextArg.contains("<@&")) && nextArg.contains(">")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextArg.equalsIgnoreCase("true") || nextArg.equalsIgnoreCase("false")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Long.parseLong(nextArg);
|
||||||
|
break;
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Double.parseDouble(nextArg);
|
||||||
|
break;
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
|
||||||
|
if (!strBuilder.isEmpty()) {
|
||||||
|
strBuilder.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
strBuilder.append(nextArg);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update index to skip the concatenated strings
|
||||||
|
index = index - 1;
|
||||||
|
} else {
|
||||||
|
// Next option is also a string, so just take the current argument
|
||||||
|
if (index < args.length) {
|
||||||
|
strBuilder.append(args[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strBuilder.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String str = strBuilder.toString();
|
||||||
|
|
||||||
if (!choices.isEmpty()) {
|
if (!choices.isEmpty()) {
|
||||||
List<Command.Choice> matched = choices.stream().filter(choice -> choice.getAsString().equalsIgnoreCase(str)).toList();
|
List<Command.Choice> matched = choices.stream().filter(choice -> choice.getAsString().equalsIgnoreCase(str)).toList();
|
||||||
if (matched.isEmpty()) {
|
if (matched.isEmpty()) {
|
||||||
@@ -116,8 +166,6 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
} else if (max != null && num > max.longValue()) {
|
} else if (max != null && num > max.longValue()) {
|
||||||
value = max.longValue();
|
value = max.longValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
value = num;
|
|
||||||
}
|
}
|
||||||
case BOOLEAN -> {
|
case BOOLEAN -> {
|
||||||
String str = args[index];
|
String str = args[index];
|
||||||
@@ -129,7 +177,7 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
invalidateContext(data, "expected true or false");
|
invalidateContext(data, "expected true or false");
|
||||||
}
|
}
|
||||||
case NUMBER -> {
|
case NUMBER -> {
|
||||||
double num = Long.parseLong(args[index]);
|
double num = Double.parseDouble(args[index]);
|
||||||
if (!choices.isEmpty()) {
|
if (!choices.isEmpty()) {
|
||||||
List<Command.Choice> matched = choices.stream().filter(choice -> choice.getAsDouble() == num).toList();
|
List<Command.Choice> matched = choices.stream().filter(choice -> choice.getAsDouble() == num).toList();
|
||||||
if (matched.isEmpty()) {
|
if (matched.isEmpty()) {
|
||||||
@@ -206,9 +254,9 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
if (mentions.getChannels().size() > channelMentionIndex) {
|
if (mentions.getChannels().size() > channelMentionIndex) {
|
||||||
GuildChannel channel = mentions.getChannels().get(channelMentionIndex++);
|
GuildChannel channel = mentions.getChannels().get(channelMentionIndex++);
|
||||||
|
|
||||||
if (!requiredChannelTypes.contains(channel.getType())) {
|
if (!requiredChannelTypes.isEmpty() && !requiredChannelTypes.contains(channel.getType())) {
|
||||||
invalidateContext(data, "not a valid channel type at index " + (index + 1) +
|
invalidateContext(data, "not a valid channel type at index " + (index + 1) +
|
||||||
" , valid types are: " + validTypes(requiredChannelTypes));
|
" , valid types are: " + validTypes(requiredChannelTypes));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +270,11 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
if (data.isRequired()) {
|
if (options.size() < required) {
|
||||||
|
invalidateContext(data, "missing required argument at index " + (index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.isRequired() && index < required) {
|
||||||
// This should never happen because required options are validated before calling parseOptions()
|
// This should never happen because required options are validated before calling parseOptions()
|
||||||
throw new IllegalArgumentException("Required option " + data.getName() + " was not found at index " + index);
|
throw new IllegalArgumentException("Required option " + data.getName() + " was not found at index " + index);
|
||||||
}
|
}
|
||||||
@@ -237,6 +289,13 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there are leftover arguments that weren't consumed
|
||||||
|
if (index < args.length) {
|
||||||
|
if (options.size() >= required) {
|
||||||
|
invalidateContext(commandOptions.getLast(), "too many arguments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,8 @@ package me.bobert.netneutrality.context.tasks;
|
|||||||
import me.bobert.netneutrality.context.AsyncContext;
|
import me.bobert.netneutrality.context.AsyncContext;
|
||||||
import me.bobert.netneutrality.core.context.NoMessageContext;
|
import me.bobert.netneutrality.core.context.NoMessageContext;
|
||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
|
||||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,7 +42,7 @@ public class EmojiTaskContext extends TaskContext implements NoMessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (getChannel() != null && getChannel().canTalk()) {
|
if (getChannel() != null && getChannel().canTalk()) {
|
||||||
getChannel().sendMessage(messageCreateData).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
getChannel().sendMessage(messageCreateData).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ public class LogHandler {
|
|||||||
|
|
||||||
public static void sendMessageToDebugChannel(Guild guild, String message) {
|
public static void sendMessageToDebugChannel(Guild guild, String message) {
|
||||||
guild.getTextChannels()
|
guild.getTextChannels()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||||
.filter(TextChannel::canTalk)
|
.filter(TextChannel::canTalk)
|
||||||
.forEach(textChannel -> textChannel.sendMessage(message).queue());
|
.forEach(textChannel -> textChannel.sendMessage(message).queue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +63,8 @@ public class LogHandler {
|
|||||||
String guildId = context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId();
|
String guildId = context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId();
|
||||||
|
|
||||||
logger.error("Exception thrown from context (guild: {}, user: {}): {}", guildId,
|
logger.error("Exception thrown from context (guild: {}, user: {}): {}", guildId,
|
||||||
context.getDiscordUser().getId(),
|
context.getDiscordUser().getId(),
|
||||||
exception.getMessage()
|
exception.getMessage()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (context instanceof CommandContext commandContext) {
|
if (context instanceof CommandContext commandContext) {
|
||||||
@@ -82,11 +82,11 @@ public class LogHandler {
|
|||||||
if (context.getGuild() != null) {
|
if (context.getGuild() != null) {
|
||||||
if (GuildService.get(context.getGuild()).isDebugEnabled()) {
|
if (GuildService.get(context.getGuild()).isDebugEnabled()) {
|
||||||
context.getGuild()
|
context.getGuild()
|
||||||
.getTextChannels()
|
.getTextChannels()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||||
.filter(TextChannel::canTalk)
|
.filter(TextChannel::canTalk)
|
||||||
.forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue());
|
.forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package me.bobert.netneutrality.core.command;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
|
|||||||
@@ -5,35 +5,178 @@ package me.bobert.netneutrality.core.command;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptions;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
|
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
public class CommandContainer {
|
public class CommandContainer {
|
||||||
public static final CommandContainer NULL_COMMAND = new CommandContainer(null);
|
public static final CommandContainer NULL_COMMAND = new CommandContainer(null);
|
||||||
private final Command command;
|
private final Command command;
|
||||||
private CommandOptions commandOptions;
|
private CommandDataImpl commandData;
|
||||||
|
private List<OptionData> options;
|
||||||
|
private List<SubcommandData> subcommands;
|
||||||
|
private List<SubcommandGroupData> subcommandGroups;
|
||||||
|
|
||||||
public CommandContainer(Command command) {
|
public CommandContainer(Command command) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
|
||||||
|
if (command != null) {
|
||||||
|
CommandOptionsBuilder commandOptionsBuilder = new CommandOptionsBuilder(command.getType(), command);
|
||||||
|
command.registerCommandOptions(commandOptionsBuilder);
|
||||||
|
initContainer(commandOptionsBuilder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command getCommand() {
|
public Command getCommand() {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandOptions getCommandOptions() {
|
public SlashCommandData getSlashCommandData() {
|
||||||
return commandOptions;
|
return commandData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public List<OptionData> getOptions() {
|
||||||
initOptions();
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initOptions() {
|
public List<SubcommandData> getSubcommands() {
|
||||||
if (command != null) {
|
return subcommands;
|
||||||
CommandOptionsBuilder commandOptionsBuilder = new CommandOptionsBuilder(command.getType(), command);
|
}
|
||||||
command.registerCommandOptions(commandOptionsBuilder);
|
|
||||||
commandOptions = commandOptionsBuilder.build();
|
public List<SubcommandGroupData> getSubcommandGroups() {
|
||||||
|
return subcommandGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initContainer(CommandOptionsBuilder builder) {
|
||||||
|
this.commandData = builder.build();
|
||||||
|
this.options = commandData.getOptions();
|
||||||
|
this.subcommands = commandData.getSubcommands();
|
||||||
|
this.subcommandGroups = commandData.getSubcommandGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return options.isEmpty() && subcommands.isEmpty() && subcommandGroups.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String printUsage() {
|
||||||
|
StringBuilder usage = new StringBuilder();
|
||||||
|
if (!options.isEmpty()) {
|
||||||
|
usage.append("- Usage: /").append(command.getCommandName());
|
||||||
|
for (OptionData option : options) {
|
||||||
|
usage.append(" <").append(option.getName()).append(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(printOptions(options, null, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!subcommands.isEmpty()) {
|
||||||
|
for (SubcommandData subcommand : subcommands) {
|
||||||
|
usage.append("- Usage: /").append(command.getCommandName()).append(" ").append(subcommand.getName());
|
||||||
|
|
||||||
|
for (OptionData option : subcommand.getOptions()) {
|
||||||
|
usage.append(" <").append(option.getName()).append(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(" (").append(subcommand.getDescription()).append(")");
|
||||||
|
usage.append(printOptions(subcommand.getOptions(), null, false));
|
||||||
|
|
||||||
|
usage.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subcommandGroups.isEmpty()) {
|
||||||
|
for (SubcommandGroupData subcommandGroup : subcommandGroups) {
|
||||||
|
usage.append("- Subcommand: /").append(command.getCommandName())
|
||||||
|
.append(" ").append(subcommandGroup.getName())
|
||||||
|
.append(" (").append(subcommandGroup.getDescription()).append(")")
|
||||||
|
.append("\n");
|
||||||
|
|
||||||
|
for (SubcommandData subcommand : subcommandGroup.getSubcommands()) {
|
||||||
|
usage.append(" - Usage: /").append(command.getCommandName())
|
||||||
|
.append(" ").append(subcommandGroup.getName())
|
||||||
|
.append(" ").append(subcommand.getName());
|
||||||
|
|
||||||
|
for (OptionData option : subcommand.getOptions()) {
|
||||||
|
usage.append(" <").append(option.getName()).append(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(printOptions(subcommand.getOptions(), subcommand.getDescription(), true));
|
||||||
|
|
||||||
|
usage.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty()) {
|
||||||
|
usage.append("\n\n-# *: required argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
return usage.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String printOptions(List<OptionData> options, String description, boolean group) {
|
||||||
|
StringBuilder usage = new StringBuilder();
|
||||||
|
|
||||||
|
if (description != null) {
|
||||||
|
usage.append(" (").append(description).append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (OptionData option : options) {
|
||||||
|
usage.append("\n");
|
||||||
|
if (group) {
|
||||||
|
usage.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(" - ");
|
||||||
|
if (option.isRequired()) {
|
||||||
|
usage.append("*");
|
||||||
|
}
|
||||||
|
usage.append(option.getName()).append(": ").append(option.getDescription());
|
||||||
|
|
||||||
|
if (option.getMinValue() != null) {
|
||||||
|
usage.append(" [Min value: ").append(option.getMinValue().longValue()).append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.getMaxValue() != null) {
|
||||||
|
usage.append(" [Max value: ").append(option.getMaxValue().longValue()).append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.getMinLength() != null) {
|
||||||
|
usage.append(" [Min length: ").append(option.getMinLength().longValue()).append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.getMaxLength() != null) {
|
||||||
|
usage.append(" [Max length: ").append(option.getMaxLength().longValue()).append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices = option.getChoices();
|
||||||
|
if (!choices.isEmpty()) {
|
||||||
|
StringJoiner joiner = new StringJoiner(", ");
|
||||||
|
for (net.dv8tion.jda.api.interactions.commands.Command.Choice choice : choices) {
|
||||||
|
joiner.add(choice.getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(" [Available choices: ").append(joiner).append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<ChannelType> requiredChannelTypes = option.getChannelTypes();
|
||||||
|
if (!requiredChannelTypes.isEmpty()) {
|
||||||
|
StringJoiner joiner = new StringJoiner(", ");
|
||||||
|
for (ChannelType type : requiredChannelTypes) {
|
||||||
|
joiner.add(type.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.append(" [Required channel types: ").append(joiner).append("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return usage.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,16 +5,19 @@ package me.bobert.netneutrality.core.command;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import me.bobert.netneutrality.utils.ReflectionHelper;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionContextType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.reflections.Reflections;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.util.ArrayList;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
@@ -30,45 +33,32 @@ public class CommandManager {
|
|||||||
logger.info("Loaded {} commands!", commands.size());
|
logger.info("Loaded {} commands!", commands.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Command getCommand(String commandString) {
|
|
||||||
return getCommandContainer(commandString).getCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandContainer getCommandContainer(String commandString) {
|
public static CommandContainer getCommandContainer(String commandString) {
|
||||||
return commands.getOrDefault(commandString, CommandContainer.NULL_COMMAND);
|
return commands.getOrDefault(commandString, CommandContainer.NULL_COMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initCommands() {
|
public static void initCommands() {
|
||||||
Set<Class<? extends Command>> classes = new Reflections("me.bobert.netneutrality.command").getSubTypesOf(Command.class);
|
ReflectionHelper.loadCommands(Command.class, command -> {
|
||||||
for (Class<? extends Command> s : classes) {
|
if (!command.isEnabled()) {
|
||||||
try {
|
logger.info("Skipping command {} as it is disabled", command.getClass().getName());
|
||||||
if (Modifier.isAbstract(s.getModifiers())) {
|
return;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Command command = s.getConstructor().newInstance();
|
|
||||||
if (!command.isEnabled()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.getCommandName() == null) {
|
|
||||||
throw new IllegalArgumentException("Command name is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.getDescription() == null && command.getType() == Command.Type.SLASH) {
|
|
||||||
throw new IllegalArgumentException("Command description is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandContainer container = new CommandContainer(command);
|
|
||||||
container.init();
|
|
||||||
|
|
||||||
if (!commands.containsKey(command.getCommandName())) {
|
|
||||||
commands.put(command.getCommandName(), container);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Failed to load command {}: {}", s.getSimpleName(), e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (command.getCommandName() == null) {
|
||||||
|
logger.error("Failed to load command {}: Command name is null", command.getClass().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.getDescription() == null && command.getType() == Command.Type.SLASH) {
|
||||||
|
logger.error("Failed to load command {}: Command description is null", command.getClass().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandContainer container = new CommandContainer(command);
|
||||||
|
if (!commands.containsKey(command.getCommandName())) {
|
||||||
|
commands.put(command.getCommandName(), container);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerSlashCommands(JDA jda) {
|
public static void registerSlashCommands(JDA jda) {
|
||||||
@@ -83,9 +73,9 @@ public class CommandManager {
|
|||||||
logger.debug("Registering slash command: {}", command.getCommandName());
|
logger.debug("Registering slash command: {}", command.getCommandName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SlashCommandData data = container.getCommandOptions().getSlashCommandData();
|
SlashCommandData data = container.getSlashCommandData();
|
||||||
data.setDefaultPermissions(command.getSlashCommandPermission());
|
data.setDefaultPermissions(command.getSlashCommandPermission());
|
||||||
data.setGuildOnly(command.isGuildOnly());
|
data.setContexts(command.isGuildOnly() ? Set.of(InteractionContextType.GUILD) : Set.of(InteractionContextType.GUILD, InteractionContextType.BOT_DM));
|
||||||
|
|
||||||
slashCommands.add(data);
|
slashCommands.add(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+26
-11
@@ -1,30 +1,35 @@
|
|||||||
package me.bobert.netneutrality.core.command.options;
|
package me.bobert.netneutrality.core.command;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.Command;
|
|
||||||
import net.dv8tion.jda.api.interactions.DiscordLocale;
|
import net.dv8tion.jda.api.interactions.DiscordLocale;
|
||||||
|
import net.dv8tion.jda.api.interactions.IntegrationType;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionContextType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.*;
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction;
|
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction;
|
||||||
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationMap;
|
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationMap;
|
||||||
import net.dv8tion.jda.api.utils.data.DataObject;
|
import net.dv8tion.jda.api.utils.data.DataObject;
|
||||||
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class CommandOptionsBuilder implements SlashCommandData {
|
public class CommandOptionsBuilder implements SlashCommandData {
|
||||||
private final Command command;
|
|
||||||
private CommandDataImpl commandData;
|
private CommandDataImpl commandData;
|
||||||
|
|
||||||
public CommandOptionsBuilder(Command.Type type, Command command) {
|
public CommandOptionsBuilder(Command.Type type, Command command) {
|
||||||
this.command = command;
|
|
||||||
|
|
||||||
if (type == Command.Type.SLASH) {
|
if (type == Command.Type.SLASH) {
|
||||||
commandData = (CommandDataImpl) Commands.slash(command.getCommandName(), command.getDescription());
|
commandData = (CommandDataImpl) Commands.slash(command.getCommandName(), command.getDescription());
|
||||||
@@ -39,8 +44,8 @@ public class CommandOptionsBuilder implements SlashCommandData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandOptions build() {
|
public CommandDataImpl build() {
|
||||||
return new CommandOptions(command, commandData);
|
return commandData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -69,8 +74,13 @@ public class CommandOptionsBuilder implements SlashCommandData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nonnull SlashCommandData setGuildOnly(boolean guildOnly) {
|
public @Nonnull SlashCommandData setContexts(@Nonnull Collection<InteractionContextType> contexts) {
|
||||||
return commandData.setGuildOnly(guildOnly);
|
return commandData.setContexts(contexts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nonnull SlashCommandData setIntegrationTypes(@Nonnull Collection<IntegrationType> integrationTypes) {
|
||||||
|
return commandData.setIntegrationTypes(integrationTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,8 +109,13 @@ public class CommandOptionsBuilder implements SlashCommandData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGuildOnly() {
|
public @Nonnull Set<InteractionContextType> getContexts() {
|
||||||
return commandData.isGuildOnly();
|
return commandData.getContexts();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nonnull Set<IntegrationType> getIntegrationTypes() {
|
||||||
|
return commandData.getIntegrationTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -8,15 +8,12 @@ package me.bobert.netneutrality.core.command;
|
|||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import me.bobert.netneutrality.context.command.SlashCommandContext;
|
import me.bobert.netneutrality.context.command.SlashCommandContext;
|
||||||
import me.bobert.netneutrality.core.LogHandler;
|
import me.bobert.netneutrality.core.LogHandler;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptions;
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.context.InteractionContext;
|
import me.bobert.netneutrality.core.context.InteractionContext;
|
||||||
import me.bobert.netneutrality.core.tasks.Task;
|
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import me.bobert.netneutrality.exceptions.CommandExecutionException;
|
import me.bobert.netneutrality.exceptions.CommandExecutionException;
|
||||||
import me.bobert.netneutrality.exceptions.GracefulContextError;
|
import me.bobert.netneutrality.exceptions.GracefulContextError;
|
||||||
import me.bobert.netneutrality.utils.UserFunction;
|
import me.bobert.netneutrality.utils.UserFunction;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
@@ -29,7 +26,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.function.Predicate.not;
|
import static java.util.function.Predicate.not;
|
||||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.*;
|
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.ERROR;
|
||||||
|
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.NOACTION;
|
||||||
|
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.TASK;
|
||||||
|
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.WARN;
|
||||||
|
|
||||||
public class CommandProcessor {
|
public class CommandProcessor {
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Context ID: {}", context.getId());
|
logger.debug("Context ID: {}", context.getId());
|
||||||
logger.info("Executing command {} on guild {}", command.getCommandName(), context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId());
|
logger.info("Executing command {} on guild {}", command.getCommandName(), context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId());
|
||||||
configureSentry(command);
|
configureSentry(command);
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class CommandProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.getType() == Command.Type.SLASH && !checkUsage(container.getCommandOptions())) {
|
if (command.getType() == Command.Type.SLASH && !checkUsage(container)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,10 +123,10 @@ public class CommandProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkUsage(CommandOptions commandOptions) {
|
private boolean checkUsage(CommandContainer container) {
|
||||||
List<SubcommandGroupData> groups = commandOptions.getSubcommandGroups();
|
List<SubcommandGroupData> groups = container.getSubcommandGroups();
|
||||||
List<SubcommandData> subcommands = commandOptions.getSubcommands();
|
List<SubcommandData> subcommands = container.getSubcommands();
|
||||||
List<OptionData> options = commandOptions.getOptions();
|
List<OptionData> options = container.getOptions();
|
||||||
String[] possibleCommands = Arrays.stream(context.getFullCommand().split(" ")).skip(1).toArray(String[]::new);
|
String[] possibleCommands = Arrays.stream(context.getFullCommand().split(" ")).skip(1).toArray(String[]::new);
|
||||||
if (possibleCommands.length == 0) {
|
if (possibleCommands.length == 0) {
|
||||||
if (!groups.isEmpty()) {
|
if (!groups.isEmpty()) {
|
||||||
@@ -203,22 +203,6 @@ public class CommandProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if last option is a string, if it is then combine all remaining strings into one
|
|
||||||
// ["@user", "you", "are", "banned"] becomes ["@user", "you are banned"]
|
|
||||||
if (!options.isEmpty() && arguments.size() > 1) {
|
|
||||||
OptionData last = options.get(options.size() - 1);
|
|
||||||
if (last.getType() == OptionType.STRING) {
|
|
||||||
List<String> lastArgs = arguments.stream().skip(options.size() - 1).toList();
|
|
||||||
arguments.removeAll(lastArgs);
|
|
||||||
arguments.add(String.join(" ", lastArgs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.size() > required + optional) {
|
|
||||||
context.reply(invalidUsage("too many arguments"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.setCurrentCommandOptions(arguments.toArray(String[]::new), options);
|
context.setCurrentCommandOptions(arguments.toArray(String[]::new), options);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -241,7 +225,7 @@ public class CommandProcessor {
|
|||||||
|
|
||||||
private String invalidUsage(String message) {
|
private String invalidUsage(String message) {
|
||||||
return String.format("Invalid usage for command: %s\n" +
|
return String.format("Invalid usage for command: %s\n" +
|
||||||
"Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName());
|
"Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureSentry(Command command) {
|
private void configureSentry(Command command) {
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.command;
|
package me.bobert.netneutrality.core.command.impl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
@@ -6,6 +6,7 @@ package me.bobert.netneutrality.core.command;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import me.bobert.netneutrality.core.command.Command;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||||
+4
-2
@@ -1,11 +1,13 @@
|
|||||||
package me.bobert.netneutrality.core.command;
|
package me.bobert.netneutrality.core.command.impl;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class AbstractAdminCommand extends AbstractCommand {
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
|
|
||||||
|
public abstract class AdminCommand extends AbstractCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needAdmin() {
|
public boolean needAdmin() {
|
||||||
+5
-3
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.command;
|
package me.bobert.netneutrality.core.command.impl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
@@ -7,11 +7,13 @@ package me.bobert.netneutrality.core.command;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.command.MessageMenuContext;
|
import me.bobert.netneutrality.context.command.MessageMenuContext;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
public abstract class AbstractMessageMenuCommand extends AbstractCommand {
|
public abstract class MessageMenuCommand extends AbstractCommand {
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return null;
|
return null;
|
||||||
+5
-3
@@ -1,10 +1,11 @@
|
|||||||
package me.bobert.netneutrality.core.command;
|
package me.bobert.netneutrality.core.command.impl;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||||
import me.bobert.netneutrality.db.GSettings;
|
import me.bobert.netneutrality.db.GSettings;
|
||||||
import me.bobert.netneutrality.db.service.GuildService;
|
import me.bobert.netneutrality.db.service.GuildService;
|
||||||
import me.bobert.netneutrality.utils.UserFunction;
|
import me.bobert.netneutrality.utils.UserFunction;
|
||||||
@@ -15,7 +16,7 @@ import net.dv8tion.jda.api.entities.channel.ChannelType;
|
|||||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
|
|
||||||
public abstract class AbstractMusicCommand extends AbstractCommand {
|
public abstract class MusicCommand extends AbstractCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needAdmin() {
|
public boolean needAdmin() {
|
||||||
@@ -63,8 +64,9 @@ public abstract class AbstractMusicCommand extends AbstractCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canBeExecutedFrom(MessageChannel channel) {
|
public boolean canBeExecutedFrom(MessageChannel channel) {
|
||||||
if (channel instanceof GuildMessageChannel guildMessageChannel) {
|
if (channel instanceof GuildMessageChannel guildMessageChannel) {
|
||||||
if (channel.getType() != ChannelType.TEXT)
|
if (channel.getType() != ChannelType.TEXT) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String channelDb = GuildService.get(guildMessageChannel.getGuild()).getGuildSettingService().getSetting(GSettings.MUSIC_CHANNEL);
|
String channelDb = GuildService.get(guildMessageChannel.getGuild()).getGuildSettingService().getSetting(GSettings.MUSIC_CHANNEL);
|
||||||
if (channelDb != null && !channelDb.isEmpty()) {
|
if (channelDb != null && !channelDb.isEmpty()) {
|
||||||
+4
-3
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.command;
|
package me.bobert.netneutrality.core.command.impl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
@@ -7,11 +7,12 @@ package me.bobert.netneutrality.core.command;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.command.UserMenuContext;
|
import me.bobert.netneutrality.context.command.UserMenuContext;
|
||||||
import me.bobert.netneutrality.core.command.options.CommandOptionsBuilder;
|
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||||
|
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
|
||||||
public abstract class AbstractUserMenuCommand extends AbstractCommand {
|
public abstract class UserMenuCommand extends AbstractCommand {
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return null;
|
return null;
|
||||||
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.IMentionable;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
@@ -29,10 +33,8 @@ public interface CommandOption {
|
|||||||
* <br>This is represented as an {@link Message.Attachment#isEphemeral() ephemeral} attachment which will only be hosted for up to 2 weeks.
|
* <br>This is represented as an {@link Message.Attachment#isEphemeral() ephemeral} attachment which will only be hosted for up to 2 weeks.
|
||||||
* If you want a permanent reference, you must download it.
|
* If you want a permanent reference, you must download it.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT}
|
|
||||||
*
|
|
||||||
* @return {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment}
|
* @return {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment}
|
||||||
|
* @throws IllegalStateException If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT}
|
||||||
*/
|
*/
|
||||||
Message.Attachment getAsAttachment();
|
Message.Attachment getAsAttachment();
|
||||||
|
|
||||||
@@ -48,10 +50,8 @@ public interface CommandOption {
|
|||||||
/**
|
/**
|
||||||
* The boolean value.
|
* The boolean value.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#BOOLEAN BOOLEAN}
|
|
||||||
*
|
|
||||||
* @return The boolean value
|
* @return The boolean value
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#BOOLEAN BOOLEAN}
|
||||||
*/
|
*/
|
||||||
boolean getAsBoolean();
|
boolean getAsBoolean();
|
||||||
|
|
||||||
@@ -59,12 +59,9 @@ public interface CommandOption {
|
|||||||
* The long value for this option.
|
* The long value for this option.
|
||||||
* <br>This will be the ID of any resolved entity such as {@link Role} or {@link Member}.
|
* <br>This will be the ID of any resolved entity such as {@link Role} or {@link Member}.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option {@link #getType() type} cannot be converted to a long
|
|
||||||
* @throws NumberFormatException
|
|
||||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
|
||||||
*
|
|
||||||
* @return The long value
|
* @return The long value
|
||||||
|
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long
|
||||||
|
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||||
*/
|
*/
|
||||||
long getAsLong();
|
long getAsLong();
|
||||||
|
|
||||||
@@ -74,36 +71,27 @@ public interface CommandOption {
|
|||||||
*
|
*
|
||||||
* <p><b>It is highly recommended to assert int values by using {@link OptionData#setRequiredRange(long, long)}</b>
|
* <p><b>It is highly recommended to assert int values by using {@link OptionData#setRequiredRange(long, long)}</b>
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option {@link #getType() type} cannot be converted to a long
|
|
||||||
* @throws NumberFormatException
|
|
||||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
|
||||||
* @throws ArithmeticException
|
|
||||||
* If the provided integer value cannot fit into a 32bit signed int
|
|
||||||
*
|
|
||||||
* @return The int value
|
* @return The int value
|
||||||
|
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long
|
||||||
|
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||||
|
* @throws ArithmeticException If the provided integer value cannot fit into a 32bit signed int
|
||||||
*/
|
*/
|
||||||
int getAsInt();
|
int getAsInt();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The double value for this option.
|
* The double value for this option.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option {@link #getType() type} cannot be converted to a double
|
|
||||||
* @throws NumberFormatException
|
|
||||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value
|
|
||||||
*
|
|
||||||
* @return The double value
|
* @return The double value
|
||||||
|
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a double
|
||||||
|
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value
|
||||||
*/
|
*/
|
||||||
double getAsDouble();
|
double getAsDouble();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resolved {@link IMentionable} instance for this option value.
|
* The resolved {@link IMentionable} instance for this option value.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If the mentioned entity is not resolvable
|
|
||||||
*
|
|
||||||
* @return The resolved {@link IMentionable}
|
* @return The resolved {@link IMentionable}
|
||||||
|
* @throws IllegalStateException If the mentioned entity is not resolvable
|
||||||
*/
|
*/
|
||||||
IMentionable getAsMentionable();
|
IMentionable getAsMentionable();
|
||||||
|
|
||||||
@@ -111,42 +99,34 @@ public interface CommandOption {
|
|||||||
* The resolved {@link Member} for this option value.
|
* The resolved {@link Member} for this option value.
|
||||||
* <br>Note that {@link OptionType#USER OptionType.USER} can also accept users that are not members of a guild, in which case this will be null!
|
* <br>Note that {@link OptionType#USER OptionType.USER} can also accept users that are not members of a guild, in which case this will be null!
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE}
|
|
||||||
*
|
|
||||||
* @return The resolved {@link Member}, or null
|
* @return The resolved {@link Member}, or null
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE}
|
||||||
*/
|
*/
|
||||||
Member getAsMember();
|
Member getAsMember();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resolved {@link User} for this option value.
|
* The resolved {@link User} for this option value.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#USER USER} or
|
|
||||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user
|
|
||||||
*
|
|
||||||
* @return The resolved {@link User}
|
* @return The resolved {@link User}
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or
|
||||||
|
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user
|
||||||
*/
|
*/
|
||||||
User getAsUser();
|
User getAsUser();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resolved {@link Role} for this option value.
|
* The resolved {@link Role} for this option value.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#ROLE ROLE} or
|
|
||||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role
|
|
||||||
*
|
|
||||||
* @return The resolved {@link Role}
|
* @return The resolved {@link Role}
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#ROLE ROLE} or
|
||||||
|
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role
|
||||||
*/
|
*/
|
||||||
Role getAsRole();
|
Role getAsRole();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ChannelType} for the resolved channel.
|
* The {@link ChannelType} for the resolved channel.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
|
||||||
*
|
|
||||||
* @return The {@link ChannelType}
|
* @return The {@link ChannelType}
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||||
*/
|
*/
|
||||||
ChannelType getChannelType();
|
ChannelType getChannelType();
|
||||||
|
|
||||||
@@ -154,11 +134,9 @@ public interface CommandOption {
|
|||||||
* The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel} for this option value.
|
* The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel} for this option value.
|
||||||
* <br>Note that {@link OptionType#CHANNEL OptionType.CHANNEL} can accept channels of any type!
|
* <br>Note that {@link OptionType#CHANNEL OptionType.CHANNEL} can accept channels of any type!
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
|
||||||
* If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
|
||||||
* or could not be resolved for unexpected reasons
|
|
||||||
*
|
|
||||||
* @return The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel}
|
* @return The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel}
|
||||||
|
* @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||||
|
* or could not be resolved for unexpected reasons
|
||||||
*/
|
*/
|
||||||
GuildChannelUnion getAsChannel();
|
GuildChannelUnion getAsChannel();
|
||||||
}
|
}
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
package me.bobert.netneutrality.core.command.options;
|
|
||||||
/*
|
|
||||||
* Copyright (c) anthorob
|
|
||||||
*
|
|
||||||
* https://discord.gg/qUa6zNFZsd
|
|
||||||
*/
|
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.command.Command;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
|
||||||
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
public class CommandOptions {
|
|
||||||
private final Command command;
|
|
||||||
private final CommandDataImpl commandData;
|
|
||||||
private final List<OptionData> options;
|
|
||||||
private final List<SubcommandData> subcommands;
|
|
||||||
private final List<SubcommandGroupData> subcommandGroups;
|
|
||||||
|
|
||||||
public CommandOptions(Command command, CommandDataImpl commandData) {
|
|
||||||
this.command = command;
|
|
||||||
this.commandData = commandData;
|
|
||||||
this.options = commandData.getOptions();
|
|
||||||
this.subcommands = commandData.getSubcommands();
|
|
||||||
this.subcommandGroups = commandData.getSubcommandGroups();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command getCommand() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlashCommandData getSlashCommandData() {
|
|
||||||
return commandData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OptionData> getOptions() {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SubcommandData> getSubcommands() {
|
|
||||||
return subcommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SubcommandGroupData> getSubcommandGroups() {
|
|
||||||
return subcommandGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return options.isEmpty() && subcommands.isEmpty() && subcommandGroups.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String printUsage() {
|
|
||||||
StringBuilder usage = new StringBuilder();
|
|
||||||
if (!options.isEmpty()) {
|
|
||||||
usage.append("- Usage: /").append(command.getCommandName());
|
|
||||||
for (OptionData option : options) {
|
|
||||||
usage.append(" <").append(option.getName()).append(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
usage.append(printOptions(options, null, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subcommands.isEmpty()) {
|
|
||||||
for (SubcommandData subcommand : subcommands) {
|
|
||||||
usage.append("- Usage: /").append(command.getCommandName()).append(" ").append(subcommand.getName());
|
|
||||||
|
|
||||||
for (OptionData option : subcommand.getOptions()) {
|
|
||||||
usage.append(" <").append(option.getName()).append(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
usage.append(" (").append(subcommand.getDescription()).append(")");
|
|
||||||
usage.append(printOptions(subcommand.getOptions(), null, false));
|
|
||||||
|
|
||||||
usage.append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subcommandGroups.isEmpty()) {
|
|
||||||
for (SubcommandGroupData subcommandGroup : subcommandGroups) {
|
|
||||||
usage.append("- Subcommand: /").append(command.getCommandName())
|
|
||||||
.append(" ").append(subcommandGroup.getName())
|
|
||||||
.append(" (").append(subcommandGroup.getDescription()).append(")")
|
|
||||||
.append("\n");
|
|
||||||
|
|
||||||
for (SubcommandData subcommand : subcommandGroup.getSubcommands()) {
|
|
||||||
usage.append(" - Usage: /").append(command.getCommandName())
|
|
||||||
.append(" ").append(subcommandGroup.getName())
|
|
||||||
.append(" ").append(subcommand.getName());
|
|
||||||
|
|
||||||
for (OptionData option : subcommand.getOptions()) {
|
|
||||||
usage.append(" <").append(option.getName()).append(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
usage.append(printOptions(subcommand.getOptions(), subcommand.getDescription(), true));
|
|
||||||
|
|
||||||
usage.append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isEmpty()) {
|
|
||||||
usage.append("\n\n-# *: required argument");
|
|
||||||
}
|
|
||||||
|
|
||||||
return usage.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String printOptions(List<OptionData> options, String description, boolean group) {
|
|
||||||
StringBuilder usage = new StringBuilder();
|
|
||||||
|
|
||||||
if (description != null) {
|
|
||||||
usage.append(" (").append(description).append(")");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (OptionData option : options) {
|
|
||||||
usage.append("\n");
|
|
||||||
if (group) usage.append(" ");
|
|
||||||
usage.append(" - ");
|
|
||||||
if (option.isRequired()) {
|
|
||||||
usage.append("*");
|
|
||||||
}
|
|
||||||
usage.append(option.getName()).append(": ").append(option.getDescription());
|
|
||||||
|
|
||||||
if (option.getMinValue() != null) {
|
|
||||||
usage.append(" [Min value: ").append(option.getMinValue().longValue()).append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option.getMaxValue() != null) {
|
|
||||||
usage.append(" [Max value: ").append(option.getMaxValue().longValue()).append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option.getMinLength() != null) {
|
|
||||||
usage.append(" [Min length: ").append(option.getMinLength().longValue()).append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option.getMaxLength() != null) {
|
|
||||||
usage.append(" [Max length: ").append(option.getMaxLength().longValue()).append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices = option.getChoices();
|
|
||||||
if (!choices.isEmpty()) {
|
|
||||||
StringJoiner joiner = new StringJoiner(", ");
|
|
||||||
for (net.dv8tion.jda.api.interactions.commands.Command.Choice choice : choices) {
|
|
||||||
joiner.add(choice.getAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
usage.append(" [Available choices: ").append(joiner).append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<ChannelType> requiredChannelTypes = option.getChannelTypes();
|
|
||||||
if (!requiredChannelTypes.isEmpty()) {
|
|
||||||
StringJoiner joiner = new StringJoiner(", ");
|
|
||||||
for (ChannelType type : requiredChannelTypes) {
|
|
||||||
joiner.add(type.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
usage.append(" [Required channel types: ").append(joiner).append("]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return usage.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+13
-5
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.IMentionable;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
@@ -116,6 +120,10 @@ public class MessageCommandOption implements CommandOption {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getAsUser() {
|
public User getAsUser() {
|
||||||
|
if (value instanceof Member) {
|
||||||
|
return ((Member) value).getUser();
|
||||||
|
}
|
||||||
|
|
||||||
if (value instanceof User) {
|
if (value instanceof User) {
|
||||||
return (User) value;
|
return (User) value;
|
||||||
}
|
}
|
||||||
@@ -149,9 +157,9 @@ public class MessageCommandOption implements CommandOption {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MessageCommandOption{" +
|
return "MessageCommandOption{" +
|
||||||
"name=" + data.getName() +
|
"name=" + data.getName() +
|
||||||
", type=" + type +
|
", type=" + type +
|
||||||
", value=" + value +
|
", value=" + value +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.IMentionable;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ package me.bobert.netneutrality.core.context;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import me.bobert.netneutrality.context.command.SlashCommandContext;
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
|||||||
@@ -17,7 +17,12 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -26,7 +31,7 @@ public abstract class CommandContext extends AbstractContext {
|
|||||||
private Command command;
|
private Command command;
|
||||||
private SubcommandGroupData subcommandGroup;
|
private SubcommandGroupData subcommandGroup;
|
||||||
private SubcommandData subcommand;
|
private SubcommandData subcommand;
|
||||||
private final Map <OptionData, String> invalidOptions = new HashMap<>();
|
private final Map<OptionData, String> invalidOptions = new HashMap<>();
|
||||||
private final List<CommandOption> options;
|
private final List<CommandOption> options;
|
||||||
|
|
||||||
public CommandContext(JDA jda, Guild guild, MessageChannel channel, Member member, User user) {
|
public CommandContext(JDA jda, Guild guild, MessageChannel channel, Member member, User user) {
|
||||||
@@ -70,16 +75,20 @@ public abstract class CommandContext extends AbstractContext {
|
|||||||
public <T> T getOption(String name, Supplier<? extends T> fallback, Function<? super CommandOption, ? extends T> resolver) {
|
public <T> T getOption(String name, Supplier<? extends T> fallback, Function<? super CommandOption, ? extends T> resolver) {
|
||||||
Objects.requireNonNull(resolver, "resolver cannot be null");
|
Objects.requireNonNull(resolver, "resolver cannot be null");
|
||||||
CommandOption mapping = getOption(name);
|
CommandOption mapping = getOption(name);
|
||||||
if (mapping != null)
|
if (mapping != null) {
|
||||||
return resolver.apply(mapping);
|
return resolver.apply(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
return fallback == null ? null : fallback.get();
|
return fallback == null ? null : fallback.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getOption(String name, T fallback, Function<? super CommandOption, ? extends T> resolver) {
|
public <T> T getOption(String name, T fallback, Function<? super CommandOption, ? extends T> resolver) {
|
||||||
Objects.requireNonNull(resolver, "resolver cannot be null");
|
Objects.requireNonNull(resolver, "resolver cannot be null");
|
||||||
CommandOption mapping = getOption(name);
|
CommandOption mapping = getOption(name);
|
||||||
if (mapping != null)
|
if (mapping != null) {
|
||||||
return resolver.apply(mapping);
|
return resolver.apply(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +141,4 @@ public abstract class CommandContext extends AbstractContext {
|
|||||||
public abstract String parseCommandName();
|
public abstract String parseCommandName();
|
||||||
|
|
||||||
public abstract String getFullCommand();
|
public abstract String getFullCommand();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,17 @@ package me.bobert.netneutrality.core.context;
|
|||||||
import me.bobert.netneutrality.context.AsyncContext;
|
import me.bobert.netneutrality.context.AsyncContext;
|
||||||
import me.bobert.netneutrality.utils.ContextUtils;
|
import me.bobert.netneutrality.utils.ContextUtils;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
import net.dv8tion.jda.api.modals.Modal;
|
||||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
||||||
|
|
||||||
@@ -48,7 +52,7 @@ public interface Context {
|
|||||||
|
|
||||||
void reply(Modal modal);
|
void reply(Modal modal);
|
||||||
|
|
||||||
void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer);
|
void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer);
|
||||||
|
|
||||||
void defer(boolean ephemeral, Consumer<AsyncContext> consumer);
|
void defer(boolean ephemeral, Consumer<AsyncContext> consumer);
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ public interface Context {
|
|||||||
reply(messageCreateData, false, List.of(), asyncMessage -> {});
|
reply(messageCreateData, false, List.of(), asyncMessage -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
default void reply(MessageCreateData messageCreateData, List<LayoutComponent> components) {
|
default void reply(MessageCreateData messageCreateData, List<MessageTopLevelComponent> components) {
|
||||||
reply(messageCreateData, false, components, asyncMessage -> {});
|
reply(messageCreateData, false, components, asyncMessage -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +94,7 @@ public interface Context {
|
|||||||
reply(MessageCreateData.fromEmbeds(embeds));
|
reply(MessageCreateData.fromEmbeds(embeds));
|
||||||
}
|
}
|
||||||
|
|
||||||
default void edit(MessageEditData messageEditData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
default void edit(MessageEditData messageEditData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (isAcknowledged() && getInteractionHook() != null) {
|
if (isAcknowledged() && getInteractionHook() != null) {
|
||||||
getInteractionHook().editOriginal(messageEditData).setComponents(components).queue(message1 -> consumer.accept(new AsyncContext(message1)));
|
getInteractionHook().editOriginal(messageEditData).setComponents(components).queue(message1 -> consumer.accept(new AsyncContext(message1)));
|
||||||
return;
|
return;
|
||||||
@@ -99,7 +103,7 @@ public interface Context {
|
|||||||
reply(MessageCreateData.fromEditData(messageEditData), ephemeral, components, consumer);
|
reply(MessageCreateData.fromEditData(messageEditData), ephemeral, components, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void edit(MessageEditData messageEditData, List<LayoutComponent> components) {
|
default void edit(MessageEditData messageEditData, List<MessageTopLevelComponent> components) {
|
||||||
edit(messageEditData, false, components, asyncMessage -> {});
|
edit(messageEditData, false, components, asyncMessage -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,11 +119,11 @@ public interface Context {
|
|||||||
edit(List.of(embed), List.of());
|
edit(List.of(embed), List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
default void edit(List<MessageEmbed> embeds, List<LayoutComponent> components) {
|
default void edit(List<MessageEmbed> embeds, List<MessageTopLevelComponent> components) {
|
||||||
edit(MessageEditData.fromEmbeds(embeds), components);
|
edit(MessageEditData.fromEmbeds(embeds), components);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void edit(MessageEmbed embed, List<LayoutComponent> components) {
|
default void edit(MessageEmbed embed, List<MessageTopLevelComponent> components) {
|
||||||
edit(List.of(embed), components);
|
edit(List.of(embed), components);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +139,7 @@ public interface Context {
|
|||||||
defer(false, consumer);
|
defer(false, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void replyEphemeral(MessageCreateData messageCreateData, List<LayoutComponent> components) {
|
default void replyEphemeral(MessageCreateData messageCreateData, List<MessageTopLevelComponent> components) {
|
||||||
reply(messageCreateData, true, components, asyncMessage -> {});
|
reply(messageCreateData, true, components, asyncMessage -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +151,11 @@ public interface Context {
|
|||||||
replyEphemeralWithLimit(message);
|
replyEphemeralWithLimit(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void replyEphemeral(String message, List<LayoutComponent> components) {
|
default void replyEphemeral(String message, MessageTopLevelComponent component) {
|
||||||
|
replyEphemeral(message, List.of(component));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void replyEphemeral(String message, List<MessageTopLevelComponent> components) {
|
||||||
replyEphemeral(MessageCreateData.fromContent(message), components);
|
replyEphemeral(MessageCreateData.fromContent(message), components);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,20 +163,20 @@ public interface Context {
|
|||||||
replyEphemeral(MessageCreateData.fromEmbeds(embeds));
|
replyEphemeral(MessageCreateData.fromEmbeds(embeds));
|
||||||
}
|
}
|
||||||
|
|
||||||
default void sendMessageInPrivate(MessageCreateData messageCreateData, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
default void sendMessageInPrivate(MessageCreateData messageCreateData, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
User user = getDiscordUser();
|
User user = getDiscordUser();
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
user.openPrivateChannel()
|
user.openPrivateChannel()
|
||||||
.flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components))
|
.flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components))
|
||||||
.queue(message -> consumer.accept(new AsyncContext(message)));
|
.queue(message -> consumer.accept(new AsyncContext(message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default void sendMessageInPrivate(String message, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
default void sendMessageInPrivate(String message, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
sendMessageInPrivate(MessageCreateData.fromContent(message), components, consumer);
|
sendMessageInPrivate(MessageCreateData.fromContent(message), components, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void sendMessageInPrivate(MessageCreateData messageCreateData, List<LayoutComponent> components) {
|
default void sendMessageInPrivate(MessageCreateData messageCreateData, List<MessageTopLevelComponent> components) {
|
||||||
sendMessageInPrivate(messageCreateData, components, asyncContext -> {});
|
sendMessageInPrivate(messageCreateData, components, asyncContext -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ package me.bobert.netneutrality.core.context;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.AsyncContext;
|
import me.bobert.netneutrality.context.AsyncContext;
|
||||||
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
import net.dv8tion.jda.api.interactions.Interaction;
|
import net.dv8tion.jda.api.interactions.Interaction;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import net.dv8tion.jda.api.interactions.callbacks.IModalCallback;
|
import net.dv8tion.jda.api.interactions.callbacks.IModalCallback;
|
||||||
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
|
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
import net.dv8tion.jda.api.modals.Modal;
|
||||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -58,7 +58,7 @@ public interface InteractionContext extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
default void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (isAcknowledged()) {
|
if (isAcknowledged()) {
|
||||||
getInteractionHook().sendMessage(messageCreateData).setEphemeral(ephemeral).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
getInteractionHook().sendMessage(messageCreateData).setEphemeral(ephemeral).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ package me.bobert.netneutrality.core.context;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.AsyncContext;
|
import me.bobert.netneutrality.context.AsyncContext;
|
||||||
|
import net.dv8tion.jda.api.components.MessageTopLevelComponent;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,7 +32,7 @@ public interface MessageContext extends NoMessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
default void reply(MessageCreateData messageCreateData, boolean ephemeral, List<MessageTopLevelComponent> components, Consumer<AsyncContext> consumer) {
|
||||||
if (ephemeral && getType() != ChannelType.PRIVATE) {
|
if (ephemeral && getType() != ChannelType.PRIVATE) {
|
||||||
sendMessageInPrivate(messageCreateData, components);
|
sendMessageInPrivate(messageCreateData, components);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package me.bobert.netneutrality.core.context;
|
|||||||
import me.bobert.netneutrality.context.AsyncContext;
|
import me.bobert.netneutrality.context.AsyncContext;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
import net.dv8tion.jda.api.modals.Modal;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import me.bobert.netneutrality.utils.Settings;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.flywaydb.core.Flyway;
|
import org.flywaydb.core.Flyway;
|
||||||
|
import org.flywaydb.core.api.output.MigrateResult;
|
||||||
|
|
||||||
public class DatabaseMigration {
|
public class DatabaseMigration {
|
||||||
private final static Logger logger = LogManager.getLogger(DatabaseMigration.class);
|
private final static Logger logger = LogManager.getLogger(DatabaseMigration.class);
|
||||||
@@ -18,14 +19,17 @@ public class DatabaseMigration {
|
|||||||
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
||||||
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
||||||
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
||||||
|
String dbPort = Settings.getInstance().get("MYSQL_PORT", "3306");
|
||||||
|
String dbUrl = String.format("jdbc:mysql://%s:%s/%s", dbHost, dbPort, dbName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
logger.info("Running database migrations..");
|
||||||
Flyway flyway = Flyway.configure()
|
Flyway flyway = Flyway.configure()
|
||||||
.dataSource(String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName), dbUser, dbPass)
|
.dataSource(dbUrl, dbUser, dbPass)
|
||||||
.baselineOnMigrate(true)
|
.load();
|
||||||
.load();
|
|
||||||
|
|
||||||
flyway.migrate();
|
MigrateResult result = flyway.migrate();
|
||||||
|
logger.info("Database migrations finished successfully! (total: {})", result.migrationsExecuted);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ public class SessionManager {
|
|||||||
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
||||||
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
||||||
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
||||||
logger.info(String.format("Connecting to database '%s' at %s:3306 with user '%s'", dbName, dbHost, dbUser));
|
String dbPort = Settings.getInstance().get("MYSQL_PORT", "3306");
|
||||||
|
logger.info("Connecting to database '{}' at {}:{} with user '{}'", dbName, dbHost, dbPort, dbUser);
|
||||||
|
|
||||||
settings.put(Environment.JAKARTA_JDBC_URL, String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName));
|
settings.put(Environment.JAKARTA_JDBC_URL, String.format("jdbc:mysql://%s:%s/%s", dbHost, dbPort, dbName));
|
||||||
settings.put(Environment.JAKARTA_JDBC_USER, dbUser);
|
settings.put(Environment.JAKARTA_JDBC_USER, dbUser);
|
||||||
settings.put(Environment.JAKARTA_JDBC_PASSWORD, dbPass);
|
settings.put(Environment.JAKARTA_JDBC_PASSWORD, dbPass);
|
||||||
registryBuilder.applySettings(settings);
|
registryBuilder.applySettings(settings);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a task that has a known ID and is loaded at runtime.
|
* Represents a task that has a known ID and is loaded at runtime.
|
||||||
@@ -13,13 +13,5 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|||||||
*/
|
*/
|
||||||
public interface BuiltInTask extends Task {
|
public interface BuiltInTask extends Task {
|
||||||
|
|
||||||
static Button createButton(Class<? extends BuiltInTask> clazz) {
|
void executeTask(TaskContext context);
|
||||||
BuiltInTask builtInTask = TaskManager.getInstance().findBuiltInTaskByClass(clazz);
|
|
||||||
|
|
||||||
if (builtInTask == null) {
|
|
||||||
throw new IllegalArgumentException("Task class " + clazz.getName() + " was not registered by the task manager.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builtInTask.createButton();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package me.bobert.netneutrality.core.tasks;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) anthorob
|
||||||
|
*
|
||||||
|
* https://discord.gg/qUa6zNFZsd
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public interface ScheduledTask {
|
||||||
|
|
||||||
|
class TimeFrame {
|
||||||
|
private final int interval;
|
||||||
|
private final TimeUnit unit;
|
||||||
|
|
||||||
|
private TimeFrame(int interval, TimeUnit unit) {
|
||||||
|
this.interval = interval;
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame minutely() {
|
||||||
|
return new TimeFrame(1, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame minutely(int interval) {
|
||||||
|
return new TimeFrame(interval, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame hourly() {
|
||||||
|
return new TimeFrame(1, TimeUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame hourly(int interval) {
|
||||||
|
return new TimeFrame(interval, TimeUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame daily() {
|
||||||
|
return new TimeFrame(1, TimeUnit.DAYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame daily(int interval) {
|
||||||
|
return new TimeFrame(interval, TimeUnit.DAYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeFrame custom(int interval, TimeUnit unit) {
|
||||||
|
return new TimeFrame(interval, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInterval() {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeUnit getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String getId();
|
||||||
|
|
||||||
|
TimeFrame getTimeFrame();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
}
|
||||||
+1
-1
@@ -6,7 +6,7 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface IStepTask {
|
public interface StepTask {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the type of input expected for a step.
|
* Defines the type of input expected for a step.
|
||||||
@@ -7,8 +7,9 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
|
import me.bobert.netneutrality.core.tasks.trait.WithButton;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.WithChildren;
|
import me.bobert.netneutrality.core.tasks.trait.WithChildren;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import net.dv8tion.jda.api.components.buttons.Button;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
@@ -20,12 +21,13 @@ public interface Task {
|
|||||||
REMOVE_SELF,
|
REMOVE_SELF,
|
||||||
REMOVE_SELF_AND_CHILDREN
|
REMOVE_SELF_AND_CHILDREN
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method should generate a unique ID to differentiate it from other tasks.
|
* This method should generate a unique ID to differentiate it from other tasks.
|
||||||
* <p>
|
* <p>
|
||||||
* This determines what triggers a task to be executed.
|
* This determines what triggers a task to be executed.
|
||||||
* For example, a modal or button would use the component id.
|
* For example, a modal or button would use the component id.
|
||||||
* For an emoji reaction, the guild and message id would be combined.
|
* For an emoji reaction, the guild and message id would be combined.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a unique ID for this task
|
* @return a unique ID for this task
|
||||||
@@ -44,6 +46,7 @@ public interface Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is only used for debugging purpose.
|
* This is only used for debugging purpose.
|
||||||
|
*
|
||||||
* @return Name of the task
|
* @return Name of the task
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
@@ -55,14 +58,13 @@ public interface Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* When this returns true, the task will get removed by the cleanup thread.
|
* When this returns true, the task will get removed by the cleanup thread.
|
||||||
|
*
|
||||||
* @return If the task is expired
|
* @return If the task is expired
|
||||||
*/
|
*/
|
||||||
boolean isExpired();
|
boolean isExpired();
|
||||||
|
|
||||||
OffsetDateTime getCreationTime();
|
OffsetDateTime getCreationTime();
|
||||||
|
|
||||||
Button createButton();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This method is used to reply to the interaction that triggered this task.</p>
|
* <p>This method is used to reply to the interaction that triggered this task.</p>
|
||||||
* <p>If the task is implementing {@link WithChildren}, the child tasks must be instanciated in this method.</p>
|
* <p>If the task is implementing {@link WithChildren}, the child tasks must be instanciated in this method.</p>
|
||||||
@@ -71,9 +73,20 @@ public interface Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the task.
|
* Executes the task.
|
||||||
|
*
|
||||||
* @param context The context for this task.
|
* @param context The context for this task.
|
||||||
*/
|
*/
|
||||||
Lifecycle execute(TaskContext context);
|
Lifecycle execute(TaskContext context);
|
||||||
|
|
||||||
void insert(CommandContext context);
|
void insert(CommandContext context);
|
||||||
|
|
||||||
|
static Button createButton(Class<? extends WithButton> clazz) {
|
||||||
|
WithButton withButton = TaskManager.getInstance().findButtonTaskByClass(clazz);
|
||||||
|
|
||||||
|
if (withButton == null) {
|
||||||
|
throw new IllegalArgumentException("Task " + clazz.getName() + " was not registered by the task manager.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return withButton.createButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,24 +11,24 @@ import me.bobert.netneutrality.core.context.InteractionContext;
|
|||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.Deletable;
|
import me.bobert.netneutrality.core.tasks.trait.Deletable;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.NotAcknowledgeable;
|
import me.bobert.netneutrality.core.tasks.trait.NotAcknowledgeable;
|
||||||
|
import me.bobert.netneutrality.core.tasks.trait.WithButton;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.WithChildren;
|
import me.bobert.netneutrality.core.tasks.trait.WithChildren;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.WithParent;
|
import me.bobert.netneutrality.core.tasks.trait.WithParent;
|
||||||
import me.bobert.netneutrality.core.thread.ThreadManager;
|
import me.bobert.netneutrality.core.thread.ScheduledTaskManager;
|
||||||
import me.bobert.netneutrality.db.service.TaskService;
|
import me.bobert.netneutrality.db.service.TaskService;
|
||||||
import me.bobert.netneutrality.exceptions.GracefulContextError;
|
import me.bobert.netneutrality.exceptions.GracefulContextError;
|
||||||
import me.bobert.netneutrality.exceptions.TaskExecutionException;
|
import me.bobert.netneutrality.exceptions.TaskExecutionException;
|
||||||
import me.bobert.netneutrality.thread.CleanupTaskThread;
|
import me.bobert.netneutrality.utils.ReflectionHelper;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.reflections.Reflections;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.util.Collection;
|
||||||
import java.lang.reflect.Modifier;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -58,13 +58,14 @@ public class TaskManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
loadBuiltInTasks();
|
logger.info("Initializing task manager...");
|
||||||
taskService.loadTasks();
|
|
||||||
|
|
||||||
ThreadManager.getScheduledExecutor().scheduleWithFixedDelay(new CleanupTaskThread(), 1, 5, TimeUnit.MINUTES);
|
loadBuiltInTasks();
|
||||||
|
loadScheduledTasks();
|
||||||
|
taskService.loadTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TaskService getTaskService() {
|
public TaskService getTaskService() {
|
||||||
return taskService;
|
return taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ public class TaskManager {
|
|||||||
taskService.persistTask(persistableTask);
|
taskService.persistTask(persistableTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task instanceof IStepTask) {
|
if (task instanceof StepTask) {
|
||||||
pendingTasks.add(task);
|
pendingTasks.add(task);
|
||||||
} else {
|
} else {
|
||||||
tasks.put(id, task);
|
tasks.put(id, task);
|
||||||
@@ -125,7 +126,7 @@ public class TaskManager {
|
|||||||
if (pendingTasks.remove(task)) {
|
if (pendingTasks.remove(task)) {
|
||||||
tasks.put(task.getId(), task);
|
tasks.put(task.getId(), task);
|
||||||
logger.info("Updating task {} with new id: {} (was: {})",
|
logger.info("Updating task {} with new id: {} (was: {})",
|
||||||
task.getName(), task.getId(), oldId);
|
task.getName(), task.getId(), oldId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ public class TaskManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Executing task: {}", taskId);
|
logger.info("Executing task: {}", taskId);
|
||||||
Task.Lifecycle status = task.execute(context);
|
Task.Lifecycle status = task.execute(context);
|
||||||
handleTaskLifecycle(task, status);
|
handleTaskLifecycle(task, status);
|
||||||
|
|
||||||
@@ -201,23 +202,23 @@ public class TaskManager {
|
|||||||
|
|
||||||
public <E extends Task> Optional<E> findTaskByPartialId(Class<E> clazz, String partialId) {
|
public <E extends Task> Optional<E> findTaskByPartialId(Class<E> clazz, String partialId) {
|
||||||
List<E> tasks = findTasksByPartialId(clazz, partialId);
|
List<E> tasks = findTasksByPartialId(clazz, partialId);
|
||||||
return Optional.ofNullable(tasks.isEmpty() ? null : tasks.get(0));
|
return Optional.ofNullable(tasks.isEmpty() ? null : tasks.getFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends Task> List<E> findTasksByPartialId(Class<E> clazz, String partialId) {
|
public <E extends Task> List<E> findTasksByPartialId(Class<E> clazz, String partialId) {
|
||||||
return tasks.values().stream()
|
return tasks.values().stream()
|
||||||
.filter(clazz::isInstance)
|
.filter(clazz::isInstance)
|
||||||
.map(clazz::cast)
|
.map(clazz::cast)
|
||||||
.filter(task -> task.getId().contains(partialId))
|
.filter(task -> task.getId().contains(partialId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuiltInTask findBuiltInTaskByClass(Class<? extends BuiltInTask> clazz) {
|
public WithButton findButtonTaskByClass(Class<? extends WithButton> clazz) {
|
||||||
return tasks.values().stream()
|
return tasks.values().stream()
|
||||||
.filter(clazz::isInstance)
|
.filter(clazz::isInstance)
|
||||||
.map(task -> (BuiltInTask) task)
|
.map(task -> (WithButton) task)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertPersistableTask(PersistableTask task) {
|
public void insertPersistableTask(PersistableTask task) {
|
||||||
@@ -233,22 +234,27 @@ public class TaskManager {
|
|||||||
private void loadBuiltInTasks() {
|
private void loadBuiltInTasks() {
|
||||||
logger.info("Loading built-in tasks...");
|
logger.info("Loading built-in tasks...");
|
||||||
|
|
||||||
Set<Class<? extends BuiltInTask>> classes = new Reflections("me.bobert.netneutrality.tasks").getSubTypesOf(BuiltInTask.class);
|
ReflectionHelper.loadTasks(BuiltInTask.class, builtInTask -> {
|
||||||
for (Class<? extends BuiltInTask> s : classes) {
|
if (builtInTask.isInsertable()) {
|
||||||
try {
|
logger.info("Loaded task: {}", builtInTask.getClass().getName());
|
||||||
if (Modifier.isAbstract(s.getModifiers())) {
|
tasks.put(builtInTask.getId(), builtInTask);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuiltInTask task = s.getConstructor().newInstance();
|
|
||||||
|
|
||||||
logger.info("Loaded task: {}", task);
|
|
||||||
tasks.put(task.getId(), task);
|
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
|
||||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
|
||||||
logger.error("Failed to instantiate built-in task", e);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadScheduledTasks() {
|
||||||
|
logger.info("Loading scheduled tasks...");
|
||||||
|
|
||||||
|
ReflectionHelper.loadTasks(ScheduledTask.class, scheduledTask -> {
|
||||||
|
String taskId = scheduledTask.getId();
|
||||||
|
|
||||||
|
if (taskId == null || taskId.trim().isEmpty()) {
|
||||||
|
logger.error("Cannot load scheduled task {}: task ID is null or empty", scheduledTask.getClass().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScheduledTaskManager.schedule(scheduledTask);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteInteraction(Task task) {
|
private void deleteInteraction(Task task) {
|
||||||
@@ -267,7 +273,7 @@ public class TaskManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void deleteInteraction(String taskId, Deletable deletable) {
|
private void deleteInteraction(String taskId, Deletable deletable) {
|
||||||
logger.debug("Deleting interaction: {}", deletable);
|
logger.debug("Deleting interaction: {}", taskId);
|
||||||
|
|
||||||
CommandContext context = deletableTasksContext.get(taskId);
|
CommandContext context = deletableTasksContext.get(taskId);
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
|
|||||||
+2
-3
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.tasks;
|
package me.bobert.netneutrality.core.tasks.impl;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
@@ -7,6 +7,7 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
|
import me.bobert.netneutrality.core.tasks.BuiltInTask;
|
||||||
|
|
||||||
public abstract class AbstractBuiltInTask extends AbstractTask implements BuiltInTask {
|
public abstract class AbstractBuiltInTask extends AbstractTask implements BuiltInTask {
|
||||||
|
|
||||||
@@ -35,6 +36,4 @@ public abstract class AbstractBuiltInTask extends AbstractTask implements BuiltI
|
|||||||
executeTask(context);
|
executeTask(context);
|
||||||
return Lifecycle.BUILTIN;
|
return Lifecycle.BUILTIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void executeTask(TaskContext context);
|
|
||||||
}
|
}
|
||||||
+3
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.tasks;
|
package me.bobert.netneutrality.core.tasks.impl;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
@@ -6,6 +6,8 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
|
import me.bobert.netneutrality.core.tasks.PersistableTask;
|
||||||
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public abstract class AbstractPersistableTask extends AbstractTask implements PersistableTask {
|
public abstract class AbstractPersistableTask extends AbstractTask implements PersistableTask {
|
||||||
+3
-10
@@ -9,13 +9,11 @@ package me.bobert.netneutrality.core.tasks.impl;
|
|||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
import me.bobert.netneutrality.core.context.MessageContext;
|
import me.bobert.netneutrality.core.context.MessageContext;
|
||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
import me.bobert.netneutrality.core.tasks.AbstractTask;
|
import me.bobert.netneutrality.core.tasks.StepTask;
|
||||||
import me.bobert.netneutrality.core.tasks.IStepTask;
|
|
||||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|
||||||
import net.fellbaum.jemoji.Emoji;
|
import net.fellbaum.jemoji.Emoji;
|
||||||
import net.fellbaum.jemoji.EmojiManager;
|
import net.fellbaum.jemoji.EmojiManager;
|
||||||
|
|
||||||
@@ -27,7 +25,7 @@ import java.util.UUID;
|
|||||||
* Represents a task that consists of multiple sequential steps. The task starts with an initial message (question)
|
* Represents a task that consists of multiple sequential steps. The task starts with an initial message (question)
|
||||||
* and expects a user response. Each step can lead to another step, forming a workflow.
|
* and expects a user response. Each step can lead to another step, forming a workflow.
|
||||||
*/
|
*/
|
||||||
public abstract class StepTask extends AbstractTask implements IStepTask {
|
public abstract class AbstractStepTask extends AbstractTask implements StepTask {
|
||||||
private final Object stepLock = new Object();
|
private final Object stepLock = new Object();
|
||||||
private CommandContext commandContext;
|
private CommandContext commandContext;
|
||||||
private Guild guild;
|
private Guild guild;
|
||||||
@@ -63,7 +61,7 @@ public abstract class StepTask extends AbstractTask implements IStepTask {
|
|||||||
|
|
||||||
context.replyEphemeral("Please follow the instructions sent in DM.");
|
context.replyEphemeral("Please follow the instructions sent in DM.");
|
||||||
context.sendMessageInPrivate(getStepDescription() + "\n\n" + getStepQuestion(),
|
context.sendMessageInPrivate(getStepDescription() + "\n\n" + getStepQuestion(),
|
||||||
asyncContext -> assignId(asyncContext.getMessageId()));
|
asyncContext -> assignId(asyncContext.getMessageId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,11 +108,6 @@ public abstract class StepTask extends AbstractTask implements IStepTask {
|
|||||||
return getCreationTime().plusMinutes(60).isBefore(OffsetDateTime.now());
|
return getCreationTime().plusMinutes(60).isBefore(OffsetDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Button createButton() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the user input against the expected step type.
|
* Validates the user input against the expected step type.
|
||||||
*
|
*
|
||||||
+9
-3
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.tasks;
|
package me.bobert.netneutrality.core.tasks.impl;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
@@ -6,6 +6,8 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.context.CommandContext;
|
import me.bobert.netneutrality.core.context.CommandContext;
|
||||||
|
import me.bobert.netneutrality.core.tasks.Task;
|
||||||
|
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -29,8 +31,12 @@ public abstract class AbstractTask implements Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
AbstractTask that = (AbstractTask) o;
|
AbstractTask that = (AbstractTask) o;
|
||||||
return Objects.equals(getId(), that.getId());
|
return Objects.equals(getId(), that.getId());
|
||||||
@@ -5,49 +5,40 @@ package me.bobert.netneutrality.core.tasks.impl;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.tasks.GenericRandomIdTask;
|
|
||||||
import me.bobert.netneutrality.core.tasks.Task;
|
import me.bobert.netneutrality.core.tasks.Task;
|
||||||
import me.bobert.netneutrality.core.tasks.trait.WithChildren;
|
import me.bobert.netneutrality.core.tasks.trait.WithButton;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
import net.dv8tion.jda.api.components.buttons.Button;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import net.dv8tion.jda.api.components.buttons.ButtonStyle;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class ButtonTask extends GenericRandomIdTask {
|
public abstract class ButtonTask extends GenericRandomIdTask implements WithButton {
|
||||||
private final ButtonStyle buttonStyle;
|
private final ButtonStyle buttonStyle;
|
||||||
private final String buttonLabel;
|
private final String buttonLabel;
|
||||||
|
private Emoji emoji;
|
||||||
|
|
||||||
public ButtonTask(ButtonStyle buttonStyle, String buttonLabel) {
|
public ButtonTask(ButtonStyle buttonStyle, String buttonLabel) {
|
||||||
this.buttonStyle = buttonStyle;
|
this.buttonStyle = buttonStyle;
|
||||||
this.buttonLabel = buttonLabel;
|
this.buttonLabel = buttonLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task setEmoji(Emoji emoji) {
|
||||||
|
this.emoji = emoji;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Button createButton() {
|
public Button createButton() {
|
||||||
if (buttonStyle == null || buttonLabel == null) {
|
if (buttonStyle == null || buttonLabel == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Button.of(buttonStyle, getId(), buttonLabel);
|
return Button.of(buttonStyle, getId(), buttonLabel, emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return getCreationTime().plusMinutes(15).isBefore(OffsetDateTime.now());
|
return getCreationTime().plusMinutes(15).isBefore(OffsetDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionRow createActionRow(List<Task> tasks) {
|
|
||||||
ActionRow row = ActionRow.of(tasks.stream().map(Task::createButton).toList());
|
|
||||||
if (this instanceof WithChildren parent) {
|
|
||||||
parent.addChild(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionRow createActionRow(Task... tasks) {
|
|
||||||
return createActionRow(List.of(tasks));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,6 @@ package me.bobert.netneutrality.core.tasks.impl;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.context.tasks.EmojiTaskContext;
|
import me.bobert.netneutrality.context.tasks.EmojiTaskContext;
|
||||||
import me.bobert.netneutrality.core.tasks.AbstractPersistableTask;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -54,9 +52,4 @@ public abstract class EmojiTask extends AbstractPersistableTask {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return String.format(EmojiTaskContext.ID, getGuildId(), getMessageId());
|
return String.format(EmojiTaskContext.ID, getGuildId(), getMessageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Button createButton() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-8
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.tasks;
|
package me.bobert.netneutrality.core.tasks.impl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
@@ -6,8 +6,6 @@ package me.bobert.netneutrality.core.tasks;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|
||||||
|
|
||||||
public abstract class GenericCustomIdTask extends AbstractTask {
|
public abstract class GenericCustomIdTask extends AbstractTask {
|
||||||
private final String customId;
|
private final String customId;
|
||||||
|
|
||||||
@@ -19,9 +17,4 @@ public abstract class GenericCustomIdTask extends AbstractTask {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return customId;
|
return customId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Button createButton() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.bobert.netneutrality.core.tasks;
|
package me.bobert.netneutrality.core.tasks.impl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
@@ -6,11 +6,11 @@ package me.bobert.netneutrality.core.tasks.impl;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.core.context.TaskContext;
|
import me.bobert.netneutrality.core.context.TaskContext;
|
||||||
import me.bobert.netneutrality.core.tasks.GenericRandomIdTask;
|
|
||||||
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class ModalTask extends GenericRandomIdTask {
|
public abstract class ModalTask extends GenericRandomIdTask {
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ public abstract class ModalTask extends GenericRandomIdTask {
|
|||||||
return getCreationTime().plusMinutes(5).isBefore(OffsetDateTime.now());
|
return getCreationTime().plusMinutes(5).isBefore(OffsetDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModalMapping getValue(String key, TaskContext context) {
|
public Optional<ModalMapping> getValue(String key, TaskContext context) {
|
||||||
List<?> mappings = (List<?>) context.getContextData("values");
|
List<?> mappings = (List<?>) context.getContextData("values");
|
||||||
return mappings.stream()
|
return mappings.stream()
|
||||||
.filter(o -> o instanceof ModalMapping)
|
.filter(o -> o instanceof ModalMapping)
|
||||||
.map(o -> (ModalMapping) o)
|
.map(o -> (ModalMapping) o)
|
||||||
.filter(mapping -> mapping.getId().equals(key))
|
.filter(mapping -> mapping.getCustomId().equals(key))
|
||||||
.findFirst().orElse(null);
|
.findFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package me.bobert.netneutrality.core.tasks.trait;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) anthorob
|
||||||
|
*
|
||||||
|
* https://discord.gg/qUa6zNFZsd
|
||||||
|
*/
|
||||||
|
|
||||||
|
import me.bobert.netneutrality.core.tasks.Task;
|
||||||
|
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.components.buttons.Button;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface WithButton {
|
||||||
|
|
||||||
|
Button createButton();
|
||||||
|
|
||||||
|
default ActionRow createActionRow(List<Task> tasks) {
|
||||||
|
ActionRow row = ActionRow.of(tasks.stream().filter(task -> task instanceof WithButton).map(task -> (WithButton) task).map(WithButton::createButton).toList());
|
||||||
|
if (this instanceof WithChildren parent) {
|
||||||
|
parent.addChild(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
default ActionRow createActionRow(Task... tasks) {
|
||||||
|
return createActionRow(List.of(tasks));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@ package me.bobert.netneutrality.core.thread;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import me.bobert.netneutrality.exceptions.ExecutorException;
|
import me.bobert.netneutrality.exceptions.ExecutorException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ public class BaseThreadFactory implements ThreadFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(@NotNull Runnable r) {
|
public Thread newThread(@Nonnull Runnable r) {
|
||||||
Thread thread = new Thread(r);
|
Thread thread = new Thread(r);
|
||||||
thread.setName(name + "-" + threadId.getAndIncrement());
|
thread.setName(name + "-" + threadId.getAndIncrement());
|
||||||
thread.setUncaughtExceptionHandler(new ExecutorException());
|
thread.setUncaughtExceptionHandler(new ExecutorException());
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package me.bobert.netneutrality.core.thread;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) anthorob
|
||||||
|
*
|
||||||
|
* https://discord.gg/qUa6zNFZsd
|
||||||
|
*/
|
||||||
|
|
||||||
|
import me.bobert.netneutrality.core.LogHandler;
|
||||||
|
import me.bobert.netneutrality.core.tasks.ScheduledTask;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
|
public class ScheduledTaskManager {
|
||||||
|
private static final Logger logger = LogManager.getLogger(ScheduledTaskManager.class);
|
||||||
|
private static final ScheduledExecutorService executorService = ThreadManager.getScheduledExecutor();
|
||||||
|
private static final Map<String, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private ScheduledTaskManager() {}
|
||||||
|
|
||||||
|
public static void schedule(ScheduledTask task) {
|
||||||
|
String taskId = task.getId();
|
||||||
|
|
||||||
|
if (scheduledTasks.containsKey(taskId)) {
|
||||||
|
logger.warn("Task {} is already scheduled.", taskId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScheduledTask.TimeFrame timeFrame = task.getTimeFrame();
|
||||||
|
|
||||||
|
Runnable runnable = () -> {
|
||||||
|
logger.info("Executing scheduled task: {}", taskId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
task.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("An exception was thrown while executing scheduled task {}", taskId);
|
||||||
|
LogHandler.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ScheduledFuture<?> future = executorService.scheduleWithFixedDelay(
|
||||||
|
runnable,
|
||||||
|
1,
|
||||||
|
timeFrame.getInterval(),
|
||||||
|
timeFrame.getUnit()
|
||||||
|
);
|
||||||
|
|
||||||
|
scheduledTasks.put(taskId, future);
|
||||||
|
logger.info("Successfully scheduled task: {} with interval {} {}",
|
||||||
|
taskId, timeFrame.getInterval(), timeFrame.getUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cancelAll() {
|
||||||
|
logger.info("Cancelling all {} scheduled tasks", scheduledTasks.size());
|
||||||
|
scheduledTasks.forEach((id, future) -> future.cancel(false));
|
||||||
|
scheduledTasks.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.core.thread;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ThreadManager {
|
public class ThreadManager {
|
||||||
|
|
||||||
@@ -14,11 +18,11 @@ public class ThreadManager {
|
|||||||
|
|
||||||
public static ScheduledExecutorService getScheduledExecutor() {
|
public static ScheduledExecutorService getScheduledExecutor() {
|
||||||
return (ScheduledExecutorService) executors.computeIfAbsent(
|
return (ScheduledExecutorService) executors.computeIfAbsent(
|
||||||
"scheduled-executor",
|
"scheduled-executor",
|
||||||
s -> Executors.newScheduledThreadPool(
|
s -> Executors.newScheduledThreadPool(
|
||||||
Runtime.getRuntime().availableProcessors(),
|
Runtime.getRuntime().availableProcessors(),
|
||||||
new BaseThreadFactory(s)
|
new BaseThreadFactory(s)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,11 +42,9 @@ public class ThreadManager {
|
|||||||
ex.shutdown();
|
ex.shutdown();
|
||||||
ex.awaitTermination(1, TimeUnit.SECONDS);
|
ex.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch (InterruptedException e) {
|
|
||||||
System.err.println("[Executor] Running tasks interrupted");
|
System.err.println("[Executor] Running tasks interrupted");
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
executors.forEach((name, ex) -> {
|
executors.forEach((name, ex) -> {
|
||||||
if (!ex.isTerminated()) {
|
if (!ex.isTerminated()) {
|
||||||
System.err.println("[Executor: " + name + "] Forcing shutdown of running tasks..");
|
System.err.println("[Executor: " + name + "] Forcing shutdown of running tasks..");
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public interface Repository<O> {
|
|||||||
default void save(O entity) {
|
default void save(O entity) {
|
||||||
Transaction transaction = null;
|
Transaction transaction = null;
|
||||||
|
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
transaction = session.beginTransaction();
|
transaction = session.beginTransaction();
|
||||||
session.merge(entity);
|
session.merge(entity);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
|||||||
@@ -6,7 +6,15 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "blacklist")
|
@Table(name = "blacklist")
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -108,9 +112,9 @@ public class OGuild {
|
|||||||
|
|
||||||
public OGuildSetting getSettingByName(String name) {
|
public OGuildSetting getSettingByName(String name) {
|
||||||
Optional<OGuildSetting> setting = getGuildSettings()
|
Optional<OGuildSetting> setting = getGuildSettings()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(setting1 -> setting1.getName().equalsIgnoreCase(name))
|
.filter(setting1 -> setting1.getName().equalsIgnoreCase(name))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
return setting.orElse(null);
|
return setting.orElse(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,23 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.NamedQueries;
|
||||||
|
import jakarta.persistence.NamedQuery;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "guild_settings")
|
@Table(name = "guild_settings")
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)")
|
@NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)")
|
||||||
})
|
})
|
||||||
public class OGuildSetting {
|
public class OGuildSetting {
|
||||||
@Id
|
@Id
|
||||||
|
|||||||
@@ -6,7 +6,16 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Convert;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,14 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.EmbeddedId;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.MapsId;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "logging")
|
@Table(name = "logging")
|
||||||
|
|||||||
@@ -46,10 +46,14 @@ public class OLoggingId implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
OLoggingId entity = (OLoggingId) o;
|
OLoggingId entity = (OLoggingId) o;
|
||||||
return Objects.equals(this.guildId, entity.guildId) &&
|
return Objects.equals(this.guildId, entity.guildId) &&
|
||||||
Objects.equals(this.channelId, entity.channelId);
|
Objects.equals(this.channelId, entity.channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,14 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.persistence.UniqueConstraint;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "tasks", uniqueConstraints = {@UniqueConstraint(columnNames = {"task_id"})})
|
@Table(name = "tasks", uniqueConstraints = {@UniqueConstraint(columnNames = {"task_id"})})
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities;
|
|||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class BlacklistRepository implements Repository<OBlacklist> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private OBlacklist getWordFromDb(String guildId, String word) {
|
private OBlacklist getWordFromDb(String guildId, String word) {
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
Query<OBlacklist> query = session.createQuery("SELECT o FROM OBlacklist o WHERE upper(o.word) = upper(:word) AND o.guild.guildId = :guildId", OBlacklist.class);
|
Query<OBlacklist> query = session.createQuery("SELECT o FROM OBlacklist o WHERE upper(o.word) = upper(:word) AND o.guild.guildId = :guildId", OBlacklist.class);
|
||||||
query.setParameter("guildId", guildId);
|
query.setParameter("guildId", guildId);
|
||||||
query.setParameter("word", word);
|
query.setParameter("word", word);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class GuildRepository implements Repository<OGuild> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OGuild findById(String id) {
|
public OGuild findById(String id) {
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
Query<OGuild> query = session.createQuery("SELECT o FROM OGuild o WHERE o.guildId = :guildId", OGuild.class);
|
Query<OGuild> query = session.createQuery("SELECT o FROM OGuild o WHERE o.guildId = :guildId", OGuild.class);
|
||||||
query.setParameter("guildId", id);
|
query.setParameter("guildId", id);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class GuildSettingRepository implements Repository<OGuildSetting> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OGuildSetting findById(String id) {
|
public OGuildSetting findById(String id) {
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
Query<OGuildSetting> query = session.createQuery("SELECT o FROM OGuildSetting o WHERE o.id = :id", OGuildSetting.class);
|
Query<OGuildSetting> query = session.createQuery("SELECT o FROM OGuildSetting o WHERE o.id = :id", OGuildSetting.class);
|
||||||
query.setParameter("id", id);
|
query.setParameter("id", id);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class MessageRepository implements Repository<OLogMessage> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OLogMessage findById(String id) {
|
public OLogMessage findById(String id) {
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
Query<OLogMessage> query = session.createQuery("SELECT o FROM OLogMessage o WHERE o.messageId = :messageId", OLogMessage.class);
|
Query<OLogMessage> query = session.createQuery("SELECT o FROM OLogMessage o WHERE o.messageId = :messageId", OLogMessage.class);
|
||||||
query.setParameter("messageId", id);
|
query.setParameter("messageId", id);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class TaskRepository implements Repository<OTask> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OTask findById(String id) {
|
public OTask findById(String id) {
|
||||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||||
Query<OTask> query = session.createQuery("SELECT o FROM OTask o WHERE o.taskId = :taskId", OTask.class);
|
Query<OTask> query = session.createQuery("SELECT o FROM OTask o WHERE o.taskId = :taskId", OTask.class);
|
||||||
query.setParameter("taskId", id);
|
query.setParameter("taskId", id);
|
||||||
|
|
||||||
|
|||||||
Loaded 100 of 139 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user