=Bug Fixes on Poll

This commit is contained in:
Alex
2019-07-03 03:28:32 -04:00
parent fbe9794026
commit 8daeedd1ce
11 changed files with 17 additions and 120 deletions
+2 -2
View File
@@ -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!"
1 Type Key Value
195 Localized Strings PingResponse Pong!
196 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
197 Localized Strings PollResultsInfo Will show current results of a poll and percentages of votes per choice
198 Localized Strings PollResultsResponse %s people voted for %s `%s` with `%s%` !n %s people voted for `%s` with `%s%%`
199 Localized Strings PollShowChoices And the choices are:n
200 Localized Strings PollShowInfo Will show the current poll running
201 Localized Strings PollShowNoPoll There is no poll running!
202 Localized Strings PollShowPoll The current poll is `%s`n The current poll is `%s`
203 Localized Strings PollVoteAlreadyVoted You already voted
204 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!
205 Localized Strings PollVoteNoPoll There is no poll running!
@@ -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));
}
+8
View File
@@ -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
-36
View File
@@ -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<KittyPoll> 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);
}
}
-30
View File
@@ -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);
}
}
-47
View File
@@ -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"));
}
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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));
+3
View File
@@ -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)
+1 -2
View File
@@ -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);
}
-1
View File
@@ -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
{