Search in sources :

Example 1 with CheckIfPremiumGuild

use of tk.ardentbot.utils.premium.CheckIfPremiumGuild in project Ardent by adamint.

the class Ardent method main.

public static void main(String[] args) throws Exception {
    new DefaultAudioPlayerManager();
    Logger root1 = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root1.setLevel(Level.OFF);
    for (String s : args) {
        if (s.contains("premium"))
            premiumBot = true;
    }
    if (!testingBot) {
        spotifyApi = Api.builder().clientId("471f277107704e3b89d489284b65c6c6").clientSecret(IOUtils.toString(new FileInputStream(new File("/root/Ardent/spotifysecret.key")))).redirectURI("https://ardentbot.tk").build();
        SpotifyTokenRefresh spotifyTokenRefresh = new SpotifyTokenRefresh();
        spotifyTokenRefresh.run();
        globalExecutorService.scheduleAtFixedRate(spotifyTokenRefresh, 10, 10, TimeUnit.MINUTES);
    } else
        spotifyApi = Api.DEFAULT_API;
    if (!testingBot) {
        dbPassword = IOUtils.toString(new FileReader(new File("/root/Ardent/v2password.key")));
        botsDiscordPwToken = IOUtils.toString(new FileReader(new File("/root/Ardent/botsdiscordpw.key")));
        discordBotsOrgToken = IOUtils.toString(new FileReader(new File("/root/Ardent/discordbotsorg.key")));
    } else {
        try {
            dbPassword = IOUtils.toString(new FileReader(new File("C:\\Users\\AMR\\Desktop\\Ardent\\v2password.key")));
            discordBotsOrgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE2OTkwNDMyNDk4MDI0NDQ4MCIsImlhdCI6MTQ5MzMyNDM1OX0.LQ97UtslzaM5Qo__gkihOX5afaZA5z3TjMjSovMzDTI";
        } catch (Exception ex) {
            dbPassword = IOUtils.toString(new FileReader(new File("/root/Ardent/.key")));
        }
    }
    Database.setup();
    Cursor<HashMap> apiKeys = r.db("data").table("api_keys").run(connection);
    apiKeys.forEach((outside) -> {
        outside.forEach((uId, uValue) -> {
            String id = (String) uId;
            String value = (String) uValue;
            if (id.equalsIgnoreCase("mashape"))
                mashapeKey = value;
            else if (id.equalsIgnoreCase("google"))
                GOOGLE_API_KEY = value;
            else if (id.equalsIgnoreCase("node0"))
                node0Url = value;
            else if (id.equalsIgnoreCase("node1"))
                node1Url = value;
            else if (id.equalsIgnoreCase("cleverbotuser"))
                cleverbotUser = value;
            else if (id.equalsIgnoreCase("cleverbotkey"))
                cleverbotKey = value;
            else if (id.equalsIgnoreCase("premiumbottoken"))
                premiumBotToken = value;
            else if (id.equalsIgnoreCase("testbottoken"))
                testBotToken = value;
            else if (id.equalsIgnoreCase("googlesecret"))
                clientSecret = value;
            else if (id.equalsIgnoreCase("twitch"))
                twitch = value;
        });
    });
    ShardManager.register(shardCount);
    BotlistUpdater updater = new BotlistUpdater();
    globalExecutorService.scheduleAtFixedRate(updater, 0, 1, TimeUnit.HOURS);
    StuckVoiceConnection playerStuckDaemon = new StuckVoiceConnection();
    globalExecutorService.scheduleAtFixedRate(playerStuckDaemon, 10, 10, TimeUnit.SECONDS);
    UpdatePremiumMembers updatePremiumMembers = new UpdatePremiumMembers();
    globalExecutorService.scheduleAtFixedRate(updatePremiumMembers, 0, 1, TimeUnit.MINUTES);
    ProfileUpdater profileUpdater = new ProfileUpdater();
    globalExecutorService.scheduleWithFixedDelay(profileUpdater, 1, 5, TimeUnit.MINUTES);
    if (!premiumBot) {
        SparkServer.setup();
    /*Class currentClass = new Object() {
            }.getClass().getEnclosingClass();
            premiumProcess = Runtime.getRuntime().exec("java -jar " + currentClass.getProtectionDomain().getCodeSource().getLocation()
                    .getPath() + " -premium");*/
    } else {
        CheckIfPremiumGuild checkIfPremiumGuild = new CheckIfPremiumGuild();
        globalExecutorService.scheduleAtFixedRate(checkIfPremiumGuild, 1, 5, TimeUnit.MINUTES);
    }
    GoogleSearch.setup(GOOGLE_API_KEY);
    int status = Unirest.post("https://cleverbot.io/1.0/create").field("user", cleverbotUser).field("key", cleverbotKey).field("nick", "ardent").asString().getStatus();
    if (status != 200)
        new BotException("Unable to connect to cleverbot!");
    WebsiteDaemon websiteDaemon = new WebsiteDaemon();
    globalExecutorService.scheduleAtFixedRate(websiteDaemon, 5, 15, TimeUnit.SECONDS);
    PermissionsDaemon permissionsDaemon = new PermissionsDaemon();
    globalExecutorService.scheduleAtFixedRate(permissionsDaemon, 0, 60, TimeUnit.SECONDS);
    GuildDaemon guildDaemon = new GuildDaemon();
    globalExecutorService.scheduleAtFixedRate(guildDaemon, 0, 10, TimeUnit.SECONDS);
    MuteDaemon muteDaemon = new MuteDaemon();
    globalExecutorService.scheduleAtFixedRate(muteDaemon, 1, 5, TimeUnit.SECONDS);
    RankableDaemon rankableDaemon = new RankableDaemon();
    globalExecutorService.scheduleAtFixedRate(rankableDaemon, 0, 1, TimeUnit.MINUTES);
    Music.checkMusicConnections();
    globalExecutorService.scheduleAtFixedRate(() -> {
        Shard[] shards = ShardManager.getShards();
        for (int i = 0; i < shards.length; i++) {
            Shard shard = shards[i];
            if ((System.currentTimeMillis() - shard.getLAST_EVENT()) > 20000) {
                shard.jda.getRegisteredListeners().forEach(shard.jda::removeEventListener);
                int finalI = i;
                globalExecutorService.schedule(() -> {
                    shard.jda.shutdown(false);
                    try {
                        shards[finalI] = new Shard(testingBot, finalI, shardCount);
                    } catch (Exception e) {
                        new BotException(e);
                    }
                }, 3, TimeUnit.SECONDS);
            }
        }
    }, 60, 15, TimeUnit.SECONDS);
    if (!testingBot) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("Fi9IjqqsGmOXqjR5uYK8YM2Pr").setOAuthConsumerSecret(IOUtils.toString(new FileReader(new File("/root/Ardent/twitterconsumersecret.key")))).setOAuthAccessToken("818984879018954752-aCzxyML6Xp0QcRpq5sjoe8wfp0sjVDt").setOAuthAccessTokenSecret(IOUtils.toString(new FileReader(new File("/root/Ardent/twitteroauthsecret.key"))));
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();
    }
    java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.OFF);
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.OFF);
    try {
        transport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        jsonFactory = JacksonFactory.getDefaultInstance();
        sheetsApi = getSheetsService();
        globalExecutorService.schedule(() -> {
            try {
                triviaSheet = sheetsApi.spreadsheets().values().get("1qm27kGVQ4BdYjvPSlF0zM64j7nkW4HXzALFNcan4fbs", "A2:C").execute();
            } catch (IOException e) {
                new BotException(e);
            }
            List<List<Object>> values = triviaSheet.getValues();
            values.forEach(row -> {
                String category = (String) row.get(0);
                String q = (String) row.get(1);
                String answerUnparsed = (String) row.get(2);
                TriviaQuestion triviaQuestion = new TriviaQuestion();
                triviaQuestion.setQuestion(q);
                triviaQuestion.setCategory(category);
                for (String answer : answerUnparsed.split("~")) {
                    triviaQuestion.withAnswer(answer);
                }
                Trivia.triviaQuestions.add(triviaQuestion);
            });
        }, 30, TimeUnit.SECONDS);
    } catch (Exception e) {
        e.printStackTrace();
    }
    started = true;
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) Logger(ch.qos.logback.classic.Logger) FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) BotException(tk.ardentbot.core.misc.logging.BotException) ArrayList(java.util.ArrayList) List(java.util.List) GoogleSearch(tk.ardentbot.utils.searching.GoogleSearch) TwitterFactory(twitter4j.TwitterFactory) BotException(tk.ardentbot.core.misc.logging.BotException) Logger(ch.qos.logback.classic.Logger) StuckVoiceConnection(tk.ardentbot.commands.music.StuckVoiceConnection) TriviaQuestion(tk.ardentbot.utils.models.TriviaQuestion) CheckIfPremiumGuild(tk.ardentbot.utils.premium.CheckIfPremiumGuild) UpdatePremiumMembers(tk.ardentbot.utils.premium.UpdatePremiumMembers)

Aggregations

Logger (ch.qos.logback.classic.Logger)1 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)1 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 StuckVoiceConnection (tk.ardentbot.commands.music.StuckVoiceConnection)1 BotException (tk.ardentbot.core.misc.logging.BotException)1 TriviaQuestion (tk.ardentbot.utils.models.TriviaQuestion)1 CheckIfPremiumGuild (tk.ardentbot.utils.premium.CheckIfPremiumGuild)1 UpdatePremiumMembers (tk.ardentbot.utils.premium.UpdatePremiumMembers)1 GoogleSearch (tk.ardentbot.utils.searching.GoogleSearch)1 TwitterFactory (twitter4j.TwitterFactory)1 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)1