Search in sources :

Example 31 with IUser

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());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) Place(me.shadorc.shadbot.command.game.roulette.RouletteCmd.Place)

Example 32 with IUser

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());
}
Also used : IUser(sx.blah.discord.handle.obj.IUser)

Example 33 with IUser

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;
}
Also used : IUser(sx.blah.discord.handle.obj.IUser)

Example 34 with IUser

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);
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 35 with IUser

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();
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel) BotCommand(com.discordbolt.api.command.BotCommand)

Aggregations

IUser (sx.blah.discord.handle.obj.IUser)67 ArrayList (java.util.ArrayList)15 IGuild (sx.blah.discord.handle.obj.IGuild)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)13 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 IMessage (sx.blah.discord.handle.obj.IMessage)9 IRole (sx.blah.discord.handle.obj.IRole)8 List (java.util.List)7 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 HashMap (java.util.HashMap)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)4 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)4 Context (me.shadorc.shadbot.core.command.Context)4 Command (me.shadorc.shadbot.core.command.annotation.Command)4 BotUtils (me.shadorc.shadbot.utils.BotUtils)4 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)4 TextUtils (me.shadorc.shadbot.utils.TextUtils)4