=SubCommand Routine modifications

This commit is contained in:
Alex
2019-07-02 01:57:02 -04:00
parent 2ac0ff99ef
commit 2f2474fde8
19 changed files with 239 additions and 159 deletions
+47
View File
@@ -0,0 +1,47 @@
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"));
}
}