本文整理汇总了Java中net.dv8tion.jda.core.entities.Icon类的典型用法代码示例。如果您正苦于以下问题:Java Icon类的具体用法?Java Icon怎么用?Java Icon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Icon类属于net.dv8tion.jda.core.entities包,在下文中一共展示了Icon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
@Override
public void action(String head, String[] args, MessageReceivedEvent event)
{
AccountManagerUpdatable manager = Main.getShardManager().getJDA().getSelfUser().getManagerUpdatable();
if(event.getMessage().getAttachments().isEmpty()) return;
Message.Attachment attachment = event.getMessage().getAttachments().get(0);
try
{
File file = new File(attachment.getFileName());
attachment.download(file);
Icon icon = Icon.from(file);
manager.getAvatarField().setValue(icon).update().complete();
MessageUtilities.sendPrivateMsg("Updated bot avatar!", event.getAuthor(), null);
file.delete();
}
catch (IOException e)
{
Logging.exception(this.getClass(), e);
MessageUtilities.sendPrivateMsg("Failed to update bot avatar!", event.getAuthor(), null);
}
}
示例2: execute
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
@Override
protected void execute(CommandEvent event) {
String url;
if(event.getArgs().isEmpty())
if(!event.getMessage().getAttachments().isEmpty() && event.getMessage().getAttachments().get(0).isImage())
url = event.getMessage().getAttachments().get(0).getUrl();
else
url = null;
else
url = event.getArgs();
InputStream s = OtherUtil.imageFromUrl(url);
if(s==null)
{
event.reply(event.getClient().getError()+" Invalid or missing URL");
}
else
{
try {
event.getSelfUser().getManager().setAvatar(Icon.from(s)).queue(
v -> event.reply(event.getClient().getSuccess()+" Successfully changed avatar."),
t -> event.reply(event.getClient().getError()+" Failed to set avatar."));
} catch(IOException e) {
event.reply(event.getClient().getError()+" Could not load from provided URL.");
}
}
}
示例3: changeBotAvatar
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
public static void changeBotAvatar(File image) {
try {
Bot.getInstance().getBots().get(0).getSelfUser().getManager().setAvatar(Icon.from(image)).queue();
} catch (Exception e) {
LoggerFactory.getLogger(State.class).error("Error changing avatar");
}
}
示例4: doCommand
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
@Override
protected void doCommand(CommandEvent event) {
String url;
if (event.getArgs().isEmpty())
if (!event.getMessage().getAttachments().isEmpty() && event.getMessage().getAttachments().get(0).isImage())
url = event.getMessage().getAttachments().get(0).getUrl();
else
url = null;
else
url = event.getArgs();
InputStream s = OtherUtil.imageFromUrl(url);
if (s == null) {
respond(event, event.getClient().getError() +
" " + Locale.getCommandsMessage("setavatar.invalid").finish());
} else {
try {
event.getSelfUser().getManager().setAvatar(Icon.from(s)).queue(
v -> respond(event, event.getClient().getSuccess() + " " +
Locale.getCommandsMessage("setavatar.changed").finish()),
t -> respond(event,event.getClient().getError() + " " +
Locale.getCommandsMessage("setavatar.failed").finish()));
} catch (IOException e) {
respond(event, event.getClient().getError() + " " +
Locale.getCommandsMessage("setavatar.couldNotLoad").finish());
}
}
}
示例5: execute
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
@Override
protected void execute(CommandEvent event) {
final List<Emote> currentEmotes = event.getGuild().getEmotes();
final Set<String> emoteNamesToInstall = new HashSet<>(Arrays.asList("mystic", "valor", "instinct"));
boolean emotesAlreadyInstalled = false;
for (Emote emote : currentEmotes) {
final String emoteToInstall = emote.getName().toLowerCase();
if (emoteNamesToInstall.contains(emoteToInstall)) {
event.reply(localeService.getMessageFor(LocaleService.EMOTE_INSTALLED_ALREADY,
localeService.getLocaleForUser(event.getAuthor()), emoteToInstall));
emotesAlreadyInstalled = true;
}
}
if (emotesAlreadyInstalled) {
return;
}
final InputStream mysticPngResource =
InstallEmotesCommand.class.getResourceAsStream("/static/img/mystic.png");
final InputStream valorPngResource =
InstallEmotesCommand.class.getResourceAsStream("/static/img/valor.png");
final InputStream instinctPngResource =
InstallEmotesCommand.class.getResourceAsStream("/static/img/instinct.png");
try {
event.reply("Installing icons for Pokemon go teams...");
createEmote("mystic", event, Icon.from(mysticPngResource));
createEmote("valor", event, Icon.from(valorPngResource));
createEmote("instinct", event, Icon.from(instinctPngResource));
event.reply("Emotes installed. Try them out: :mystic: :valor: :instinct:");
} catch (Throwable t) {
event.reply(t.getMessage());
}
}
示例6: createEmote
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
private void createEmote(String iconName, CommandEvent commandEvent, Icon icon, Role... roles) {
JSONObject body = new JSONObject();
body.put("name", iconName);
body.put("image", icon.getEncoding());
if (roles.length > 0) // making sure none of the provided roles are null before mapping them to the snowflake id
{
body.put("roles",
Stream.of(roles).filter(Objects::nonNull).map(ISnowflake::getId).collect(Collectors.toSet()));
}
// todo: check bot permissions, must be able to handle emojis
GuildImpl guild = (GuildImpl) commandEvent.getGuild();
JDA jda = commandEvent.getJDA();
Route.CompiledRoute route = Route.Emotes.CREATE_EMOTE.compile(guild.getId());
AuditableRestAction<Emote> action = new AuditableRestAction<Emote>(jda, route, body)
{
@Override
protected void handleResponse(Response response, Request<Emote> request)
{
if (response.isOk()) {
JSONObject obj = response.getObject();
final long id = obj.getLong("id");
String name = obj.getString("name");
EmoteImpl emote = new EmoteImpl(id, guild).setName(name);
// managed is false by default, should always be false for emotes created by client accounts.
JSONArray rolesArr = obj.getJSONArray("roles");
Set<Role> roleSet = emote.getRoleSet();
for (int i = 0; i < rolesArr.length(); i++)
{
roleSet.add(guild.getRoleById(rolesArr.getString(i)));
}
// put emote into cache
guild.getEmoteMap().put(id, emote);
request.onSuccess(emote);
}
else {
request.onFailure(response);
throw new RuntimeException("Couldn't install emojis. " +
"Make sure that pokeraidbot has access to manage emojis.");
}
}
};
action.queue();
}
示例7: onCommand
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
// set <> <>
if (args.length == 3) {
// set avatar <>
if (args[1].equalsIgnoreCase("avatar")) {
try (InputStream is = new URL(args[2]).openStream()) {
e.getJDA().getSelfUser().getManager().setAvatar(Icon.from(is));
SendMessage.sendMessage(e, "Successfully set avatar.");
} catch (IOException ex) {
SendMessage.sendMessage(e, "Error: Failed to set avatar. " + ex.getMessage());
}
}
else if (args[1].equalsIgnoreCase("nickname")) {
Guild guild = e.getGuild();
guild.getManager().setName(args[2]);
SendMessage.sendMessage(e, "Successfully set nickname.");
}
}
// !set <> <> <>
else if (args.length >= 4) {
// !set config <> <>
if (args[1].equalsIgnoreCase("config")) {
Config config = ConfigManager.getInstance().getConfig();
// !set config name <newName>
if (args[2].equalsIgnoreCase("name") || args[2].equalsIgnoreCase("username")) {
String newName = remainingArgs(args, 3);
config.setBotName(newName);
e.getJDA().getSelfUser().getManager().setName(newName);
}
// !set config game <newGame>
else if (args[2].equalsIgnoreCase("game")) {
String newGame = remainingArgs(args, 3);
config.setBotGame(newGame);
e.getJDA().getPresence().setGame(Game.of(newGame));
}
ConfigManager.getInstance().saveConfig();
}
else if (args[1].equalsIgnoreCase("setting") || args[1].equalsIgnoreCase("settings")) {
if (args[2].equalsIgnoreCase("prefix")) {
// Prefix requires 5 arguments
if (args.length != 5) {
SendMessage.sendMessage(e, "Error: Incorrect usage.");
return;
}
Settings settings;
if (args[3].equalsIgnoreCase("null") || args[3].equalsIgnoreCase("-")) {
settings = SettingsManager.getInstance(null).getSettings();
}
else if (NumberUtils.isDigits(args[3])) {
if (e.getJDA().getGuildById(args[3]) != null) {
settings = SettingsManager.getInstance(args[3]).getSettings();
}
else {
SendMessage.sendMessage(e, "Error: Could not find guild with ID " + args[3] + ".");
return;
}
}
else {
SendMessage.sendMessage(e, "Error: Unknown argument " + args[3]);
return;
}
settings.setPrefix(args[4]);
SendMessage.sendMessage(e, "Set prefix for " + (args[3] == null ? "global" : args[3]) + " to \"" + args[4] + "\".");
}
}
}
}
示例8: setupFields
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
protected void setupFields()
{
name = new AccountField<String>(this, selfUser::getName)
{
@Override
public void checkValue(String value)
{
Checks.notNull(value, "account name");
if (value.length() < 2 || value.length() > 32)
throw new IllegalArgumentException("Provided name must be 2 to 32 characters in length");
}
};
avatar = new AccountField<Icon>(this, null)
{
@Override
public void checkValue(Icon value) { }
@Override
public Icon getOriginalValue()
{
throw new UnsupportedOperationException("Cannot easily provide the original Avatar. Use User#getIconUrl() and download it yourself.");
}
@Override
public boolean shouldUpdate()
{
return isSet();
}
};
if (isType(AccountType.CLIENT))
{
email = new AccountField<String>(this, selfUser::getEmail)
{
@Override
public void checkValue(String value)
{
Checks.notNull(value, "account email");
if (!EMAIL_PATTERN.matcher(value).find())
throw new IllegalArgumentException("Provided email is in invalid format. Provided value: " + value);
}
};
password = new AccountField<String>(this, null)
{
@Override
public void checkValue(String value)
{
Checks.notNull(value, "account password");
if (value.length() < 6 || value.length() > 128)
throw new IllegalArgumentException("Provided password must ben 6 to 128 characters in length");
}
@Override
public String getOriginalValue()
{
throw new UnsupportedOperationException("Cannot get the original password. We are not given this information.");
}
@Override
public boolean shouldUpdate()
{
return isSet();
}
};
}
}
示例9: getIconField
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* An {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField}
* for the {@link net.dv8tion.jda.core.entities.Icon Icon} of the selected {@link net.dv8tion.jda.core.entities.Guild Guild}.
* <br>To reset the Icon of a Guild provide {@code null} to {@link net.dv8tion.jda.core.managers.fields.Field#setValue(Object) setValue(Icon)}.
*
* <p>To set the value use {@link net.dv8tion.jda.core.managers.fields.Field#setValue(Object) setValue(Icon)}
* on the returned {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField} instance.
*
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the Guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField} - Type: {@link net.dv8tion.jda.core.entities.Icon Icon}
*/
public GuildField<Icon> getIconField()
{
checkAvailable();
return icon;
}
示例10: getSplashField
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* An {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField}
* for the <b><u>splash {@link net.dv8tion.jda.core.entities.Icon Icon}</u></b> of the selected {@link net.dv8tion.jda.core.entities.Guild Guild}.
* <br>To reset the splash of a Guild provide {@code null} to {@link net.dv8tion.jda.core.managers.fields.Field#setValue(Object) setValue(Icon)}.
*
* <p>To set the value use {@link net.dv8tion.jda.core.managers.fields.Field#setValue(Object) setValue(Icon)}
* on the returned {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField} instance.
*
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the Guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.managers.fields.GuildField GuildField} - Type: {@link net.dv8tion.jda.core.entities.Icon Icon}
*/
public GuildField<Icon> getSplashField()
{
checkAvailable();
return splash;
}
示例11: setIcon
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* Sets the {@link net.dv8tion.jda.core.entities.Icon Icon}
* for the resulting {@link net.dv8tion.jda.core.entities.Guild Guild}
*
* @param icon
* The {@link net.dv8tion.jda.core.entities.Icon Icon} to use
*
* @return The current GuildAction for chaining convenience
*/
@CheckReturnValue
public GuildAction setIcon(Icon icon)
{
this.icon = icon;
return this;
}
示例12: setAvatar
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* Sets the <b>Avatar</b> for the custom Webhook User
*
* @param icon
* An {@link net.dv8tion.jda.core.entities.Icon Icon} for the new avatar.
* Or null to use default avatar.
*
* @return The current WebhookAction for chaining convenience.
*/
@CheckReturnValue
public WebhookAction setAvatar(Icon icon)
{
this.avatar = icon;
return this;
}
示例13: setIcon
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* Sets the <b><u>icon</u></b> of the selected {@link net.dv8tion.jda.client.entities.Application Application}.
* <br>Wraps {@link net.dv8tion.jda.client.managers.ApplicationManagerUpdatable#getIconField() ApplicationManagerUpdatable#getIconField()}.
*
* @param icon
* The new {@link net.dv8tion.jda.core.entities.Icon Icon}
* for the selected {@link net.dv8tion.jda.client.entities.Application Application}
*
* @return {@link net.dv8tion.jda.core.requests.RestAction}
* <br>Update RestAction from {@link ApplicationManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.client.managers.ApplicationManagerUpdatable#getIconField()
* @see net.dv8tion.jda.client.managers.ApplicationManagerUpdatable#update()
*/
@CheckReturnValue
public RestAction<Void> setIcon(final Icon icon)
{
return this.updatable.getIconField().setValue(icon).update();
}
示例14: getIconField
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* An {@link net.dv8tion.jda.client.managers.fields.ApplicationField ApplicationField}
* for the {@link net.dv8tion.jda.core.entities.Icon Icon} of the selected
* {@link net.dv8tion.jda.client.entities.Application Application}.
*
* <p>To set the value use {@link net.dv8tion.jda.core.managers.fields.Field#setValue(Object) setValue(Icon)}
* on the returned {@link net.dv8tion.jda.client.managers.fields.ApplicationField ApplicationField} instance.
*
* @return {@link net.dv8tion.jda.client.managers.fields.ApplicationField ApplicationField}
* - Type: {@link net.dv8tion.jda.core.entities.Icon Icon}
*/
public final ApplicationField<Icon> getIconField()
{
return this.icon;
}
示例15: setIcon
import net.dv8tion.jda.core.entities.Icon; //导入依赖的package包/类
/**
* Sets the {@link net.dv8tion.jda.core.entities.Icon Icon} of the selected {@link net.dv8tion.jda.client.entities.Application Application}.
*
* @param icon
* The {@link net.dv8tion.jda.core.entities.Icon Icon} for new {@link net.dv8tion.jda.client.entities.Application Application}
*
* @return The current ApplicationAction for chaining
*/
public ApplicationAction setIcon(final Icon icon)
{
this.icon = icon;
return this;
}