Search in sources :

Example 36 with IUser

use of sx.blah.discord.handle.obj.IUser in project BoltBot by DiscordBolt.

the class Playlist method toEmbed.

public EmbedObject toEmbed() {
    EmbedBuilder embed = new EmbedBuilder();
    embed.withColor(MusicModule.EMBED_COLOR);
    embed.withAuthorName(getTitle());
    embed.withAuthorIcon(getOwner().getAvatarURL());
    embed.withTitle("Songs");
    StringBuilder songs = new StringBuilder();
    int index = 1;
    for (String songID : getSongIDs()) {
        songs.append(index).append(". ").append(getSongTitle(songID).replace("*", " ").replace("_", "").replace("~", "")).append('\n');
        index++;
    }
    songs.setLength(2048);
    embed.withDesc(songs.toString());
    if (getContributors().size() > 0) {
        StringBuilder contributors = new StringBuilder();
        for (IUser c : getContributors()) {
            contributors.append("\n").append(c.getName());
        }
        embed.appendField("Contributors", contributors.toString() + " ", false);
    }
    embed.withFooterText("Playlist by " + getOwner().getName());
    return embed.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser)

Example 37 with IUser

use of sx.blah.discord.handle.obj.IUser in project BoltBot by DiscordBolt.

the class SeenModule method seenCommand.

@BotCommand(command = "seen", module = "Seen Module", description = "See when the user was last online.", usage = "Seen [User]", minArgs = 2, maxArgs = 100)
public static void seenCommand(CommandContext cc) throws CommandException {
    IUser searchUser = UserUtil.findUser(cc.getMessage(), cc.getMessageContent().indexOf(' ') + 1);
    String name = cc.getMessageContent().substring(cc.getMessageContent().indexOf(' ') + 1, cc.getMessageContent().length());
    if (searchUser == null)
        throw new CommandArgumentException("Sorry, I could not find '" + name + "'.");
    Optional<UserData> userData = UserData.getById(searchUser.getLongID());
    if (!userData.isPresent() || userData.get().getLastStatusChange() == null)
        throw new CommandArgumentException("Sorry, I could not find \"" + name + "\".");
    cc.replyWith(searchUser.getName() + " has been " + userData.get().getStatus().name().replace("dnd", "do not disturb").toLowerCase() + " since " + format(userData.get().getLastStatusChange()) + '.');
}
Also used : UserData(com.discordbolt.boltbot.system.mysql.data.persistent.UserData) IUser(sx.blah.discord.handle.obj.IUser) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 38 with IUser

use of sx.blah.discord.handle.obj.IUser in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistListCommand.

