use of net.kodehawa.mantarobot.data.Config in project MantaroBot by Mantaro.
the class MantaroShard method updateStatus.
void updateStatus() {
Runnable changeStatus = () -> {
AtomicInteger users = new AtomicInteger(0), guilds = new AtomicInteger(0);
if (MantaroBot.getInstance() != null) {
Arrays.stream(MantaroBot.getInstance().getShards()).map(MantaroShard::getJDA).forEach(jda -> {
users.addAndGet(jda.getUsers().size());
guilds.addAndGet(jda.getGuilds().size());
});
}
String newStatus = random(SPLASHES.get(), RANDOM).replace("%ramgb%", String.valueOf(((long) (Runtime.getRuntime().maxMemory() * 1.2D)) >> 30L)).replace("%usercount%", users.toString()).replace("%guildcount%", guilds.toString()).replace("%shardcount%", String.valueOf(getTotalShards())).replace("%prettyusercount%", pretty(users.get())).replace("%prettyguildcount%", pretty(guilds.get()));
getJDA().getPresence().setGame(Game.of(config().get().prefix + "help | " + newStatus + " | [" + getId() + "]"));
log.debug("Changed status to: " + newStatus);
};
changeStatus.run();
Async.task("Splash Thread", changeStatus, 600, TimeUnit.SECONDS);
}
use of net.kodehawa.mantarobot.data.Config in project MantaroBot by Mantaro.
the class MantaroShard method updateServerCount.
public void updateServerCount() {
Config config = config().get();
Holder<Integer> guildCount = new Holder<>(jda.getGuilds().size());
String dbotsToken = config.dbotsToken;
String dbotsorgToken = config.dbotsorgToken;
if (dbotsToken != null || dbotsorgToken != null) {
Async.task("Botlist API update Thread", () -> {
int newC = jda.getGuilds().size();
try {
guildCount.accept(newC);
if (dbotsToken != null) {
log.debug("Successfully posted the botdata to bots.discord.pw: " + Unirest.post("https://bots.discord.pw/api/bots/" + jda.getSelfUser().getId() + "/stats").header("Authorization", dbotsToken).header("Content-Type", "application/json").body(new JSONObject().put("server_count", newC).put("shard_id", getId()).put("shard_count", totalShards).toString()).asString().getBody());
}
if (dbotsorgToken != null) {
log.debug("Successfully posted the botdata to discordbots.org: " + Unirest.post("https://discordbots.org/api/bots/" + jda.getSelfUser().getId() + "/stats").header("Authorization", dbotsorgToken).header("Content-Type", "application/json").body(new JSONObject().put("server_count", newC).put("shard_id", getId()).put("shard_count", totalShards).toString()).asString().getBody());
}
} catch (Exception e) {
log.warn("An error occurred while posting the botdata to discord lists (DBots/Carbonitex/DBots.org)", e);
}
}, 1, TimeUnit.HOURS);
}
//Carbon is special now.
Async.task(new Carbonitex(jda, getId(), getTotalShards()), 30, TimeUnit.MINUTES);
}
use of net.kodehawa.mantarobot.data.Config in project MantaroBot by Mantaro.
the class CommandRegistry method process.
public boolean process(GuildMessageReceivedEvent event, String cmdname, String content) {
Command cmd = commands.get(cmdname);
Config conf = MantaroData.config().get();
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
if (cmd == null)
return false;
if (data.getDisabledCommands().contains(cmdname)) {
return false;
}
if (data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()) != null && data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).contains(cmdname)) {
return false;
}
if (data.getDisabledUsers().contains(event.getAuthor().getId())) {
return false;
}
if (MantaroData.db().getGuild(event.getGuild()).getData().getDisabledChannels().contains(event.getChannel().getId()) && cmd.category() != Category.MODERATION) {
return false;
}
if (MantaroData.config().get().isPremiumBot() && cmd.category() == Category.CURRENCY) {
return false;
}
if (data.getDisabledCategories().contains(cmd.category())) {
return false;
}
//If we are in the patreon bot, deny all requests from unknown guilds.
if (conf.isPremiumBot() && !conf.isOwner(event.getAuthor()) && !dbg.isPremium()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like you're trying to use the Patreon bot when this guild is **not** marked as premium. " + "**If you think this is an error please contact Kodehawa#3457 or poke me on #donators in the support guild**").queue();
return false;
}
if (!cmd.permission().test(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.STOP + "You have no permissions to trigger this command").queue();
return false;
}
cmd.run(event, cmdname, content);
return true;
}
Aggregations