From 8daeedd1cef6bb203a9171c878dc51a0f33fb641 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jul 2019 03:28:32 -0400 Subject: [PATCH] =Bug Fixes on Poll --- assets/config.csv | 4 +- .../guildrole/CommandGuildRoleMain.java | 1 + src/commands/poll/CommandPollMain.java | 8 ++++ src/commands/poll/CommandPollResults.java | 36 -------------- src/commands/poll/CommandPollShow.java | 30 ------------ src/commands/poll/CommandPollVote.java | 47 ------------------- src/commands/poll/SubCommandResults.java | 2 +- src/commands/poll/SubCommandVote.java | 2 +- src/core/CommandManager.java | 3 ++ src/core/SubCommand.java | 3 +- src/core/SubCommandFramework.java | 1 - 11 files changed, 17 insertions(+), 120 deletions(-) delete mode 100644 src/commands/poll/CommandPollResults.java delete mode 100644 src/commands/poll/CommandPollShow.java delete mode 100644 src/commands/poll/CommandPollVote.java diff --git a/assets/config.csv b/assets/config.csv index 231f522..4847ae2 100644 --- a/assets/config.csv +++ b/assets/config.csv @@ -195,11 +195,11 @@ "Localized Strings","PingResponse","Pong!" "Localized Strings","PollManageInfo","'start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll" "Localized Strings","PollResultsInfo","Will show current results of a poll and percentages of votes per choice" -"Localized Strings","PollResultsResponse","%s people voted for %s `%s` with `%s%` !n" +"Localized Strings","PollResultsResponse","%s people voted for `%s` with `%s%%` " "Localized Strings","PollShowChoices","And the choices are:n" "Localized Strings","PollShowInfo","Will show the current poll running" "Localized Strings","PollShowNoPoll","There is no poll running!" -"Localized Strings","PollShowPoll","The current poll is `%s`n" +"Localized Strings","PollShowPoll","The current poll is `%s`" "Localized Strings","PollVoteAlreadyVoted","You already voted" "Localized Strings","PollVoteInfo","Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful!" "Localized Strings","PollVoteNoPoll","There is no poll running!" diff --git a/src/commands/guildrole/CommandGuildRoleMain.java b/src/commands/guildrole/CommandGuildRoleMain.java index 2c5807d..5b00142 100644 --- a/src/commands/guildrole/CommandGuildRoleMain.java +++ b/src/commands/guildrole/CommandGuildRoleMain.java @@ -19,6 +19,7 @@ public class CommandGuildRoleMain extends Command super(level, rating); framework.addCommand("add", new SubCommandAdd (KittyRole.General, KittyRating.Safe)); framework.addCommand("remove", new SubCommandRemove(KittyRole.General, KittyRating.Safe)); + framework.addCommand("list", new SubCommandList(KittyRole.General, KittyRating.Safe)); framework.addCommand("allowed", new SubCommandAllowed(KittyRole.Admin, KittyRating.Safe)); framework.addCommand("unallowed", new SubCommandNotAllowed(KittyRole.Admin, KittyRating.Safe)); } diff --git a/src/commands/poll/CommandPollMain.java b/src/commands/poll/CommandPollMain.java index dd63503..a7036fb 100644 --- a/src/commands/poll/CommandPollMain.java +++ b/src/commands/poll/CommandPollMain.java @@ -16,6 +16,14 @@ public class CommandPollMain extends Command public CommandPollMain(KittyRole level, KittyRating rating) { super(level, rating); + + framework.addCommand("start", new SubCommandStart(KittyRole.Mod, KittyRating.Safe)); + framework.addCommand("addoption", new SubCommandAddOption(KittyRole.Mod, KittyRating.Safe)); + framework.addCommand("end", new SubCommandEnd(KittyRole.Mod, KittyRating.Safe)); + + framework.addCommand("show", new SubCommandShow(KittyRole.General, KittyRating.Safe)); + framework.addCommand("results", new SubCommandResults(KittyRole.General, KittyRating.Safe)); + framework.addCommand("vote", new SubCommandVote(KittyRole.General, KittyRating.Safe)); } @Override diff --git a/src/commands/poll/CommandPollResults.java b/src/commands/poll/CommandPollResults.java deleted file mode 100644 index f34145e..0000000 --- a/src/commands/poll/CommandPollResults.java +++ /dev/null @@ -1,36 +0,0 @@ -package commands.poll; - -import java.util.ArrayList; - -import core.*; -import dataStructures.*; - -public class CommandPollResults extends Command -{ - public CommandPollResults(KittyRole level, KittyRating rating) { super(level, rating); } - - @Override - public String getHelpText() { return LocStrings.stub("PollResultsInfo"); } - - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - String results = ""; - int totalVotes = 0; - ArrayList votes = guild.choices; - - for(int i = 0; i < votes.size(); i++) - { - totalVotes += votes.get(i).votes; - } - - results += "The poll was " + guild.poll + "\n"; - - for(int i = 0; i < votes.size(); i++) - { - results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100)); - } - - res.send(results); - } -} diff --git a/src/commands/poll/CommandPollShow.java b/src/commands/poll/CommandPollShow.java deleted file mode 100644 index 27a870e..0000000 --- a/src/commands/poll/CommandPollShow.java +++ /dev/null @@ -1,30 +0,0 @@ -package commands.poll; - -import core.*; -import dataStructures.*; - -public class CommandPollShow extends Command -{ - public CommandPollShow(KittyRole level, KittyRating rating) { super(level, rating); } - - @Override - public String getHelpText() { return LocStrings.stub("PollShowInfo"); } - - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - if(!guild.polling) - { - res.send(LocStrings.stub("PollShowNoPoll")); - return; - } - String poll = String.format(LocStrings.stub("PollShowPoll"), guild.poll); - poll += LocStrings.stub("PollShowChoices"); - for(int i = 0; i < guild.choices.size(); i++) - { - poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n"; - } - - res.send(poll); - } -} diff --git a/src/commands/poll/CommandPollVote.java b/src/commands/poll/CommandPollVote.java deleted file mode 100644 index 5348523..0000000 --- a/src/commands/poll/CommandPollVote.java +++ /dev/null @@ -1,47 +0,0 @@ -package commands.poll; - -import core.*; -import dataStructures.*; - -public class CommandPollVote extends Command -{ - public CommandPollVote(KittyRole level, KittyRating rating) { super(level, rating); } - - @Override - public String getHelpText() { return LocStrings.stub("PollVoteInfo"); } - - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - if(guild.polling) - { - if(guild.hasVoted.contains(user.uniqueID)) - { - res.send(LocStrings.stub("PollVoteAlreadyVoted")); - return; - } - try - { - int voteNum = Integer.parseInt(input.args)-1; - if(voteNum >= guild.choices.size() || voteNum < 0) - { - res.send(String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum)); - return; - } - - KittyPoll polled = guild.choices.get(voteNum); - polled.votes++; - guild.hasVoted.add(user.uniqueID); - res.send(LocStrings.stub("PollVoteSuccess") + " `" + polled.choice + "`!"); - return; - } - catch (NumberFormatException e) - { - res.send(LocStrings.stub("PollVoteNotValidNumber")); - return; - } - } - - res.send(LocStrings.stub("PollVoteNoPoll")); - } -} diff --git a/src/commands/poll/SubCommandResults.java b/src/commands/poll/SubCommandResults.java index 3c8fc3d..d793251 100644 --- a/src/commands/poll/SubCommandResults.java +++ b/src/commands/poll/SubCommandResults.java @@ -25,7 +25,7 @@ public class SubCommandResults extends SubCommand for(int i = 0; i < votes.size(); i++) { - results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100)); + results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100)) + "\n"; } return new SubCommandFormattable (results); diff --git a/src/commands/poll/SubCommandVote.java b/src/commands/poll/SubCommandVote.java index 400f50b..b4c9252 100644 --- a/src/commands/poll/SubCommandVote.java +++ b/src/commands/poll/SubCommandVote.java @@ -25,7 +25,7 @@ public class SubCommandVote extends SubCommand } try { - int voteNum = Integer.parseInt(input)-1; + int voteNum = Integer.parseInt(input.substring(input.indexOf(" ")).trim())-1; if(voteNum >= guild.choices.size() || voteNum < 0) { return new SubCommandFormattable (String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum)); diff --git a/src/core/CommandManager.java b/src/core/CommandManager.java index 82b8fff..a3c2703 100644 --- a/src/core/CommandManager.java +++ b/src/core/CommandManager.java @@ -47,6 +47,7 @@ import commands.general.CommandTweet; import commands.general.CommandWolfram; import commands.general.CommandYeet; import commands.guildrole.CommandGuildRoleMain; +import commands.poll.CommandPollMain; import commands.raffle.CommandRaffleMain; import dataStructures.KittyChannel; import dataStructures.KittyGuild; @@ -148,6 +149,8 @@ public class CommandManager this.register(LocCommands.stub("role"), new CommandGuildRoleMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe)); + this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe)); + } // Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands) diff --git a/src/core/SubCommand.java b/src/core/SubCommand.java index ee04f16..6410ff8 100644 --- a/src/core/SubCommand.java +++ b/src/core/SubCommand.java @@ -23,7 +23,6 @@ public abstract class SubCommand private boolean CanCall(KittyGuild guild, KittyChannel channel, KittyUser user) { - System.out.println("TESTING CAN CALL"); if(guild.contentRating.getValue() < contentRating.getValue()) { Reject(user, "content rating"); @@ -46,7 +45,7 @@ public abstract class SubCommand protected final SubCommandFormattable Invoke(KittyGuild guild, KittyChannel channel, KittyUser user, String input) { if(!CanCall(guild, channel, user)) - return new SubCommandFormattable("Can't run that!"); + return null; return OnRun(guild, channel, user, input); } diff --git a/src/core/SubCommandFramework.java b/src/core/SubCommandFramework.java index 257e474..8af80f5 100644 --- a/src/core/SubCommandFramework.java +++ b/src/core/SubCommandFramework.java @@ -27,7 +27,6 @@ public class SubCommandFramework public SubCommandFormattable run(KittyGuild guild, KittyChannel channel, KittyUser user, String input) { - System.out.println(input); SubCommandFormattable res = null; try {