Skip to content
Permalink
Browse files

Version 2.7.0

- CmdLevel.java
- LevelManager.java
- RewardHandler.java
- Botlist.java
- LBots.java
~ Removed Leveling-system and vote-system
  • Loading branch information
Andre601 committed Feb 13, 2020
1 parent 0844e1c commit ed4dab1a3e2a8292aa8c45e67bac607d0214c49c
@@ -6,7 +6,7 @@ plugins {
id 'net.kyori.blossom' version '1.1.0'
}

version = '2.6.6'
version = '2.7.0'

description = """"""

@@ -36,7 +36,6 @@ dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile group: 'com.sparkjava', name: 'spark-core', version: '2.9.1'
compile group: 'com.github.rainestormee', name: 'jda-command', version: '1.1.3'
compile group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.0'
compile group: 'org.botblock', name: 'JavaBotBlockAPI', version: '5.1.9'
@@ -19,24 +19,19 @@
package site.purrbot.bot;

import ch.qos.logback.classic.Logger;
import com.github.benmanes.caffeine.cache.CacheWriter;
import com.github.benmanes.caffeine.cache.RemovalCause;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import org.botblock.javabotblockapi.BotBlockAPI;
import org.botblock.javabotblockapi.Site;
import org.botblock.javabotblockapi.requests.PostAction;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.rainestormee.jdacommand.CommandHandler;
import com.google.gson.Gson;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Message;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import site.purrbot.bot.commands.CommandListener;
import site.purrbot.bot.commands.CommandLoader;
@@ -51,18 +46,13 @@
import site.purrbot.bot.util.message.EmbedUtil;
import site.purrbot.bot.util.message.MessageUtil;
import site.purrbot.bot.util.message.WebhookUtil;
import site.purrbot.bot.votes.Botlist;
import site.purrbot.bot.votes.LBots;
import spark.Spark;

import javax.security.auth.login.LoginException;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static spark.Spark.*;

