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> <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:mariadb://localhost:3306/</url>
<outOfOrder>false</outOfOrder> <outOfOrder>false</outOfOrder>
<schemas> <schemas>
<schema>eighttrack</schema> <schema>eighttrack</schema>
@ -126,8 +126,6 @@
<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>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": case "-playlist":
gmh.playlist(event, commands); gmh.playlist(event, commands);
return; return;
case "+playlist":
gmh.adminPlaylist(event, commands);
return;
case "+delete": case "+delete":
gmh.delete(event, commands); gmh.delete(event, commands);
return; return;

View File

@ -295,10 +295,7 @@ public class GuildMusicHandler {
} }
public void upload(GuildMessageReceivedEvent event) { public void upload(GuildMessageReceivedEvent event) {
if (!event.getMessage().getMember().hasPermission(Permission.ADMINISTRATOR, Permission.MANAGE_SERVER)) { isAdmin(event);
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()) { for(Attachment attachment : event.getMessage().getAttachments()) {
attachment.retrieveInputStream().thenAccept((in) -> { attachment.retrieveInputStream().thenAccept((in) -> {
@ -362,19 +359,16 @@ public class GuildMusicHandler {
event.getChannel().sendMessage(sb.toString()).queue(); 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) { public void delete(GuildMessageReceivedEvent event, List<String> commands) {
if (!event.getMessage().getMember().hasPermission(Permission.ADMINISTRATOR, Permission.MANAGE_SERVER)) { if(!isAdmin(event)) return;
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 (commands == null || commands.isEmpty()) { if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue(); event.getChannel().sendMessage(event.getMember().getAsMention() + ", Missing command for +delete. Valid commandis : +delete song uuids...").queue();
return;
}
if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage("Missing command for +delete. Valid commands are: song, playlist").queue();
return; return;
} }
@ -384,9 +378,6 @@ public class GuildMusicHandler {
case "song": case "song":
deleteSong(event, commands); deleteSong(event, commands);
return; return;
case "playlist":
deleteUserPlayList(event, commands);
return;
} }
} }
@ -591,10 +582,8 @@ public class GuildMusicHandler {
} }
private void deleteSong(GuildMessageReceivedEvent event, List<String> commands) { private void deleteSong(GuildMessageReceivedEvent event, List<String> commands) {
if (commands == null || commands.isEmpty()) { if(!checkCommands(event, commands,
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", you have to provide the list of uuids for songs to remove").queue(); event.getAuthor().getAsMention() + ", you have to provide the list of uuids for songs to remove")) return;
return;
}
List<GuildSong> songs = guildSongRepoService.getGuildSongRepo().findByGuildAndUuidIn(event.getGuild().getIdLong(), commands.stream().collect(Collectors.toSet())); List<GuildSong> songs = guildSongRepoService.getGuildSongRepo().findByGuildAndUuidIn(event.getGuild().getIdLong(), commands.stream().collect(Collectors.toSet()));
if (songs.isEmpty()) { if (songs.isEmpty()) {
@ -629,7 +618,7 @@ public class GuildMusicHandler {
private void deleteUserPlayList(GuildMessageReceivedEvent event, List<String> commands) { private void deleteUserPlayList(GuildMessageReceivedEvent event, List<String> commands) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println(commands.stream().collect(Collectors.joining(", ")));
} }
private void deleteGuildSongsConfirm(List<GuildSong> songs, String user, Message msg) { 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) { private void deletePlayList(GuildMessageReceivedEvent event, List<String> commands) {
if (commands == null || commands.isEmpty()) { if(!checkCommands(event, commands,
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(); event.getAuthor().getAsMention() + " you have to provide the playlist name and optionally a list of uuids for songs to remove")) return;
return;
}
Long guildId = event.getGuild().getIdLong(); Long guildId = event.getGuild().getIdLong();
@ -743,10 +730,8 @@ public class GuildMusicHandler {
} }
private void addPlayList(GuildMessageReceivedEvent event, List<String> commands) { private void addPlayList(GuildMessageReceivedEvent event, List<String> commands) {
if (commands == null || commands.isEmpty()) { if(!checkCommands(event, commands,
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(); 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;
return;
}
Long guildId = event.getGuild().getIdLong(); Long guildId = event.getGuild().getIdLong();
@ -851,6 +836,22 @@ public class GuildMusicHandler {
return true; 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) { private void deleteMessage(Message msg) {
try { try {
msg.delete().complete(); msg.delete().complete();
@ -859,4 +860,5 @@ public class GuildMusicHandler {
if (ex.getErrorResponse() != ErrorResponse.UNKNOWN_MESSAGE) throw ex; if (ex.getErrorResponse() != ErrorResponse.UNKNOWN_MESSAGE) throw ex;
} }
} }
} }

View File

@ -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;
@ -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);
} }

View File

@ -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;

View File

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

View File

@ -2,7 +2,7 @@ dbAdmin=root
dbAdminPassword=gSkjsvZbQTQtogOrPYqorCuuzp4WUpGFVtPYtMVj47U= dbAdminPassword=gSkjsvZbQTQtogOrPYqorCuuzp4WUpGFVtPYtMVj47U=
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=E:/Music