@BotCommand(command = { "playlist", "list" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "List all stored playlists", usage = "Playlist list", allowedChannels = "music", args = 2)
public static void playlistListCommand(CommandContext cc) throws CommandException {
    EmbedBuilder embed = new EmbedBuilder();
    embed.withColor(MusicModule.EMBED_COLOR);
    embed.withAuthorName("Playlists");
    List<Playlist> playlists = MusicModule.getPlaylistManager().getPlaylists();
    embed.withTitle("Number of Playlists:");
    embed.withDescription(playlists.size() + "");
    IUser currentUser = null;
    StringBuilder sb = new StringBuilder();
    int id = 1;
    for (Playlist pl : playlists) {
        if (currentUser == null || !pl.getOwnerID().equals(currentUser.getLongID())) {
            if (currentUser != null)
                embed.appendField(currentUser.getName(), sb.toString(), false);
            sb.setLength(0);
            currentUser = pl.getOwner();
        }
        if (sb.length() != 0)
            sb.append('\n');
        sb.append(id++).append(". ").append(pl.getTitle());
    }
    if (currentUser != null)
        embed.appendField(currentUser.getName(), sb.toString(), false);
    cc.replyWith(embed.build());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) IUser(sx.blah.discord.handle.obj.IUser) BotCommand(com.discordbolt.api.command.BotCommand)

Example 39 with IUser

use of sx.blah.discord.handle.obj.IUser in project BoltBot by DiscordBolt.

the class VoiceManager method queue.

public void queue(IGuild guild, IUser requester, String songID) throws CommandPermissionException, CommandRuntimeException, CommandStateException {
    if (songID.toLowerCase().contains("twitch.tv") && !MusicModule.hasAdminPermissions(requester, guild))
        throw new CommandPermissionException("You must be a \"" + MusicModule.ADMIN_ROLE + "\" to add Twitch.tv live streams!");
    if (requester.getVoiceStateForGuild(guild).getChannel() == null)
        throw new CommandStateException("You must be connected to a voice channel to execute this command!");
    if (getDJ(guild).getVoiceChannel() != null && !requester.getVoiceStateForGuild(guild).getChannel().equals(getDJ(guild).getVoiceChannel()))
        throw new CommandStateException("You must be in my voice channel to control the music!");
    DJ dj = getDJ(guild);
    if ((dj.getPlaying() != null && songID.contains(dj.getPlaying().getIdentifier())) || dj.getQueue().stream().anyMatch(t -> songID.contains(t.getIdentifier()))) {
        throw new CommandStateException("That song is already in the queue!");
    }
    playerManager.loadItemOrdered(dj, songID, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            dj.queue(requester, track);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            for (AudioTrack track : playlist.getTracks()) {
                dj.queue(requester, track);
            }
        }

        @Override
        public void noMatches() {
            throw new CommandRuntimeException("Sorry, I was unable to find the song you specified.");
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            if (exception.severity == FriendlyException.Severity.COMMON)
                throw new CommandRuntimeException(exception.getMessage());
            throw new CommandRuntimeException("Sorry, an error occurred while loading your song. Please try again later.");
        }
    });
}
Also used : ExceptionMessage(com.discordbolt.boltbot.utils.ExceptionMessage) com.discordbolt.api.command.exceptions(com.discordbolt.api.command.exceptions) HashMap(java.util.HashMap) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException) ReactionRemoveEvent(sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionRemoveEvent) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) Semaphore(java.util.concurrent.Semaphore) ReactionAddEvent(sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionAddEvent) EventSubscriber(sx.blah.discord.api.events.EventSubscriber) Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioConfiguration(com.sedmelluq.discord.lavaplayer.player.AudioConfiguration) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) ChannelUtil(com.discordbolt.boltbot.utils.ChannelUtil) IGuild(sx.blah.discord.handle.obj.IGuild) List(java.util.List) MusicModule(com.discordbolt.boltbot.modules.music.MusicModule) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) StandardAudioDataFormats(com.sedmelluq.discord.lavaplayer.format.StandardAudioDataFormats) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 40 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementMessageFormatter method getSubscriberMentions.

private static String getSubscriberMentions(Announcement a, IGuild guild) {
    StringBuilder userMentions = new StringBuilder();
    for (String userId : a.getSubscriberUserIds()) {
        try {
            IUser user = guild.getUserByID(Long.valueOf(userId));
            if (user != null) {
                userMentions.append(user.mention(true)).append(" ");
            }
        } catch (Exception e) {
        // User does not exist, safely ignore.
        }
    }
    StringBuilder roleMentions = new StringBuilder();
    Boolean mentionEveryone = false;
    Boolean mentionHere = false;
    for (String roleId : a.getSubscriberRoleIds()) {
        if (roleId.equalsIgnoreCase("everyone")) {
            mentionEveryone = true;
        } else if (roleId.equalsIgnoreCase("here")) {
            mentionHere = true;
        } else {
            try {
                IRole role = guild.getRoleByID(Long.valueOf(roleId));
                if (role != null) {
                    roleMentions.append(role.mention()).append(" ");
                }
            } catch (Exception e) {
            // Role does not exist, safely ignore.
            }
        }
    }
    if (!mentionEveryone && !mentionHere && userMentions.toString().equals("") && roleMentions.toString().equals("")) {
        return "";
    }
    String message = "Subscribers: " + userMentions + " " + roleMentions;
    if (mentionEveryone) {
        message = message + " " + guild.getEveryoneRole().mention();
    }
    if (mentionHere) {
        message = message + " @here";
    }
    return message;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser)

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