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();
}
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()) + '.');
}
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());
}
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.");
}
});
}
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;
}
Aggregations