=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
+28
View File
@@ -0,0 +1,28 @@
package commands.raffle;
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 CommandRaffleEnd extends SubCommand
{
public CommandRaffleEnd(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(guild.endRaffle())
{
return new SubCommandFormattable (LocStrings.stub("RaffleEndSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleEndFailure"));
}
}
}
@@ -0,0 +1,24 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.*;
public class CommandRaffleJoin extends SubCommand
{
public CommandRaffleJoin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(guild.joinRaffle(user))
{
return new SubCommandFormattable (LocStrings.stub("RaffleJoinSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleJoinFailure"));
}
}
}
@@ -0,0 +1,24 @@
package commands.raffle;
import core.Command;
import core.SubCommandFramework;
import dataStructures.*;
public class CommandRaffleMain extends Command
{
SubCommandFramework framework = new SubCommandFramework();
public CommandRaffleMain(KittyRole level, KittyRating rating)
{
super(level, rating);
framework.addCommand("start", new CommandRaffleStart(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("spin", new CommandRaffleSpin(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("end", new CommandRaffleEnd(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("join", new CommandRaffleJoin(KittyRole.General, KittyRating.Safe));
}
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
framework.run(guild, channel, user, input.args).Call(res);
}
}
@@ -0,0 +1,28 @@
package commands.raffle;
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 CommandRaffleSpin extends SubCommand
{
public CommandRaffleSpin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
return new SubCommandFormattable (String.format(LocStrings.stub("RaffleSpinSuccess"), guild.chooseRaffleWinner().name));
}
catch(Exception e)
{
return new SubCommandFormattable (LocStrings.stub("RaffleSpinFailure"));
}
}
}
@@ -0,0 +1,35 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.*;
public class CommandRaffleStart extends SubCommand
{
public CommandRaffleStart(KittyRole level, KittyRating rating) { super(level, rating); }
public int beanCost;
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
beanCost = Integer.parseInt(input);
}
catch(Exception e)
{
beanCost = 100;
}
if(guild.startRaffle(beanCost))
{
return new SubCommandFormattable (String.format(LocStrings.stub("RaffleStartSuccess"), beanCost));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleStartFailure"));
}
}
}