use of stream.flarebot.flarebot.scheduler.FlareBotTask in project FlareBot by FlareBot.
the class VoteUtil method sendVoteMessage.
public static void sendVoteMessage(UUID id, VoteGroup.VoteRunnable voteRunnable, VoteGroup group, long timeout, TextChannel channel, User user, String buttonGroupString, ButtonGroup.Button... optionalButtons) {
EmbedBuilder votesEmbed = new EmbedBuilder().setDescription("Vote to " + group.getMessageDesc()).addField("Yes", "0", true).addField("No", "0", true);
String messageDesc = group.getMessageDesc();
votesEmbed.setColor(ColorUtils.FLAREBOT_BLUE);
group.setVotesEmbed(votesEmbed);
ButtonGroup buttonGroup = new ButtonGroup(user.getIdLong(), buttonGroupString);
groupMap.put(id + channel.getGuild().getId(), group);
runnableMap.put(id + channel.getGuild().getId(), voteRunnable);
buttonGroup.addButton(new ButtonGroup.Button(355776056092917761L, (owner, user1, message) -> {
if (group.addVote(VoteGroup.Vote.YES, user1)) {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted yes on " + messageDesc).build(), 2000, channel);
} else {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
}
}));
buttonGroup.addButton(new ButtonGroup.Button(355776081384570881L, (owner, user1, message) -> {
if (group.addVote(VoteGroup.Vote.NO, user1)) {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted no on " + messageDesc).build(), 2000, channel);
} else {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
}
}));
for (ButtonGroup.Button button : optionalButtons) {
buttonGroup.addButton(button);
}
Message voteMessage = ButtonUtil.sendReturnedButtonedMessage(channel, votesEmbed.build(), buttonGroup);
group.setVoteMessage(voteMessage);
new FlareBotTask("Votes-" + voteMessage.getId()) {
@Override
public void run() {
voteRunnable.run(group.won());
groupMap.remove(group.getMessageDesc() + channel.getGuild().getId());
runnableMap.remove(group.getMessageDesc() + channel.getGuild().getId());
channel.deleteMessageById(voteMessage.getId()).queue();
}
}.delay(timeout);
}
use of stream.flarebot.flarebot.scheduler.FlareBotTask in project FlareBot by FlareBot.
the class FlareBot method runTasks.
public void runTasks() {
new FlareBotTask("FixThatStatus") {
@Override
public void run() {
if (!UPDATING.get())
setStatus("_help | _invite");
}
}.repeat(10, TimeUnit.SECONDS.toMillis(32));
new FlareBotTask("PostDbotsData") {
@Override
public void run() {
if (config.getString("botlists.discordBots").isPresent()) {
postToBotList(config.getString("botlists.discordBots").get(), String.format("https://bots.discord.pw/api/bots/%s/stats", Getters.getSelfUser().getId()));
}
}
}.repeat(10, TimeUnit.MINUTES.toMillis(10));
new FlareBotTask("PostBotlistData") {
@Override
public void run() {
if (config.getString("botlists.botlist").isPresent()) {
postToBotList(config.getString("botlists.botlist").get(), String.format("https://discordbots.org/api/bots/%s/stats", Getters.getSelfUser().getId()));
}
}
}.repeat(10, TimeUnit.MINUTES.toMillis(10));
new FlareBotTask("PostCarbonData") {
@Override
public void run() {
if (config.getString("botlists.carbon").isPresent()) {
try {
WebUtils.post("https://www.carbonitex.net/discord/data/botdata.php", WebUtils.APPLICATION_JSON, new JSONObject().put("key", config.getString("botlists.carbon").get()).put("servercount", Getters.getGuildCache().size()).put("shardcount", Getters.getShards().size()).toString());
} catch (IOException e) {
LOGGER.error("Failed to update carbon!", e);
}
}
}
}.repeat(10, TimeUnit.MINUTES.toMillis(10));
new FlareBotTask("spam" + System.currentTimeMillis()) {
@Override
public void run() {
events.getSpamMap().clear();
}
}.repeat(TimeUnit.SECONDS.toMillis(3), TimeUnit.SECONDS.toMillis(3));
new FlareBotTask("DeadShard-Checker") {
@Override
public void run() {
if (getImportantWebhook() == null) {
LOGGER.warn("No webhook for the important-log channel! Due to this the dead shard checker has been disabled!");
cancel();
return;
}
if (Getters.getShards().size() == 1) {
LOGGER.warn("Single sharded bot, the DeadShard-Checker has been disabled!");
cancel();
return;
}
// 10 mins without an event... this son bitch is dead.
if (Getters.getShards().stream().anyMatch(shard -> ShardUtils.isDead(shard, TimeUnit.MINUTES.toMillis(10)))) {
Getters.getShards().stream().filter(shard -> ShardUtils.isDead(shard, TimeUnit.MINUTES.toMillis(10))).forEach(shard -> {
getImportantWebhook().send("Restarting " + ShardUtils.getShardId(shard) + " as it seems to be dead.");
shardManager.restart(ShardUtils.getShardId(shard));
});
}
Set<Integer> deadShards = Getters.getShards().stream().filter(ShardUtils::isDead).map(ShardUtils::getShardId).collect(Collectors.toSet());
if (!deadShards.isEmpty()) {
getImportantWebhook().send("Found " + deadShards.size() + " possibly dead shards! Shards: " + deadShards.toString());
}
}
}.repeat(TimeUnit.MINUTES.toMillis(10), TimeUnit.MINUTES.toMillis(5));
new FlareBotTask("GuildCleanup") {
@Override
public void run() {
FlareBotManager.instance().getGuilds().cleanUp();
}
}.repeat(0, TimeUnit.SECONDS.toMillis(30));
/*new FlareBotTask("ActivityChecker") {
@Override
public void run() {
for (VoiceChannel channel : Getters.getConnectedVoiceChannel()) {
if (channel.getMembers().stream().anyMatch(member -> !member.getUser().isBot()
&& !member.getUser().isFake())
&& !getMusicManager().getPlayer(channel.getGuild().getId()).getPlaylist().isEmpty()
&& !getMusicManager().getPlayer(channel.getGuild().getId()).getPaused()) {
manager.getLastActive().remove(channel.getGuild().getIdLong());
return;
}
if (manager.getLastActive().containsKey(channel.getGuild().getIdLong())
&& System.currentTimeMillis() >= (manager.getLastActive().get(channel.getGuild().getIdLong())
+ TimeUnit.MINUTES.toMillis(10)))
channel.getGuild().getAudioManager().closeAudioConnection();
}
}
}.repeat(10_000, 10_000);*/
new VoiceChannelCleanup("VoiceChannelCleanup");
}
use of stream.flarebot.flarebot.scheduler.FlareBotTask in project FlareBot by FlareBot.
the class UpdateJDACommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length == 1) {
String version = args[0];
try {
File f = new File("pom.xml");
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);
Node jdaNode = doc.getElementsByTagName("dependency").item(0);
NodeList children = jdaNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().equalsIgnoreCase("version"))
node.setTextContent(version);
}
DOMSource source = new DOMSource(doc);
TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(f));
channel.sendMessage("Updated to JDA version `" + version + "`\n" + "I will now restart in 10 minutes and apply the update!").queue();
new FlareBotTask("JDA-Update") {
@Override
public void run() {
FlareBot.instance().quit(true);
}
}.delay(TimeUnit.MINUTES.toMillis(10));
// _update-jda 3.3.1_306
} catch (SAXException | IOException | ParserConfigurationException | TransformerException e) {
FlareBot.LOGGER.error("Failed to parse the pom file!", e);
channel.sendMessage("Parsing failed! " + e.getMessage()).queue();
}
}
}
Aggregations