=SubCommand Routine Mods, Hopefully the last of it
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package commands.poll;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.*;
|
||||
|
||||
public class SubCommandResults extends SubCommand
|
||||
{
|
||||
public SubCommandResults(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
return new SubCommandFormattable (results);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package commands.poll;
|
||||
|
||||
import core.LocStrings;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
|
||||
public class SubCommandShow extends SubCommand
|
||||
{
|
||||
public SubCommandShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
|
||||
{
|
||||
if(!guild.polling)
|
||||
{
|
||||
return new SubCommandFormattable (LocStrings.stub("PollShowNoPoll"));
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
return new SubCommandFormattable (poll);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package commands.poll;
|
||||
|
||||
import core.LocStrings;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyPoll;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
|
||||
public class SubCommandVote extends SubCommand
|
||||
{
|
||||
public SubCommandVote(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
|
||||
{
|
||||
if(guild.polling)
|
||||
{
|
||||
if(guild.hasVoted.contains(user.uniqueID))
|
||||
{
|
||||
return new SubCommandFormattable (LocStrings.stub("PollVoteAlreadyVoted"));
|
||||
}
|
||||
try
|
||||
{
|
||||
int voteNum = Integer.parseInt(input)-1;
|
||||
if(voteNum >= guild.choices.size() || voteNum < 0)
|
||||
{
|
||||
return new SubCommandFormattable (String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum));
|
||||
}
|
||||
|
||||
KittyPoll polled = guild.choices.get(voteNum);
|
||||
polled.votes++;
|
||||
guild.hasVoted.add(user.uniqueID);
|
||||
return new SubCommandFormattable (LocStrings.stub("PollVoteSuccess") + " `" + polled.choice + "`!");
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return new SubCommandFormattable (LocStrings.stub("PollVoteNotValidNumber"));
|
||||
}
|
||||
}
|
||||
|
||||
return new SubCommandFormattable (LocStrings.stub("PollVoteNoPoll"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user