use of me.shadorc.shadbot.exception.IllegalCmdArgumentException in project Shadbot by Shadorc.
the class TransferCoinsCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
if (context.getMessage().getMentions().isEmpty()) {
throw new MissingArgumentException();
}
List<String> splitCmd = StringUtils.split(context.getArg(), 2);
if (splitCmd.size() != 2) {
throw new MissingArgumentException();
}
IUser receiverUser = context.getMessage().getMentions().get(0);
IUser senderUser = context.getAuthor();
if (receiverUser.equals(senderUser)) {
throw new IllegalCmdArgumentException("You cannot transfer coins to yourself.");
}
Integer coins = CastUtils.asPositiveInt(splitCmd.get(0));
if (coins == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid amount for coins.", splitCmd.get(0)));
}
if (Database.getDBUser(context.getGuild(), senderUser).getCoins() < coins) {
BotUtils.sendMessage(TextUtils.notEnoughCoins(context.getAuthor()), context.getChannel());
return;
}
if (Database.getDBUser(context.getGuild(), receiverUser).getCoins() + coins >= Config.MAX_COINS) {
BotUtils.sendMessage(String.format(Emoji.BANK + " This transfer cannot be done because %s would exceed the maximum coins cap.", receiverUser.getName()), context.getChannel());
return;
}
Database.getDBUser(context.getGuild(), senderUser).addCoins(-coins);
Database.getDBUser(context.getGuild(), receiverUser).addCoins(coins);
BotUtils.sendMessage(String.format(Emoji.BANK + " %s has transfered **%s** to %s", senderUser.mention(), FormatUtils.formatCoins(coins), receiverUser.mention()), context.getChannel());
}
use of me.shadorc.shadbot.exception.IllegalCmdArgumentException in project Shadbot by Shadorc.
the class HolidaysCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
Zone zone = Utils.getValueOrNull(Zone.class, context.getArg());
if (zone == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid zone. %s", context.getArg(), FormatUtils.formatOptions(Zone.class)));
}
LoadingMessage loadingMsg = new LoadingMessage("Loading holiday information...", context.getChannel());
loadingMsg.send();
try {
String holidays = StringUtils.remove(TwitterUtils.getLastTweet("Vacances_Zone" + zone), "#");
loadingMsg.edit(Emoji.BEACH + " " + holidays);
} catch (TwitterException err) {
loadingMsg.delete();
Utils.handle("getting holidays information", context, err.getCause());
}
}
use of me.shadorc.shadbot.exception.IllegalCmdArgumentException in project Shadbot by Shadorc.
the class LottoCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
this.show(context);
return;
}
DBUser dbUser = Database.getDBUser(context.getGuild(), context.getAuthor());
if (dbUser.getCoins() < PAID_COST) {
BotUtils.sendMessage(TextUtils.notEnoughCoins(context.getAuthor()), context.getChannel());
return;
}
LottoPlayer player = LottoManager.getPlayers().stream().filter(lottoPlayer -> lottoPlayer.getUserID() == context.getAuthor().getLongID()).findAny().orElse(null);
if (player != null) {
throw new IllegalCmdArgumentException("You're already participating.");
}
Integer num = CastUtils.asIntBetween(context.getArg(), MIN_NUM, MAX_NUM);
if (num == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid number, it must be between %d and %d.", context.getArg(), MIN_NUM, MAX_NUM));
}
dbUser.addCoins(-PAID_COST);
LottoManager.addPlayer(context.getGuild(), context.getAuthor(), num);
BotUtils.sendMessage(String.format(Emoji.TICKET + " You bought a lottery ticket and bet on number **%d**. Good luck !", num), context.getChannel());
}
use of me.shadorc.shadbot.exception.IllegalCmdArgumentException in project Shadbot by Shadorc.
the class HangmanCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
Difficulty difficulty = Utils.getValueOrNull(Difficulty.class, context.getArg());
if (context.hasArg() && difficulty == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid difficulty. %s", context.getArg(), FormatUtils.formatOptions(Difficulty.class)));
}
if (difficulty == null) {
difficulty = Difficulty.EASY;
}
if (HARD_WORDS.isEmpty() || EASY_WORDS.isEmpty()) {
LoadingMessage loadingMsg = new LoadingMessage("Loading word...", context.getChannel());
loadingMsg.send();
try {
this.load();
} catch (JSONException | IOException err) {
Utils.handle("getting words list", context, err);
}
loadingMsg.delete();
}
HangmanManager hangmanManager = MANAGERS.get(context.getChannel().getLongID());
if (hangmanManager == null) {
hangmanManager = new HangmanManager(this, context.getPrefix(), context.getChannel(), context.getAuthor(), difficulty);
if (MANAGERS.putIfAbsent(context.getChannel().getLongID(), hangmanManager) == null) {
hangmanManager.start();
}
} else {
BotUtils.sendMessage(String.format(Emoji.INFO + " A Hangman game has already been started by **%s**. Please, wait for him to finish.", hangmanManager.getAuthor().getName()), context.getChannel());
}
}
use of me.shadorc.shadbot.exception.IllegalCmdArgumentException in project Shadbot by Shadorc.
the class VolumeCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
TrackScheduler scheduler = guildMusic.getScheduler();
if (!context.hasArg()) {
BotUtils.sendMessage(String.format(Emoji.SOUND + " Current volume level: **%d%%**", scheduler.getAudioPlayer().getVolume()), context.getChannel());
return;
}
Integer volume = CastUtils.asPositiveInt(context.getArg());
if (volume == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid volume.", context.getArg()));
}
scheduler.setVolume(volume);
BotUtils.sendMessage(String.format(Emoji.SOUND + " Volume level set to **%s%%**", scheduler.getAudioPlayer().getVolume()), context.getChannel());
}
Aggregations