public class PurrBot {

private Logger logger = (Logger)LoggerFactory.getLogger(PurrBot.class);
@@ -72,16 +62,13 @@
private Random random;

private FileManager fileManager = new FileManager();
private ReadyListener readyListener;
private DBUtil dbUtil;
private PermUtil permUtil;
private MessageUtil messageUtil;
private RewardHandler rewardHandler;
private EmbedUtil embedUtil;
private HttpUtil httpUtil;
private WebhookUtil webhookUtil;
private ImageUtil imageUtil;
private LevelManager levelManager;
private LangUtils langUtils;

private boolean beta = false;
@@ -114,31 +101,6 @@
private Cache<String, String> welcomeMsg = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();

private Cache<String, Long> xp = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.writer(new CacheWriter<String, Long>(){
@Override
public void write(@NonNull String key, @NonNull Long value){}

@Override
public void delete(@NonNull String key, Long value, @NonNull RemovalCause cause){
getDbUtil().setXp(key, value);
}
})
.build();
private Cache<String, Long> level = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.writer(new CacheWriter<String, Long>(){
@Override
public void write(@NonNull String key, @NonNull Long value){}

@Override
public void delete(@NonNull String key, Long value, @NonNull RemovalCause cause){
getDbUtil().setLevel(key, value);
}
})
.build();

public static void main(String[] args){
try{
@@ -156,17 +118,13 @@ private void setup() throws LoginException{
.addFile("ko", "/lang/ko.json", "./lang/ko.json");

random = new Random();

readyListener = new ReadyListener(this);
dbUtil = new DBUtil(this);
permUtil = new PermUtil();
messageUtil = new MessageUtil(this);
rewardHandler = new RewardHandler(this);
embedUtil = new EmbedUtil(this);
httpUtil = new HttpUtil();
webhookUtil = new WebhookUtil();
imageUtil = new ImageUtil(this);
levelManager = new LevelManager(this);
langUtils = new LangUtils(this);

waiter = new EventWaiter();
@@ -179,7 +137,7 @@ private void setup() throws LoginException{
.setToken(getFileManager().getString("config", "bot-token"))
.setChunkingFilter(ChunkingFilter.NONE)
.addEventListeners(
readyListener,
new ReadyListener(this),
new ConnectionListener(this),
new GuildListener(this),
new CommandListener(this, CMD_HANDLER),
@@ -189,56 +147,6 @@ private void setup() throws LoginException{
.setActivity(Activity.of(Activity.ActivityType.DEFAULT, getMessageUtil().getRandomStartupMsg()))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.build();

if(!isBeta()){
Spark.port(1000);

path("/votes", () -> {
Gson voteGson = new Gson();
JSONObject json = new JSONObject();

post("/lbots_org", (request, response) -> {
LBots lBots = voteGson.fromJson(request.body(), LBots.class);

if(getReadyListener().isReady() && lBots.isFavourited()){
if(rewardHandler.lbotsReward(lBots.getUserid())){
response.status(200);
json.put("code", 200).put("message", "POST-request valid!");
}else{
response.status(403);
json.put("code", 403).put("message", "Invalid POST-request!");
}
}

response.type("application/json");
response.body(json.toString());

return response.body();
});

post("/botlist_space", (request, response) -> {
Botlist botlist = voteGson.fromJson(request.body(), Botlist.class);

if(getReadyListener().isReady()){
if(rewardHandler.botlistSpaceReward(botlist.getBotId(), botlist.getUserId())){
response.status(200);
json.put("code", 200).put("message", "POST-request valid!");
}else{
response.status(403);
json.put("code", 403).put("message", "Invalid POST-request!");
}
}else{
response.status(403);
json.put("code", 403).put("message", "Vote-listener is not ready.");
}

response.type("application/json");
response.body(json.toString());

return response.body();
});
});
}
}

public void startUpdates(){
@@ -273,9 +181,6 @@ public Random getRandom(){
public ShardManager getShardManager(){
return shardManager;
}
private ReadyListener getReadyListener(){
return readyListener;
}
public DBUtil getDbUtil(){
return dbUtil;
}
@@ -300,9 +205,6 @@ public WebhookUtil getWebhookUtil(){
public ImageUtil getImageUtil(){
return imageUtil;
}
public LevelManager getLevelManager(){
return levelManager;
}

public boolean isBeta(){
return beta;
@@ -336,13 +238,6 @@ public String getWelcomeIcon(String id){
public String getWelcomeMsg(String id){
return welcomeMsg.get(id, k -> getDbUtil().getWelcomeMsg(id));
}

public Long getXp(String id){
return xp.get(id, k -> getDbUtil().getXp(id));
}
public Long getLevel(String id){
return level.get(id, k -> getDbUtil().getLevel(id));
}

public void setLanguage(String key, String value){
getDbUtil().setLanguage(key, value);
@@ -372,13 +267,6 @@ public void setWelcomeMsg(String key, String value){
getDbUtil().setWelcomeMsg(key, value);
welcomeMsg.put(key, value);
}

public void setXp(String key, Long value){
xp.put(key, value);
}
public void setLevel(String key, Long value){
level.put(key, value);
}

public void invalidateCache(String id){
language.invalidate(id);
@@ -27,7 +27,6 @@
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import site.purrbot.bot.PurrBot;
import site.purrbot.bot.constants.Emotes;
import site.purrbot.bot.constants.IDs;
import site.purrbot.bot.constants.Links;

@@ -72,8 +71,6 @@ public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event){
String userMention = "<@" + guild.getJDA().getSelfUser().getId() + ">";

if(!raw.toLowerCase().startsWith(prefix) && !raw.startsWith(userMention) && !raw.startsWith(memberMention)){
if(guild.getId().equals(IDs.GUILD.getId()))
bot.getLevelManager().giveXP(user.getId(), false, msg.getTextChannel());

return;
}
@@ -158,9 +155,6 @@ public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event){

try{
HANDLER.execute(command, msg, args[1] == null ? "" : args[1]);

if(guild.getId().equals(IDs.GUILD.getId()))
bot.getLevelManager().giveXP(member.getId(), true, tc);
}catch(Exception ex){
logger.error("Couldn't perform command!", ex);
bot.getEmbedUtil().sendError(tc, user, "errors.unknown", ex.getMessage());
@@ -61,7 +61,6 @@ public CommandLoader(PurrBot bot){
new CmdHelp(bot),
new CmdInfo(bot),
new CmdInvite(bot),
new CmdLevel(bot),
new CmdPing(bot),
new CmdQuote(bot),
new CmdShards(bot),

0 comments on commit ed4dab1

Please sign in to comment.
You can’t perform that action at this time.