Compare commits
22 Commits
develop
...
feature/co
Author | SHA1 | Date | |
---|---|---|---|
eb612e1761 | |||
a24810a53a | |||
599052a235 | |||
2305b314cb | |||
4c40d33050 | |||
f051e98768 | |||
bbddcb93ba | |||
f4805fd8b5 | |||
79b5c695b0 | |||
2f89362a8b | |||
4c68e6bf09 | |||
bc2edd70fe | |||
431b93d5b8 | |||
c85bea52a2 | |||
c8260444bb | |||
52c8253aa0 | |||
6ec37452f9 | |||
fd3c942164 | |||
75c3892e61 | |||
232fd1746d | |||
68a472d804 | |||
c169061b07 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@
|
|||||||
/key.bin
|
/key.bin
|
||||||
/logs/
|
/logs/
|
||||||
/conf/
|
/conf/
|
||||||
|
.metadata/
|
||||||
|
140
Jenkinsfile
vendored
140
Jenkinsfile
vendored
@ -1,7 +1,18 @@
|
|||||||
#!groovy
|
#!groovy
|
||||||
|
|
||||||
|
// Required Jenkins plugins:
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/Timestamper
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/Static+Code+Analysis+Plug-ins
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin ?
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/FindBugs+Plugin
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin ?
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/DRY+Plugin ?
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/Task+Scanner+Plugin
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/Javadoc+Plugin
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin ?
|
||||||
|
|
||||||
init()
|
|
||||||
|
init()
|
||||||
|
|
||||||
def branch_name
|
def branch_name
|
||||||
def branch_name_base
|
def branch_name_base
|
||||||
@ -23,7 +34,8 @@ def init() {
|
|||||||
build_url = env.BUILD_URL
|
build_url = env.BUILD_URL
|
||||||
job_name = "${env.JOB_NAME}"
|
job_name = "${env.JOB_NAME}"
|
||||||
branch_name = env.BRANCH_NAME
|
branch_name = env.BRANCH_NAME
|
||||||
persist = branch_name
|
branch_name_docker = branch_name.replaceAll(/\//,'.')
|
||||||
|
persist = "/var/lib/jenkins/PERSIST/${branch_name_docker}"
|
||||||
|
|
||||||
// execute the branch type specific pipeline code
|
// execute the branch type specific pipeline code
|
||||||
try {
|
try {
|
||||||
@ -31,52 +43,44 @@ def init() {
|
|||||||
if (branch_name.indexOf('release/')==0) build_type='release'
|
if (branch_name.indexOf('release/')==0) build_type='release'
|
||||||
if (branch_name.indexOf('feature/')==0) build_type='feature'
|
if (branch_name.indexOf('feature/')==0) build_type='feature'
|
||||||
if (branch_name.indexOf('develop')==0) build_type='develop'
|
if (branch_name.indexOf('develop')==0) build_type='develop'
|
||||||
|
if (branch_name.indexOf('hotfix')==0) build_type='hotfix'
|
||||||
|
if (branch_name.indexOf('bugfix')==0) build_type='bugfix'
|
||||||
if (branch_name.indexOf('master')==0) build_type='master'
|
if (branch_name.indexOf('master')==0) build_type='master'
|
||||||
if (branch_name.indexOf('hotfix/')==0) build_type='hotfix'
|
|
||||||
if (branch_name.indexOf('bugfix/')==0) build_type='bugfix'
|
// common pipeline elements
|
||||||
|
node('master') {
|
||||||
|
Initialize()
|
||||||
|
SetVersion(build_type)
|
||||||
|
print_vars() // after SetVersion - all variables now defined
|
||||||
|
set_result('INPROGRESS')
|
||||||
|
Build() // builds database via flyway migration
|
||||||
|
}
|
||||||
|
|
||||||
switch(build_type) {
|
if (branch_name.indexOf('develop')==0) {
|
||||||
case ~/feature/:
|
node('master') {
|
||||||
case ~/hotfix/:
|
Deploy();
|
||||||
case ~/bugfix/:
|
}
|
||||||
case ~/master/:
|
} else if (branch_name.indexOf('release/')==0) {
|
||||||
case ~/develop/:
|
node('master') {
|
||||||
CommonBuild();
|
Deploy();
|
||||||
break;
|
}
|
||||||
case ~/release/:
|
|
||||||
CommonBuild();
|
|
||||||
Deploy();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw "unsupported branch type: ${branch_name}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node('master') {
|
node('master') {
|
||||||
set_result('SUCCESS')
|
set_result('SUCCESS')
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
node() {
|
node() {
|
||||||
set_result('FAILURE')
|
set_result('FAILURE')
|
||||||
}
|
}
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def CommonBuild() {
|
|
||||||
// common pipeline elements
|
|
||||||
node('master') {
|
|
||||||
Initialize()
|
|
||||||
SetVersion(build_type)
|
|
||||||
print_vars() // after SetVersion - all variables now defined
|
|
||||||
set_result('INPROGRESS')
|
|
||||||
Build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def Build() {
|
def Build() {
|
||||||
stage ('build') {
|
stage ('build') {
|
||||||
mvn_alt("install -DskipTests=true -Dbuild.revision=${git_commit}")
|
mvn "install -DskipTests=true -Dbuild.revision=${git_commit}"
|
||||||
step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])
|
step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,10 +96,8 @@ def Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def Deploy() {
|
def Deploy() {
|
||||||
node('master') {
|
stage ('deploy') {
|
||||||
stage ('deploy') {
|
mvn "deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}"
|
||||||
mvn_alt("deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,17 +107,19 @@ def getSha1() {
|
|||||||
return sha1
|
return sha1
|
||||||
}
|
}
|
||||||
|
|
||||||
def mvn_initial(args) {
|
def mvn(args) {
|
||||||
mvn_alt(args)
|
withMaven(
|
||||||
|
maven: 'maven-3.6.1',
|
||||||
|
globalMavenSettingsConfig: 'locusworks-settings'
|
||||||
|
) {
|
||||||
|
|
||||||
|
sh "mvn ${args}"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def mvn_alt(args) {
|
def mvn_initial(args) {
|
||||||
// add maven tools to path before calling maven
|
mvn(args)
|
||||||
withMaven(maven: 'maven-3.6.1', jdk: 'jdk1.8.0_221', mavenSettingsConfig: 'maven_settings') {
|
|
||||||
writeFile file: '.skip-task-scanner', text: ''
|
|
||||||
writeFile file: '.skip-publish-junit-results', text: ''
|
|
||||||
sh "mvn ${args}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_result(status) {
|
def set_result(status) {
|
||||||
@ -130,10 +134,13 @@ def set_result(status) {
|
|||||||
} else {
|
} else {
|
||||||
error ("unknown status")
|
error ("unknown status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save in persistence file for access the status page
|
||||||
|
// make sure the directory exists first
|
||||||
|
sh "mkdir -p $persist && echo $status > $persist/build.result"
|
||||||
}
|
}
|
||||||
|
|
||||||
def notify_bitbucket(state) {
|
def notify_bitbucket(state) {
|
||||||
echo "notify bitbucket, state = $state, commit: ${git_commit}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_vars() {
|
def print_vars() {
|
||||||
@ -146,35 +153,34 @@ def print_vars() {
|
|||||||
echo "display_name = ${currentBuild.displayName}"
|
echo "display_name = ${currentBuild.displayName}"
|
||||||
echo "version = ${version}"
|
echo "version = ${version}"
|
||||||
echo "git_commit = ${git_commit}"
|
echo "git_commit = ${git_commit}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def SetVersion( v ) {
|
def SetVersion( v ) {
|
||||||
stage ('set version') {
|
stage ('set version') {
|
||||||
echo "set version ${v}"
|
echo "set version ${v}"
|
||||||
branch_name_base = (branch_name =~ /([^\/]+$)/)[0][0]
|
branch_name_base = (branch_name =~ /([^\/]+$)/)[0][0]
|
||||||
|
if ( v == 'release' ) {
|
||||||
switch(build_type) {
|
// for release branches, where the branch is named "release/1.2.3",
|
||||||
case ~/develop/:
|
// derive the version and display name derive from the numeric suffix and append the build number
|
||||||
version = build_number + '-SNAPSHOT'
|
// 3.2.1.100
|
||||||
currentBuild.displayName = version
|
version = branch_name_base + "." + build_number + "-RELEASE";
|
||||||
break;
|
//version = branch_name.substring('release/'.length()) + "." + build_number
|
||||||
case ~/release/:
|
currentBuild.displayName = version
|
||||||
// for release branches, where the branch is named "release/1.2.3",
|
} else if (v == 'develop') {
|
||||||
// derive the version and display name derive from the numeric suffix and append the build number
|
version = branch_name_base + "." + build_number + "-SNAPSHOT";
|
||||||
// 3.2.1.100
|
currentBuild.displayName = version
|
||||||
version = branch_name_base + '.' + build_number + '-RELEASE'
|
} else {
|
||||||
currentBuild.displayName = version
|
// for all other branches the version number is 0 with an appended build number
|
||||||
break;
|
// and for the display name use the jenkins default #n and add the branch name
|
||||||
default:
|
// #101 - feature/user/foo
|
||||||
// for all other branches the version number is 0 with an appended build number
|
//version = '0.' + build_number
|
||||||
// and for the display name use the jenkins default #n and add the branch name
|
version = branch_name_base + "." + build_number
|
||||||
version = branch_name_base + "." + build_number
|
currentBuild.displayName = "#" + build_number + " - " + branch_name_base
|
||||||
currentBuild.displayName = "#" + build_number + " - " + branch_name_base
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display_name = currentBuild.displayName
|
display_name = currentBuild.displayName
|
||||||
mvn_initial("versions:set -DnewVersion=${version}")
|
mvn_initial "versions:set -DnewVersion=${version}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Project: ${project.name}, File: ${file.name}
|
Project: ${project.name}, File: ${file.name}
|
||||||
|
|
||||||
Copyright 2019-${license.git.copyrightLastYear} Locusworks LLC.
|
Copyright ${project.inceptionYear}-${license.git.copyrightLastYear} Locusworks LLC.
|
||||||
All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
any means and imposes fines up to $25,000 for violation. No part of this material
|
any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
165
pom.xml
165
pom.xml
@ -14,23 +14,23 @@
|
|||||||
</organization>
|
</organization>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<url>git@gitea.locusworks.net:Locusworks/eight-track.git</url>
|
<url>ssh://gitea@gitea.locusworks.net:7999/locusworks/eight-track.git</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<flyway.version>7.15.0</flyway.version>
|
||||||
<flyway.version>6.0.3</flyway.version>
|
<mysql.version>8.0.26</mysql.version>
|
||||||
<mariadb.version>2.4.4</mariadb.version>
|
<hibernate.version>5.5.7.Final</hibernate.version>
|
||||||
<hibernate.version>5.4.4.Final</hibernate.version>
|
<spring.version>5.3.9</spring.version>
|
||||||
<spring.version>5.1.9.RELEASE</spring.version>
|
<spring.boot.version>2.5.4</spring.boot.version>
|
||||||
<spring.boot.version>2.1.8.RELEASE</spring.boot.version>
|
<spring.data.version>2.5.4</spring.data.version>
|
||||||
<spring.data.version>2.1.10.RELEASE</spring.data.version>
|
<jackson.version>2.12.5</jackson.version>
|
||||||
<log4j.version>2.12.1</log4j.version>
|
<log4j.version>2.14.1</log4j.version>
|
||||||
<slf4j.version>1.7.28</slf4j.version>
|
<slf4j.version>1.7.32</slf4j.version>
|
||||||
<maven.enforcer.version>3.0.0-M2</maven.enforcer.version>
|
<maven.enforcer.version>3.0.0</maven.enforcer.version>
|
||||||
<dep.check.version>5.2.2</dep.check.version>
|
<dep.check.version>6.3.1</dep.check.version>
|
||||||
<license-maven-plugin.version>3.0</license-maven-plugin.version>
|
<license-maven-plugin.version>4.1</license-maven-plugin.version>
|
||||||
<nexus.repo>http://nexus.locusworks.net</nexus.repo>
|
<nexus.repo>https://nexus.locusworks.net</nexus.repo>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-enforcer-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
<version>3.0.0-M2</version>
|
<version>${maven.enforcer.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<rules>
|
<rules>
|
||||||
<dependencyConvergence />
|
<dependencyConvergence />
|
||||||
@ -93,13 +93,14 @@
|
|||||||
<artifactId>license-maven-plugin</artifactId>
|
<artifactId>license-maven-plugin</artifactId>
|
||||||
<version>${license-maven-plugin.version}</version>
|
<version>${license-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<quiet>false</quiet>
|
<licenseSets>
|
||||||
<header>${basedir}/licenses/LICENSE.template</header>
|
<licenseSet>
|
||||||
<strictCheck>true</strictCheck>
|
<header>${project.baseUri}/licenses/LICENSE.template</header>
|
||||||
<useDefaultExcludes>true</useDefaultExcludes>
|
<includes>
|
||||||
<includes>
|
<include>**/*.java</include>
|
||||||
<include>**/*.java</include>
|
</includes>
|
||||||
</includes>
|
</licenseSet>
|
||||||
|
</licenseSets>
|
||||||
</configuration>
|
</configuration>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- this dependency allows ${license.git.copyrightLastYear} in the
|
<!-- this dependency allows ${license.git.copyrightLastYear} in the
|
||||||
@ -116,7 +117,7 @@
|
|||||||
<artifactId>flyway-maven-plugin</artifactId>
|
<artifactId>flyway-maven-plugin</artifactId>
|
||||||
<version>${flyway.version}</version>
|
<version>${flyway.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<url>jdbc:mariadb://devops.locusworks.net:3306/</url>
|
<url>jdbc:mysql://localhost:3306/</url>
|
||||||
<outOfOrder>false</outOfOrder>
|
<outOfOrder>false</outOfOrder>
|
||||||
<schemas>
|
<schemas>
|
||||||
<schema>eighttrack</schema>
|
<schema>eighttrack</schema>
|
||||||
@ -126,13 +127,11 @@
|
|||||||
<location>filesystem:${basedir}/src/main/resources/database/migration</location>
|
<location>filesystem:${basedir}/src/main/resources/database/migration</location>
|
||||||
</locations>
|
</locations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<!-- <executions> <execution> <phase>process-sources</phase> <goals>
|
|
||||||
<goal>migrate</goal> </goals> </execution> </executions> -->
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mariadb.jdbc</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mariadb-java-client</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>${mariadb.version}</version>
|
<version>${mysql.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
@ -149,26 +148,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.locusworks</groupId>
|
<groupId>net.locusworks</groupId>
|
||||||
<artifactId>crypto</artifactId>
|
<artifactId>crypto</artifactId>
|
||||||
<version>1.0.5-RELEASE</version>
|
<version>1.0.2-RELEASE</version>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.tika</groupId>
|
|
||||||
<artifactId>tika-core</artifactId>
|
|
||||||
<version>1.22</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.tika</groupId>
|
|
||||||
<artifactId>tika-parsers</artifactId>
|
|
||||||
<version>1.22</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/net.dv8tion/JDA2 -->
|
<!-- https://mvnrepository.com/artifact/net.dv8tion/JDA2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.dv8tion</groupId>
|
<groupId>net.dv8tion</groupId>
|
||||||
<artifactId>JDA</artifactId>
|
<artifactId>JDA</artifactId>
|
||||||
<version>4.0.0_50</version>
|
<version>4.3.0_277</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
@ -188,9 +175,34 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sedmelluq</groupId>
|
<groupId>com.sedmelluq</groupId>
|
||||||
<artifactId>lavaplayer</artifactId>
|
<artifactId>lavaplayer</artifactId>
|
||||||
<version>1.3.22</version>
|
<version>1.3.77</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.14.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-core -->
|
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
@ -198,17 +210,11 @@
|
|||||||
<version>${flyway.version}</version>
|
<version>${flyway.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mariadb.jdbc</groupId>
|
|
||||||
<artifactId>mariadb-java-client</artifactId>
|
|
||||||
<version>${mariadb.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.17</version>
|
<version>${mysql.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -217,14 +223,13 @@
|
|||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
|
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>commons-dbcp2</artifactId>
|
<artifactId>hibernate-hikaricp</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
|
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -296,43 +301,54 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>2.10.0.pr3</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.10.0.pr3</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<version>2.10.0.pr3</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
<version>2.2.11</version>
|
<version>2.4.0-b180830.0359</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
<artifactId>jaxb-core</artifactId>
|
<artifactId>jaxb-core</artifactId>
|
||||||
<version>2.2.11</version>
|
<version>3.0.0-M3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
<artifactId>jaxb-impl</artifactId>
|
<artifactId>jaxb-impl</artifactId>
|
||||||
<version>2.2.11</version>
|
<version>3.0.0-M3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.activation</groupId>
|
<groupId>javax.activation</groupId>
|
||||||
<artifactId>activation</artifactId>
|
<artifactId>activation</artifactId>
|
||||||
<version>1.1.1</version>
|
<version>1.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jthink</groupId>
|
||||||
|
<artifactId>jaudiotagger</artifactId>
|
||||||
|
<version>2.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
@ -346,4 +362,31 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>locusworks-public</id>
|
||||||
|
<name>locusworks-public</name>
|
||||||
|
<url>${nexus.repo}/repository/locusworks-public/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>locusworks-public</id>
|
||||||
|
<url>${nexus.repo}/repository/locusworks-public/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
1
scripts/start-mysql.ps1
Normal file
1
scripts/start-mysql.ps1
Normal file
@ -0,0 +1 @@
|
|||||||
|
Start-Service -Name "MySQL80"
|
1
scripts/stop-mysql.ps1
Normal file
1
scripts/stop-mysql.ps1
Normal file
@ -0,0 +1 @@
|
|||||||
|
Stop-Service -Name "MySQL80"
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: DiscordEventListener.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface DiscordEventListener {
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: EightTrackAudioSendHandler.java
|
* Project: Eight Track, File: EightTrackAudioSendHandler.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -25,7 +25,7 @@
|
|||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.handlers;
|
package net.locusworks.discord.eighttrack.audio;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: Mp3UploadHandler.java
|
* Project: Eight Track, File: Mp3UploadHandler.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -25,34 +25,31 @@
|
|||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.handlers;
|
package net.locusworks.discord.eighttrack.audio;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.UUID;
|
||||||
import org.apache.tika.exception.TikaException;
|
import org.jaudiotagger.audio.AudioFile;
|
||||||
import org.apache.tika.metadata.Metadata;
|
import org.jaudiotagger.audio.AudioFileIO;
|
||||||
import org.apache.tika.parser.ParseContext;
|
import org.jaudiotagger.tag.Tag;
|
||||||
import org.apache.tika.parser.mp3.Mp3Parser;
|
|
||||||
import org.apache.tika.sax.BodyContentHandler;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class Mp3UploadHandler {
|
public class Mp3UploadHandler {
|
||||||
|
|
||||||
public Mp3UploadResults parse(Path file) throws IOException {
|
public Mp3UploadResults parse(Path file) throws IOException {
|
||||||
InputStream is = Files.newInputStream(file);
|
InputStream is = Files.newInputStream(file);
|
||||||
return parse(is);
|
return parse(is, file.getFileName().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mp3UploadResults parse(InputStream is) throws IOException {
|
public Mp3UploadResults parse(InputStream is, String fileName) throws IOException {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
Path tmp = null;
|
||||||
try(InputStream in = is; ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
try(InputStream in = is; ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||||
int read = 0;
|
int read = 0;
|
||||||
byte[] buffer = new byte[1024 * 1024];
|
byte[] buffer = new byte[1024 * 1024];
|
||||||
@ -60,29 +57,23 @@ public class Mp3UploadHandler {
|
|||||||
baos.write(buffer, 0, read);
|
baos.write(buffer, 0, read);
|
||||||
}
|
}
|
||||||
data = baos.toByteArray();
|
data = baos.toByteArray();
|
||||||
}
|
|
||||||
|
|
||||||
try (InputStream in = new ByteArrayInputStream(data)) {
|
|
||||||
BodyContentHandler handler = new BodyContentHandler();
|
|
||||||
Metadata metadata = new Metadata();
|
|
||||||
ParseContext context = new ParseContext();
|
|
||||||
|
|
||||||
Mp3Parser parser = new Mp3Parser();
|
|
||||||
|
|
||||||
parser.parse(in, handler, metadata, context);
|
|
||||||
|
|
||||||
return new Mp3UploadResults(metadata, data);
|
String id = UUID.nameUUIDFromBytes(data).toString();
|
||||||
|
|
||||||
|
tmp = Paths.get(String.format("%s_%s", id, fileName));
|
||||||
|
|
||||||
|
Files.write(tmp, data);
|
||||||
|
|
||||||
|
AudioFile f = AudioFileIO.read(tmp.toFile());
|
||||||
|
Tag tag = f.getTag();
|
||||||
|
|
||||||
|
return new Mp3UploadResults(tag, data);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IOException(ex);
|
return new Mp3UploadResults(ex);
|
||||||
|
} finally {
|
||||||
|
if (tmp != null) {
|
||||||
|
Files.deleteIfExists(tmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws IOException, SAXException, TikaException {
|
|
||||||
String file = "E:\\Music2\\Alan Walker\\Itinerary_ Dallas.pdf";
|
|
||||||
Path path = Paths.get(file);
|
|
||||||
|
|
||||||
Mp3UploadHandler fuh = new Mp3UploadHandler();
|
|
||||||
fuh.parse(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: Mp3UploadResults.java
|
* Project: Eight Track, File: Mp3UploadResults.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -25,34 +25,13 @@
|
|||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.handlers;
|
package net.locusworks.discord.eighttrack.audio;
|
||||||
|
|
||||||
import org.apache.tika.metadata.Metadata;
|
import org.jaudiotagger.tag.FieldKey;
|
||||||
|
import org.jaudiotagger.tag.Tag;
|
||||||
|
|
||||||
public class Mp3UploadResults {
|
public class Mp3UploadResults {
|
||||||
|
|
||||||
private enum MetaDataField {
|
|
||||||
GENRE("xmpDM:genre"),
|
|
||||||
COMPOSER("xmpDM:composer"),
|
|
||||||
ALBUM("xmpDM:album"),
|
|
||||||
TRACK_NUMBER("xmpDM:trackNumber"),
|
|
||||||
DISC_NUMBER("xmpDM:discNumber"),
|
|
||||||
ARTIST("xmpDM:artist"),
|
|
||||||
TITLE("title"),
|
|
||||||
RELEASE_DATE("xmpDM:releaseDate"),
|
|
||||||
DURATION("xmpDM:duration");
|
|
||||||
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
private MetaDataField(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String genre;
|
private String genre;
|
||||||
private String composure;
|
private String composure;
|
||||||
private String album;
|
private String album;
|
||||||
@ -61,29 +40,28 @@ public class Mp3UploadResults {
|
|||||||
private String artist;
|
private String artist;
|
||||||
private String title;
|
private String title;
|
||||||
private String releaseDate;
|
private String releaseDate;
|
||||||
private Long duration;
|
|
||||||
|
|
||||||
private byte[] rawData;
|
private byte[] rawData;
|
||||||
|
private Throwable err;
|
||||||
|
|
||||||
public Mp3UploadResults( Metadata metadata, byte[] data) {
|
public Mp3UploadResults(Tag tag, byte[] data) {
|
||||||
parseResults(metadata);
|
parseResults(tag);
|
||||||
this.rawData = data;
|
this.rawData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Mp3UploadResults(Throwable err) {
|
||||||
|
this.err = err;
|
||||||
|
}
|
||||||
|
|
||||||
private void parseResults(Metadata metadata) {
|
private void parseResults(Tag tag) {
|
||||||
genre = metadata.get(MetaDataField.GENRE.getValue());
|
genre = tag.getFirst(FieldKey.GENRE);
|
||||||
composure = metadata.get(MetaDataField.COMPOSER.getValue());
|
composure = tag.getFirst(FieldKey.COMPOSER);
|
||||||
album = metadata.get(MetaDataField.ALBUM.getValue());
|
album = tag.getFirst(FieldKey.ALBUM);
|
||||||
trackNumber = metadata.get(MetaDataField.TRACK_NUMBER.getValue());
|
trackNumber = tag.getFirst(FieldKey.TRACK);
|
||||||
discNumber = metadata.get(MetaDataField.DISC_NUMBER.getValue());
|
discNumber = tag.getFirst(FieldKey.DISC_NO);
|
||||||
artist = metadata.get(MetaDataField.ARTIST.getValue());
|
artist = tag.getFirst(FieldKey.ARTIST);
|
||||||
title = metadata.get(MetaDataField.TITLE.getValue());
|
title = tag.getFirst(FieldKey.TITLE);
|
||||||
releaseDate = metadata.get(MetaDataField.RELEASE_DATE.getValue());
|
releaseDate = tag.getFirst(FieldKey.ORIGINAL_YEAR);
|
||||||
|
|
||||||
String durationStr = metadata.get(MetaDataField.DURATION.getValue()).trim();
|
|
||||||
if (durationStr != null) {
|
|
||||||
duration = Double.valueOf(metadata.get(MetaDataField.DURATION.getValue())).longValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte[] getData() {
|
public final byte[] getData() {
|
||||||
@ -146,23 +124,24 @@ public class Mp3UploadResults {
|
|||||||
return releaseDate;
|
return releaseDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the duration
|
|
||||||
*/
|
|
||||||
public final Long getDuration() {
|
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String getDurationFormat() {
|
|
||||||
return dateFormat(duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validFile() {
|
public boolean validFile() {
|
||||||
return getTitle() != null && !getTitle().isEmpty();
|
return (getTitle() != null && !getTitle().isEmpty() && getArtist() != null && !getArtist().trim().isEmpty()) || this.err != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasError() {
|
||||||
|
return this.err != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Throwable getError() {
|
||||||
|
return this.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if (this.hasError()) {
|
||||||
|
return "Unable to parse file due to exception: " + this.err.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (getTitle() != null)
|
if (getTitle() != null)
|
||||||
sb.append(String.format("%-10s: %s%n", "Title", getTitle()));
|
sb.append(String.format("%-10s: %s%n", "Title", getTitle()));
|
||||||
@ -185,32 +164,10 @@ public class Mp3UploadResults {
|
|||||||
if (getGenre() != null)
|
if (getGenre() != null)
|
||||||
sb.append(String.format("%-10s: %s%n", "Genre", getGenre()));
|
sb.append(String.format("%-10s: %s%n", "Genre", getGenre()));
|
||||||
|
|
||||||
if (duration != null)
|
|
||||||
sb.append(String.format("%-10s: %s%n", "Duration", dateFormat(getDuration())));
|
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
rawData = new byte[0];
|
rawData = new byte[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dateFormat(long timeInMilliSeconds) {
|
|
||||||
long seconds = timeInMilliSeconds / 1000;
|
|
||||||
long minutes = seconds / 60;
|
|
||||||
long hours = minutes / 60;
|
|
||||||
long days = hours / 24;
|
|
||||||
|
|
||||||
long sec = seconds % 60;
|
|
||||||
long min = minutes % 60;
|
|
||||||
long hr = hours % 24;
|
|
||||||
|
|
||||||
String time = "" + sec;
|
|
||||||
if (min > 0) time = min + ":" + time;
|
|
||||||
if (hr > 0) time = hr + ":" + time;
|
|
||||||
if (days > 0) time = days + ":" + time;
|
|
||||||
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: TrackManager.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.audio;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayer;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
||||||
|
|
||||||
|
public class TrackManager extends DefaultAudioPlayer {
|
||||||
|
|
||||||
|
private LinkedBlockingDeque<String> queue;
|
||||||
|
private AudioPlayerManager playerManager;
|
||||||
|
private TrackScheduler trackScheduler;
|
||||||
|
private String currentItem;
|
||||||
|
|
||||||
|
public TrackManager() {
|
||||||
|
super(new DefaultAudioPlayerManager());
|
||||||
|
this.queue = new LinkedBlockingDeque<String>();
|
||||||
|
this.trackScheduler = new TrackScheduler();
|
||||||
|
|
||||||
|
addListener(trackScheduler);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field f = this.getClass().getSuperclass().getDeclaredField("manager");
|
||||||
|
f.setAccessible(true);
|
||||||
|
this.playerManager = (AudioPlayerManager) f.get(this);
|
||||||
|
} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioSourceManagers.registerLocalSource(this.playerManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queueLast(String track) {
|
||||||
|
queue.addLast(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queueNext(String track) {
|
||||||
|
queue.addFirst(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTracks() {
|
||||||
|
return queue.peek() != null && !queue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentItem() {
|
||||||
|
return currentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioTrack play() {
|
||||||
|
if (!queue.isEmpty()) {
|
||||||
|
try {
|
||||||
|
currentItem = queue.poll();
|
||||||
|
playerManager.loadItem(currentItem, trackScheduler).get();
|
||||||
|
return trackScheduler.getNextTrack();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinishedCallback(Consumer<AudioTrackEndReason> callback) {
|
||||||
|
trackScheduler.setFinishedCallback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearTracks() {
|
||||||
|
queue.clear();
|
||||||
|
trackScheduler.clearTracks();
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: TrackScheduler.java
|
* Project: Eight Track, File: TrackScheduler.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -25,7 +25,7 @@
|
|||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.scheduler;
|
package net.locusworks.discord.eighttrack.audio;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: EightTrackBeanConfiguration.java
|
* Project: Eight Track, File: EightTrackBeanConfiguration.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -34,6 +34,9 @@ import javax.sql.DataSource;
|
|||||||
|
|
||||||
import org.flywaydb.core.Flyway;
|
import org.flywaydb.core.Flyway;
|
||||||
import org.flywaydb.core.api.configuration.FluentConfiguration;
|
import org.flywaydb.core.api.configuration.FluentConfiguration;
|
||||||
|
import org.flywaydb.core.api.logging.Log;
|
||||||
|
import org.flywaydb.core.api.logging.LogCreator;
|
||||||
|
import org.flywaydb.core.api.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -48,6 +51,8 @@ import org.springframework.orm.jpa.vendor.Database;
|
|||||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
@Configuration(value="net.locusworks.discord.eighttrack.database.config.EightTrackBeanConfiguration")
|
@Configuration(value="net.locusworks.discord.eighttrack.database.config.EightTrackBeanConfiguration")
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@ -69,9 +74,6 @@ public class EightTrackBeanConfiguration {
|
|||||||
static {
|
static {
|
||||||
hibernateProperties = new Properties();
|
hibernateProperties = new Properties();
|
||||||
hibernateProperties.setProperty("hibernate.connection.zeroDateTimeBehavior", "convertToNull");
|
hibernateProperties.setProperty("hibernate.connection.zeroDateTimeBehavior", "convertToNull");
|
||||||
hibernateProperties.setProperty("hibernate.dbcp.maxActive", "50");
|
|
||||||
hibernateProperties.setProperty("hibernate.dbcp.maxIdle", "10");
|
|
||||||
hibernateProperties.setProperty("hibernate.dbcp.maxWait", "5000");
|
|
||||||
hibernateProperties.setProperty("hibernate.jdbc.batch_size property", "50");
|
hibernateProperties.setProperty("hibernate.jdbc.batch_size property", "50");
|
||||||
hibernateProperties.setProperty("hibernate.connection.charSet", "utf8");
|
hibernateProperties.setProperty("hibernate.connection.charSet", "utf8");
|
||||||
hibernateProperties.setProperty("hibernate.connection.characterEncoding", "utf8");
|
hibernateProperties.setProperty("hibernate.connection.characterEncoding", "utf8");
|
||||||
@ -143,6 +145,7 @@ public class EightTrackBeanConfiguration {
|
|||||||
|
|
||||||
@Bean(name="flyway", initMethod="migrate")
|
@Bean(name="flyway", initMethod="migrate")
|
||||||
public Flyway flyway() {
|
public Flyway flyway() {
|
||||||
|
LogFactory.setLogCreator(new FlywayLogCreator());
|
||||||
FluentConfiguration fc = Flyway.configure();
|
FluentConfiguration fc = Flyway.configure();
|
||||||
fc.schemas("eighttrack");
|
fc.schemas("eighttrack");
|
||||||
fc.table("_flyway_migration");
|
fc.table("_flyway_migration");
|
||||||
@ -152,5 +155,53 @@ public class EightTrackBeanConfiguration {
|
|||||||
|
|
||||||
return fc.load();
|
return fc.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FlywayLogCreator implements LogCreator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Log createLogger(Class<?> clazz) {
|
||||||
|
return new FlywayLog(clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FlywayLog implements Log {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
public FlywayLog(Class<?> clazz) {
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
return logger.isDebugEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String message) {
|
||||||
|
logger.debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String message) {
|
||||||
|
logger.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String message) {
|
||||||
|
logger.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String message, Exception e) {
|
||||||
|
logger.error(message, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: EightTrackDataSource.java
|
* Project: Eight Track, File: EightTrackDataSource.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -30,30 +30,20 @@ package net.locusworks.discord.eighttrack.database.config;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.dbcp2.ConnectionFactory;
|
|
||||||
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
|
|
||||||
import org.apache.commons.dbcp2.PoolableConnection;
|
|
||||||
import org.apache.commons.dbcp2.PoolableConnectionFactory;
|
|
||||||
import org.apache.commons.dbcp2.PoolingDataSource;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.pool2.impl.AbandonedConfig;
|
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
||||||
import org.mariadb.jdbc.MariaDbDataSource;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
@Component
|
@Component
|
||||||
@ -72,7 +62,7 @@ public class EightTrackDataSource {
|
|||||||
mysqlProperties.put("serverTimezone", TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT));
|
mysqlProperties.put("serverTimezone", TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(EightTrackDataSource.class);
|
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(EightTrackDataSource.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigurationService confService;
|
private ConfigurationService confService;
|
||||||
@ -84,36 +74,17 @@ public class EightTrackDataSource {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource dataSource() throws Exception {
|
public DataSource dataSource() throws Exception {
|
||||||
return getDataSource(false);
|
logger.debug("Getting datasource");
|
||||||
|
return getDataSource(confService.getDatabaseUsername(), confService.getDatabasePassword(), "/eighttrack");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource flywayDataSource() throws Exception {
|
public DataSource flywayDataSource() throws Exception {
|
||||||
logger.debug("Logging in with flyway for migrations");
|
logger.debug("Logging in with flyway for migrations");;
|
||||||
|
return getDataSource(confService.getDatabaseRootUsername(), confService.getDatabaseRootPassword(), "");
|
||||||
String user = confService.getDatabaseRootUsername();
|
|
||||||
String passwd = confService.getDatabaseRootPassword();
|
|
||||||
|
|
||||||
String url = String.format("jdbc:mariadb://%s:%d?user=%s&password=%s",
|
|
||||||
confService.getDatabaseHost(), confService.getDatabasePort(),
|
|
||||||
user, passwd);
|
|
||||||
|
|
||||||
MariaDbDataSource mariadbDS = new MariaDbDataSource(url);
|
|
||||||
|
|
||||||
return mariadbDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSource getDataSource(Boolean isFlyway) throws Exception {
|
private DataSource getDataSource(String user, String passwd, String db) throws Exception {
|
||||||
logger.debug("Gettind datasource");
|
|
||||||
Class.forName(DRIVER).getDeclaredConstructor().newInstance();
|
|
||||||
|
|
||||||
String user = confService.getDatabaseUsername();
|
|
||||||
String passwd = confService.getDatabasePassword();
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.setProperty("user", user);
|
|
||||||
props.setProperty("password", passwd);
|
|
||||||
|
|
||||||
List<String> params = mysqlProperties
|
List<String> params = mysqlProperties
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@ -123,40 +94,19 @@ public class EightTrackDataSource {
|
|||||||
String host = confService.getDatabaseHost();
|
String host = confService.getDatabaseHost();
|
||||||
int port = confService.getDatabasePort();
|
int port = confService.getDatabasePort();
|
||||||
|
|
||||||
String url = String.format(JNDI_STRING, host, port, "/eighttrack");
|
String url = String.format(JNDI_STRING, host, port, db);
|
||||||
|
|
||||||
url = String.format("%s?%s", url, StringUtils.join(params, "&"));
|
url = String.format("%s?%s", url, StringUtils.join(params, "&"));
|
||||||
|
|
||||||
logger.debug("Database connection string: %s", url);
|
logger.debug(String.format("Database connection string: %s", url));
|
||||||
|
|
||||||
ConnectionFactory cf = new DriverManagerConnectionFactory(url, props);
|
return DataSourceBuilder
|
||||||
//Create the poolable connection factory
|
.create()
|
||||||
PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, null);
|
.username(user)
|
||||||
pcf.setValidationQuery("SELECT 1");
|
.password(passwd)
|
||||||
pcf.setDefaultAutoCommit(true);
|
.url(url)
|
||||||
|
.driverClassName(DRIVER)
|
||||||
GenericObjectPoolConfig<PoolableConnection> poolConfig = new GenericObjectPoolConfig<>();
|
.build();
|
||||||
poolConfig.setMinIdle(10);
|
|
||||||
poolConfig.setMaxTotal(100);
|
|
||||||
|
|
||||||
AbandonedConfig abandonConfig = new AbandonedConfig();
|
|
||||||
abandonConfig.setRemoveAbandonedTimeout(60);
|
|
||||||
abandonConfig.setLogAbandoned(false);
|
|
||||||
abandonConfig.setRemoveAbandonedOnBorrow(true);
|
|
||||||
abandonConfig.setRemoveAbandonedOnMaintenance(true);
|
|
||||||
|
|
||||||
//Create the pool of connections
|
|
||||||
GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(pcf, poolConfig);
|
|
||||||
connectionPool.setTestOnBorrow(true);
|
|
||||||
connectionPool.setTestWhileIdle(true);
|
|
||||||
connectionPool.setTimeBetweenEvictionRunsMillis(10000);
|
|
||||||
connectionPool.setMinEvictableIdleTimeMillis(1000);
|
|
||||||
connectionPool.setAbandonedConfig(abandonConfig);
|
|
||||||
pcf.setPool(connectionPool);
|
|
||||||
|
|
||||||
//Pooling data source itself
|
|
||||||
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
|
|
||||||
return dataSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: DiscordGuild.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
@ -50,6 +77,8 @@ public class DiscordGuild implements Serializable {
|
|||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
||||||
private List<GuildSong> guildSongList;
|
private List<GuildSong> guildSongList;
|
||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
||||||
|
private List<Log> logList;
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
||||||
private List<GuildPlaylist> guildPlaylistList;
|
private List<GuildPlaylist> guildPlaylistList;
|
||||||
|
|
||||||
public DiscordGuild() {
|
public DiscordGuild() {
|
||||||
@ -105,6 +134,14 @@ public class DiscordGuild implements Serializable {
|
|||||||
this.guildSongList = guildSongList;
|
this.guildSongList = guildSongList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Log> getLogList() {
|
||||||
|
return logList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogList(List<Log> logList) {
|
||||||
|
this.logList = logList;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GuildPlaylist> getGuildPlaylistList() {
|
public List<GuildPlaylist> getGuildPlaylistList() {
|
||||||
return guildPlaylistList;
|
return guildPlaylistList;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: GuildPlaylist.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: GuildPlaylistSong.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: GuildSong.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: Log.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.database.entities;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.Lob;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author isaac
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "log", catalog = "eighttrack", schema = "")
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(name = "Log.findAll", query = "SELECT l FROM Log l")})
|
||||||
|
public class Log implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Long id;
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Lob
|
||||||
|
@Column(name = "log")
|
||||||
|
private String log;
|
||||||
|
@Lob
|
||||||
|
@Column(name = "exception")
|
||||||
|
private byte[] exception;
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "is_exception")
|
||||||
|
private boolean isException;
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "date_added")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date dateAdded;
|
||||||
|
@JoinColumn(name = "guild", referencedColumnName = "id")
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
private DiscordGuild guild;
|
||||||
|
|
||||||
|
public Log() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log(Long id, String log, boolean isException, Date dateAdded) {
|
||||||
|
this.id = id;
|
||||||
|
this.log = log;
|
||||||
|
this.isException = isException;
|
||||||
|
this.dateAdded = dateAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLog() {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLog(String log) {
|
||||||
|
this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setException(byte[] exception) {
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsException() {
|
||||||
|
return isException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsException(boolean isException) {
|
||||||
|
this.isException = isException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDateAdded() {
|
||||||
|
return dateAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateAdded(Date dateAdded) {
|
||||||
|
this.dateAdded = dateAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscordGuild getGuild() {
|
||||||
|
return guild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGuild(DiscordGuild guild) {
|
||||||
|
this.guild = guild;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 0;
|
||||||
|
hash += (id != null ? id.hashCode() : 0);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||||
|
if (!(object instanceof Log)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Log other = (Log) object;
|
||||||
|
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "net.locusworks.discord.eighttrack.database.entities.Log[ id=" + id + " ]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: Song.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: GuildLogRepository.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.database.repos;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.Log;
|
||||||
|
|
||||||
|
public interface GuildLogRepository extends CrudRepository<Log, Long> {
|
||||||
|
|
||||||
|
List<Log> findByGuild(DiscordGuild guild);
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildSongRepository.java
|
* Project: Eight Track, File: GuildPlaylistRepository.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -42,6 +42,11 @@ public interface GuildPlaylistRepository extends CrudRepository<GuildPlaylist, L
|
|||||||
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3")
|
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3")
|
||||||
GuildPlaylist findByGuildAndUserIdAndPlaylist(Long guild, Long userId, String playlist);
|
GuildPlaylist findByGuildAndUserIdAndPlaylist(Long guild, Long userId, String playlist);
|
||||||
|
|
||||||
|
List<GuildPlaylist> findByGuild(DiscordGuild guild);
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT gpl FROM GuildPlaylist gpl LEFT JOIN FETCH gpl.guildPlaylistSongList WHERE gpl.guild.guildId = ?1")
|
||||||
|
List<GuildPlaylist> findByGuildFetchSongs(Long guild);
|
||||||
|
|
||||||
List<GuildPlaylist> findByGuildAndUserId(DiscordGuild guild, Long userId);
|
List<GuildPlaylist> findByGuildAndUserId(DiscordGuild guild, Long userId);
|
||||||
|
|
||||||
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2")
|
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2")
|
||||||
@ -51,6 +56,6 @@ public interface GuildPlaylistRepository extends CrudRepository<GuildPlaylist, L
|
|||||||
List<GuildPlaylist> findByGuildAndUserIdFetchSongs(Long guild, Long userId);
|
List<GuildPlaylist> findByGuildAndUserIdFetchSongs(Long guild, Long userId);
|
||||||
|
|
||||||
@Query("SELECT DISTINCT gpl FROM GuildPlaylist gpl LEFT JOIN FETCH gpl.guildPlaylistSongList WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3")
|
@Query("SELECT DISTINCT gpl FROM GuildPlaylist gpl LEFT JOIN FETCH gpl.guildPlaylistSongList WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3")
|
||||||
GuildPlaylist findGuildUserPlaylistFetchSongs(Long guild, Long userId, String playlist);
|
GuildPlaylist findByGuildUserPlaylistFetchSongs(Long guild, Long userId, String playlist);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildSongRepository.java
|
* Project: Eight Track, File: GuildPlaylistSongRepository.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildRepository.java
|
* Project: Eight Track, File: GuildRepository.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildSongRepository.java
|
* Project: Eight Track, File: GuildSongRepository.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -28,6 +28,7 @@
|
|||||||
package net.locusworks.discord.eighttrack.database.repos;
|
package net.locusworks.discord.eighttrack.database.repos;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
@ -53,4 +54,9 @@ public interface GuildSongRepository extends CrudRepository<GuildSong, Long> {
|
|||||||
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 ORDER BY RAND()")
|
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 ORDER BY RAND()")
|
||||||
List<GuildSong> findRandomSong(Long guildId);
|
List<GuildSong> findRandomSong(Long guildId);
|
||||||
|
|
||||||
|
List<GuildSong> findByGuildAndUuidIn(DiscordGuild guild, Set<String> uuid);
|
||||||
|
|
||||||
|
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 AND gs.uuid in ?2")
|
||||||
|
List<GuildSong> findByGuildAndUuidIn(Long guildId, Set<String> uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: SongRepository.java
|
* Project: Eight Track, File: SongRepository.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: Configuration.java
|
* Project: Eight Track, File: Configuration.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AbstractEvent.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
||||||
|
import net.dv8tion.jda.api.requests.ErrorResponse;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||||
|
|
||||||
|
public abstract class AbstractEvent {
|
||||||
|
|
||||||
|
private String command;
|
||||||
|
|
||||||
|
protected AbstractEvent(String command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommand() {
|
||||||
|
return this.command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void executeEvent(GuildMessageReceivedEvent event, List<String> commands);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract String help();
|
||||||
|
|
||||||
|
protected boolean isAdmin(GuildMessageReceivedEvent event) {
|
||||||
|
if (!event.getMessage().getMember().hasPermission(Permission.ADMINISTRATOR, Permission.MANAGE_SERVER)) {
|
||||||
|
event.getChannel().sendMessage(String.format("Sorry <@%s> i can't do that. *psst: you have to have manage server, or administrator role*", event.getMember().getIdLong())).queue();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkCommands(GuildMessageReceivedEvent event, List<String> commands, String msg) {
|
||||||
|
return checkCommands(event, commands, 0, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkCommands(GuildMessageReceivedEvent event, List<String> commands, int minParams, String msg) {
|
||||||
|
if (commands == null || commands.isEmpty() || commands.size() < minParams) {
|
||||||
|
event.getChannel().sendMessage(msg).queue();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendMessage(GuildMessageReceivedEvent event, String msg) {
|
||||||
|
sendMessage(event, msg, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendMessage(GuildMessageReceivedEvent event, String msg, boolean wait) {
|
||||||
|
if (!wait) {
|
||||||
|
event.getChannel().sendMessage(msg).queue();
|
||||||
|
} else {
|
||||||
|
event.getChannel().sendMessage(msg).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendMessage(GuildMessageReceivedEvent event, String msgFmt, Object... args) {
|
||||||
|
sendMessage(event, String.format(msgFmt, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendMessage(GuildMessageReceivedEvent event, boolean wait, String msgFmt, Object... args) {
|
||||||
|
sendMessage(event, String.format(msgFmt, args), wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteMessage(Message msg, ReactionHandler reactionHandler, Long guildId) {
|
||||||
|
try {
|
||||||
|
msg.delete().complete();
|
||||||
|
if (reactionHandler != null) {
|
||||||
|
reactionHandler.removeReactionListener(guildId, msg.getIdLong());
|
||||||
|
}
|
||||||
|
} catch (ErrorResponseException ex) {
|
||||||
|
if (ex.getErrorResponse() != ErrorResponse.UNKNOWN_MESSAGE) throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AbstractAdminEventHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.admin;
|
||||||
|
|
||||||
|
import net.locusworks.discord.eighttrack.events.AbstractEvent;
|
||||||
|
|
||||||
|
public abstract class AbstractAdminEventHandler extends AbstractEvent {
|
||||||
|
|
||||||
|
|
||||||
|
public AbstractAdminEventHandler(String command) {
|
||||||
|
super(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AdminPlaylistDeleteHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.admin.handlers;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
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.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.discord.eighttrack.utils.Reactions;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AdminPlaylistDeleteHandler extends AbstractAdminEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactionHandler reactionHandler;
|
||||||
|
|
||||||
|
public AdminPlaylistDeleteHandler() {
|
||||||
|
super("delete");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(AdminPlaylistDeleteHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (!isAdmin(event)) return;
|
||||||
|
|
||||||
|
if (!checkCommands(event, commands, 2, "Must provide playlist and user's tag (in that order)")) return;
|
||||||
|
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
String userTag = commands.remove(0);
|
||||||
|
|
||||||
|
Member m = event.getGuild().getMemberByTag(userTag);
|
||||||
|
if (m == null) {
|
||||||
|
sendMessage(event, String.format("Unable to find user with tag %s", userTag));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuildPlaylist gpl = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(event.getGuild().getIdLong(), m.getIdLong(), playlist);
|
||||||
|
if (gpl == null) {
|
||||||
|
sendMessage(event, String.format("Unable to find play list %s for user %s", playlist, userTag));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long userId = event.getMember().getIdLong();
|
||||||
|
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTitle("Delete Playlist " + playlist)
|
||||||
|
.setDescription("Are you sure you want to delete the playlist " + playlist)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(embed).queue((msg) -> {
|
||||||
|
|
||||||
|
ReactionListener<String> handler = new ReactionListener<>(userId, msg.getId());
|
||||||
|
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
||||||
|
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deletePlayListConfirm(gpl, event.getMember().getAsMention(), msg));
|
||||||
|
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg, reactionHandler, event.getGuild().getIdLong()));
|
||||||
|
|
||||||
|
reactionHandler.addReactionListener( event.getGuild().getIdLong(), msg, handler);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deletePlayListConfirm(GuildPlaylist gpl, String user, Message msg) {
|
||||||
|
String playlist = gpl.getPlaylist();
|
||||||
|
try {
|
||||||
|
guildRepoService.getGuildPlaylistRepo().delete(gpl);
|
||||||
|
msg.getChannel().sendMessage(user + " " + playlist + " deleted successfully").complete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove playlist " + playlist + ". Reason: " + ex.getMessage()).complete();
|
||||||
|
logger.error("Unable to delete playlist " + playlist + ": " + ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
guildRepoService.logEntry(msg.getGuild().getIdLong(), ex, "Unable to delete playlist: %s", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
deleteMessage(msg, reactionHandler, msg.getGuild().getIdLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "delete <playlist name> <user discord tag>";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AdminPlaylistListHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.admin.handlers;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AdminPlaylistListHandler extends AbstractAdminEventHandler {
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
public AdminPlaylistListHandler() {
|
||||||
|
super("list");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (!isAdmin(event)) return;
|
||||||
|
|
||||||
|
List<GuildPlaylist> userPlaylist = guildRepoService.getGuildPlaylistRepo().findByGuildFetchSongs(event.getGuild().getIdLong());
|
||||||
|
if (userPlaylist == null || userPlaylist.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", there are no playlists for this guild").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int longestPlaylist = 10;
|
||||||
|
int longestUserName = 10;
|
||||||
|
Map<Long, String> userMap = new HashMap<>();
|
||||||
|
for(GuildPlaylist gpl : userPlaylist) {
|
||||||
|
if (gpl.getPlaylist().length() > longestPlaylist) longestPlaylist = gpl.getPlaylist().length();
|
||||||
|
|
||||||
|
Member m = event.getGuild().getMemberById(gpl.getUserId());
|
||||||
|
if (m == null) continue;
|
||||||
|
|
||||||
|
if (m.getUser().getAsTag().length() > longestUserName) longestUserName = m.getUser().getAsTag().length();
|
||||||
|
userMap.put(gpl.getUserId(), m.getUser().getAsTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
String fmt = "%6s | %-" + longestPlaylist +"s | %-" + longestUserName + "s | %s%n";
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("```");
|
||||||
|
sb.append(String.format(fmt, "", "Playlist", "User", "Song Count"));
|
||||||
|
sb.append(StringUtils.repeat("-", 24 + longestPlaylist + longestUserName)).append("\n");
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for(GuildPlaylist gpl : userPlaylist) {
|
||||||
|
sb.append(String.format(fmt, ++count, gpl.getPlaylist(), userMap.get(gpl.getUserId()), gpl.getGuildPlaylistSongList().size()));
|
||||||
|
}
|
||||||
|
sb.append("```");
|
||||||
|
event.getChannel().sendMessage("**Playlists for " + event.getGuild().getName() + "**").queue((succcess)->
|
||||||
|
event.getChannel().sendMessage(sb.toString()).queue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "list" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AbstractMainEventHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main;
|
||||||
|
|
||||||
|
import net.locusworks.discord.eighttrack.events.AbstractEvent;
|
||||||
|
|
||||||
|
public abstract class AbstractMainEventHandler extends AbstractEvent {
|
||||||
|
|
||||||
|
public AbstractMainEventHandler(String command) {
|
||||||
|
super(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AdminPlaylistHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AdminPlaylistHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
private Map<String, AbstractAdminEventHandler> handlers;
|
||||||
|
|
||||||
|
public AdminPlaylistHandler() {
|
||||||
|
super("+playlist");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(AdminPlaylistHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private void init(List<AbstractAdminEventHandler> eventHandlers) {
|
||||||
|
handlers = new TreeMap<>();
|
||||||
|
for(AbstractAdminEventHandler apeh : eventHandlers) {
|
||||||
|
handlers.put(apeh.getCommand(), apeh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (!isAdmin(event)) return;
|
||||||
|
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage("Missing command for +playlist. Valid commands are: list, delete").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String command = commands.remove(0);
|
||||||
|
|
||||||
|
AbstractAdminEventHandler apeh = handlers.get(command);
|
||||||
|
if (apeh == null) {
|
||||||
|
sendMessage(event, help());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
apeh.executeEvent(event, commands);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to display playlist: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to display playlist: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to display the playlist: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(Entry<String, AbstractAdminEventHandler> entry : handlers.entrySet()) {
|
||||||
|
sb.append(entry.getValue().help()).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "+playlist | " + sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: DeleteSongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.discord.eighttrack.utils.Reactions;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DeleteSongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactionHandler reactionHandler;
|
||||||
|
|
||||||
|
public DeleteSongHandler() {
|
||||||
|
super("+delete");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(DeleteSongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if(!isAdmin(event)) return;
|
||||||
|
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getMember().getAsMention() + ", Missing command for +delete. Valid command is : +delete uuids...").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteSong(event, commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteSong(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if(!checkCommands(event, commands,
|
||||||
|
event.getAuthor().getAsMention() + ", you have to provide the list of uuids for songs to remove")) return;
|
||||||
|
|
||||||
|
List<GuildSong> songs = guildRepoService.getGuildSongRepo().findByGuildAndUuidIn(event.getGuild().getIdLong(), commands.stream().collect(Collectors.toSet()));
|
||||||
|
if (songs.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", there are no songs for this guild").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("Are you sure you want to delete the following songs?\n");
|
||||||
|
for (GuildSong gs : songs) {
|
||||||
|
sb.append(String.format("**%s** by __%s__%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTitle("Delete Playlist Songs")
|
||||||
|
.setDescription(sb.toString())
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(embed).queue((msg) -> {
|
||||||
|
|
||||||
|
ReactionListener<String> handler = new ReactionListener<>(event.getAuthor().getIdLong(), msg.getId());
|
||||||
|
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
||||||
|
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deleteGuildSongsConfirm(songs, event.getMember().getAsMention(), msg));
|
||||||
|
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg, reactionHandler, event.getGuild().getIdLong()));
|
||||||
|
|
||||||
|
reactionHandler.addReactionListener(event.getGuild().getIdLong(), msg, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteGuildSongsConfirm(List<GuildSong> songs, String user, Message msg) {
|
||||||
|
try {
|
||||||
|
guildRepoService.getGuildSongRepo().deleteAll(songs);
|
||||||
|
msg.getChannel().sendMessage(user + ", songs were deleted successfully").complete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove the selected songs. Reason: " + ex.getMessage()).complete();
|
||||||
|
logger.error("Unable to delete songs: " + ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
guildRepoService.logEntry(msg.getGuild().getIdLong(), ex, "Unable to delete songs: %s", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
deleteMessage(msg, reactionHandler, msg.getGuild().getIdLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-next <id of song to play> (will stop song if one already playing)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: NextSongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class NextSongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService musicService;
|
||||||
|
|
||||||
|
public NextSongHandler() {
|
||||||
|
super("-next");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(NextSongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
musicHandler.next(event, commands);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to play next song: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to play next song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to play next song: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-next <id of song to play> (will stop song if one already playing)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaySongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaySongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService musicService;
|
||||||
|
|
||||||
|
public PlaySongHandler() {
|
||||||
|
super("-play");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(PlaySongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
musicHandler.play(event, commands);
|
||||||
|
musicHandler.isPlaying(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to play song: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to play song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to play requested song: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-play <id of song to play> (will not play song if a song is already playing)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaylistHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaylistHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
private Map<String, AbstractPlaylistEventHandler> handlers;
|
||||||
|
|
||||||
|
public PlaylistHandler() {
|
||||||
|
super("-playlist");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(PlaylistHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private void init(List<AbstractPlaylistEventHandler> eventHandlers) {
|
||||||
|
handlers = new TreeMap<>();
|
||||||
|
for(AbstractPlaylistEventHandler apeh : eventHandlers) {
|
||||||
|
handlers.put(apeh.getCommand(), apeh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage("Missing command for -playlist. Valid commands are: add, delete, list, play").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String command = commands.remove(0);
|
||||||
|
|
||||||
|
AbstractPlaylistEventHandler apeh = handlers.get(command);
|
||||||
|
if (apeh == null) {
|
||||||
|
sendMessage(event, help());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
apeh.executeEvent(event, commands);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to display playlist: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to display playlist: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to display the playlist: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(Entry<String, AbstractPlaylistEventHandler> entry : handlers.entrySet()) {
|
||||||
|
sb.append(entry.getValue().help()).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "-playlist | " + sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: RepeatSongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RepeatSongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService musicService;
|
||||||
|
|
||||||
|
public RepeatSongHandler() {
|
||||||
|
super("-repeat");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(RepeatSongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
musicHandler.repeat(event);
|
||||||
|
musicHandler.isPlaying(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to repeat songs: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to repeat song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to repeat songs: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-repeat (repeats the current song list)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: SongListHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SongListHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
public SongListHandler() {
|
||||||
|
super("-list");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(SongListHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
listSongs(event, commands);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to play next song: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to play next song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to play next song: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listSongs(GuildMessageReceivedEvent event, List<String> commands) throws Exception {
|
||||||
|
List<GuildSong> gsList = guildRepoService.getGuildSongRepo().findByGuild(event.getGuild().getIdLong());
|
||||||
|
|
||||||
|
if (gsList == null || gsList.isEmpty()) {
|
||||||
|
sendMessage(event, "There is no music for this guild.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int longestSong = 0;
|
||||||
|
int longestArtist = 0;
|
||||||
|
for(GuildSong gs : gsList) {
|
||||||
|
if (gs.getSong().getTitle().length() > longestSong) longestSong = gs.getSong().getTitle().length();
|
||||||
|
if (gs.getSong().getArtist().length() > longestArtist) longestArtist = gs.getSong().getArtist().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(event, true, "**Currently available songs for %s**\n\n", event.getGuild().getName());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
String fmt = "%6s | %-" + longestSong +"s | %-" + longestArtist +"s | %s%n";
|
||||||
|
StringBuilder sb = new StringBuilder("```");
|
||||||
|
sb.append(String.format(fmt, "Track", "Title", "Artist", "id"));
|
||||||
|
sb.append(StringUtils.repeat("-", 27 + longestSong + longestArtist)).append("\n");
|
||||||
|
|
||||||
|
for(GuildSong gs : gsList) {
|
||||||
|
String msg = String.format(fmt, ++count, gs.getSong().getTitle(), gs.getSong().getArtist(), gs.getUuid());
|
||||||
|
if (sb.length() + msg.length() > 2000) {
|
||||||
|
sb.append("```");
|
||||||
|
sendMessage(event, sb.toString(), true);
|
||||||
|
sb = new StringBuilder("```");
|
||||||
|
} else {
|
||||||
|
sb.append(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("```");
|
||||||
|
sendMessage(event, sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-list (lists the sonds to play)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: StopSongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class StopSongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService musicService;
|
||||||
|
|
||||||
|
public StopSongHandler() {
|
||||||
|
super("-stop");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(StopSongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
musicHandler.isPlaying(false);
|
||||||
|
musicHandler.stop(event);
|
||||||
|
event.getGuild().getAudioManager().closeAudioConnection();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to stop song: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to stop song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to stop current song: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-stop (stops the current song)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: UpNextSongHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class UpNextSongHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService musicService;
|
||||||
|
|
||||||
|
public UpNextSongHandler() {
|
||||||
|
super("-upnext");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(UpNextSongHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
try {
|
||||||
|
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
musicHandler.repeat(event);
|
||||||
|
musicHandler.isPlaying(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to show the next songs: " + ex.getMessage(), ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to show next song: %s", ex.getMessage());
|
||||||
|
sendMessage(event, "Sorry I am unable to show next songs: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "-upnext (shows which song is up next)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: UploadHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.main.handlers;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.entities.Message.Attachment;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.crypto.utils.HashUtils;
|
||||||
|
import net.locusworks.discord.eighttrack.audio.Mp3UploadHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.audio.Mp3UploadResults;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||||
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class UploadHandler extends AbstractMainEventHandler {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Mp3UploadHandler uploadHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildSongRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurationService confService;
|
||||||
|
|
||||||
|
public UploadHandler() {
|
||||||
|
super("+upload");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(UploadHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (!isAdmin(event)) return;
|
||||||
|
|
||||||
|
for(Attachment attachment : event.getMessage().getAttachments()) {
|
||||||
|
attachment.retrieveInputStream().thenAccept((in) -> {
|
||||||
|
Mp3UploadResults res = null;
|
||||||
|
MessageEmbed embed = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
res = uploadHandler.parse(in, attachment.getFileName());
|
||||||
|
if (res.validFile()) {
|
||||||
|
embed = persistSong(res, event, attachment.getFileName());
|
||||||
|
} else {
|
||||||
|
embed = wrongFile(event, attachment.getFileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to get file information: %s", ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
embed = error(event, ex, attachment.getFileName());
|
||||||
|
} finally {
|
||||||
|
event.getMessage().delete().queue();
|
||||||
|
if (res != null) res.clear();
|
||||||
|
|
||||||
|
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}).exceptionally((err) -> {
|
||||||
|
event.getMessage().delete().queue();
|
||||||
|
MessageEmbed embed = error(event, err, attachment.getFileName());
|
||||||
|
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageEmbed error(GuildMessageReceivedEvent event, Throwable ex, String fileName) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle("Unable to upload file: " + fileName)
|
||||||
|
.setDescription("There was an error uploading your file: " + ex.getMessage() + ". Please contact admin")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageEmbed wrongFile(GuildMessageReceivedEvent event, String fileName) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle("Invalid File: " + fileName)
|
||||||
|
.setDescription("Only music type files are allowed to be uploaded")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageEmbed persistSong(Mp3UploadResults result, GuildMessageReceivedEvent event, String fileName) throws Exception {
|
||||||
|
|
||||||
|
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(event.getGuild().getIdLong());
|
||||||
|
if(guild == null) {
|
||||||
|
throw new IOException("Unable to find guild in database. Please contact administrator");
|
||||||
|
}
|
||||||
|
|
||||||
|
String hash = HashUtils.hash("SHA-1", result.getData());
|
||||||
|
|
||||||
|
GuildSong gs = guildSongRepoService.getGuildSongRepo().findByGuildAndSongHash(event.getGuild().getIdLong(), hash);
|
||||||
|
if (gs != null) {
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setColor(Color.ORANGE)
|
||||||
|
.setThumbnail(event.getGuild().getIconUrl())
|
||||||
|
.setTitle("Upload Results for " + fileName)
|
||||||
|
.setDescription(String.format("**%s** by __%s__ already exists. ID: `%s`", gs.getSong().getTitle(), gs.getSong().getArtist(), gs.getUuid()))
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Song song = guildSongRepoService.getSongRepo().findByFileHash(hash);
|
||||||
|
if (song == null) {
|
||||||
|
|
||||||
|
Path output = confService.getMusicDirectory();
|
||||||
|
if (result.getArtist() != null) {
|
||||||
|
output = output.resolve(result.getArtist());
|
||||||
|
if (result.getAlbum() != null) {
|
||||||
|
output = output.resolve(result.getAlbum());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output = output.resolve(fileName);
|
||||||
|
|
||||||
|
if (!Files.exists(output.toAbsolutePath().getParent())) {
|
||||||
|
Files.createDirectories(output.toAbsolutePath().getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.write(output, result.getData());
|
||||||
|
|
||||||
|
song = new Song();
|
||||||
|
song.setAlbum(result.getAlbum());
|
||||||
|
song.setArtist(result.getArtist());
|
||||||
|
song.setDateAdded(new Date());
|
||||||
|
song.setDiscNumber(result.getDiscNumber());
|
||||||
|
song.setFileHash(hash);
|
||||||
|
song.setFilePath(output.toAbsolutePath().toString());
|
||||||
|
song.setGenre(result.getGenre());
|
||||||
|
song.setReleaseYear(result.getReleaseDate());
|
||||||
|
song.setTitle(result.getTitle());
|
||||||
|
song.setTrackNumber(result.getTrackNumber());
|
||||||
|
|
||||||
|
guildSongRepoService.getSongRepo().save(song);
|
||||||
|
}
|
||||||
|
|
||||||
|
gs = new GuildSong();
|
||||||
|
gs.setDateAdded(new Date());
|
||||||
|
gs.setGuild(guild);
|
||||||
|
gs.setSong(song);
|
||||||
|
|
||||||
|
String[] uuidArray = UUID.randomUUID().toString().split("-");
|
||||||
|
|
||||||
|
gs.setUuid(uuidArray[uuidArray.length - 1]);
|
||||||
|
|
||||||
|
guildSongRepoService.getGuildSongRepo().save(gs);
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder()
|
||||||
|
.setColor(Color.GREEN)
|
||||||
|
.setThumbnail(event.getGuild().getIconUrl())
|
||||||
|
.setTitle("Upload Results for " + fileName)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.addField("Title", result.getTitle(), true);
|
||||||
|
|
||||||
|
if (!StringUtils.isBlank(result.getArtist())) builder.addField("Artist", result.getArtist(), true);
|
||||||
|
if (!StringUtils.isBlank(result.getAlbum())) builder.addField("Album", result.getAlbum(), true);
|
||||||
|
if (!StringUtils.isBlank(result.getTrackNumber())) builder.addField("Track", result.getTrackNumber(), true);
|
||||||
|
if (!StringUtils.isBlank(result.getDiscNumber())) builder.addField("Disc", result.getDiscNumber(), true);
|
||||||
|
if (!StringUtils.isBlank(result.getReleaseDate())) builder.addField("Year", result.getReleaseDate(), true);
|
||||||
|
|
||||||
|
builder.addField("ID", gs.getUuid(), true);
|
||||||
|
|
||||||
|
MessageEmbed embed = builder.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
guildSongRepoService.logEntry(event.getGuild().getIdLong(), "%s uploaded", result);
|
||||||
|
} catch (Exception ex) {}
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
return "upload song";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AbstractPlaylistEventHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.playlist;
|
||||||
|
|
||||||
|
import net.locusworks.discord.eighttrack.events.AbstractEvent;
|
||||||
|
|
||||||
|
public abstract class AbstractPlaylistEventHandler extends AbstractEvent {
|
||||||
|
|
||||||
|
|
||||||
|
public AbstractPlaylistEventHandler(String command) {
|
||||||
|
super(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaylistAddHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.playlist.handlers;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaylistAddHandler extends AbstractPlaylistEventHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
public PlaylistAddHandler() {
|
||||||
|
super("add");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if(!checkCommands(event, commands,
|
||||||
|
event.getAuthor().getAsMention() + " you have to provide the playlist to create a new playlist (no spaces in name) and optionally a list of uuids for songs to add")) return;
|
||||||
|
|
||||||
|
Long guildId = event.getGuild().getIdLong();
|
||||||
|
|
||||||
|
DiscordGuild guild = guildRepoService.getGuildRepo().findByGuildId(guildId);
|
||||||
|
if (guild == null) {
|
||||||
|
event.getChannel().sendMessage("Unable to find guild in local database. Please contact administrator").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
|
||||||
|
long userId = event.getMember().getIdLong();
|
||||||
|
|
||||||
|
GuildPlaylist gpl = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guild, userId, playlist);
|
||||||
|
boolean newList = false;
|
||||||
|
if (gpl != null && commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " a playlist with the name " + playlist + " already exist for you.").queue();
|
||||||
|
return;
|
||||||
|
} else if (gpl == null) {
|
||||||
|
newList = true;
|
||||||
|
gpl = new GuildPlaylist();
|
||||||
|
gpl.setDateAdded(new Date());
|
||||||
|
gpl.setGuild(guild);
|
||||||
|
gpl.setPlaylist(playlist);
|
||||||
|
gpl.setUserId(userId);
|
||||||
|
guildRepoService.getGuildPlaylistRepo().save(gpl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commands.isEmpty() && newList) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " playlist " + playlist + " successfully created.").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> songIds = guildRepoService.getGuildPlaylistSongRepo()
|
||||||
|
.findByGuildPlaylistAndSongIds(gpl, commands).stream()
|
||||||
|
.map(g -> g.getGuildSong().getUuid())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
List<GuildPlaylistSong> gplsList = new ArrayList<>();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(String id : commands.stream().collect(Collectors.toSet())) {
|
||||||
|
GuildSong gs = guildRepoService.getGuildSongRepo().findByUuid(id);
|
||||||
|
if (songIds.contains(id)) {
|
||||||
|
sb.append(String.format("**%s** by __%s__ already exists in this playlist.%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gs == null) {
|
||||||
|
sb.append("Song with id `" + id + "` not found. Please check id\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuildPlaylistSong gpls = new GuildPlaylistSong();
|
||||||
|
gpls.setDateAdded(new Date());
|
||||||
|
gpls.setGuildPlaylist(gpl);
|
||||||
|
gpls.setGuildSong(gs);
|
||||||
|
gplsList.add(gpls);
|
||||||
|
|
||||||
|
sb.append(String.format("**%s** by __%s__ added to playlist.%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gplsList.isEmpty()) {
|
||||||
|
guildRepoService.getGuildPlaylistSongRepo().saveAll(gplsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setTitle("Results for adding playlist " + playlist)
|
||||||
|
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
||||||
|
.setColor(Color.GREEN)
|
||||||
|
.setDescription(sb.toString())
|
||||||
|
.setFooter("", event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(embed).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaylistDeleteHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.playlist.handlers;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.discord.eighttrack.utils.Reactions;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaylistDeleteHandler extends AbstractPlaylistEventHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactionHandler reactionHandler;
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
public PlaylistDeleteHandler() {
|
||||||
|
super("delete");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(PlaylistDeleteHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if(!checkCommands(event, commands,
|
||||||
|
event.getAuthor().getAsMention() + " you have to provide the playlist name and optionally a list of uuids for songs to remove")) return;
|
||||||
|
|
||||||
|
Long guildId = event.getGuild().getIdLong();
|
||||||
|
|
||||||
|
DiscordGuild guild = guildRepoService.getGuildRepo().findByGuildId(guildId);
|
||||||
|
if (guild == null) {
|
||||||
|
event.getChannel().sendMessage("Unable to find guild in local database. Please contact administrator").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
|
||||||
|
long userId = event.getMember().getIdLong();
|
||||||
|
|
||||||
|
GuildPlaylist gpl = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guild, userId, playlist);
|
||||||
|
|
||||||
|
if (commands.isEmpty()) {
|
||||||
|
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTitle("Delete Playlist " + playlist)
|
||||||
|
.setDescription("Are you sure you want to delete the playlist " + playlist)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(embed).queue((msg) -> {
|
||||||
|
|
||||||
|
ReactionListener<String> handler = new ReactionListener<>(userId, msg.getId());
|
||||||
|
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
||||||
|
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deletePlayListConfirm(gpl, event.getMember().getAsMention(), msg));
|
||||||
|
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg, reactionHandler, event.getGuild().getIdLong()));
|
||||||
|
|
||||||
|
reactionHandler.addReactionListener(guildId, msg, handler);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<GuildPlaylistSong> songs = guildRepoService.getGuildPlaylistSongRepo().findByGuildPlaylistAndSongIds(gpl, commands);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("Are you sure you want to delete the following songs from playlist " + playlist + "?\n");
|
||||||
|
for (GuildPlaylistSong gpls : songs) {
|
||||||
|
GuildSong gs = gpls.getGuildSong();
|
||||||
|
sb.append(String.format("**%s** by __%s__%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTitle("Delete Playlist Songs")
|
||||||
|
.setDescription(sb.toString())
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(embed).queue((msg) -> {
|
||||||
|
|
||||||
|
ReactionListener<String> handler = new ReactionListener<>(userId, msg.getId());
|
||||||
|
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
||||||
|
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deletePlayListSongConfirm(songs, event.getMember().getAsMention(), msg));
|
||||||
|
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg, reactionHandler, event.getGuild().getIdLong()));
|
||||||
|
|
||||||
|
reactionHandler.addReactionListener(guildId, msg, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deletePlayListSongConfirm(List<GuildPlaylistSong> songs, String user, Message msg) {
|
||||||
|
try {
|
||||||
|
guildRepoService.getGuildPlaylistSongRepo().deleteAll(songs);
|
||||||
|
msg.getChannel().sendMessage(user + ", songs removed successfully fom playlist").complete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove songs from the playlist. Reason: " + ex.getMessage()).complete();
|
||||||
|
logger.error("Unable to delete songs from playlist : " + ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
guildRepoService.logEntry(msg.getGuild().getIdLong(), ex, "Unable to delete playlist: %s", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
deleteMessage(msg, reactionHandler, msg.getGuild().getIdLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deletePlayListConfirm(GuildPlaylist gpl, String user, Message msg) {
|
||||||
|
String playlist = gpl.getPlaylist();
|
||||||
|
try {
|
||||||
|
guildRepoService.getGuildPlaylistRepo().delete(gpl);
|
||||||
|
msg.getChannel().sendMessage(user + " " + playlist + " deleted successfully").complete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove playlist " + playlist + ". Reason: " + ex.getMessage()).complete();
|
||||||
|
logger.error("Unable to delete playlist " + playlist + ": " + ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
guildRepoService.logEntry(msg.getGuild().getIdLong(), ex, "Unable to delete playlist: %s", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
deleteMessage(msg, reactionHandler, msg.getGuild().getIdLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaylistListHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.playlist.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
|
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaylistListHandler extends AbstractPlaylistEventHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
public PlaylistListHandler() {
|
||||||
|
super("list");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
List<GuildPlaylist> userPlaylist = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong());
|
||||||
|
if (userPlaylist.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined playlists on this server").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int longestPlaylist = 10;
|
||||||
|
for(GuildPlaylist gpl : userPlaylist) {
|
||||||
|
if (gpl.getPlaylist().length() > longestPlaylist) longestPlaylist = gpl.getPlaylist().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
String fmt = "%6s | %-" + longestPlaylist +"s | %s%n";
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("```");
|
||||||
|
sb.append(String.format(fmt, "", "Playlist", "Song Count"));
|
||||||
|
sb.append(StringUtils.repeat("-", 24 + longestPlaylist)).append("\n");
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for(GuildPlaylist gpl : userPlaylist) {
|
||||||
|
sb.append(String.format(fmt, ++count, gpl.getPlaylist(), gpl.getGuildPlaylistSongList().size()));
|
||||||
|
}
|
||||||
|
sb.append("```");
|
||||||
|
event.getChannel().sendMessage("**" + "Currently available playlists for " + event.getMember().getAsMention() + "**").queue((succcess)->
|
||||||
|
event.getChannel().sendMessage(sb.toString()).queue());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
|
||||||
|
GuildPlaylist gpl = guildRepoService.getGuildPlaylistRepo().findByGuildUserPlaylistFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong(), playlist);
|
||||||
|
if (gpl == null) {
|
||||||
|
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined playlists on this server by the name of " + playlist).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gpl.getGuildPlaylistSongList().isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined songs for playlist " + playlist).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int longestSong = 0;
|
||||||
|
int longestArtist = 0;
|
||||||
|
for(GuildPlaylistSong gpls : gpl.getGuildPlaylistSongList()) {
|
||||||
|
GuildSong gs = gpls.getGuildSong();
|
||||||
|
if (gs.getSong().getTitle().length() > longestSong) longestSong = gs.getSong().getTitle().length();
|
||||||
|
if (gs.getSong().getArtist().length() > longestArtist) longestArtist = gs.getSong().getArtist().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
String fmt = "%6s | %-" + longestSong +"s | %-" + longestArtist +"s | %s%n";
|
||||||
|
int count = 0;
|
||||||
|
StringBuilder sb = new StringBuilder("```");
|
||||||
|
sb.append(String.format(fmt, "Track", "Title", "Artist", "id"));
|
||||||
|
sb.append(StringUtils.repeat("-", 27 + longestSong + longestArtist)).append("\n");
|
||||||
|
|
||||||
|
for(GuildPlaylistSong gpls : gpl.getGuildPlaylistSongList()) {
|
||||||
|
GuildSong gs = gpls.getGuildSong();
|
||||||
|
sb.append(String.format(fmt, ++count, gs.getSong().getTitle(), gs.getSong().getArtist(), gs.getUuid()));
|
||||||
|
}
|
||||||
|
sb.append("```");
|
||||||
|
event.getChannel().sendMessage("**" + "Current songs in playlists " + playlist + " for " + event.getMember().getAsMention() + "**").queue((succcess)->
|
||||||
|
event.getChannel().sendMessage(sb.toString()).queue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: PlaylistPlayHandler.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.events.playlist.handlers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||||
|
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PlaylistPlayHandler extends AbstractPlaylistEventHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildMusicService guildMusicService;
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
public PlaylistPlayHandler() {
|
||||||
|
super("play");
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(PlaylistPlayHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
|
||||||
|
|
||||||
|
GuildPlaylist currentPlaylist = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(event.getGuild().getIdLong(), event.getMember().getIdLong(), playlist);
|
||||||
|
|
||||||
|
if (currentPlaylist == null) {
|
||||||
|
sendMessage(event, event.getAuthor().getAsMention() + ", no playlist with the name of " + playlist + " exists");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuildMusicHandler musicHandler = guildMusicService.getMusicHandler(event.getGuild().getIdLong());
|
||||||
|
|
||||||
|
musicHandler.setCurrentPlaylist(currentPlaylist);
|
||||||
|
|
||||||
|
musicHandler.getTrackManager().clearTracks();
|
||||||
|
|
||||||
|
for(GuildPlaylistSong gpls : guildRepoService.getGuildPlaylistSongRepo().findByGuildPlaylist(currentPlaylist)) {
|
||||||
|
Song s = gpls.getGuildSong().getSong();
|
||||||
|
musicHandler.getTrackManager().queueLast(s.getFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
musicHandler.isPlaying(false);
|
||||||
|
musicHandler.play(event);
|
||||||
|
musicHandler.isPlaying(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
sendMessage(event, "Sorry " + event.getAuthor().getAsMention() + " I was unable to remove songs from the playlist. Reason: " + ex.getMessage(), true);
|
||||||
|
logger.error("Unable to play playlist : " + ex.getMessage());
|
||||||
|
logger.error(ex);
|
||||||
|
guildRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to play playlist: %s", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildMusicHandler.java
|
* Project: Eight Track, File: GuildMusicHandler.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -27,111 +27,53 @@
|
|||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.handlers;
|
package net.locusworks.discord.eighttrack.handlers;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.Message.Attachment;
|
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
|
||||||
import net.dv8tion.jda.api.managers.AudioManager;
|
import net.dv8tion.jda.api.managers.AudioManager;
|
||||||
import net.dv8tion.jda.api.requests.ErrorResponse;
|
import net.locusworks.discord.eighttrack.audio.EightTrackAudioSendHandler;
|
||||||
import net.locusworks.crypto.utils.HashUtils;
|
import net.locusworks.discord.eighttrack.audio.TrackManager;
|
||||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
|
||||||
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||||
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
|
||||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
|
||||||
import net.locusworks.discord.eighttrack.scheduler.TrackScheduler;
|
|
||||||
import net.locusworks.discord.eighttrack.services.GuildSongRepoService;
|
|
||||||
import net.locusworks.discord.eighttrack.utils.Reactions;
|
|
||||||
import net.locusworks.logger.ApplicationLogger;
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
public class GuildMusicHandler {
|
public class GuildMusicHandler {
|
||||||
|
|
||||||
private Path musicDir;
|
|
||||||
private TrackScheduler ts;
|
|
||||||
private DefaultAudioPlayerManager apm;
|
|
||||||
private ApplicationLogger logger;
|
private ApplicationLogger logger;
|
||||||
private AudioPlayer player;
|
|
||||||
private AtomicBoolean playing;
|
private AtomicBoolean playing;
|
||||||
private Long voiceChannelId;
|
private Long voiceChannelId;
|
||||||
|
|
||||||
private OffsetDateTime lastPlayed;
|
private OffsetDateTime lastPlayed;
|
||||||
|
|
||||||
private Consumer<Long> callback;
|
private Consumer<Long> callback;
|
||||||
private Mp3UploadHandler uploadHandler;
|
private RepositoryService guildSongRepoService;
|
||||||
private GuildSongRepoService guildSongRepoService;
|
|
||||||
private ReactionHandler reactionHandler;
|
|
||||||
private long guildId;
|
private long guildId;
|
||||||
|
|
||||||
private GuildPlaylist currentPlaylist;
|
private GuildPlaylist currentPlaylist;
|
||||||
|
|
||||||
public GuildMusicHandler(Path musicDir, long guildId, Mp3UploadHandler uploadHandler, ReactionHandler reactionHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
private TrackManager trackManager;
|
||||||
|
|
||||||
|
public GuildMusicHandler(long guildId, RepositoryService guildSongRepoService) {
|
||||||
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
||||||
this.playing = new AtomicBoolean(false);
|
this.playing = new AtomicBoolean(false);
|
||||||
this.musicDir = musicDir;
|
|
||||||
this.lastPlayed = OffsetDateTime.now();
|
this.lastPlayed = OffsetDateTime.now();
|
||||||
this.uploadHandler = uploadHandler;
|
|
||||||
this.guildSongRepoService = guildSongRepoService;
|
this.guildSongRepoService = guildSongRepoService;
|
||||||
this.guildId = guildId;
|
this.guildId = guildId;
|
||||||
this.reactionHandler = reactionHandler;
|
this.trackManager = new TrackManager();
|
||||||
this.apm = new DefaultAudioPlayerManager();
|
|
||||||
|
|
||||||
AudioSourceManagers.registerLocalSource(apm);
|
|
||||||
this.player = apm.createPlayer();
|
|
||||||
|
|
||||||
this.ts = new TrackScheduler();
|
|
||||||
player.addListener(ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playlist(GuildMessageReceivedEvent event, List<String> commands) throws Exception {
|
|
||||||
|
|
||||||
String command = commands.remove(0);
|
|
||||||
|
|
||||||
switch(command) {
|
|
||||||
case "add":
|
|
||||||
addPlayList(event, commands);
|
|
||||||
return;
|
|
||||||
case "delete":
|
|
||||||
deletePlayList(event, commands);
|
|
||||||
return;
|
|
||||||
case "list":
|
|
||||||
listPlayList(event, commands);
|
|
||||||
return;
|
|
||||||
case "play":
|
|
||||||
playPlayList(event, commands);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getCurrentVoiceChannelId() {
|
public Long getCurrentVoiceChannelId() {
|
||||||
@ -163,10 +105,10 @@ public class GuildMusicHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ts.peek() == null) {
|
if (!trackManager.hasTracks()) {
|
||||||
loadRandomSong();
|
loadRandomSong();
|
||||||
}
|
}
|
||||||
AudioTrack track = ts.peek();
|
AudioTrack track = trackManager.play();
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
||||||
.setTitle("Next Up:")
|
.setTitle("Next Up:")
|
||||||
@ -178,7 +120,7 @@ public class GuildMusicHandler {
|
|||||||
|
|
||||||
public void repeat(GuildMessageReceivedEvent event) throws Exception {
|
public void repeat(GuildMessageReceivedEvent event) throws Exception {
|
||||||
next(event);
|
next(event);
|
||||||
ts.setFinishedCallback((ater) -> {
|
trackManager.setFinishedCallback((ater) -> {
|
||||||
if (!playing.get()) return;
|
if (!playing.get()) return;
|
||||||
try {
|
try {
|
||||||
next(event);
|
next(event);
|
||||||
@ -198,6 +140,7 @@ public class GuildMusicHandler {
|
|||||||
playing.set(true);
|
playing.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuildChannel gc = event.getGuild().getGuildChannelById(ChannelType.VOICE, voiceChannelId);
|
GuildChannel gc = event.getGuild().getGuildChannelById(ChannelType.VOICE, voiceChannelId);
|
||||||
if (gc != null && gc.getMembers().size() == 1) {
|
if (gc != null && gc.getMembers().size() == 1) {
|
||||||
event.getChannel().sendMessage("Going silent since no one is currently listening to the channel").queue();
|
event.getChannel().sendMessage("Going silent since no one is currently listening to the channel").queue();
|
||||||
@ -207,18 +150,20 @@ public class GuildMusicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playing.set(false);
|
playing.set(false);
|
||||||
stop(event, true);
|
stop(event, true, true);
|
||||||
play(event, commands);
|
play(event, commands);
|
||||||
playing.set(true);
|
playing.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(GuildMessageReceivedEvent event) {
|
public void stop(GuildMessageReceivedEvent event) {
|
||||||
stop(event, false);
|
stop(event, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(GuildMessageReceivedEvent event, boolean stoppedFromRepeat) {
|
public void stop(GuildMessageReceivedEvent event, boolean stoppedFromRepeat, boolean stoppedFromNext) {
|
||||||
player.stopTrack();
|
trackManager.stopTrack();
|
||||||
voiceChannelId = null;
|
if (!stoppedFromNext) {
|
||||||
|
voiceChannelId = null;
|
||||||
|
}
|
||||||
if (!stoppedFromRepeat) {
|
if (!stoppedFromRepeat) {
|
||||||
currentPlaylist = null;
|
currentPlaylist = null;
|
||||||
}
|
}
|
||||||
@ -256,7 +201,7 @@ public class GuildMusicHandler {
|
|||||||
AudioManager manager = event.getGuild().getAudioManager();
|
AudioManager manager = event.getGuild().getAudioManager();
|
||||||
manager.openAudioConnection(vc);
|
manager.openAudioConnection(vc);
|
||||||
|
|
||||||
manager.setSendingHandler(new EightTrackAudioSendHandler(player));
|
manager.setSendingHandler(new EightTrackAudioSendHandler(trackManager));
|
||||||
|
|
||||||
if (commands != null && !commands.isEmpty()) {
|
if (commands != null && !commands.isEmpty()) {
|
||||||
String uuid = commands.remove(0);
|
String uuid = commands.remove(0);
|
||||||
@ -265,17 +210,21 @@ public class GuildMusicHandler {
|
|||||||
event.getChannel().sendMessageFormat("Unable to find song with identifier: %s", uuid).queue();
|
event.getChannel().sendMessageFormat("Unable to find song with identifier: %s", uuid).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stop(event, true);
|
stop(event, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ts.hasTracks()) {
|
if (!trackManager.hasTracks()) {
|
||||||
loadRandomSong();
|
loadRandomSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts.hasTracks()) {
|
if (trackManager.hasTracks()) {
|
||||||
lastPlayed = OffsetDateTime.now();
|
lastPlayed = OffsetDateTime.now();
|
||||||
|
|
||||||
AudioTrack track = ts.getNextTrack();
|
AudioTrack track = trackManager.play();
|
||||||
|
if (track == null) {
|
||||||
|
logger.warn("Unable to find track: " + trackManager.getCurrentItem()) ;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
||||||
@ -285,190 +234,10 @@ public class GuildMusicHandler {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed).queue();
|
event.getChannel().sendMessage(embed).queue();
|
||||||
player.playTrack(track);
|
trackManager.playTrack(track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void upload(GuildMessageReceivedEvent event) {
|
|
||||||
if (!event.getMessage().getMember().hasPermission(Permission.ADMINISTRATOR, Permission.MANAGE_SERVER)) {
|
|
||||||
event.getChannel().sendMessage(String.format("Sorry <@%s> i can't do that. *psst: you have to have manage server, or administrator role*", event.getMember().getIdLong())).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Attachment attachment : event.getMessage().getAttachments()) {
|
|
||||||
attachment.retrieveInputStream().thenAccept((in) -> {
|
|
||||||
Mp3UploadResults res = null;
|
|
||||||
MessageEmbed embed = null;
|
|
||||||
try {
|
|
||||||
|
|
||||||
res = uploadHandler.parse(in);
|
|
||||||
if (res.validFile()) {
|
|
||||||
embed = persistSong(res, event, attachment.getFileName());
|
|
||||||
} else {
|
|
||||||
embed = wrongFile(event, attachment.getFileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to get file information: %s", ex.getMessage());
|
|
||||||
logger.error(ex);
|
|
||||||
embed = error(event, ex, attachment.getFileName());
|
|
||||||
} finally {
|
|
||||||
event.getMessage().delete().queue();
|
|
||||||
if (res != null) res.clear();
|
|
||||||
|
|
||||||
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}).exceptionally((err) -> {
|
|
||||||
event.getMessage().delete().queue();
|
|
||||||
MessageEmbed embed = error(event, err, attachment.getFileName());
|
|
||||||
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playPlayList(GuildMessageReceivedEvent event, List<String> commands) throws Exception {
|
|
||||||
if (commands == null || commands.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String playlist = commands.remove(0);
|
|
||||||
currentPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guildId, event.getMember().getIdLong(), playlist);
|
|
||||||
if (currentPlaylist == null) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", no playlist with the name of " + playlist + " exists").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ts.clearTracks();
|
|
||||||
|
|
||||||
for(GuildPlaylistSong gpls : guildSongRepoService.getGuildPlaylistSongRepo().findByGuildPlaylist(currentPlaylist)) {
|
|
||||||
Song s = gpls.getGuildSong().getSong();
|
|
||||||
apm.loadItem(s.getFilePath(), ts).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
playing.set(false);
|
|
||||||
play(event);
|
|
||||||
playing.set(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MessageEmbed error(GuildMessageReceivedEvent event, Throwable ex, String fileName) {
|
|
||||||
return new EmbedBuilder()
|
|
||||||
.setTitle("Unable to upload file: " + fileName)
|
|
||||||
.setDescription("There was an error uploading your file: " + ex.getMessage() + ". Please contact admin")
|
|
||||||
.setColor(Color.RED)
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MessageEmbed wrongFile(GuildMessageReceivedEvent event, String fileName) {
|
|
||||||
return new EmbedBuilder()
|
|
||||||
.setTitle("Invalid File: " + fileName)
|
|
||||||
.setDescription("Only music type files are allowed to be uploaded")
|
|
||||||
.setColor(Color.RED)
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MessageEmbed persistSong(Mp3UploadResults result, GuildMessageReceivedEvent event, String fileName) throws Exception {
|
|
||||||
|
|
||||||
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(event.getGuild().getIdLong());
|
|
||||||
if(guild == null) {
|
|
||||||
throw new IOException("Unable to find guild in database. Please contact administrator");
|
|
||||||
}
|
|
||||||
|
|
||||||
Path output = musicDir;
|
|
||||||
if (result.getArtist() != null) {
|
|
||||||
output = output.resolve(result.getArtist());
|
|
||||||
if (result.getAlbum() != null) {
|
|
||||||
output = output.resolve(result.getAlbum());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = output.resolve(fileName);
|
|
||||||
|
|
||||||
if (!Files.exists(output.toAbsolutePath().getParent())) {
|
|
||||||
Files.createDirectories(output.toAbsolutePath().getParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.write(output, result.getData());
|
|
||||||
|
|
||||||
Song song = new Song();
|
|
||||||
song.setAlbum(result.getAlbum());
|
|
||||||
song.setArtist(result.getArtist());
|
|
||||||
song.setDateAdded(new Date());
|
|
||||||
song.setDiscNumber(result.getDiscNumber());
|
|
||||||
if (result.getDuration() != null)
|
|
||||||
song.setDuration(BigInteger.valueOf(result.getDuration()));
|
|
||||||
song.setFileHash(HashUtils.hash("SHA-1", result.getData()));
|
|
||||||
song.setFilePath(output.toAbsolutePath().toString());
|
|
||||||
song.setGenre(result.getGenre());
|
|
||||||
song.setReleaseYear(result.getReleaseDate());
|
|
||||||
song.setTitle(result.getTitle());
|
|
||||||
song.setTrackNumber(result.getTrackNumber());
|
|
||||||
|
|
||||||
guildSongRepoService.getSongRepo().save(song);
|
|
||||||
|
|
||||||
GuildSong gs = new GuildSong();
|
|
||||||
gs.setDateAdded(new Date());
|
|
||||||
gs.setGuild(guild);
|
|
||||||
gs.setSong(song);
|
|
||||||
|
|
||||||
String[] uuidArray = UUID.randomUUID().toString().split("-");
|
|
||||||
|
|
||||||
gs.setUuid(uuidArray[uuidArray.length - 1]);
|
|
||||||
|
|
||||||
guildSongRepoService.getGuildSongRepo().save(gs);
|
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
|
||||||
.setColor(Color.GREEN)
|
|
||||||
.setThumbnail(event.getGuild().getIconUrl())
|
|
||||||
.setTitle("Upload Results for " + fileName)
|
|
||||||
.addField("Title", result.getTitle(), true)
|
|
||||||
.addField("Artist", result.getArtist(), true)
|
|
||||||
.addField("Album", result.getAlbum(), true)
|
|
||||||
.addField("Track", result.getTrackNumber(), true)
|
|
||||||
.addField("Disc", result.getDiscNumber(), true)
|
|
||||||
.addField("Year", result.getReleaseDate(), true)
|
|
||||||
.addField("Duration", result.getDurationFormat(), true)
|
|
||||||
.addField("ID", gs.getUuid(), true)
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return embed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void list(GuildMessageReceivedEvent event) {
|
|
||||||
List<GuildSong> gsList = guildSongRepoService.getGuildSongRepo().findByGuild(guildId);
|
|
||||||
|
|
||||||
if (gsList == null || gsList.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage("There is no music for this guild.").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int longestSong = 0;
|
|
||||||
int longestArtist = 0;
|
|
||||||
for(GuildSong gs : gsList) {
|
|
||||||
if (gs.getSong().getTitle().length() > longestSong) longestSong = gs.getSong().getTitle().length();
|
|
||||||
if (gs.getSong().getArtist().length() > longestArtist) longestArtist = gs.getSong().getArtist().length();
|
|
||||||
}
|
|
||||||
|
|
||||||
String fmt = "%6s | %-" + longestSong +"s | %-" + longestArtist +"s | %s%n";
|
|
||||||
int count = 0;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("**" + "Currently available songs for " + event.getGuild().getName() + "**\n\n```");
|
|
||||||
sb.append(String.format(fmt, "Track", "Title", "Artist", "id"));
|
|
||||||
sb.append(StringUtils.repeat("-", 27 + longestSong + longestArtist)).append("\n");
|
|
||||||
|
|
||||||
for(GuildSong gs : gsList) {
|
|
||||||
sb.append(String.format(fmt, ++count, gs.getSong().getTitle(), gs.getSong().getArtist(), gs.getUuid()));
|
|
||||||
}
|
|
||||||
sb.append("```");
|
|
||||||
event.getChannel().sendMessage(sb.toString()).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadRandomSong() throws Exception {
|
private void loadRandomSong() throws Exception {
|
||||||
List<GuildSong> gsList = null;
|
List<GuildSong> gsList = null;
|
||||||
|
|
||||||
@ -483,272 +252,23 @@ public class GuildMusicHandler {
|
|||||||
int item = random.nextInt(gsList.size());
|
int item = random.nextInt(gsList.size());
|
||||||
|
|
||||||
GuildSong song = gsList.get(item);
|
GuildSong song = gsList.get(item);
|
||||||
|
trackManager.queueNext(song.getSong().getFilePath());
|
||||||
apm.loadItem(song.getSong().getFilePath(), ts).get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean findSong(String uuid) throws Exception {
|
private boolean findSong(String uuid) throws Exception {
|
||||||
GuildSong gs = guildSongRepoService.getGuildSongRepo().findByUuid(uuid);
|
GuildSong gs = guildSongRepoService.getGuildSongRepo().findByUuid(uuid);
|
||||||
if (gs == null) return false;
|
if (gs == null) return false;
|
||||||
|
|
||||||
apm.loadItem(gs.getSong().getFilePath(), ts).get();
|
trackManager.queueNext(gs.getSong().getFilePath());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listPlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
public void setCurrentPlaylist(GuildPlaylist currentPlaylist) {
|
||||||
if (commands == null || commands.isEmpty()) {
|
this.currentPlaylist = currentPlaylist;
|
||||||
List<GuildPlaylist> userPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong());
|
}
|
||||||
if (userPlaylist.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined playlists on this server").queue();
|
public TrackManager getTrackManager() {
|
||||||
return;
|
return this.trackManager;
|
||||||
}
|
|
||||||
|
|
||||||
int longestPlaylist = 0;
|
|
||||||
for(GuildPlaylist gpl : userPlaylist) {
|
|
||||||
if (gpl.getPlaylist().length() > longestPlaylist) longestPlaylist = gpl.getPlaylist().length();
|
|
||||||
}
|
|
||||||
|
|
||||||
String fmt = "%6s | %-" + longestPlaylist +"s | %s%n";
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("```");
|
|
||||||
sb.append(String.format(fmt, "", "Playlist", "Song Count"));
|
|
||||||
sb.append(StringUtils.repeat("-", 24 + longestPlaylist)).append("\n");
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
for(GuildPlaylist gpl : userPlaylist) {
|
|
||||||
sb.append(String.format(fmt, ++count, gpl.getPlaylist(), gpl.getGuildPlaylistSongList().size()));
|
|
||||||
}
|
|
||||||
sb.append("```");
|
|
||||||
event.getChannel().sendMessage("**" + "Currently available playlists for " + event.getMember().getAsMention() + "**").queue((succcess)->
|
|
||||||
event.getChannel().sendMessage(sb.toString()).queue()
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playlist = commands.remove(0);
|
|
||||||
|
|
||||||
GuildPlaylist gpl = guildSongRepoService.getGuildPlaylistRepo().findGuildUserPlaylistFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong(), playlist);
|
|
||||||
if (gpl == null) {
|
|
||||||
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined playlists on this server by the name of " + playlist).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gpl.getGuildPlaylistSongList().isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getMember().getAsMention() + " you have no defined songs for playlist " + playlist).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int longestSong = 0;
|
|
||||||
int longestArtist = 0;
|
|
||||||
for(GuildPlaylistSong gpls : gpl.getGuildPlaylistSongList()) {
|
|
||||||
GuildSong gs = gpls.getGuildSong();
|
|
||||||
if (gs.getSong().getTitle().length() > longestSong) longestSong = gs.getSong().getTitle().length();
|
|
||||||
if (gs.getSong().getArtist().length() > longestArtist) longestArtist = gs.getSong().getArtist().length();
|
|
||||||
}
|
|
||||||
|
|
||||||
String fmt = "%6s | %-" + longestSong +"s | %-" + longestArtist +"s | %s%n";
|
|
||||||
int count = 0;
|
|
||||||
StringBuilder sb = new StringBuilder("```");
|
|
||||||
sb.append(String.format(fmt, "Track", "Title", "Artist", "id"));
|
|
||||||
sb.append(StringUtils.repeat("-", 27 + longestSong + longestArtist)).append("\n");
|
|
||||||
|
|
||||||
for(GuildPlaylistSong gpls : gpl.getGuildPlaylistSongList()) {
|
|
||||||
GuildSong gs = gpls.getGuildSong();
|
|
||||||
sb.append(String.format(fmt, ++count, gs.getSong().getTitle(), gs.getSong().getArtist(), gs.getUuid()));
|
|
||||||
}
|
|
||||||
sb.append("```");
|
|
||||||
event.getChannel().sendMessage("**" + "Current songs in playlists " + playlist + " for " + event.getMember().getAsMention() + "**").queue((succcess)->
|
|
||||||
event.getChannel().sendMessage(sb.toString()).queue()
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deletePlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
|
||||||
if (commands == null || commands.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " you have to provide the playlist to create a new playlist (no spaces in name) and optionally a list of uuids for songs to add").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Long guildId = event.getGuild().getIdLong();
|
|
||||||
|
|
||||||
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
|
|
||||||
if (guild == null) {
|
|
||||||
event.getChannel().sendMessage("Unable to find guild in local database. Please contact administrator").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playlist = commands.remove(0);
|
|
||||||
|
|
||||||
long userId = event.getMember().getIdLong();
|
|
||||||
|
|
||||||
GuildPlaylist gpl = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guild, userId, playlist);
|
|
||||||
|
|
||||||
if (commands.isEmpty()) {
|
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
|
||||||
.setColor(Color.RED)
|
|
||||||
.setTitle("Delete Playlist " + playlist)
|
|
||||||
.setDescription("Are you sure you want to delete the playlist " + playlist)
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed).queue((msg) -> {
|
|
||||||
|
|
||||||
ReactionListener<String> handler = new ReactionListener<>(userId, msg.getId());
|
|
||||||
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
|
||||||
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deletePlayListConfirm(gpl, event.getMember().getAsMention(), msg));
|
|
||||||
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg));
|
|
||||||
|
|
||||||
reactionHandler.addReactionListener(guildId, msg, handler);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GuildPlaylistSong> songs = guildSongRepoService.getGuildPlaylistSongRepo().findByGuildPlaylistAndSongIds(gpl, commands);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("Are you sure you want to delete the following songs from playlist " + playlist + "?\n");
|
|
||||||
for (GuildPlaylistSong gpls : songs) {
|
|
||||||
GuildSong gs = gpls.getGuildSong();
|
|
||||||
sb.append(String.format("**%s** by __%s__%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
|
||||||
.setColor(Color.RED)
|
|
||||||
.setTitle("Delete Playlist Songs")
|
|
||||||
.setDescription(sb.toString())
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed).queue((msg) -> {
|
|
||||||
|
|
||||||
ReactionListener<String> handler = new ReactionListener<>(userId, msg.getId());
|
|
||||||
handler.setExpiresIn(TimeUnit.MINUTES, 1);
|
|
||||||
handler.registerReaction(Reactions.CHECK_MARK_BUTTON, (ret) -> deletePlayListSongConfirm(songs, event.getMember().getAsMention(), msg));
|
|
||||||
handler.registerReaction(Reactions.CROSS_MARK_BUTTON, (ret) -> deleteMessage(msg));
|
|
||||||
|
|
||||||
reactionHandler.addReactionListener(guildId, msg, handler);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deletePlayListSongConfirm(List<GuildPlaylistSong> songs, String user, Message msg) {
|
|
||||||
try {
|
|
||||||
guildSongRepoService.getGuildPlaylistSongRepo().deleteAll(songs);
|
|
||||||
msg.getChannel().sendMessage(user + ", songs removed successfully fom playlist").complete();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove songs from the playlist. Reason: " + ex.getMessage()).complete();
|
|
||||||
logger.error("Unable to delete songs from playlist : " + ex.getMessage());
|
|
||||||
logger.error(ex);
|
|
||||||
} finally {
|
|
||||||
deleteMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deletePlayListConfirm(GuildPlaylist gpl, String user, Message msg) {
|
|
||||||
String playlist = gpl.getPlaylist();
|
|
||||||
try {
|
|
||||||
guildSongRepoService.getGuildPlaylistRepo().delete(gpl);
|
|
||||||
msg.getChannel().sendMessage(user + " " + playlist + " deleted successfully").complete();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
msg.getChannel().sendMessage("Sorry " + user + " I was unable to remove playlist " + playlist + ". Reason: " + ex.getMessage()).complete();
|
|
||||||
logger.error("Unable to delete playlist " + playlist + ": " + ex.getMessage());
|
|
||||||
logger.error(ex);
|
|
||||||
} finally {
|
|
||||||
deleteMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addPlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
|
||||||
if (commands == null || commands.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " you have to provide the playlist to create a new playlist (no spaces in name) and optionally a list of uuids for songs to add").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Long guildId = event.getGuild().getIdLong();
|
|
||||||
|
|
||||||
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
|
|
||||||
if (guild == null) {
|
|
||||||
event.getChannel().sendMessage("Unable to find guild in local database. Please contact administrator").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playlist = commands.remove(0);
|
|
||||||
|
|
||||||
long userId = event.getMember().getIdLong();
|
|
||||||
|
|
||||||
GuildPlaylist gpl = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guild, userId, playlist);
|
|
||||||
boolean newList = false;
|
|
||||||
if (gpl != null && commands.isEmpty()) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " a playlist with the name " + playlist + " already exist for you.").queue();
|
|
||||||
return;
|
|
||||||
} else if (gpl == null) {
|
|
||||||
newList = true;
|
|
||||||
gpl = new GuildPlaylist();
|
|
||||||
gpl.setDateAdded(new Date());
|
|
||||||
gpl.setGuild(guild);
|
|
||||||
gpl.setPlaylist(playlist);
|
|
||||||
gpl.setUserId(userId);
|
|
||||||
guildSongRepoService.getGuildPlaylistRepo().save(gpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commands.isEmpty() && newList) {
|
|
||||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " playlist " + playlist + " successfully created.").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> songIds = guildSongRepoService.getGuildPlaylistSongRepo()
|
|
||||||
.findByGuildPlaylistAndSongIds(gpl, commands).stream()
|
|
||||||
.map(g -> g.getGuildSong().getUuid())
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
List<GuildPlaylistSong> gplsList = new ArrayList<>();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for(String id : commands.stream().collect(Collectors.toSet())) {
|
|
||||||
GuildSong gs = guildSongRepoService.getGuildSongRepo().findByUuid(id);
|
|
||||||
if (songIds.contains(id)) {
|
|
||||||
sb.append(String.format("**%s** by __%s__ already exists in this playlist.%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gs == null) {
|
|
||||||
sb.append("Song with id `" + id + "` not found. Please check id\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
GuildPlaylistSong gpls = new GuildPlaylistSong();
|
|
||||||
gpls.setDateAdded(new Date());
|
|
||||||
gpls.setGuildPlaylist(gpl);
|
|
||||||
gpls.setGuildSong(gs);
|
|
||||||
gplsList.add(gpls);
|
|
||||||
|
|
||||||
sb.append(String.format("**%s** by __%s__ added to playlist.%n", gs.getSong().getTitle(), gs.getSong().getArtist()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gplsList.isEmpty()) {
|
|
||||||
guildSongRepoService.getGuildPlaylistSongRepo().saveAll(gplsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
|
||||||
.setTitle("Results for adding playlist " + playlist)
|
|
||||||
.setAuthor(event.getMember().getEffectiveName(), null, event.getAuthor().getAvatarUrl())
|
|
||||||
.setColor(Color.GREEN)
|
|
||||||
.setDescription(sb.toString())
|
|
||||||
.setFooter("", event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
|
||||||
.setTimestamp(OffsetDateTime.now())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteMessage(Message msg) {
|
|
||||||
try {
|
|
||||||
msg.delete().complete();
|
|
||||||
reactionHandler.removeReactionListener(guildId, msg.getIdLong());
|
|
||||||
} catch (ErrorResponseException ex) {
|
|
||||||
if (ex.getErrorResponse() != ErrorResponse.UNKNOWN_MESSAGE) throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Pseudo-Bot, File: ReactionHandler.java
|
* Project: Eight Track, File: ReactionHandler.java
|
||||||
*
|
*
|
||||||
* Copyright 2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
* affirms that PSEUDO-BOT(R) software and data is subject to United States
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: AbstractDiscordEventListener.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.listeners;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
|
||||||
|
public abstract class AbstractDiscordEventListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: DiscordEventHandler.java
|
* Project: Eight Track, File: DiscordEventListener.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -25,60 +25,62 @@
|
|||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.handlers;
|
package net.locusworks.discord.eighttrack.listeners;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import javax.annotation.PostConstruct;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.TreeMap;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.api.events.ExceptionEvent;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
import net.locusworks.discord.eighttrack.services.GuildSongRepoService;
|
|
||||||
import net.locusworks.logger.ApplicationLogger;
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DiscordEventHandler extends ListenerAdapter {
|
public class DiscordEventListener extends AbstractDiscordEventListener {
|
||||||
|
|
||||||
private Path musicDir;
|
private Path musicDir;
|
||||||
|
|
||||||
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(DiscordEventHandler.class);
|
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(DiscordEventListener.class);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConfigurationService confService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private Mp3UploadHandler uploadHandler;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuildSongRepoService guildSongRepoService;
|
private RepositoryService guildSongRepoService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ReactionHandler reactionHandler;
|
private ReactionHandler reactionHandler;
|
||||||
|
|
||||||
@PostConstruct
|
private Map<String, AbstractMainEventHandler> events;
|
||||||
private void init() throws IOException {
|
|
||||||
this.musicDir = confService.getMusicDirectory();
|
@Autowired
|
||||||
|
private void setup(ConfigurationService cService, List<AbstractMainEventHandler> eventHandlers) throws IOException {
|
||||||
|
this.musicDir = cService.getMusicDirectory();
|
||||||
if (!Files.exists(this.musicDir.toAbsolutePath())) {
|
if (!Files.exists(this.musicDir.toAbsolutePath())) {
|
||||||
Files.createDirectories(this.musicDir.toAbsolutePath());
|
Files.createDirectories(this.musicDir.toAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events = new TreeMap<>();
|
||||||
|
|
||||||
|
for(AbstractMainEventHandler handler : eventHandlers) {
|
||||||
|
events.put(handler.getCommand(), handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRate = 300000L, initialDelay=300000L)
|
@Scheduled(fixedRate = 300000L, initialDelay=300000L)
|
||||||
@ -101,81 +103,51 @@ public class DiscordEventHandler extends ListenerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuildJoin(GuildJoinEvent event) {
|
|
||||||
try {
|
|
||||||
long guildId = event.getGuild().getIdLong();
|
|
||||||
DiscordGuild discordGuild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
|
|
||||||
if (discordGuild != null) return;
|
|
||||||
|
|
||||||
logger.debug("Joining Server: " + event.getGuild().getName());
|
|
||||||
|
|
||||||
discordGuild = new DiscordGuild();
|
|
||||||
discordGuild.setGuildId(guildId);
|
|
||||||
discordGuild.setGuildName(event.getGuild().getName());
|
|
||||||
discordGuild.setDateJoined(new Date());
|
|
||||||
|
|
||||||
guildSongRepoService.getGuildRepo().save(discordGuild);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to persist server information to database: " + ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
|
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
|
||||||
if (event.getAuthor().isBot()) return;
|
if (event.getAuthor().isBot()) return;
|
||||||
try {
|
try {
|
||||||
onGuildMessageReceivedHelper(event);
|
onGuildMessageReceivedHelper(event);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
guildSongRepoService.logEntry(event.getGuild().getIdLong(), t, "An error occured: %s", t.getMessage());
|
||||||
logger.error(t);
|
logger.error(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onException(ExceptionEvent event) {
|
||||||
|
logger.error("A general exception occured: " + event.getCause().getMessage());
|
||||||
|
logger.error(event.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws Exception {
|
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws Exception {
|
||||||
|
|
||||||
if (!GuildMusicService.getMap().containsKey(event.getGuild().getIdLong())) {
|
|
||||||
GuildMusicService.getMap().put(event.getGuild().getIdLong(),
|
|
||||||
new GuildMusicHandler(musicDir, event.getGuild().getIdLong(), uploadHandler, reactionHandler, guildSongRepoService));
|
|
||||||
}
|
|
||||||
|
|
||||||
GuildMusicHandler gmh = GuildMusicService.getMap().get(event.getGuild().getIdLong());
|
|
||||||
gmh.accept((id) -> GuildMusicService.getMap().remove(id));
|
|
||||||
|
|
||||||
|
|
||||||
List<String> commands = new ArrayList<String>(Arrays.asList(event.getMessage().getContentRaw().trim().toLowerCase().split(" ")));
|
List<String> commands = new ArrayList<String>(Arrays.asList(event.getMessage().getContentRaw().trim().toLowerCase().split(" ")));
|
||||||
|
|
||||||
String command = commands.remove(0);
|
String command = commands.remove(0);
|
||||||
|
|
||||||
switch(command) {
|
AbstractMainEventHandler aeh = events.get(command.toLowerCase());
|
||||||
case "-upload":
|
if (aeh != null) {
|
||||||
gmh.upload(event);
|
aeh.executeEvent(event, commands);
|
||||||
return;
|
return;
|
||||||
case "-play":
|
|
||||||
gmh.play(event, commands);
|
|
||||||
gmh.isPlaying(true);
|
|
||||||
return;
|
|
||||||
case "-stop":
|
|
||||||
gmh.isPlaying(false);
|
|
||||||
gmh.stop(event);
|
|
||||||
event.getGuild().getAudioManager().closeAudioConnection();
|
|
||||||
return;
|
|
||||||
case "-next":
|
|
||||||
gmh.next(event, commands);
|
|
||||||
return;
|
|
||||||
case "-repeat":
|
|
||||||
gmh.repeat(event);
|
|
||||||
gmh.isPlaying(true);
|
|
||||||
return;
|
|
||||||
case "-upnext":
|
|
||||||
gmh.upNext(event, commands);
|
|
||||||
return;
|
|
||||||
case "-list":
|
|
||||||
gmh.list(event);
|
|
||||||
return;
|
|
||||||
case "-playlist":
|
|
||||||
gmh.playlist(event, commands);
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!command.equalsIgnoreCase("-help")) return;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Entry<String, AbstractMainEventHandler> entry : events.entrySet()) {
|
||||||
|
sb.append(String.format("%s | %s%n", entry.getKey(), entry.getValue().help()));
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder()
|
||||||
|
.setColor(Color.GREEN)
|
||||||
|
.setThumbnail(event.getGuild().getIconUrl())
|
||||||
|
.setTitle("Eight Track Help Menu")
|
||||||
|
.setDescription(sb.toString())
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl());
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(builder.build()).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: DiscordGuildJoinEventListener.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.listeners;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DiscordGuildJoinEventListener extends AbstractDiscordEventListener {
|
||||||
|
|
||||||
|
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(DiscordGuildJoinEventListener.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildSongRepoService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildJoin(GuildJoinEvent event) {
|
||||||
|
try {
|
||||||
|
long guildId = event.getGuild().getIdLong();
|
||||||
|
DiscordGuild discordGuild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
|
||||||
|
if (discordGuild != null) {
|
||||||
|
guildSongRepoService.logEntry(guildId, "Eight Track joined guild %s", discordGuild.getGuildName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Joining Server: " + event.getGuild().getName());
|
||||||
|
|
||||||
|
discordGuild = new DiscordGuild();
|
||||||
|
discordGuild.setGuildId(guildId);
|
||||||
|
discordGuild.setGuildName(event.getGuild().getName());
|
||||||
|
discordGuild.setDateJoined(new Date());
|
||||||
|
|
||||||
|
guildSongRepoService.getGuildRepo().save(discordGuild);
|
||||||
|
|
||||||
|
guildSongRepoService.logEntry(guildId, "Eight Track joined guild %s", discordGuild.getGuildName());
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Unable to persist server information to database: " + ex.getMessage(), ex);
|
||||||
|
guildSongRepoService.logEntry(event.getGuild().getIdLong(), ex, "Unable to persist guild server info to database: %s", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Pseudo-Bot, File: ReactionListener.java
|
* Project: Eight Track, File: ReactionListener.java
|
||||||
*
|
*
|
||||||
* Copyright 2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
* affirms that PSEUDO-BOT(R) software and data is subject to United States
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
*
|
*
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: EightTrackLauncher.java
|
* Project: Eight Track, File: EightTrackLauncher.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -74,7 +74,5 @@ public class EightTrackLauncher implements ApplicationRunner {
|
|||||||
logger.info("Starting Eight-Track");
|
logger.info("Starting Eight-Track");
|
||||||
|
|
||||||
service.begin();
|
service.begin();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: AESService.java
|
* Project: Eight Track, File: AESService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -67,7 +67,7 @@ public class AESService {
|
|||||||
AESService service = new AESService();
|
AESService service = new AESService();
|
||||||
service.init();
|
service.init();
|
||||||
|
|
||||||
System.out.println(service.encrypt("zeGAPgbH9HFbqmjRjmwzUDKv"));
|
System.out.println(service.encrypt("yqwAK!H5KAc0d2xWdN6*S0w4"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: ConfigurationService.java
|
* Project: Eight Track, File: ConfigurationService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -36,6 +36,7 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ public class ConfigurationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
PropertiesManager.saveConfiguration(configuration, eightTrackConf, "Patch Repository properties file");
|
PropertiesManager.saveConfiguration(configuration, eightTrackConf, "Eight Track properties file");
|
||||||
}
|
}
|
||||||
|
|
||||||
lastModified = Files.getLastModifiedTime(eightTrackConf).toMillis();
|
lastModified = Files.getLastModifiedTime(eightTrackConf).toMillis();
|
||||||
@ -132,7 +133,7 @@ public class ConfigurationService {
|
|||||||
* @throws Exception general exception
|
* @throws Exception general exception
|
||||||
*/
|
*/
|
||||||
public void saveToConf(Properties confs) throws Exception {
|
public void saveToConf(Properties confs) throws Exception {
|
||||||
PropertiesManager.saveConfiguration(confs, eightTrackConf, "Patch Repository properties file");
|
PropertiesManager.saveConfiguration(confs, eightTrackConf, "Eight Track properties file");
|
||||||
logger.info("Saved config file: " + eightTrackConf + ", " + confs.size() + " entries");
|
logger.info("Saved config file: " + eightTrackConf + ", " + confs.size() + " entries");
|
||||||
loadConf();
|
loadConf();
|
||||||
}
|
}
|
||||||
@ -214,7 +215,10 @@ public class ConfigurationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Path getMusicDirectory() {
|
public Path getMusicDirectory() {
|
||||||
String dir = configuration.getProperty(Configuration.MUSIC_DIR.getValue(), "");
|
String dir = System.getProperty("MUSIC_DIR") == null ? System.getenv("MUSIC_DIR") : System.getProperty("MUSIC_DIR");
|
||||||
|
if (StringUtils.isBlank(dir)) {
|
||||||
|
dir = configuration.getProperty(Configuration.MUSIC_DIR.getValue(), "");
|
||||||
|
}
|
||||||
return Paths.get(dir);
|
return Paths.get(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: DatabaseCleanupService.java
|
* Project: Eight Track, File: DatabaseCleanupService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -27,24 +27,17 @@
|
|||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.services;
|
package net.locusworks.discord.eighttrack.services;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
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.VoiceChannel;
|
|
||||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DatabaseCleanupService {
|
public class DatabaseCleanupService {
|
||||||
@ -54,63 +47,15 @@ public class DatabaseCleanupService {
|
|||||||
private static final long HOUR = 60 * MINUTE;
|
private static final long HOUR = 60 * MINUTE;
|
||||||
private static final long DAY = 24 * HOUR;
|
private static final long DAY = 24 * HOUR;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(DatabaseCleanupService.class);
|
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(DatabaseCleanupService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuildRepository guildRepo;
|
private GuildRepository guildRepo;
|
||||||
|
|
||||||
private JDA client;
|
|
||||||
|
|
||||||
public void setClient(JDA client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close out connections that are no long being played. clean up resources
|
|
||||||
*/
|
|
||||||
@Scheduled(fixedRate = 5 * MINUTE)
|
|
||||||
private void checkPlayers() {
|
|
||||||
if (client == null) {
|
|
||||||
logger.warn("Discord client is null. Unable to do cleanup");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("Checking players to see if anyone is listening");
|
|
||||||
OffsetDateTime now = OffsetDateTime.now();
|
|
||||||
for(Iterator<Entry<Long, GuildMusicHandler>> iterator = GuildMusicService.getMap().entrySet().iterator(); iterator.hasNext();) {
|
|
||||||
Entry<Long, GuildMusicHandler> entry = iterator.next();
|
|
||||||
GuildMusicHandler gmh = entry.getValue();
|
|
||||||
long guildId = entry.getKey();
|
|
||||||
|
|
||||||
Guild guild = client.getGuildById(guildId);
|
|
||||||
if (guild == null) {
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
OffsetDateTime lastPlayed = gmh.getLastPlayed();
|
|
||||||
Duration duration = Duration.between(lastPlayed, now);
|
|
||||||
if (duration.toMillis() > 5 * MINUTE) {
|
|
||||||
guild.getAudioManager().closeAudioConnection();
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
Long voiceChannelId = gmh.getCurrentVoiceChannelId();
|
|
||||||
if (voiceChannelId == null) {
|
|
||||||
guild.getAudioManager().closeAudioConnection();
|
|
||||||
iterator.remove();
|
|
||||||
} else {
|
|
||||||
VoiceChannel vc = guild.getVoiceChannelById(voiceChannelId);
|
|
||||||
if (vc != null && vc.getMembers().size() == 1) {
|
|
||||||
guild.getAudioManager().closeAudioConnection();
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Scheduled(fixedRate = DAY)
|
@Scheduled(fixedRate = DAY)
|
||||||
private void cleanDatabase() {
|
private void cleanDatabase() {
|
||||||
|
JDA client = EightTrackService.getClient();
|
||||||
|
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
logger.warn("Discord client is null. Unable to do cleanup");
|
logger.warn("Discord client is null. Unable to do cleanup");
|
||||||
return;
|
return;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: EightTrackService.java
|
* Project: Eight Track, File: EightTrackService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -27,43 +27,61 @@
|
|||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.services;
|
package net.locusworks.discord.eighttrack.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.AccountType;
|
|
||||||
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.locusworks.discord.eighttrack.handlers.DiscordEventHandler;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import net.locusworks.discord.eighttrack.listeners.AbstractDiscordEventListener;
|
||||||
import net.locusworks.logger.ApplicationLogger;
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EightTrackService {
|
public class EightTrackService {
|
||||||
|
|
||||||
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(EightTrackService.class);
|
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(EightTrackService.class);
|
||||||
|
|
||||||
private JDA client;
|
private static JDA client;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigurationService confService;
|
private ConfigurationService confService;
|
||||||
|
|
||||||
@Autowired
|
private List<AbstractDiscordEventListener> eventListeners;
|
||||||
private DiscordEventHandler eventListener;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatabaseCleanupService dcs;
|
private void setup(List<AbstractDiscordEventListener> eventListeners) {
|
||||||
|
this.eventListeners = eventListeners;
|
||||||
public void begin() throws LoginException {
|
}
|
||||||
String token = confService.getDiscordToken();
|
|
||||||
logger.debug("Logging in with token %s", token);
|
public void begin() throws LoginException {
|
||||||
|
try {
|
||||||
client = new JDABuilder(AccountType.BOT).setToken(token).build();
|
if (eventListeners == null ||eventListeners.size() < 1) {
|
||||||
client.addEventListener(eventListener);
|
throw new LoginException("No event listeners found. Exiting");
|
||||||
|
}
|
||||||
dcs.setClient(client);
|
|
||||||
|
String token = confService.getDiscordToken();
|
||||||
|
JDABuilder builder = JDABuilder.createDefault(token);
|
||||||
|
logger.debug("Logging in with token %s", token);
|
||||||
|
|
||||||
|
logger.info(String.format("Loading %d listeners", eventListeners.size()));
|
||||||
|
for (ListenerAdapter la : eventListeners) {
|
||||||
|
logger.debug("Loading eventListener: %s", la.getClass().getName());
|
||||||
|
builder.addEventListeners(la);
|
||||||
|
}
|
||||||
|
|
||||||
|
client = builder.build();
|
||||||
|
|
||||||
|
} catch (BeansException e) {
|
||||||
|
throw new LoginException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JDA getClient() {
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildMusicService.java
|
* Project: Eight Track, File: GuildMusicService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -27,17 +27,104 @@
|
|||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.services;
|
package net.locusworks.discord.eighttrack.services;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||||
|
import net.locusworks.logger.ApplicationLogger;
|
||||||
|
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class GuildMusicService {
|
public class GuildMusicService {
|
||||||
|
|
||||||
|
private ApplicationLogger logger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService guildRepoService;
|
||||||
|
|
||||||
private static Map<Long, GuildMusicHandler> handlerMap = new ConcurrentHashMap<>();
|
private static Map<Long, GuildMusicHandler> handlerMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static Map<Long, GuildMusicHandler> getMap() {
|
@PostConstruct
|
||||||
return handlerMap;
|
private void init() {
|
||||||
|
logger = ApplicationLoggerFactory.getLogger(GuildMusicService.class);
|
||||||
|
for (DiscordGuild dg : guildRepoService.getGuildRepo().findAll()) {
|
||||||
|
GuildMusicHandler gmh = createMusicHandler(dg.getGuildId());
|
||||||
|
handlerMap.put(dg.getGuildId(), gmh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close out connections that are no long being played. clean up resources
|
||||||
|
*/
|
||||||
|
@Scheduled(fixedRate = 5 * 60 * 1000)
|
||||||
|
private void checkPlayers() {
|
||||||
|
JDA client = EightTrackService.getClient();
|
||||||
|
if (client == null) {
|
||||||
|
logger.warn("Discord client is null. Unable to do cleanup");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Checking players to see if anyone is listening");
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
for(Iterator<Entry<Long, GuildMusicHandler>> iterator = handlerMap.entrySet().iterator(); iterator.hasNext();) {
|
||||||
|
Entry<Long, GuildMusicHandler> entry = iterator.next();
|
||||||
|
GuildMusicHandler gmh = entry.getValue();
|
||||||
|
long guildId = entry.getKey();
|
||||||
|
|
||||||
|
Guild guild = client.getGuildById(guildId);
|
||||||
|
if (guild == null) {
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
OffsetDateTime lastPlayed = gmh.getLastPlayed();
|
||||||
|
Duration duration = Duration.between(lastPlayed, now);
|
||||||
|
if (duration.toMillis() > 5 * 60 * 1000) {
|
||||||
|
guild.getAudioManager().closeAudioConnection();
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
Long voiceChannelId = gmh.getCurrentVoiceChannelId();
|
||||||
|
if (voiceChannelId == null) {
|
||||||
|
guild.getAudioManager().closeAudioConnection();
|
||||||
|
iterator.remove();
|
||||||
|
} else {
|
||||||
|
VoiceChannel vc = guild.getVoiceChannelById(voiceChannelId);
|
||||||
|
if (vc != null && vc.getMembers().size() == 1) {
|
||||||
|
guild.getAudioManager().closeAudioConnection();
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuildMusicHandler getMusicHandler(Long guildId) {
|
||||||
|
if (!handlerMap.containsKey(guildId)) {
|
||||||
|
GuildMusicHandler gmh = createMusicHandler(guildId);
|
||||||
|
handlerMap.put(guildId, gmh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handlerMap.get(guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param guildId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GuildMusicHandler createMusicHandler(Long guildId) {
|
||||||
|
GuildMusicHandler gmh = new GuildMusicHandler(guildId, guildRepoService);
|
||||||
|
gmh.accept((id) -> handlerMap.remove(id));
|
||||||
|
return gmh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Eight Track, File: GuildSongRepoService.java
|
* Project: Eight Track, File: RepositoryService.java
|
||||||
*
|
*
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
@ -27,9 +27,14 @@
|
|||||||
*/
|
*/
|
||||||
package net.locusworks.discord.eighttrack.services;
|
package net.locusworks.discord.eighttrack.services;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Date;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||||
|
import net.locusworks.discord.eighttrack.database.entities.Log;
|
||||||
|
import net.locusworks.discord.eighttrack.database.repos.GuildLogRepository;
|
||||||
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistRepository;
|
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistRepository;
|
||||||
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistSongRepository;
|
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistSongRepository;
|
||||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||||
@ -37,7 +42,7 @@ import net.locusworks.discord.eighttrack.database.repos.GuildSongRepository;
|
|||||||
import net.locusworks.discord.eighttrack.database.repos.SongRepository;
|
import net.locusworks.discord.eighttrack.database.repos.SongRepository;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GuildSongRepoService {
|
public class RepositoryService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuildRepository guildRepo;
|
private GuildRepository guildRepo;
|
||||||
@ -53,6 +58,43 @@ public class GuildSongRepoService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SongRepository songRepo;
|
private SongRepository songRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GuildLogRepository guildLogRepo;
|
||||||
|
|
||||||
|
public void logEntry(long guildId, String msg) {
|
||||||
|
logEntry(guildId, null, "%s", new Object[] {msg});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logEntry(long guildId, String msgFmt, Object... args) {
|
||||||
|
logEntry(guildId, null, msgFmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logEntry(long guildId, Throwable ex, String msgFmt, Object... args) {
|
||||||
|
DiscordGuild dg = guildRepo.findByGuildId(guildId);
|
||||||
|
if (dg == null) return;
|
||||||
|
|
||||||
|
String msg = String.format(msgFmt, args);
|
||||||
|
Log log = new Log();
|
||||||
|
log.setDateAdded(new Date());
|
||||||
|
log.setGuild(dg);
|
||||||
|
log.setIsException(ex != null);
|
||||||
|
log.setLog(msg);
|
||||||
|
|
||||||
|
if (ex != null) {
|
||||||
|
log.setException(printTrace(ex));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
guildLogRepo.save(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] printTrace(Throwable ex) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ex.printStackTrace(new PrintWriter(baos));
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the guildRepo
|
* @return the guildRepo
|
||||||
@ -88,5 +130,9 @@ public class GuildSongRepoService {
|
|||||||
public final SongRepository getSongRepo() {
|
public final SongRepository getSongRepo() {
|
||||||
return songRepo;
|
return songRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final GuildLogRepository getGuildLogRepo() {
|
||||||
|
return guildLogRepo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: ApplicationContextHolder.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ApplicationContextHolder implements ApplicationContextAware {
|
||||||
|
|
||||||
|
private static ApplicationContext context;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
|
||||||
|
if (context == null) {
|
||||||
|
context = ctx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Project: Eight Track, File: BeanFinder.java
|
||||||
|
*
|
||||||
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||||
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||||
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||||
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||||
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||||
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*/
|
||||||
|
package net.locusworks.discord.eighttrack.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.BeanInitializationException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowire;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||||
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
|
|
||||||
|
public class BeanFinder {
|
||||||
|
|
||||||
|
|
||||||
|
public static List<BeanDefinition> getBeans(String basePackage, TypeFilter... filters) {
|
||||||
|
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
|
scanner.addIncludeFilter(new TypeFilter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
|
||||||
|
boolean found = true;
|
||||||
|
|
||||||
|
for (TypeFilter filter : filters) {
|
||||||
|
found &= filter.match(metadataReader, metadataReaderFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return scanner.findCandidateComponents(basePackage).stream().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> List<T> autowireBeans(Class<T> clazz, String basePackage, TypeFilter... filters) throws BeansException {
|
||||||
|
try {
|
||||||
|
List<T> list = new ArrayList<>();
|
||||||
|
for (BeanDefinition bd : getBeans(basePackage, filters)) {
|
||||||
|
Object obj = ApplicationContextHolder.getContext().getAutowireCapableBeanFactory().createBean(Class.forName(bd.getBeanClassName()), Autowire.BY_TYPE.value(), true);
|
||||||
|
if (clazz.isInstance(obj)) {
|
||||||
|
list.add((T) obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BeanInitializationException(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
/**
|
/*
|
||||||
*
|
*
|
||||||
* Project: Pseudo-Bot, File: Reactions.java
|
* Project: Eight Track, File: Reactions.java
|
||||||
*
|
*
|
||||||
* Copyright 2019 Locusworks LLC.
|
* Copyright 2019-2021 Locusworks LLC.
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
* modified, duplicated, adapted or translated into another program language in any
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||||
* affirms that PSEUDO-BOT(R) software and data is subject to United States
|
* affirms that Eight-Track(R) software and data is subject to United States
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||||
*
|
*
|
||||||
|
@ -7,11 +7,8 @@
|
|||||||
<class>net.locusworks.discord.eighttrack.database.entities.DiscordGuild</class>
|
<class>net.locusworks.discord.eighttrack.database.entities.DiscordGuild</class>
|
||||||
<class>net.locusworks.discord.eighttrack.database.entities.Song</class>
|
<class>net.locusworks.discord.eighttrack.database.entities.Song</class>
|
||||||
<class>net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong</class>
|
<class>net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong</class>
|
||||||
|
<class>net.locusworks.discord.eighttrack.database.entities.Log</class>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:mariadb://devops.locusworks.net:3306/eighttrack"/>
|
|
||||||
<property name="javax.persistence.jdbc.user" value="root"/>
|
|
||||||
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
|
|
||||||
<property name="javax.persistence.jdbc.password" value="0a0wNt6aX4e66LNhA5uKLdnnN"/>
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
CREATE TABLE eighttrack.discord_guild (
|
CREATE TABLE eighttrack.discord_guild (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Auto increment primary key',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT 'Auto increment primary key',
|
||||||
guild_id bigint(20) NOT NULL COMMENT 'id of the discord guild',
|
guild_id bigint NOT NULL COMMENT 'id of the discord guild',
|
||||||
guild_name varchar(100) NOT NULL COMMENT 'name of the discord guild',
|
guild_name varchar(100) NOT NULL COMMENT 'name of the discord guild',
|
||||||
date_joined datetime DEFAULT NULL COMMENT 'date the guild joined',
|
date_joined datetime DEFAULT NULL COMMENT 'date the guild joined',
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE KEY guild_UN (guild_id)
|
UNIQUE KEY guild_UN (guild_id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Information about discord guild';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Information about discord guild';
|
||||||
|
|
||||||
CREATE TABLE eighttrack.song (
|
CREATE TABLE eighttrack.song (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
||||||
title varchar(500) NOT NULL COMMENT 'title of song',
|
title varchar(500) NOT NULL COMMENT 'title of song',
|
||||||
artist varchar(500) DEFAULT NULL COMMENT 'songs artist',
|
artist varchar(500) DEFAULT NULL COMMENT 'songs artist',
|
||||||
album varchar(500) DEFAULT NULL COMMENT 'songs album',
|
album varchar(500) DEFAULT NULL COMMENT 'songs album',
|
||||||
@ -16,7 +16,7 @@ CREATE TABLE eighttrack.song (
|
|||||||
track_number varchar(100) DEFAULT NULL COMMENT 'track number',
|
track_number varchar(100) DEFAULT NULL COMMENT 'track number',
|
||||||
disc_number varchar(100) DEFAULT NULL COMMENT 'disc number',
|
disc_number varchar(100) DEFAULT NULL COMMENT 'disc number',
|
||||||
release_year varchar(100) DEFAULT NULL COMMENT 'release year',
|
release_year varchar(100) DEFAULT NULL COMMENT 'release year',
|
||||||
duration bigint(20) DEFAULT NULL COMMENT 'songs duration',
|
duration bigint DEFAULT NULL COMMENT 'songs duration',
|
||||||
file_path varchar(5000) NOT NULL COMMENT 'file location on local file system',
|
file_path varchar(5000) NOT NULL COMMENT 'file location on local file system',
|
||||||
file_hash varchar(40) NOT NULL COMMENT 'sha1 hash of file',
|
file_hash varchar(40) NOT NULL COMMENT 'sha1 hash of file',
|
||||||
date_added timestamp NULL DEFAULT NULL,
|
date_added timestamp NULL DEFAULT NULL,
|
||||||
@ -25,10 +25,10 @@ CREATE TABLE eighttrack.song (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE eighttrack.guild_song (
|
CREATE TABLE eighttrack.guild_song (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||||
uuid varchar(100) NOT NULL COMMENT 'Unique Identifier',
|
uuid varchar(100) NOT NULL COMMENT 'Unique Identifier',
|
||||||
guild bigint(20) NOT NULL COMMENT 'guild the song belongs to',
|
guild bigint NOT NULL COMMENT 'guild the song belongs to',
|
||||||
song bigint(20) NOT NULL COMMENT 'the song',
|
song bigint NOT NULL COMMENT 'the song',
|
||||||
date_added timestamp NULL DEFAULT NULL COMMENT 'date added',
|
date_added timestamp NULL DEFAULT NULL COMMENT 'date added',
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE KEY guild_song_UN (guild,song),
|
UNIQUE KEY guild_song_UN (guild,song),
|
||||||
@ -39,9 +39,9 @@ CREATE TABLE eighttrack.guild_song (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE eighttrack.guild_playlist (
|
CREATE TABLE eighttrack.guild_playlist (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
id bigint NOT NULL AUTO_INCREMENT,
|
||||||
guild bigint(20) NOT NULL,
|
guild bigint NOT NULL,
|
||||||
userId bigint(20) NOT NULL,
|
userId bigint NOT NULL,
|
||||||
playlist varchar(500) NOT NULL,
|
playlist varchar(500) NOT NULL,
|
||||||
date_added timestamp NULL DEFAULT NULL,
|
date_added timestamp NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
@ -51,13 +51,25 @@ CREATE TABLE eighttrack.guild_playlist (
|
|||||||
|
|
||||||
|
|
||||||
CREATE TABLE eighttrack.guild_playlist_song (
|
CREATE TABLE eighttrack.guild_playlist_song (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
id bigint NOT NULL AUTO_INCREMENT,
|
||||||
guild_playlist bigint(20) NOT NULL,
|
guild_playlist bigint NOT NULL,
|
||||||
guild_song bigint(20) NOT NULL,
|
guild_song bigint NOT NULL,
|
||||||
date_added timestamp NULL DEFAULT NULL,
|
date_added timestamp NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE KEY guild_playlist_song_UN (guild_playlist,guild_song),
|
UNIQUE KEY guild_playlist_song_UN (guild_playlist,guild_song),
|
||||||
KEY guild_playlist_song_FK_1 (guild_song),
|
KEY guild_playlist_song_FK_1 (guild_song),
|
||||||
CONSTRAINT guild_playlist_song_FK FOREIGN KEY (guild_playlist) REFERENCES eighttrack.guild_playlist (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
CONSTRAINT guild_playlist_song_FK FOREIGN KEY (guild_playlist) REFERENCES eighttrack.guild_playlist (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
CONSTRAINT guild_playlist_song_FK_1 FOREIGN KEY (guild_song) REFERENCES eighttrack.guild_song (id)
|
CONSTRAINT guild_playlist_song_FK_1 FOREIGN KEY (guild_song) REFERENCES eighttrack.guild_song (id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
CREATE TABLE eighttrack.log (
|
||||||
|
id bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
guild bigint NOT NULL,
|
||||||
|
log longtext NOT NULL,
|
||||||
|
exception longblob,
|
||||||
|
is_exception boolean NOT NULL,
|
||||||
|
date_added timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
KEY log_fk (guild),
|
||||||
|
CONSTRAINT log_fk FOREIGN KEY (guild) REFERENCES eighttrack.discord_guild (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
@ -1,4 +1,4 @@
|
|||||||
USE pseudobot;
|
USE eighttrack;
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE PROCEDURE set_optimizer_switch_on()
|
CREATE PROCEDURE set_optimizer_switch_on()
|
||||||
@ -15,10 +15,6 @@ BEGIN
|
|||||||
IF foo = 0 THEN
|
IF foo = 0 THEN
|
||||||
CREATE USER 'eighttrackAdmin'@'localhost' IDENTIFIED BY 'zeGAPgbH9HFbqmjRjmwzUDKv';
|
CREATE USER 'eighttrackAdmin'@'localhost' IDENTIFIED BY 'zeGAPgbH9HFbqmjRjmwzUDKv';
|
||||||
END IF;
|
END IF;
|
||||||
SELECT COUNT(*) INTO foo FROM mysql.user WHERE User = 'eighttrackAdmin' and Host = '%';
|
|
||||||
IF foo = 0 THEN
|
|
||||||
CREATE USER 'eighttrackAdmin'@'%' IDENTIFIED BY 'zeGAPgbH9HFbqmjRjmwzUDKv';
|
|
||||||
END IF;
|
|
||||||
END ;$$
|
END ;$$
|
||||||
|
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
@ -30,5 +26,4 @@ CALL create_user();
|
|||||||
DROP PROCEDURE create_user;
|
DROP PROCEDURE create_user;
|
||||||
|
|
||||||
GRANT SELECT,INSERT,UPDATE,DELETE ON eighttrack.* TO 'eighttrackAdmin'@'localhost';
|
GRANT SELECT,INSERT,UPDATE,DELETE ON eighttrack.* TO 'eighttrackAdmin'@'localhost';
|
||||||
GRANT SELECT,INSERT,UPDATE,DELETE ON eighttrack.* TO 'eighttrackAdmin'@'%';
|
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
@ -0,0 +1 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS eighttrack;
|
@ -1,10 +1,10 @@
|
|||||||
dbAdmin=root
|
dbAdmin=root
|
||||||
dbAdminPassword=gSkjsvZbQTQtogOrPYqorCuuzp4WUpGFVtPYtMVj47U=
|
dbAdminPassword=bDNuBX0IqflafBFBfr10MQkdGgamC3UeZ0GcsWUWeCI=
|
||||||
dbUser=eighttrackAdmin
|
dbUser=eighttrackAdmin
|
||||||
dbUserPassword=RaamWDMgA2p09R3kAiKHqauu6mmKU2HLQ4nAfEGMNOs=
|
dbUserPassword=RaamWDMgA2p09R3kAiKHqauu6mmKU2HLQ4nAfEGMNOs=
|
||||||
dbHost=devops.locusworks.net
|
dbHost=localhost
|
||||||
dbPort=3306
|
dbPort=3306
|
||||||
logLevel=INFO
|
logLevel=INFO
|
||||||
musicDir=E:/Music
|
musicDir=D:/Music
|
||||||
discordToken=NjI5MTQ0OTk1ODA2MzE0NTA5.XZVlRQ.7hiB0u4Zp5pxPrPfvdOdyr4TCh4
|
discordToken=NjMzMDA2ODIzNzk1OTgyMzQ0.XtLtpA.sramb2b8w4itTFPQ92HqZgyeBJU
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<Configuration status="WARN" shutdownHook="disable"
|
<Configuration status="WARN" shutdownHook="disable"
|
||||||
packages="net.locusworks.discord.eighttrack">
|
packages="net.locusworks.discord.eighttrack">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="logFormat">%d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5p] [%c{1}] %m%n</Property>
|
<Property name="logFormat">%d{dd-MMM-yyyy HH:mm:ss.SSS} %m%n</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
<Appenders>
|
<Appenders>
|
||||||
<Console name="ConsoleAppender" target="SYSTEM_OUT">
|
<Console name="ConsoleAppender" target="SYSTEM_OUT">
|
||||||
@ -20,9 +20,10 @@
|
|||||||
</RollingFile>
|
</RollingFile>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="TRACE">
|
<Root level="ALL"/>
|
||||||
<AppenderRef ref="ConsoleAppender" level="INFO" />
|
<Logger name="net.locusworks.logger" level="ALL">
|
||||||
<AppenderRef ref="eighttrack" level="INFO" />
|
<AppenderRef ref="eighttrack"/>
|
||||||
</Root>
|
<AppenderRef ref="ConsoleAppender"/>
|
||||||
|
</Logger>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
Reference in New Issue
Block a user