use of com.jagrosh.jdautilities.commons.waiter.EventWaiter in project GordoBot by Pedroleal19.
the class Main method main.
public static void main(String[] args) throws LoginException, IOException, IllegalArgumentException, RateLimitedException {
fileConfig fc = new fileConfig();
String token = fc.fileConfig();
String ownerId = fc.ownerId();
EventWaiter waiter = new EventWaiter();
CommandClientBuilder client = new CommandClientBuilder();
client.setPrefix("gordo ");
// ADICIONAR FUNÇÃO DE PROCURAR PELA OWNERID NA CONFIG.TXT, POR AGORA TO COM PREGUIÇA
client.setOwnerId(ownerId);
client.addCommands(new HelloWorld(), new kick(), new ban(), new teste(), new help(), new say(), new sobre());
client.setHelpWord("%JDAOldHelp%");
client.useHelpBuilder(false);
client.setGame(Game.playing("e comendo biscoito"));
try {
new JDABuilder(AccountType.BOT).setToken(token).addEventListener(waiter).addEventListener(client.build()).setGame(Game.playing("REINICIANDO")).setStatus(OnlineStatus.IDLE).buildAsync();
} catch (Exception e) {
System.out.println("PROBLEMAS NA CONEXÃO // ERRO PROVAVEL NO TOKEN // VOCÊ COLOCOU O TOKEN CORRETAMENTE?" + "\n" + "Script encerrado");
return;
}
}
use of com.jagrosh.jdautilities.commons.waiter.EventWaiter in project PurrBot by purrbot-site.
the class CmdFuck method handleButton.
private void handleButton(Message botMsg, Member author, Member target, String... args) {
Guild guild = botMsg.getGuild();
String channelId = botMsg.getTextChannel().getId();
queue.put(bot.getRequestUtil().getQueueString("fuck", guild.getId(), author.getId()), target.getId());
EventWaiter waiter = bot.getWaiter();
waiter.waitForEvent(ButtonClickEvent.class, event -> {
if (event.getUser().isBot())
return false;
if (event.getMember() == null)
return false;
if (!event.getComponentId().equals("purr:fuck:accept") && !event.getComponentId().equals("purr:fuck:deny"))
return false;
if (!event.isAcknowledged())
event.deferEdit().queue();
if (!event.getMember().equals(target))
return false;
return event.getMessageId().equals(botMsg.getId());
}, event -> {
TextChannel channel = event.getTextChannel();
queue.invalidate(bot.getRequestUtil().getQueueString("fuck", guild.getId(), author.getId()));
String buttonId = event.getComponentId().split(":")[2];
if (buttonId.equals("deny")) {
botMsg.delete().queue(null, e -> logger.warn("Could not delete own message for CmdFuck. Was it already deleted?"));
channel.sendMessage(bot.getMsg(guild.getId(), "purr.nsfw.fuck.request.denied", author.getAsMention(), target.getEffectiveName())).queue();
return;
}
HttpUtil.ImageAPI api;
if (bot.getMessageUtil().hasArg("anal", args)) {
api = HttpUtil.ImageAPI.NSFW_ANAL;
} else if (bot.getMessageUtil().hasArg("yaoi", args)) {
api = HttpUtil.ImageAPI.NSFW_YAOI;
} else if (bot.getMessageUtil().hasArg("yuri", args)) {
api = HttpUtil.ImageAPI.NSFW_YURI;
} else {
api = HttpUtil.ImageAPI.NSFW_FUCK;
}
bot.getRequestUtil().handleEdit(channel, botMsg, api, author, Collections.singletonList(target.getEffectiveName()));
}, 1, TimeUnit.MINUTES, () -> {
TextChannel channel = guild.getTextChannelById(channelId);
if (channel == null)
return;
botMsg.delete().queue(null, e -> logger.warn("Unable to delete own Message for fuck! Was it already deleted?"));
queue.invalidate(bot.getRequestUtil().getQueueString("fuck", guild.getId(), author.getId()));
channel.sendMessage(bot.getMsg(guild.getId(), "request.timed_out", author.getAsMention(), target.getEffectiveName())).queue();
});
}
use of com.jagrosh.jdautilities.commons.waiter.EventWaiter in project PurrBot by purrbot-site.
the class CmdThreesome method handleEvent.
public void handleEvent(Message botMsg, Member author, Member target1, Member target2, String... args) {
Guild guild = botMsg.getGuild();
List<String> list = new ArrayList<>();
list.add(target1.getId());
list.add(target2.getId());
queue.put(bot.getRequestUtil().getQueueString("threesome", guild.getId(), author.getId()), String.format("%s:%s", target1.getId(), target2.getId()));
EventWaiter waiter = bot.getWaiter();
waiter.waitForEvent(ButtonClickEvent.class, event -> {
if (event.getUser().isBot())
return false;
if (event.getMember() == null)
return false;
if (!event.getMember().equals(target1) && !event.getMember().equals(target2))
return false;
if (!event.getMessageId().equals(botMsg.getId()))
return false;
if (!event.isAcknowledged())
event.deferEdit().queue();
return allUser(list, event.getUser().getId(), event.getComponentId());
}, event -> {
TextChannel channel = event.getTextChannel();
queue.invalidate(bot.getRequestUtil().getQueueString("threesome", guild.getId(), author.getId()));
if (event.getComponentId().equals("purr:threesome:deny")) {
list.remove(target1.getId());
list.remove(target2.getId());
botMsg.delete().queue(null, e -> logger.warn("Unable to delete own Message for threesome! Was it already deleted?"));
channel.sendMessage(bot.getMsg(guild.getId(), "purr.nsfw.threesome.request.denied", author.getAsMention()).replace("{target1}", target1.getEffectiveName()).replace("{target2}", target2.getEffectiveName())).queue();
} else {
List<String> targets = Arrays.asList(target1.getEffectiveName(), target2.getEffectiveName());
HttpUtil.ImageAPI api;
if (bot.getMessageUtil().hasArg("mmf", args)) {
api = HttpUtil.ImageAPI.NSFW_THREESOME_MMF;
} else if (bot.getMessageUtil().hasArg("fff", args)) {
api = HttpUtil.ImageAPI.NSFW_THREESOME_FFF;
} else {
api = HttpUtil.ImageAPI.NSFW_THREESOME_FFM;
}
bot.getRequestUtil().handleEdit(channel, botMsg, api, author, targets);
}
}, 1, TimeUnit.MINUTES, () -> {
TextChannel channel = botMsg.getTextChannel();
botMsg.delete().queue(null, e -> logger.warn("Unable to delete own Message for Threesome! Was it already deleted?"));
queue.invalidate(bot.getRequestUtil().getQueueString("threesome", guild.getId(), author.getId()));
list.remove(target1.getId());
list.remove(target2.getId());
List<String> targets = Arrays.asList(target1.getEffectiveName(), target2.getEffectiveName());
channel.sendMessage(bot.getMsg(guild.getId(), "request.timed_out", author.getAsMention(), targets)).queue();
});
}
use of com.jagrosh.jdautilities.commons.waiter.EventWaiter in project PurrBot by purrbot-site.
the class RequestUtil method handleButton.
private void handleButton(Message msg, TextChannel tc, Member author, Member target, HttpUtil.ImageAPI api) {
queue.put(getQueueString(api.getName(), tc.getGuild().getId(), author.getId()), target.getId());
Guild guild = tc.getGuild();
String channelId = tc.getId();
EventWaiter waiter = bot.getWaiter();
waiter.waitForEvent(ButtonClickEvent.class, event -> {
if (event.getUser().isBot())
return false;
if (event.getMember() == null)
return false;
if (!event.isAcknowledged())
event.deferEdit().queue();
if (!isValidButton(event.getComponentId(), api.getName()))
return false;
if (!event.getMember().equals(target))
return false;
return event.getMessageId().equals(msg.getId());
}, event -> {
TextChannel channel = event.getTextChannel();
queue.invalidate(getQueueString(api.getName(), guild.getId(), author.getId()));
String result = event.getComponentId().split(":")[2];
if (result.equals("deny")) {
channel.sendMessage(bot.getMsg(guild.getId(), api.getPath() + "request.denied", author.getAsMention(), target.getEffectiveName())).queue();
msg.delete().queue(null, e -> logger.warn("Unable to delete Message for {}. Was it already deleted?", api.getName()));
} else {
handleEdit(tc, msg, api, author, Collections.singletonList(target.getEffectiveName()));
}
}, 1, TimeUnit.MINUTES, () -> {
TextChannel channel = guild.getTextChannelById(channelId);
if (channel == null)
return;
msg.delete().queue(null, e -> logger.warn("Unable to delete Message for {}. Was it already deleted?", api.getName()));
queue.invalidate(getQueueString(api.getName(), guild.getId(), author.getId()));
channel.sendMessage(bot.getMsg(guild.getId(), "request.timed_out", author.getAsMention(), target.getEffectiveName())).queue();
});
}
use of com.jagrosh.jdautilities.commons.waiter.EventWaiter in project GeyserDiscordBot by GeyserMC.
the class GeyserBot method main.
public static void main(String[] args) throws IOException, LoginException {
// Load properties into the PropertiesManager
Properties prop = new Properties();
prop.load(new FileInputStream("bot.properties"));
PropertiesManager.loadProperties(prop);
// Setup sentry.io
if (PropertiesManager.getSentryDsn() != null) {
LOGGER.info("Loading sentry.io...");
Sentry.init(options -> {
options.setDsn(PropertiesManager.getSentryDsn());
options.setEnvironment(PropertiesManager.getSentryEnv());
LOGGER.info("Sentry.io loaded");
});
}
// Connect to github
github = new GitHubBuilder().withOAuthToken(PropertiesManager.getGithubToken()).build();
// Initialize the waiter
EventWaiter waiter = new EventWaiter();
// Load filters
SwearHandler.loadFilters();
// Load the db
StorageType storageType = StorageType.getByName(PropertiesManager.getDatabaseType());
if (storageType == StorageType.UNKNOWN) {
LOGGER.error("Invalid database type! '" + PropertiesManager.getDatabaseType() + "'");
System.exit(1);
}
try {
storageManager = storageType.getStorageManager().getDeclaredConstructor().newInstance();
storageManager.setupStorage();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOGGER.error("Unable to create database link!");
System.exit(1);
}
// Setup the main client
CommandClientBuilder client = new CommandClientBuilder();
client.setActivity(null);
// No owner
client.setOwnerId("0");
client.setPrefix(PropertiesManager.getPrefix());
client.useHelpBuilder(false);
client.addCommands(COMMANDS.toArray(new Command[0]));
client.addSlashCommands(SLASH_COMMANDS.toArray(new SlashCommand[0]));
client.setListener(new CommandErrorHandler());
client.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
// Setup the tag client
CommandClientBuilder tagClient = new CommandClientBuilder();
tagClient.setActivity(null);
// No owner
tagClient.setOwnerId("0");
String tagPrefix = PropertiesManager.getPrefix() + PropertiesManager.getPrefix();
tagClient.setPrefix(tagPrefix);
tagClient.setPrefixes(new String[] { "!tag " });
tagClient.useHelpBuilder(false);
tagClient.addCommands(TagsManager.getTags().toArray(new Command[0]));
tagClient.setListener(new TagsListener());
tagClient.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
tagClient.setManualUpsert(true);
// Disable pings on replies
MessageAction.setDefaultMentionRepliedUser(false);
// Setup the thread pool
generalThreadPool = Executors.newScheduledThreadPool(5);
// Register JDA
try {
jda = JDABuilder.createDefault(PropertiesManager.getToken()).setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS).enableIntents(GatewayIntent.GUILD_PRESENCES).enableCache(CacheFlag.ACTIVITY).enableCache(CacheFlag.ROLE_TAGS).setStatus(OnlineStatus.ONLINE).setActivity(Activity.playing("Booting...")).setEnableShutdownHook(true).setEventManager(new SentryEventManager()).addEventListeners(waiter, new LogHandler(), new SwearHandler(), new PersistentRoleHandler(), new FileHandler(), new LevelHandler(), new DumpHandler(), new ErrorAnalyzer(), new ShutdownHandler(), new VoiceGroupHandler(), new BadLinksHandler(), client.build(), tagClient.build()).build();
} catch (IllegalArgumentException exception) {
LOGGER.error("Failed to initialize JDA!", exception);
System.exit(1);
}
// Register listeners
jda.addEventListener();
// Setup the http server
if (PropertiesManager.enableWeb()) {
try {
httpServer = new Server();
httpServer.start();
} catch (Exception e) {
// TODO
e.printStackTrace();
}
}
// Setup the update check scheduler
UpdateManager.setup();
// Setup the health check scheduler
HealthCheckerManager.setup();
// Setup the rss feed check scheduler
RssFeedManager.setup();
// Setup all slow mode handlers
generalThreadPool.schedule(() -> {
for (Guild guild : jda.getGuilds()) {
for (SlowModeInfo info : storageManager.getSlowModeChannels(guild)) {
jda.addEventListener(new SlowmodeHandler(info.getChannel(), info.getDelay()));
}
}
}, 5, TimeUnit.SECONDS);
// Start the bStats tracking thread
generalThreadPool.scheduleAtFixedRate(() -> {
JSONArray servers = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/servers/data"));
JSONArray players = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/players/data"));
int serverCount = servers.getJSONArray(servers.length() - 1).getInt(1);
int playerCount = players.getJSONArray(players.length() - 1).getInt(1);
jda.getPresence().setActivity(Activity.playing(BotHelpers.coolFormat(serverCount) + " servers, " + BotHelpers.coolFormat(playerCount) + " players"));
}, 5, 60 * 5, TimeUnit.SECONDS);
}
Aggregations