use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.
the class RouletteManager method stop.
@Override
public void stop() {
this.cancelScheduledTask();
int winningPlace = ThreadLocalRandom.current().nextInt(1, 37);
List<String> list = new ArrayList<>();
for (IUser user : playersPlace.keySet()) {
int gains = playersPlace.get(user).getFirst();
String place = playersPlace.get(user).getSecond();
Place placeEnum = Utils.getValueOrNull(Place.class, place);
Map<Place, Boolean> testsMap = new HashMap<>();
testsMap.put(Place.RED, RED_NUMS.contains(winningPlace));
testsMap.put(Place.BLACK, !RED_NUMS.contains(winningPlace));
testsMap.put(Place.LOW, Utils.isInRange(winningPlace, 1, 19));
testsMap.put(Place.HIGH, Utils.isInRange(winningPlace, 19, 37));
testsMap.put(Place.EVEN, winningPlace % 2 == 0);
testsMap.put(Place.ODD, winningPlace % 2 != 0);
int multiplier = 0;
if (place.equals(Integer.toString(winningPlace))) {
multiplier = 36;
} else if (placeEnum != null && testsMap.get(placeEnum)) {
multiplier = 2;
} else {
multiplier = -1;
}
testsMap.clear();
gains *= multiplier;
if (gains > 0) {
list.add(0, String.format("**%s** (Gains: **%s**)", user.getName(), FormatUtils.formatCoins(gains)));
MoneyStatsManager.log(MoneyEnum.MONEY_GAINED, this.getCmdName(), gains);
} else {
list.add(String.format("**%s** (Losses: **%s**)", user.getName(), FormatUtils.formatCoins(Math.abs(gains))));
MoneyStatsManager.log(MoneyEnum.MONEY_LOST, this.getCmdName(), Math.abs(gains));
}
Database.getDBUser(this.getGuild(), user).addCoins(gains);
}
BotUtils.sendMessage(String.format(Emoji.DICE + " No more bets. *The wheel is spinning...* **%d (%s)** !", winningPlace, RED_NUMS.contains(winningPlace) ? "Red" : "Black"), this.getChannel()).get();
this.results = FormatUtils.format(list, Object::toString, ", ");
this.show();
playersPlace.clear();
RouletteCmd.MANAGERS.remove(this.getChannel().getLongID());
}
use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.
the class CoinsCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
String str;
if (context.getMessage().getMentions().isEmpty()) {
str = String.format("(**%s**) You have **%s**.", context.getAuthorName(), FormatUtils.formatCoins(Database.getDBUser(context.getGuild(), context.getAuthor()).getCoins()));
} else {
IUser user = context.getMessage().getMentions().get(0);
str = String.format("**%s** has **%s**.", user.getName(), FormatUtils.formatCoins(Database.getDBUser(context.getGuild(), user).getCoins()));
}
BotUtils.sendMessage(Emoji.PURSE + " " + str, context.getChannel());
}
use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.
the class TriviaManager method intercept.
@Override
public boolean intercept(IMessage message) {
if (this.isCancelCmd(message)) {
return true;
}
String content = message.getContent();
// It's a number or a text
Integer choice = CastUtils.asIntBetween(content, 1, answers.size());
// Message is a text and doesn't match any answers, ignore it
if (choice == null && !answers.stream().anyMatch(content::equalsIgnoreCase)) {
return false;
}
IUser author = message.getAuthor();
// If the user has already answered and has been warned, ignore him
if (alreadyAnswered.containsKey(author) && alreadyAnswered.get(author)) {
return false;
}
String answer = choice == null ? content : answers.get(choice - 1);
if (alreadyAnswered.containsKey(author)) {
BotUtils.sendMessage(String.format(Emoji.GREY_EXCLAMATION + " (**%s**) You can only answer once.", author.getName()), this.getChannel());
alreadyAnswered.put(author, true);
} else if (answer.equalsIgnoreCase(correctAnswer)) {
this.win(message.getChannel(), message.getAuthor());
} else {
BotUtils.sendMessage(String.format(Emoji.THUMBSDOWN + " (**%s**) Wrong answer.", message.getAuthor().getName()), this.getChannel());
alreadyAnswered.put(author, false);
}
return true;
}
use of sx.blah.discord.handle.obj.IUser in project de-DiscordBot by DACH-Discord.
the class UserLog method command_Userlog_Test.
@CommandSubscriber(command = "userlog_test", help = "Userlog-Ausgabe testen", permissionLevel = CommandPermissions.ADMIN)
public void command_Userlog_Test(final IMessage message) {
final IUser user = message.getAuthor();
userJoinNotify(user);
userLeaveNotify(user);
userBanNotify(user);
}
use of sx.blah.discord.handle.obj.IUser in project BoltBot by DiscordBolt.
the class DisconnectModule method disconnectCommand.
@BotCommand(command = "disconnect", module = "Disconnect Module", description = "Disconnect user(s) from their voice channel.", usage = "Disconnect [User] ", permissions = Permissions.VOICE_MOVE_MEMBERS)
public static void disconnectCommand(CommandContext cc) throws CommandException {
IUser user = UserUtil.findUser(cc.getMessage(), 12);
if (user == null)
throw new CommandArgumentException("The user you specified was unable to be found!");
if (user.getVoiceStateForGuild(cc.getGuild()).getChannel() == null)
throw new CommandStateException("The user you specified is not connected to a voice channel!");
IVoiceChannel temp = cc.getGuild().createVoiceChannel("Disconnect");
user.moveToVoiceChannel(temp);
temp.delete();
cc.getMessage().delete();
}
Aggregations