Changed to use local database and started adding admin rights

This commit is contained in:
Isaac Parenteau
2019-10-13 16:00:05 -05:00
parent c169061b07
commit 68a472d804
8 changed files with 49 additions and 41 deletions

View File

@ -116,7 +116,7 @@
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<url>jdbc:mariadb://devops.locusworks.net:3306/</url>
<url>jdbc:mariadb://localhost:3306/</url>
<outOfOrder>false</outOfOrder>
<schemas>
<schema>eighttrack</schema>
@ -126,8 +126,6 @@
<location>filesystem:${basedir}/src/main/resources/database/migration</location>
</locations>
</configuration>
<!-- <executions> <execution> <phase>process-sources</phase> <goals>
<goal>migrate</goal> </goals> </execution> </executions> -->
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>

View File

@ -0,0 +1,5 @@
package net.locusworks.discord.eighttrack.enums;
public enum UserCommands {
}

View File

@ -175,6 +175,9 @@ public class DiscordEventHandler extends ListenerAdapter {
case "-playlist":
gmh.playlist(event, commands);
return;
case "+playlist":
gmh.adminPlaylist(event, commands);
return;
case "+delete":
gmh.delete(event, commands);
return;

View File

@ -295,10 +295,7 @@ public class GuildMusicHandler {
}
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;
}
isAdmin(event);
for(Attachment attachment : event.getMessage().getAttachments()) {
attachment.retrieveInputStream().thenAccept((in) -> {
@ -361,20 +358,17 @@ public class GuildMusicHandler {
sb.append("```");
event.getChannel().sendMessage(sb.toString()).queue();
}
public void adminPlaylist(GuildMessageReceivedEvent event, List<String> commands) {
if(!isAdmin(event)) return;
}
public void delete(GuildMessageReceivedEvent event, List<String> commands) {
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;
}
if(!isAdmin(event)) return;
if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue();
return;
}
if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage("Missing command for +delete. Valid commands are: song, playlist").queue();
event.getChannel().sendMessage(event.getMember().getAsMention() + ", Missing command for +delete. Valid commandis : +delete song uuids...").queue();
return;
}
@ -384,9 +378,6 @@ public class GuildMusicHandler {
case "song":
deleteSong(event, commands);
return;
case "playlist":
deleteUserPlayList(event, commands);
return;
}
}
@ -591,10 +582,8 @@ public class GuildMusicHandler {
}
private void deleteSong(GuildMessageReceivedEvent event, List<String> commands) {
if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", you have to provide the list of uuids for songs to remove").queue();
return;
}
if(!checkCommands(event, commands,
event.getAuthor().getAsMention() + ", you have to provide the list of uuids for songs to remove")) return;
List<GuildSong> songs = guildSongRepoService.getGuildSongRepo().findByGuildAndUuidIn(event.getGuild().getIdLong(), commands.stream().collect(Collectors.toSet()));
if (songs.isEmpty()) {
@ -629,7 +618,7 @@ public class GuildMusicHandler {
private void deleteUserPlayList(GuildMessageReceivedEvent event, List<String> commands) {
// TODO Auto-generated method stub
System.out.println(commands.stream().collect(Collectors.joining(", ")));
}
private void deleteGuildSongsConfirm(List<GuildSong> songs, String user, Message msg) {
@ -646,10 +635,8 @@ public class GuildMusicHandler {
}
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;
}
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();
@ -743,10 +730,8 @@ public class GuildMusicHandler {
}
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;
}
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();
@ -850,6 +835,22 @@ public class GuildMusicHandler {
return true;
}
private 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;
}
private boolean checkCommands(GuildMessageReceivedEvent event, List<String> commands, String msg) {
if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage(msg).queue();
return false;
}
return true;
}
private void deleteMessage(Message msg) {
try {
@ -859,4 +860,5 @@ public class GuildMusicHandler {
if (ex.getErrorResponse() != ErrorResponse.UNKNOWN_MESSAGE) throw ex;
}
}
}

View File

@ -36,6 +36,7 @@ import java.util.Properties;
import javax.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -214,7 +215,10 @@ public class ConfigurationService {
}
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);
}

View File

@ -1,4 +1,4 @@
USE pseudobot;
USE eighttrack;
DELIMITER $$
CREATE PROCEDURE set_optimizer_switch_on()
@ -15,10 +15,6 @@ BEGIN
IF foo = 0 THEN
CREATE USER 'eighttrackAdmin'@'localhost' IDENTIFIED BY 'zeGAPgbH9HFbqmjRjmwzUDKv';
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 ;$$
DELIMITER ;
@ -30,5 +26,4 @@ CALL 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'@'%';
FLUSH PRIVILEGES;

View File

@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS eighttrack;

View File

@ -2,7 +2,7 @@ dbAdmin=root
dbAdminPassword=gSkjsvZbQTQtogOrPYqorCuuzp4WUpGFVtPYtMVj47U=
dbUser=eighttrackAdmin
dbUserPassword=RaamWDMgA2p09R3kAiKHqauu6mmKU2HLQ4nAfEGMNOs=
dbHost=devops.locusworks.net
dbHost=localhost
dbPort=3306
logLevel=INFO
musicDir=E:/Music