本文整理汇总了Java中sx.blah.discord.api.events.EventSubscriber类的典型用法代码示例。如果您正苦于以下问题:Java EventSubscriber类的具体用法?Java EventSubscriber怎么用?Java EventSubscriber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventSubscriber类属于sx.blah.discord.api.events包,在下文中一共展示了EventSubscriber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessageReceivedEvent
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@Override
@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event)
{
String messageString = event.getMessage().getContent();
if (this.isCommand(messageString))
{
Message message = new Message(this.trimPrefix(messageString));
if (this.isPluginCommand(message))
{
String output = handleMessage(message);
event.getChannel().sendMessage(output);
}
}
}
示例2: onMessageReceived
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onMessageReceived(final MessageReceivedEvent e) {
final String msg = e.getMessage().getContent();
if (msg.startsWith("!eew")) {
final String[] args = msg.split(" ");
if (args.length<=1)
Command.reply(e, "引数が不足しています");
else {
final Command command = EnumUtils.getEnum(Command.class, args[1]);
if (command!=null)
if (!EEWBot.instance.getConfig().isEnablePermission()||userHasPermission(e.getAuthor().getLongID(), command))
if (args.length-2>=command.getMinArgLength())
command.onCommand(e, ArrayUtils.subarray(args, 2, args.length+1));
else
Command.reply(e, "引数が不足しています");
else
Command.reply(e, "権限がありません!");
else
Command.reply(e, "コマンドが存在しません\nコマンド一覧は`help`コマンドで確認出来ます");
}
}
}
示例3: onEEW
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onEEW(final EEWEvent e) {
final EEW eew = e.getElement();
final EEW prev = e.getPrev();
final Predicate<Channel> isAlert = c -> c.getElement(eew.isAlert() ? "eewAlert" : "eewPrediction").get();
final Predicate<Channel> decimation = c -> {
if (!c.getElement("eewDecimation").get())
return true;
if (prev==null)
return true;
if (eew.isInitial()||eew.isFinal())
return true;
if (eew.isAlert()!=prev.isAlert())
return true;
if (!eew.getIntensity().equals(prev.getIntensity()))
return true;
if (!eew.getRegionName().equals(prev.getRegionName()))
return true;
return false;
};
action(isAlert.and(decimation), c -> c.sendMessage(e.getElement().buildEmbed()));
e.getMonitor().ifPresent(m -> action(c -> c.getElement("monitor").get()&&(eew.isAlert()&&c.getElement("eewAlert").get()||!eew.isAlert()&&c.getElement("eewPrediction").get()), c -> c.sendFile("", new ByteArrayInputStream(m), "kyoshinmonitor.png")));
}
示例4: onGuildCreate
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onGuildCreate(GuildCreateEvent event) {
Console.println("==================NEW SERVER |" + event.getGuild().getName() + "| " + event.getGuild().getStringID());
if (SERVER_CONTROL.checkServerisBanned(event.getGuild())) {
Console.println("Leave Banned Server: "+event.getGuild().getName());
BotUtils.sendPrivMessage(event.getGuild().getOwner().getOrCreatePMChannel(), "Your Server is on the banned Server List. Please contact [email protected] and describe why do you want to get unbanned.", false);
event.getGuild().leave();
} else {
if (running) {
Stats.addServer(event.getGuild());
Console.debug("Adding Permission for new Server");
List<IGuild> server = new ArrayList<>();
server.add(event.getGuild());
PERM.setDefaultPermissions(server, true);
Console.debug("Adding Disabled Server for new Server");
saveGuild(event.getGuild());
DRIVER.saveJson();
}
Console.debug("===================new Server added====");
}
}
示例5: onReadyEvent
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onReadyEvent(ReadyEvent event) {
LogUtils.infof("Shadbot (Version: %s) is ready.", Shadbot.getVersion());
ShardManager.start();
Shadbot.getScheduler().scheduleAtFixedRate(() -> LottoCmd.draw(), LottoCmd.getDelay(), TimeUnit.DAYS.toMillis(7), TimeUnit.MILLISECONDS);
Shadbot.getScheduler().scheduleAtFixedRate(() -> BotUtils.updatePresence(), 0, 30, TimeUnit.MINUTES);
Shadbot.getScheduler().scheduleAtFixedRate(() -> NetUtils.postStats(), 2, 2, TimeUnit.HOURS);
event.getClient().getDispatcher().registerListeners(Shadbot.getEventThreadPool(),
new ChannelListener(),
new GuildListener(),
new GuildMemberListener(),
new MessageListener(),
new UserVoiceChannelListener(),
new VoiceChannelListener());
event.getClient().changePresence(StatusType.ONLINE);
}
示例6: onMessageReceived
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onMessageReceived(MessageReceivedEvent event) {
if (discordService.isOwnUser(event.getMessage().getAuthor())) {
return;
}
IMessage m = event.getMessage();
String content = m.getContent();
Optional<Command> match = commandList.stream().filter(c -> c.matches(content)).findFirst();
if (match.isPresent()) {
Command command = match.get();
CompletableFuture.runAsync(() -> tryExecute(event, command), taskExecutor)
.exceptionally(t -> {
log.warn("Something happened while trying to execute command", t);
return null;
});
}
}
示例7: onUserSpeaking
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onUserSpeaking(VoiceUserSpeakingEvent event) {
if (!event.isSpeaking()) {
SettingsService.ResponseConfig config = settingsService.getSettings()
.getUserToVoiceResponse().get(event.getUser().getID());
if (config != null) {
List<String> responses = config.getResponses();
if (!responses.isEmpty() && RandomUtils.nextInt(0, 100) < config.getChance()) {
String text = (responses.size() == 1 ? responses.get(0) :
responses.get(RandomUtils.nextInt(0, responses.size())));
try {
discordService.sendMessage(config.getChannelId(), text);
} catch (DiscordException | MissingPermissionsException | InterruptedException e) {
log.warn("Could not send voice response", e);
}
}
}
}
}
示例8: onReady
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onReady(ReadyEvent event)
{
List<File> folderList = new ArrayList<File>();
folderList.add(new File(Util.getJarLocation() + "services/"));
folderList.add(new File(Util.getJarLocation() + "services/server-tracking/"));
folderList.add(new File(Util.getJarLocation() + "services/csgo-updates/"));
for (File folder : folderList)
{
if (!folder.isDirectory())
{
folder.mkdir();
}
}
uptime.start();
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(ServerTimer.timer, 0, 60, TimeUnit.SECONDS);
Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(UptimeTimer.timer, 600, 60, TimeUnit.SECONDS);
Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(StatsTimer.timer, 0, 300, TimeUnit.SECONDS);
}
示例9: onReactionAdd
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onReactionAdd(ReactionAddEvent event)
{
try
{
if (AbstractCommand.AWAITED.containsKey(event.getMessage().getStringID()) && event.getUser().getStringID().equals(AbstractCommand.AWAITED.get(event.getMessage().getStringID()).getID()))
{
event.getMessage().delete();
AbstractCommand.AWAITED.get(event.getMessage().getStringID()).getCommand().onReactionAdd(event);
}
}
catch (Exception e)
{
Main.log.error("", e);
}
}
示例10: onReady
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onReady (ReadyEvent event) {
this.isProduction = MMDBot.instance.getOurUser().getLongID() == 271222230438903812L;
// Public
this.guildPublic = MMDBot.instance.getGuildByID(176780432371744769L);
this.chanelDebug = MMDBot.instance.getChannelByID(179302857143615489L);
this.chanelAudit = MMDBot.instance.getChannelByID(271498021286576128L);
this.channelNewCurse = MMDBot.instance.getChannelByID(358089884692643852L);
this.chanelConsole = MMDBot.instance.getChannelByID(356312255270486027L);
this.roleAdmin = this.guildPublic.getRoleByID(176781877682634752L);
this.roleBotManager = this.guildPublic.getRoleByID(226067502977777664L);
this.roleModerator = this.guildPublic.getRoleByID(178772974990655489L);
this.roleMuted = this.guildPublic.getRoleByID(305875306529554432L);
// Staff
this.guildStaff = MMDBot.instance.getGuildByID(229851088319283202L);
this.isReady = true;
MMDBot.LOG.info("Logged in as " + Utilities.userString(MMDBot.instance.getOurUser()));
}
示例11: onUserNickNameChange
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onUserNickNameChange (NicknameChangedEvent event) {
if (MMDBot.state.isPublicGuild(event.getGuild()) && MMDBot.state.isProductionBot()) {
final IUser user = event.getUser();
final EmbedBuilder embed = new EmbedBuilder();
embed.withDescription("**USER NICKNAME CHANGE**");
embed.appendField("**User**", Utilities.userString(user), false);
if (event.getOldNickname().isPresent()) {
embed.appendField("**Old Nickname**", event.getOldNickname().get(), true);
}
if (event.getNewNickname().isPresent()) {
embed.appendField("**New Nickname**", event.getNewNickname().get(), true);
}
Utilities.sendMessage(MMDBot.state.getAuditChannel(), embed, NEUTRAL);
}
}
示例12: onMessageDelete
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onMessageDelete (MessageDeleteEvent event) {
if (MMDBot.state.isPublicGuild(event.getGuild()) && MMDBot.state.isProductionBot()) {
final IUser user = event.getAuthor();
final EmbedBuilder embed = new EmbedBuilder();
embed.withDescription("**USER DELETE MESSAGE**");
embed.appendField("**User**", Utilities.userString(user), false);
embed.appendField("**Chanel**", event.getChannel().getName(), false);
embed.appendField("**Content**", Utilities.formatMessage(event.getMessage()), false);
embed.appendField("**MESSAGE ID**", Long.toString(event.getMessage().getLongID()), false);
Utilities.sendMessage(MMDBot.state.getAuditChannel(), embed, NEGATIVE);
}
}
示例13: onUserUpdate
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onUserUpdate(UserUpdateEvent event) {
StalkCommand.StalkData stalkData = Userdata
.getGson("stalkData_" + event.getNewUser().getID(), StalkCommand.StalkData.class);
if (!event.getOldUser().getName().equals(event.getNewUser().getName())) {
if (stalkData == null)
stalkData = new StalkCommand.StalkData();
if (stalkData.nameChanges == null)
stalkData.nameChanges = new ArrayList<>();
stalkData.nameChanges.add(new StalkCommand.StalkData.NameChangeTime(null, event.getOldUser().getName(),
event.getNewUser().getName(), System.currentTimeMillis()));
}
Userdata.setGson("stalkData_" + event.getNewUser().getID(), stalkData);
Userdata.instance().save();
}
示例14: onNicknameChange
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onNicknameChange(NickNameChangeEvent event) {
ServerSettingsCommand.ServerSettings settings = Userdata
.getGson("serverSettings_" + event.getGuild().getID(), ServerSettingsCommand.ServerSettings.class);
if (settings == null)
settings = new ServerSettingsCommand.ServerSettings();
if (!settings.trackNameChanges)
return;
StalkCommand.StalkData stalkData = Userdata
.getGson("stalkData_" + event.getUser().getID(), StalkCommand.StalkData.class);
if (stalkData == null)
stalkData = new StalkCommand.StalkData();
if (stalkData.nameChanges == null)
stalkData.nameChanges = new ArrayList<>();
stalkData.nameChanges.add(new StalkCommand.StalkData.NameChangeTime(event.getGuild().getID(),
event.getOldNickname().orElse(null), event.getNewNickname().orElse(null), System.currentTimeMillis()));
Userdata.setGson("stalkData_" + event.getUser().getID(), stalkData);
Userdata.instance().save();
}
示例15: onReady
import sx.blah.discord.api.events.EventSubscriber; //导入依赖的package包/类
@EventSubscriber
public void onReady(ReadyEvent event) {
// Set game to Minecraft
DiscordMC.getClient().changePlayingText("Minecraft");
// Check for file encoder (emoji-related)
switch (System.getProperty("file.encoding")) {
case "UTF8":
case "UTF-8":
break;
default:
plugin.getLogger().warning("WARNING ::: Your file encoder is set to something else than UTF-8. This might break emoji encoding");
break;
}
if (event.getClient().getGuilds().size() == 0) {
plugin.getLogger().warning("Your bot is not joined to any guild. Please follow the instructions on the Spigot page");
DiscordMC.get().getServer().getPluginManager().disablePlugin(DiscordMC.get());
}
}