本文整理汇总了Java中com.jagrosh.jdautilities.commandclient.CommandEvent.getAuthor方法的典型用法代码示例。如果您正苦于以下问题:Java CommandEvent.getAuthor方法的具体用法?Java CommandEvent.getAuthor怎么用?Java CommandEvent.getAuthor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jagrosh.jdautilities.commandclient.CommandEvent
的用法示例。
在下文中一共展示了CommandEvent.getAuthor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String userName = user.getName();
final Locale localeForUser = localeService.getLocaleForUser(user);
String gymName = commandEvent.getArgs();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
final SignUp removed = raid.remove(user, raidRepository);
if (removed != null) {
commandEvent.reactSuccess();
removeOriginMessageIfConfigSaysSo(config, commandEvent);
} else {
final String message =
localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, userName, gym.getName());
replyErrorBasedOnConfig(config, commandEvent, new UserMessedUpException(user, message));
}
}
示例2: execute
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
protected void execute(CommandEvent event)
{
User user = event.getAuthor();
AfkManager.setAfk(user.getIdLong(), event.getArgs().isEmpty()?null:event.getArgs());
event.replySuccess("**"+user.getName()+"** is now AFK!");
}
示例3: doCommand
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void doCommand(CommandEvent event)
{
if(event.getChannelType() != ChannelType.PRIVATE)
return;
User user = event.getAuthor();
List<Guild> mutualGuilds = user.getMutualGuilds();
for(Guild guild : mutualGuilds)
{
Member member = guild.getMember(user);
if(member != null && member.getRoles().isEmpty())
{
GuildController gc = guild.getController();
gc.addSingleRoleToMember(member, MDCBot.newMemberRole).queue();
Util.info(getClass(), "New member %s given the role %s in guild %s", member.getEffectiveName(), MDCBot.newMemberRole.getName(), guild.getName());
}
}
}
示例4: execute
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void execute(CommandEvent event) {
final User user;
if(event.getArgs().isEmpty())
user = event.getAuthor();
else {
List<Member> members = FinderUtil.findMembers(event.getArgs(), event.getGuild());
if(members.size() < 1) {
event.replyError("Could not find a user matching \"" + event.getArgs() + "\"!");
return;
}
if(members.size() > 1) {
event.replyError(FormatUtils.tooManyMembers(event.getArgs(), members));
return;
}
user = members.get(0).getUser();
}
short rating = database.getUserRating(user);
if(event.getAuthor().equals(user))
event.replySuccess("Your rank is `" + rating + "`!");
else
event.replySuccess("**" + user.getName() + "**#" + user.getDiscriminator() + "'s rank is `" + rating + "`!");
}
示例5: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String[] args = commandEvent.getArgs().replaceAll("\\s{1,3}", " ").split(" ");
if (args.length < 3) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX,
localeService.getLocaleForUser(user), "!raid start ho-oh 10:00 solna platform"));
}
String pokemonName = args[0];
final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
String timeString = args[1];
LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService)
.plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
LocalDateTime endsAt = LocalDateTime.of(LocalDate.now(), endsAtTime);
assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
assertTimeNotMoreThanXHoursFromNow(user, endsAtTime, localeService, 2);
assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = new Raid(pokemon, endsAt, gym, localeService, config.getRegion());
raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid start " +
raid.getPokemon().getName() + " " + getStartOfRaid(raid.getEndOfRaid(), raid.isExRaid()) + " " +
raid.getGym().getName());
final Locale locale = localeService.getLocaleForUser(user);
final String message = localeService.getMessageFor(LocaleService.NEW_RAID_CREATED,
locale, raid.toString(locale));
replyBasedOnConfigAndRemoveAfter(config, commandEvent, message, BotServerMain.timeToRemoveFeedbackInSeconds);
}
示例6: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String userName = user.getName();
final String[] args = commandEvent.getArgs().split(" ");
String whatToChange = args[0].trim().toLowerCase();
switch (whatToChange) {
case "when":
changeWhen(commandEvent, config, user, args);
break;
case "pokemon":
if (args.length < 2) {
throw new UserMessedUpException(userName,
localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user),
"!raid change {when/pokemon/remove/group} {params}"));
}
changePokemon(this, gymRepository, localeService, pokemonRepository, raidRepository,
commandEvent, config, user, userName, args[1].trim().toLowerCase(),
ArrayUtils.removeAll(args, 0, 1));
break;
case "remove":
deleteRaid(commandEvent, config, user, userName, args);
break;
case "group":
changeOrDeleteGroup(commandEvent, config, user, userName, args);
break;
default:
throw new UserMessedUpException(userName,
localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user),
"!raid change {when/pokemon/remove/group} {params}"));
}
}
示例7: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String userName = user.getName();
final String[] args = commandEvent.getArgs().split(" ");
if (args.length < 2) {
throw new UserMessedUpException(userName,
localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user),
"!raid hatch Ho-Oh solna platform"));
}
String pokemonName = args[0].trim().toLowerCase();
final String[] gymArguments = ArrayUtils.removeAll(args, 0);
String gymName = StringUtils.join(gymArguments, " ");
final String region = config.getRegion();
final Gym gym = gymRepository.search(user, gymName, region);
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
final PokemonRaidInfo existingRaidInfo = raidStrategyService.getRaidInfo(raid.getPokemon());
final int newBossTier = raidStrategyService.getRaidInfo(pokemon).getBossTier();
if (!raid.getPokemon().isEgg()) {
throw new UserMessedUpException(user,
localeService.getMessageFor(LocaleService.EGG_ALREADY_HATCHED,
localeService.getLocaleForUser(user), raid.getPokemon().toString()));
}
if (pokemon.isEgg() || newBossTier != existingRaidInfo.getBossTier()) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_WRONG_TIER,
localeService.getLocaleForUser(user)));
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Trying to hatch raid " + raid + " into " + pokemonName);
}
AlterRaidCommand.changePokemon(this, gymRepository, localeService, pokemonRepository, raidRepository,
commandEvent, config, user, userName, pokemonName,
gymArguments);
}
示例8: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
String args = commandEvent.getArgs();
Pokemon pokemon = pokemonRepository.search(args, commandEvent.getAuthor());
final User user = commandEvent.getAuthor();
trackingService.add(pokemon, user, config);
commandEvent.reactSuccess();
removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
示例9: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String[] args = commandEvent.getArgs().replaceAll("\\s{1,3}", " ").split(" ");
if (args.length < 3) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX,
localeService.getLocaleForUser(user), "!raid new ho-oh 10:00 solna platform"));
}
String pokemonName = args[0];
final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
String timeString = args[1];
LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService);
LocalDateTime endsAt = LocalDateTime.of(LocalDate.now(), endsAtTime);
assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
assertTimeNotMoreThanXHoursFromNow(user, endsAtTime, localeService, 2);
assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = new Raid(pokemon, endsAt, gym, localeService, config.getRegion());
raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid new " +
raid.getPokemon().getName() + " " + printTimeIfSameDay(raid.getEndOfRaid()) + " " +
raid.getGym().getName());
final Locale locale = localeService.getLocaleForUser(user);
replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.NEW_RAID_CREATED,
locale, raid.toString(locale)), BotServerMain.timeToRemoveFeedbackInSeconds);
}
示例10: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
String args = commandEvent.getArgs();
final String userId = commandEvent.getAuthor().getId();
final User user = commandEvent.getAuthor();
if (args == null || args.length() < 1) {
trackingService.removeAllForUser(user);
commandEvent.reactSuccess();
} else {
Pokemon pokemon = pokemonRepository.search(args, user);
trackingService.removeForUser(new PokemonTrackingTarget(userId, pokemon), user);
commandEvent.reactSuccess();
}
removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
示例11: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final Locale localeForUser = localeService.getLocaleForUser(user);
final String[] args = Utils.prepareArguments(commandEvent);
if (args.length < 3) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX,
localeService.getLocaleForUser(user), "!raid add 1 10:00 solna platform " +
"(alt. *+1 10:00 solna platform*)"));
}
final String returnMessage = raidRepository.executeSignUpCommand(config, user, localeForUser, args, help);
replyBasedOnConfigAndRemoveAfter(config, commandEvent, returnMessage,
BotServerMain.timeToRemoveFeedbackInSeconds);
}
示例12: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String[] args = commandEvent.getArgs().split(" ");
final Locale locale = localeService.getLocaleForUser(user);
if (args.length < 2) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX,
localeService.getLocaleForUser(user), "!raid group 10:00 solna platform"));
}
String timeString = args[0];
LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 1; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
createRaidGroup(commandEvent.getChannel(), commandEvent.getGuild(),
config, user, locale, startAtTime, raid.getId(),
localeService, raidRepository, botService, serverConfigRepository, pokemonRepository, gymRepository,
clockService, executorService, pokemonRaidStrategyService);
commandEvent.reactSuccess();
removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
示例13: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
String gymName = commandEvent.getArgs();
final User user = commandEvent.getAuthor();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
final Set<SignUp> signUps = raid.getSignUps();
final int numberOfPeople = raid.getNumberOfPeopleSignedUp();
final Locale localeForUser = localeService.getLocaleForUser(user);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(null, null, null);
final Pokemon pokemon = raid.getPokemon();
embedBuilder.setTitle(localeService.getMessageFor(LocaleService.RAIDSTATUS, localeForUser, gym.getName()),
Utils.getNonStaticMapUrl(gym));
StringBuilder sb = new StringBuilder();
final String activeText = localeService.getMessageFor(LocaleService.ACTIVE, localeForUser);
final String startGroupText = localeService.getMessageFor(LocaleService.START_GROUP, localeForUser);
final String findYourWayText = localeService.getMessageFor(LocaleService.FIND_YOUR_WAY, localeForUser);
final String raidBossText = localeService.getMessageFor(LocaleService.RAID_BOSS, localeForUser);
final Set<String> signUpNames = getNamesOfThoseWithSignUps(raid.getSignUps(), true);
final String allSignUpNames = StringUtils.join(signUpNames, ", ");
sb.append(raidBossText).append(" **").append(pokemon).append("** - ")
.append("*!raid vs ").append(pokemon.getName()).append("*\n");
sb.append("**").append(activeText).append(":** ")
.append(printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), false)))
.append("-").append(printTimeIfSameDay(raid.getEndOfRaid()))
.append("\t**").append(numberOfPeople).append(" ")
.append(localeService.getMessageFor(LocaleService.SIGNED_UP, localeForUser)).append("**")
.append(signUps.size() > 0 ? ":\n" + allSignUpNames : "").append("\n").append(startGroupText)
.append(":\n*!raid group ")
.append(printTime(raid.getEndOfRaid().toLocalTime().minusMinutes(15))).append(" ")
.append(gymName).append("*\n\n");
sb.append(localeService.getMessageFor(LocaleService.CREATED_BY, localeForUser)).append(": ")
.append(raid.getCreator());
embedBuilder.setFooter(findYourWayText + localeService.getMessageFor(LocaleService.GOOGLE_MAPS,
localeService.getLocaleForUser(user)),
Utils.getPokemonIcon(pokemon));
embedBuilder.setDescription(sb.toString());
final MessageEmbed messageEmbed = embedBuilder.build();
replyBasedOnConfig(config, commandEvent, messageEmbed);
}
示例14: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final Locale locale = config.getLocale();
if (!isUserAdministrator(commandEvent) && !isUserServerMod(commandEvent, config)) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_PERMISSION,
localeService.getLocaleForUser(user)));
}
String msgId = config.getOverviewMessageId();
final String server = config.getServer();
if (!StringUtils.isEmpty(msgId)) {
final String args = commandEvent.getArgs();
if (!StringUtils.isEmpty(args) && args.equalsIgnoreCase("reset")) {
try {
commandEvent.getChannel().getMessageById(msgId).complete().delete().queue();
} catch (Throwable t) {
// Ignore, just means the message couldn't be cleared/deleted and have to be manually purged
LOGGER.debug("We couldn't find and delete overview for server " + server + ": " + t.getMessage());
}
serverConfigRepository.setOverviewMessageIdForServer(server, null);
LOGGER.info("Cleared overview message for server " + server + ".");
replyBasedOnConfig(config, commandEvent,
localeService.getMessageFor(LocaleService.OVERVIEW_CLEARED, locale));
} else {
LOGGER.info("Server overview message ID not empty. Overview already exists for this server.");
replyBasedOnConfig(config, commandEvent,
localeService.getMessageFor(LocaleService.OVERVIEW_EXISTS, locale));
}
} else {
final String messageString = getOverviewMessage(config,
localeService, raidRepository, clockService, locale);
commandEvent.getChannel().sendMessage(messageString).queue(msg -> {
final String messageId = msg.getId();
serverConfigRepository.setOverviewMessageIdForServer(server, messageId);
final Callable<Boolean> refreshEditThreadTask =
getMessageRefreshingTaskToSchedule(user, server, messageId,
localeService, locale, serverConfigRepository, raidRepository, clockService,
commandEvent.getChannel(), executorService);
executorService.submit(refreshEditThreadTask);
});
}
}
示例15: executeWithConfig
import com.jagrosh.jdautilities.commandclient.CommandEvent; //导入方法依赖的package包/类
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config serverConfig) {
final User user = commandEvent.getAuthor();
UserConfig userConfig = userConfigRepository.findOne(user.getId());
final String[] arguments = commandEvent.getArgs().split(" ");
if (arguments.length > 1 || arguments.length < 1) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_SYNTAX,
localeService.getLocaleForUser(user))
);
}
if ("show".equalsIgnoreCase(arguments[0])) {
if (userConfig == null) {
userConfig = userConfigRepository.save(new UserConfig(user.getId(), null,
null, null, serverConfig.getLocale()));
}
replyBasedOnConfig(serverConfig, commandEvent, String.valueOf(userConfig));
}
else {
final String[] paramAndValue = arguments[0].split("=");
if (paramAndValue.length > 2 || paramAndValue.length < 2) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_SYNTAX,
localeService.getLocaleForUser(user))
);
}
String param = paramAndValue[0];
String value = paramAndValue[1];
switch (param.toLowerCase()) {
case "locale":
final Locale newLocale = setLocaleForUser(user, userConfig, value);
replyBasedOnConfigAndRemoveAfter(serverConfig, commandEvent,
localeService.getMessageFor(LocaleService.LOCALE_SET,
localeService.getLocaleForUser(user), newLocale.getLanguage()),
BotServerMain.timeToRemoveFeedbackInSeconds);
break;
case "nick":
userConfig = setNickForUser(serverConfig, user, userConfig, value);
replyBasedOnConfig(serverConfig, commandEvent, String.valueOf(userConfig));
break;
default:
throw new UserMessedUpException(user,
localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_PARAM,
localeService.getLocaleForUser(user), param)
);
}
}
}