=SubCommand Routine Mods, Hopefully the last of it

This commit is contained in:
Alex
2019-07-03 01:47:21 -04:00
parent 47441e06ed
commit fbe9794026
4 changed files with 113 additions and 8 deletions
+33
View File
@@ -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);
}
}
+33
View File
@@ -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);
}
}
+47
View File
@@ -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"));
}
}
-8
View File
@@ -47,10 +47,6 @@ import commands.general.CommandTweet;
import commands.general.CommandWolfram; import commands.general.CommandWolfram;
import commands.general.CommandYeet; import commands.general.CommandYeet;
import commands.guildrole.CommandGuildRoleMain; import commands.guildrole.CommandGuildRoleMain;
import commands.poll.CommandPollManage;
import commands.poll.CommandPollResults;
import commands.poll.CommandPollShow;
import commands.poll.CommandPollVote;
import commands.raffle.CommandRaffleMain; import commands.raffle.CommandRaffleMain;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
@@ -116,7 +112,6 @@ public class CommandManager
this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe)); this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
// Mod // Mod
this.register(LocCommands.stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe)); this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe)); this.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
@@ -131,9 +126,6 @@ public class CommandManager
this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("vote"), new CommandPollVote(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("results"), new CommandPollResults(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("showpoll"), new CommandPollShow(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));