=Bug Fixes on Poll
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user