本文整理汇总了Java中net.dv8tion.jda.core.events.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于net.dv8tion.jda.core.events包,在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Listener
@Override
public void onEvent(Event event) {
if (event instanceof ShardMonitorEvent) {
((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.MANTARO_LISTENER);
return;
}
if (event instanceof GuildJoinEvent) {
Async.thread("LogThread", () -> onJoin((GuildJoinEvent) event));
return;
}
if (event instanceof GuildLeaveEvent) {
Async.thread("LogThread", () -> onLeave((GuildLeaveEvent) event));
}
if (event instanceof StatusChangeEvent) {
ThreadPoolHelper.defaultPool().startThread("LogThread", () -> logStatusChange((StatusChangeEvent) event));
}
}
示例2: handle
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void handle(Message message, Event event, String[] args) throws Throwable {
Language l = kyoko.getI18n().getLanguage(message.getGuild());
EmbedBuilder builder = kyoko.getAbstractEmbedBuilder().getNormalBuilder()
.setAuthor(kyoko.getI18n().get(l, "stats.title"), Constants.SITE_URL, kyoko.getJda().getSelfUser().getAvatarUrl())
.addField(kyoko.getI18n().get(l, "stats.field.library"), "JDA " + JDAInfo.VERSION, true)
.addField(kyoko.getI18n().get(l, "stats.field.shard"), kyoko.getShardInfo(), true)
.addField(kyoko.getI18n().get(l, "stats.field.version"), Constants.VERSION, true)
.addField(kyoko.getI18n().get(l, "stats.field.uptime"), StringUtil.prettyPeriod(rb.getUptime()), true)
.addField(kyoko.getI18n().get(l, "stats.field.users"), Integer.toString(kyoko.getJda().getUsers().size()), true)
.addField(kyoko.getI18n().get(l, "stats.field.servers"), Integer.toString(kyoko.getJda().getGuilds().size()), true)
.addField(kyoko.getI18n().get(l, "stats.field.textchans"), Integer.toString(kyoko.getJda().getTextChannels().size()), true)
.addField(kyoko.getI18n().get(l, "stats.field.voicechans"), Integer.toString(kyoko.getJda().getVoiceChannels().size()), true)
.addField(kyoko.getI18n().get(l, "stats.field.cmdsran"), Long.toString(kyoko.getCommandManager().getCommandRunCount()), true)
.addField(kyoko.getI18n().get(l, "stats.field.github"), Constants.GITHUB_URL_MD, true)
.addField(kyoko.getI18n().get(l, "stats.field.website"), Constants.SITE_URL_MD, true)
.addField(kyoko.getI18n().get(l, "stats.field.donate"), "*soon*", true)
.addField(kyoko.getI18n().get(l, "stats.field.authors"), kyoko.getI18n().get(l, "stats.authors"), true);
message.getChannel().sendMessage(builder.build()).queue();
}
示例3: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Listener
@Override
public void onEvent(Event event) {
if (event instanceof ShardMonitorEvent) {
((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.COMMAND_LISTENER);
return;
}
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent e = (GuildMessageReceivedEvent) event;
Async.thread("CmdThread", () -> onCommand(e));
// if (random.nextInt(150) > 100) {
// if (((GuildMessageReceivedEvent) event).getMember() == null) return;
// Player player = MantaroData.db().getPlayer(((GuildMessageReceivedEvent) event).getMember());
// if (player != null) {
//
// player.getData().setExperience(player.getData().getExperience() + Math.round(random.nextInt(6)));
// if (player.getData().getExperience() > (player.getLevel() * Math.log10(player.getLevel()) * 1000)) {
// player.setLevel(player.getLevel() + 1);
// }
// player.saveAsync();
// }
// }
}
}
示例4: execute
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void execute(String[] args, Event event, TaverneBot bot) {
MessageReceivedEvent mre = (MessageReceivedEvent) event;
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(new Color(192, 57, 43));
builder.setFooter("TaverneBot", null);
if(args.length>=2) {
User u = mre.getMessage().getMentionedUsers().get(0);
if(u.isBot()) return;
builder.setAuthor(u.getName(), null, u.getAvatarUrl()+"?size=256");
builder.addField("Classement", String.valueOf(bot.getScoreboard().getRank(u)), true);
builder.addField("Niveaux", String.valueOf(bot.getLevelManager().getLevel(u)), true);
builder.addField("Exp�riences", String.valueOf(bot.getLevelManager().getXP(u)), true);
} else {
builder.setAuthor(mre.getAuthor().getName(), null, mre.getAuthor().getAvatarUrl()+"?size=256");
builder.addField("Classement", String.valueOf(bot.getScoreboard().getRank(mre.getAuthor())), true);
builder.addField("Niveaux", String.valueOf(bot.getLevelManager().getLevel(mre.getAuthor())), true);
builder.addField("Exp�riences", String.valueOf(bot.getLevelManager().getXP(mre.getAuthor())), true);
}
((MessageReceivedEvent) event).getTextChannel().sendMessage(builder.build()).queue();
}
示例5: addXP
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
public void addXP(Event event, User u, int xp) {
FileProperties userFile = new FileProperties(u);
if(!userFile.exist()) {
createUserFile(u);
}
int lvlLast = getLevel(u);
userFile.load();
userFile.setProperties("xp", userFile.getInt("xp")+xp);
userFile.save();
int lvlAfter = getLevel(u);
verifyLevel((MessageReceivedEvent) event, u, lvlLast, lvlAfter);
}
示例6: getGuild
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public Guild getGuild(Event event) {
if (event == null) {
return null;
}
Class<? extends Event> clazz = event.getClass();
Method method;
if (!guildAccessors.containsKey(clazz)) {
method = ReflectionUtils.findMethod(clazz, "getGuild");
guildAccessors.put(clazz, method);
} else {
method = guildAccessors.get(clazz);
}
if (method != null) {
Object result = ReflectionUtils.invokeMethod(method, event);
if (result instanceof Guild) {
return (Guild) result;
}
}
return null;
}
示例7: getAuthor
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
private Object getAuthor(Event event) {
if (event == null) {
return null;
}
Class<? extends Event> clazz = event.getClass();
Method method;
if (!userAccessors.containsKey(clazz)) {
method = ReflectionUtils.findMethod(clazz, "getUser");
if (method == null) {
method = ReflectionUtils.findMethod(clazz, "getAuthor");
}
userAccessors.put(clazz, method);
} else {
method = userAccessors.get(clazz);
}
if (method != null) {
Object result = ReflectionUtils.invokeMethod(method, event);
if (result instanceof User) {
return result;
}
}
return null;
}
示例8: handle
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void handle(Message message, Event event, String[] args) throws Throwable {
if (categories == null) {
initCategories();
}
EmbedBuilder normal = kyoko.getAbstractEmbedBuilder().getNormalBuilder();
Language l = kyoko.getI18n().getLanguage(message.getGuild());
normal.addField(kyoko.getI18n().get(l, "help.header.title"), String.format(kyoko.getI18n().get(l, "help.header.desc"), Constants.WIKI_URL), false);
for (String s : cached.keySet()) {
normal.addField(kyoko.getI18n().get(l, s), cached.get(s), false);
}
message.getChannel().sendMessage(normal.build()).queue();
}
示例9: handle
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void handle(Message message, Event event, String[] args) throws Throwable {
Language l = kyoko.getI18n().getLanguage(message.getGuild());
StringBuilder builder = new StringBuilder();
if (args.length == 1) {
printUsage(kyoko, l, message.getTextChannel());
return;
}
for (int i = 1; i < args.length; i++) {
args[i] = args[i].replace("✔️", "✔").replace("✅", "✔").replace("☑️", "✔");
for (char c : args[i].toLowerCase().toCharArray()) {
builder.append(toRegionalIndicator(c)).append(" ");
}
builder.append(" ");
}
message.getTextChannel().sendMessage(builder.toString()).queue();
}
示例10: handle
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void handle(Message message, Event event, String[] args) throws Throwable {
if (args.length == 1) {
printUsage(kyoko, kyoko.getI18n().getLanguage(message.getGuild()), message.getTextChannel());
return;
}
String msg = message.getRawContent();
String mention = kyoko.getJda().getSelfUser().getAsMention();
if (msg.startsWith(mention)) {
msg = msg.substring(mention.length()).trim().substring(args[0].length());
} else {
msg = msg.substring(kyoko.getSettings().getPrefix().length() + args[0].length());
}
if (msg.trim().isEmpty()) {
printUsage(kyoko, kyoko.getI18n().getLanguage(message.getGuild()), message.getTextChannel());
return;
}
message.getTextChannel().sendMessage(msg).queue();
}
示例11: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void onEvent(Event e) {
if(!(e instanceof GuildMessageReceivedEvent)) return;
GuildMessageReceivedEvent event = (GuildMessageReceivedEvent)e;
if(event.getAuthor().equals(event.getJDA().getSelfUser())) return;
long channelId = event.getChannel().getIdLong();
RunningOperation o = OPERATIONS.get(channelId);
if(o == null) return;
int i = o.operation.run(event);
if(i == Operation.COMPLETED) {
OPERATIONS.remove(channelId);
o.future.complete(null);
} else if(i == Operation.RESET_TIMEOUT) {
OPERATIONS.resetExpiration(channelId);
}
}
示例12: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void onEvent(Event event) {
if (event instanceof GuildMessageReceivedEvent) {
final GuildMessageReceivedEvent guildMessageReceivedEvent = (GuildMessageReceivedEvent) event;
if (guildMessageReceivedEvent.getAuthor().isBot()) {
return;
}
final String rawContent = guildMessageReceivedEvent.getMessage().getRawContent();
if (rawContent.matches(minusXRegExp)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("It would seem this is a - command to remove signups: " + rawContent);
}
String strippedContent = rawContent.replaceAll("\\s{2,4}", " ")
.replaceFirst("[-]", "");
String[] splitArguments = strippedContent.split("\\s{1}");
attemptUnsignFromMinusCommand(guildMessageReceivedEvent, splitArguments);
}
}
}
示例13: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void onEvent(Event event) {
if (event instanceof GuildMessageReceivedEvent) {
final GuildMessageReceivedEvent guildMessageReceivedEvent = (GuildMessageReceivedEvent) event;
if (guildMessageReceivedEvent.getAuthor().isBot()) {
return;
}
final String rawContent = guildMessageReceivedEvent.getMessage().getRawContent();
if (rawContent.matches(plusXRegExp)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("It would seem this is a + command to add signups: " + rawContent);
}
String strippedContent = rawContent.replaceAll("\\s{2,4}", " ")
.replaceAll("[+]", "");
String[] splitArguments = strippedContent.split("\\s{1}");
attemptSignUpFromPlusCommand(guildMessageReceivedEvent, splitArguments);
}
}
}
示例14: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
@SubscribeEvent
public final void onEvent(Event event)
{
Class c = event.getClass();
while(c.getSuperclass()!=null) {
if(waitingEvents.containsKey(c))
{
List<WaitingEvent> list = waitingEvents.get(c);
List<WaitingEvent> ulist = new ArrayList<>(list);
list.removeAll(ulist.stream().filter(i -> i.attempt(event)).collect(Collectors.toList()));
}
if(event instanceof ShutdownEvent)
{
threadpool.shutdown();
}
c = c.getSuperclass();
}
}
示例15: onEvent
import net.dv8tion.jda.core.events.Event; //导入依赖的package包/类
@Override
public void onEvent(Event eevent) {
if (eevent instanceof MessageReceivedEvent) {
MessageReceivedEvent event = (MessageReceivedEvent) eevent;
if(event.getMessage().getMentionedUsers().isEmpty()) return;
if (event.getMessage().getMentionedUsers().get(0).getId().equals(jda.getSelfUser().getId())) {
event.getChannel().sendTyping();
try {
String s = event.getMessage().getContent().replace("@" + jda.getSelfUser().getName() +" ", "");
event.getChannel().sendMessage(botSession.think(s));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}