Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
updated lot of stuff :^)
Browse files Browse the repository at this point in the history
  • Loading branch information
ゼクロ committed Sep 30, 2017
1 parent 94d49e8 commit 7a5dcfb
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 98 deletions.
31 changes: 26 additions & 5 deletions src/main/java/commands/chat/Vote3.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ public class Poll implements Serializable {
private List<String> emotis;
private String message;
private HashMap<String, Integer> votes;
private boolean secret;

public Poll(Member creator, String heading, List<String> answers, List<String> emotis, Message message) {
public Poll(Member creator, String heading, List<String> answers, List<String> emotis, Message message, boolean secret) {
this.creator = creator.getUser().getId();
this.heading = heading;
this.answers = answers;
this.emotis = emotis;
this.votes = new HashMap<>();
this.message = message.getId();
this.secret = secret;
}

private Member getCreator(Guild guild) {
Expand Down Expand Up @@ -103,7 +105,7 @@ private static EmbedBuilder getParsedPoll(Poll poll, Guild guild) {

}

private void createPoll(String[] args, MessageReceivedEvent event) {
private void createPoll(String[] args, MessageReceivedEvent event, boolean secret) {

if (polls.containsKey(event.getGuild())) {
message("There is already a vote running on this guild!", Color.red);
Expand All @@ -126,7 +128,7 @@ private void createPoll(String[] args, MessageReceivedEvent event) {
toAddEmotis.add(randEmoti);
});

Poll poll = new Poll(event.getMember(), heading, answers, toAddEmotis, msg);
Poll poll = new Poll(event.getMember(), heading, answers, toAddEmotis, msg, secret);

polls.put(event.getGuild(), poll);

Expand Down Expand Up @@ -254,7 +256,16 @@ private void statsPoll(MessageReceivedEvent event) {
message("There is currently no vote running!", Color.red);
return;
}
channel.sendMessage(getParsedPoll(polls.get(event.getGuild()), event.getGuild()).build()).queue();

Poll poll = polls.get(event.getGuild());
Guild g = event.getGuild();

if (poll.secret && !poll.getMessage(g).getTextChannel().equals(event.getTextChannel())) {
message("The running poll is a `secret` poll and can only be accessed from the channel where it was created from!", Color.red);
return;
}

channel.sendMessage(getParsedPoll(poll, g).build()).queue();

}

Expand All @@ -268,6 +279,11 @@ private void closePoll(MessageReceivedEvent event) {
Guild g = event.getGuild();
Poll poll = polls.get(g);

if (poll.secret && !poll.getMessage(g).getTextChannel().equals(event.getTextChannel())) {
message("The running poll is a `secret` poll and can only be accessed from the channel where it was created from!", Color.red);
return;
}

if (!poll.getCreator(g).equals(event.getMember()) && Perms.getLvl(event.getMember()) < 2) {
message("Only the creator of the poll (" + poll.getCreator(g).getAsMention() + ") can close this poll!", Color.red);
return;
Expand Down Expand Up @@ -301,9 +317,13 @@ public void action(String[] args, MessageReceivedEvent event) throws ParseExcept
switch (args[0]) {

case "create":
createPoll(args, event);
createPoll(args, event, false);
break;

case "secret":
createPoll(args, event, true);
message("The created vote is `secret` and can only be accessed from this channel.", Color.yellow);
break;
case "stats":
statsPoll(event);
break;
Expand All @@ -326,6 +346,7 @@ public String help() {
return "**ATTENTION:** This vote command is not finished yet and may cause heavy bugs and errors!" +
"USAGE:\n" +
"**-vote create <question>|<answer 1>|<answer 2>|...** - `Create a poll.`\n" +
"**-vote secret <question>|<answer 1>|<answer 2>|...** - `Create a secret poll.\n`" +
"**-vote stats** - `Show the stats of the current vote.`\n" +
"**-vote close** - `Close the current vote.`";
}
Expand Down
79 changes: 41 additions & 38 deletions src/main/java/commands/music/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public class Music implements Command {
private Member endlessAuthor;


private MessageEmbed embed(String content) {
return new EmbedBuilder().setColor(Color.green).setDescription("content").build();
}

private boolean hasPlayer(Guild guild) {
return players.containsKey(guild.getId());
}
Expand Down Expand Up @@ -193,7 +189,7 @@ private boolean isCurrentDj(Member member) {

private boolean isIdle(Guild guild, MessageReceivedEvent event) {
if (!hasPlayer(guild) || getPlayer(guild).getPlayingTrack() == null) {
event.getTextChannel().sendMessage(embed("No music is being played at the moment!")).queue();
event.getTextChannel().sendMessage("No music is being played at the moment!").queue();
return true;
}
return false;
Expand Down Expand Up @@ -250,22 +246,22 @@ private void sendHelpMessage(MessageReceivedEvent event) {
":heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: ", false)

.addField(pre + "m stop",
"Stops the current playing. The current queue will be reset after this!\n" +
"Stops the current playing. The current queue will be reset after this!\n" +
":heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: ", false)

.addField(pre + "m queue <OPTIONAL INPUT>",
"`OPTIONAL INPUT:` Side of list.\n\n" +
"`OPTIONAL INPUT:` Side of list.\n\n" +
"\nShows the current queue. Displays only 20 tracks on one side. Use Optional input to switch between sides.\n" +
":heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: ", false)

.addBlankField(false)
.addField(pre + "m save <INPUT>",
"`INPUT:` Custom name of the save.\n\n" +
"`INPUT:` Custom name of the save.\n\n" +
"Saves the last attached track/playlist URL to a save with a custom name.\n" +
":heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: ", false)

.addField(pre + "m list",
"Displays a list of the names of all saved tracks/playlists.\n" +
"Displays a list of the names of all saved tracks/playlists.\n" +
":heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: ", false)

.addField(pre + "m load <INPUT>",
Expand Down Expand Up @@ -438,7 +434,7 @@ public void run() {
case "nowplaying":
case "info":
if (!hasPlayer(guild) || getPlayer(guild).getPlayingTrack() == null) {
event.getTextChannel().sendMessage(embed(NOTE + "No music currently playing!")).queue();
event.getTextChannel().sendMessage(NOTE + "No music currently playing!").queue();
} else {
AudioTrack track = getPlayer(guild).getPlayingTrack();
AudioTrackInfo info = track.getInfo();
Expand All @@ -456,7 +452,7 @@ public void run() {

case "queue":
if (!hasPlayer(guild) || getTrackManager(guild).getQueuedTracks().isEmpty()) {
event.getTextChannel().sendMessage(embed(NOTE + "The queue ist currently empty!")).queue();
event.getTextChannel().sendMessage(NOTE + "The queue ist currently empty!").queue();
} else {

int SideNumbInput = 1;
Expand All @@ -480,12 +476,12 @@ public void run() {

eb.setColor(Color.GREEN).setDescription(
NOTE + "**QUEUE**\n\n" +
"*[" + queue.size() + " Tracks | Side " + sideNumb + "/" + sideNumbAll + "]*\n\n" +
sb
"*[" + queue.size() + " Tracks | Side " + sideNumb + "/" + sideNumbAll + "]*\n\n" +
sb
);

event.getTextChannel().sendMessage(
eb.build()
eb.build()
).queue();

}
Expand Down Expand Up @@ -540,7 +536,7 @@ public void run() {

if (isDj(event.getMember())) {
getTrackManager(guild).shuffleQueue();
event.getTextChannel().sendMessage(embed(NOTE + "Shuffled queue. :twisted_rightwards_arrows: ")).queue();
event.getTextChannel().sendMessage(NOTE + "Shuffled queue. :twisted_rightwards_arrows: ").queue();
} else {
//chat.sendMessage("\u26D4 You don't have the permission to do that!");
}
Expand All @@ -551,12 +547,12 @@ public void run() {
if (getPlayer(guild).isPaused()) {
getPlayer(guild).setPaused(false);
event.getTextChannel().sendMessage(
embed(NOTE + "Player resumed.")
NOTE + "Player resumed."
).queue();
} else {
getPlayer(guild).setPaused(true);
event.getTextChannel().sendMessage(
embed(NOTE + "Player paused.")
NOTE + "Player paused."
).queue();
}
break;
Expand All @@ -572,15 +568,22 @@ public void run() {
} else if (args.length < 2) {
event.getTextChannel().sendMessage(MSGS.error().setDescription(":warning: Please enter a valid name for your playlist!").build()).queue();
return;
} else if (args.length > 3) {
event.getTextChannel().sendMessage(MSGS.error().setDescription(":warning: Please only use single-word names!").build()).queue();
return;
}

File saveFile = new File("saves_playlists/" + args[1]);
File path = new File("SERVER_SETTINGS/" + event.getGuild().getId() + "/saves_playlists");
if (!path.exists())
path.mkdirs();

File saveFile = new File("SERVER_SETTINGS/" + event.getGuild().getId() + "/saves_playlists/" + args[1]);

PrintWriter writer = new PrintWriter(saveFile);
writer.write(input);
writer.close();

event.getTextChannel().sendMessage(embed(NOTE + " Playlist \"" + args[1] + "\" successfully saved!")).queue();
event.getTextChannel().sendMessage(NOTE + " Playlist \"" + args[1] + "\" successfully saved!").queue();

break;

Expand All @@ -590,13 +593,13 @@ public void run() {

try {

File[] saves = new File("saves_playlists/").listFiles();
File[] saves = new File("SERVER_SETTINGS/" + event.getGuild().getId() + "/saves_playlists/").listFiles();
StringBuilder list = new StringBuilder();

if (saves.length > 0) {
Arrays.stream(saves).forEach(file -> list.append("- **" + file.getName() + "**\n"));
event.getTextChannel().sendMessage(
embed(NOTE + " **SAVED PLAYLISTS** " + NOTE + "\n\n" + list.toString())
NOTE + " **SAVED PLAYLISTS** " + NOTE + "\n\n" + list.toString()
).queue();
} else {
event.getTextChannel().sendMessage(MSGS.error().setDescription(":warning: Sorry, but there are no playlists saved yet!").build()).queue();
Expand All @@ -617,7 +620,7 @@ public void run() {
}

try {
File savedFile = new File("saves_playlists/" + args[1]);
File savedFile = new File("SERVER_SETTINGS/" + event.getGuild().getId() + "/saves_playlists/" + args[1]);
BufferedReader reader = new BufferedReader(new FileReader(savedFile));
String out = reader.readLine();

Expand All @@ -631,7 +634,7 @@ public void run() {
public void run() {
int tracks = getTrackManager(guild).getQueuedTracks().size();
event.getTextChannel().sendMessage(
embed(NOTE + "Queued `" + tracks + "` Tracks.")
NOTE + "Queued `" + tracks + "` Tracks."
).queue();
}
},
Expand Down Expand Up @@ -704,7 +707,7 @@ public void run() {
public void run() {
int tracks = getTrackManager(guild).getQueuedTracks().size();
event.getTextChannel().sendMessage(
embed(NOTE + "Queued `" + tracks + "` Tracks.")
NOTE + "Queued `" + tracks + "` Tracks."
).queue();
}
},
Expand All @@ -726,7 +729,7 @@ public void run() {
public void run() {
int tracks = getTrackManager(guild).getQueuedTracks().size();
event.getTextChannel().sendMessage(
embed(NOTE + "Queued `" + tracks + "` Tracks.")
NOTE + "Queued `" + tracks + "` Tracks."
).queue();
}
},
Expand All @@ -749,19 +752,19 @@ public void executed(boolean success, MessageReceivedEvent event) {
public String help() {
return
":musical_note: **MUSIC PLAYER** :musical_note: \n\n" +
"` -music play <yt/soundcloud - URL> ` - Start playing a track / Add a track to queue / Add a playlist to queue\n" +
"` -music playnext <yt/soundcloud - URL> - Add track or playlist direct after the current song in queue`\n" +
"` -music ytplay <Search string for yt> ` - Same like *play*, just let youtube search for a track you enter\n" +
"` -music queue <Side>` - Show the current music queue\n" +
"` -music skip ` - Skip the current track in queue\n" +
"` -music now ` - Show info about the now playing track\n" +
"` -music save <name> ` - Save playing playlist in a file\n" +
"` -music list ` - Get a list of saved playlists\n" +
"` -music load <name> ` - play a saved list\n" +
"` -music stop ` - Stop the music player\n" +
"` -music channel <text channel> ` - Set the channel where now playing will shown (use a channel that does not exist to disable messages)\n" +
"` -music lockchannel <true | false> ` - Only allow music commands in the music channel"
;
"` -music play <yt/soundcloud - URL> ` - Start playing a track / Add a track to queue / Add a playlist to queue\n" +
"` -music playnext <yt/soundcloud - URL> - Add track or playlist direct after the current song in queue`\n" +
"` -music ytplay <Search string for yt> ` - Same like *play*, just let youtube search for a track you enter\n" +
"` -music queue <Side>` - Show the current music queue\n" +
"` -music skip ` - Skip the current track in queue\n" +
"` -music now ` - Show info about the now playing track\n" +
"` -music save <name> ` - Save playing playlist in a file\n" +
"` -music list ` - Get a list of saved playlists\n" +
"` -music load <name> ` - play a saved list\n" +
"` -music stop ` - Stop the music player\n" +
"` -music channel <text channel> ` - Set the channel where now playing will shown (use a channel that does not exist to disable messages)\n" +
"` -music lockchannel <true | false> ` - Only allow music commands in the music channel"
;
}

@Override
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/commands/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@

public class Settings implements Command {

//private void resetSettings(Guild g) {
// File[] files = new File("SERVER_SETTINGS/" + g.getId() + "/").listFiles();
//
// Arrays.stream(files).forEach(f -> {
// try {
// FileDeleteStrategy.FORCE.delete(f);
// } catch (IOException e) {
// e.printStackTrace();
// }
// });
//}


@Override
Expand All @@ -43,23 +32,9 @@ public boolean called(String[] args, MessageReceivedEvent event) {
@Override
public void action(String[] args, MessageReceivedEvent event) throws ParseException, IOException {

if (core.Perms.check(1, event)) return;
if (core.Perms.check(2, event)) return;
core.SSSS.listSettings(event);

// THIS SHIT DOES NOT WORK
//if (args.length < 1) {
// if (core.Perms.check(1, event)) return;
// core.SSSS.listSettings(event);
//} else if (args[0].equals("reset")) {
// if (core.Perms.check(3, event)) return;
// File path = new File("SERVER_SETTINGS/" + event.getGuild().getId());
// if (path.exists()) {
// resetSettings(event.getGuild());
// event.getTextChannel().sendMessage(MSGS.success().setDescription("Successfully deleted guild specific settings for this server!").build()).queue();
// }
// else
// event.getTextChannel().sendMessage(MSGS.error().setDescription("No server specific settings found for this guild!").build()).queue();
//}
}

@Override
Expand All @@ -70,7 +45,7 @@ public void executed(boolean success, MessageReceivedEvent event) {
@Override
public String help() {
return "USING:\n" +
"**SettingsCore** - `List all current SettingsCore values of the current guild`";
"**settings** - `List all current SettingsCore values of the current guild`";
}

@Override
Expand Down
Loading

0 comments on commit 7a5dcfb

Please sign in to comment.