use of tk.ardentbot.utils.models.TriviaQuestion 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;
}
use of tk.ardentbot.utils.models.TriviaQuestion in project Ardent by adamint.
the class Trivia method dispatchRound.
public static void dispatchRound(Guild guild, TextChannel channel, User creator, TriviaGame currentGame, ScheduledExecutorService ex) {
try {
Shard shard = GuildUtils.getShard(guild);
currentGame.incrementRounds();
if (currentGame.getRound() >= currentGame.getTotalRounds()) {
currentGame.finish(shard, shard.help);
return;
}
if (!gamesInSession.contains(currentGame))
return;
channel.sendMessage(currentGame.displayScores(shard, shard.help).build()).queue();
TriviaQuestion triviaQuestion = triviaQuestions.get(new SecureRandom().nextInt(triviaQuestions.size()));
currentGame.setCurrentTriviaQuestion(triviaQuestion);
StringBuilder question = new StringBuilder();
question.append("**" + triviaQuestion.getCategory() + "**: " + triviaQuestion.getQuestion());
shard.help.sendTranslatedMessage(question.toString(), channel, creator);
int currentRound = currentGame.getRound();
ex.schedule(() -> {
if (!currentGame.isAnsweredCurrentQuestion() && currentRound == currentGame.getRound() && !(currentRound == currentGame.getTotalRounds())) {
try {
shard.help.sendEditedTranslation("No one got it right! The correct answer was {0}", creator, channel, triviaQuestion.getAnswers().get(0));
if (currentGame.getRound() + 1 < currentGame.getTotalRounds())
dispatchRound(guild, channel, creator, currentGame, ex);
else
currentGame.finish(shard, shard.help);
} catch (Exception e) {
new BotException(e);
}
}
}, 17, TimeUnit.SECONDS);
} catch (Exception ignored) {
}
}
Aggregations