mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-01-27 06:18:31 -06:00
Remove the remaining legacy java code
This commit is contained in:
@@ -2,8 +2,6 @@ import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
java
|
||||
|
||||
//kotlin
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.serialization")
|
||||
@@ -37,10 +35,6 @@ allprojects {
|
||||
apply(plugin = "kotlin")
|
||||
apply(plugin = "io.spring.dependency-management")
|
||||
|
||||
//Compiler nonsense
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
java.targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
// Versions --- found in gradle.properties
|
||||
val kotlinVersion: String by properties
|
||||
// Tool
|
||||
@@ -122,6 +116,11 @@ allprojects {
|
||||
implementation("org.jsoup:jsoup:$jsoupVersion")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
all {
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
package org.dreamexposure.discal.client.message;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.GuildMessageChannel;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import discord4j.rest.http.client.ClientException;
|
||||
import org.dreamexposure.discal.core.file.ReadFile;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author NovaFox161
|
||||
* Date Created: 9/8/2018
|
||||
* For Project: DisCal-Discord-Bot
|
||||
* Author Website: https://www.novamaday.com
|
||||
* Company Website: https://www.dreamexposure.org
|
||||
* Contact: nova@dreamexposure.org
|
||||
*/
|
||||
public class Messages {
|
||||
private static JSONObject langs;
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(Messages.class);
|
||||
|
||||
//Lang handling
|
||||
@Deprecated
|
||||
public static Mono<Boolean> reloadLangs() {
|
||||
return ReadFile.readAllLangFiles()
|
||||
.doOnNext(l -> langs = l)
|
||||
.thenReturn(true)
|
||||
.doOnError(e -> LOGGER.error("[LANGS] Failed to reload lang files", e))
|
||||
.onErrorReturn(false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getMessage(String key, GuildSettings settings) {
|
||||
JSONObject messages;
|
||||
|
||||
if (langs.has(settings.getLang()))
|
||||
messages = langs.getJSONObject(settings.getLang());
|
||||
else
|
||||
messages = langs.getJSONObject("ENGLISH");
|
||||
|
||||
if (messages.has(key))
|
||||
return messages.getString(key).replace("%lb%", GlobalVal.getLineBreak());
|
||||
else
|
||||
return "***FAILSAFE MESSAGE*** MESSAGE NOT FOUND!! Message requested: " + key;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getMessage(String key, String var, String replace, GuildSettings settings) {
|
||||
JSONObject messages;
|
||||
|
||||
if (langs.has(settings.getLang()))
|
||||
messages = langs.getJSONObject(settings.getLang());
|
||||
else
|
||||
messages = langs.getJSONObject("ENGLISH");
|
||||
|
||||
if (messages.has(key))
|
||||
return messages.getString(key).replace(var, replace).replace("%lb%", GlobalVal.getLineBreak());
|
||||
else
|
||||
return "***FAILSAFE MESSAGE*** MESSAGE NOT FOUND!! Message requested: " + key;
|
||||
}
|
||||
|
||||
//Message sending
|
||||
public static Mono<Message> sendMessage(String message, MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(c -> c.createMessage(message))
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendMessage(EmbedCreateSpec embed, MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(c -> c.createMessage(embed))
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendMessage(String message, EmbedCreateSpec embed, MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(c -> c.createMessage(message)
|
||||
.withEmbeds(embed)
|
||||
)
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendMessage(String message, GuildMessageChannel channel) {
|
||||
return channel.createMessage(message)
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendMessage(EmbedCreateSpec embed, GuildMessageChannel channel) {
|
||||
return channel.createMessage(embed)
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendMessage(String message, EmbedCreateSpec embed, GuildMessageChannel channel) {
|
||||
return channel.createMessage(message).withEmbeds(embed)
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
//Direct message sending
|
||||
public static Mono<Message> sendDirectMessage(String message, User user) {
|
||||
return user.getPrivateChannel()
|
||||
.flatMap(c -> c.createMessage(message))
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendDirectMessage(EmbedCreateSpec embed, User user) {
|
||||
return user.getPrivateChannel()
|
||||
.flatMap(c -> c.createMessage(embed))
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Message> sendDirectMessage(String message, EmbedCreateSpec embed, User user) {
|
||||
return user.getPrivateChannel()
|
||||
.flatMap(c -> c.createMessage(message).withEmbeds(embed))
|
||||
.onErrorResume(ClientException.class, e -> Mono.empty());
|
||||
}
|
||||
|
||||
//Message editing
|
||||
public static Mono<Message> editMessage(String message, Message original) {
|
||||
return original.edit().withContentOrNull(message);
|
||||
}
|
||||
|
||||
public static Mono<Message> editMessage(String message, EmbedCreateSpec embed, Message original) {
|
||||
return original.edit().withContentOrNull(message).withEmbeds(embed);
|
||||
}
|
||||
|
||||
public static Mono<Message> editMessage(String message, MessageCreateEvent event) {
|
||||
return event.getMessage().edit().withContentOrNull(message);
|
||||
}
|
||||
|
||||
public static Mono<Message> editMessage(String message, EmbedCreateSpec embed, MessageCreateEvent event) {
|
||||
return event.getMessage().edit().withContentOrNull(message).withEmbeds(embed);
|
||||
}
|
||||
|
||||
//Message deleting
|
||||
public static Mono<Void> deleteMessage(Message message) {
|
||||
return Mono.justOrEmpty(message)
|
||||
.flatMap(Message::delete)
|
||||
.onErrorResume(e -> Mono.empty());
|
||||
}
|
||||
|
||||
public static Mono<Void> deleteMessage(MessageCreateEvent event) {
|
||||
return deleteMessage(event.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package org.dreamexposure.discal.client.message;
|
||||
@@ -1,133 +0,0 @@
|
||||
package org.dreamexposure.discal.client.module.command;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import org.dreamexposure.discal.client.message.Messages;
|
||||
import org.dreamexposure.discal.client.network.google.GoogleExternalAuthHandler;
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.enums.calendar.CalendarHost;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.calendar.CalendarData;
|
||||
import org.dreamexposure.discal.core.object.command.CommandInfo;
|
||||
import org.dreamexposure.discal.core.utils.PermissionChecker;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Nova Fox on 6/29/2017.
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal
|
||||
*/
|
||||
public class AddCalendarCommand implements Command {
|
||||
/**
|
||||
* Gets the command this Object is responsible for.
|
||||
*
|
||||
* @return The command this Object is responsible for.
|
||||
*/
|
||||
@Override
|
||||
public String getCommand() {
|
||||
return "addCalendar";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the short aliases of the command this object is responsible for.
|
||||
* <br>
|
||||
* This will return an empty ArrayList if none are present
|
||||
*
|
||||
* @return The aliases of the command.
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<String> getAliases() {
|
||||
final ArrayList<String> aliases = new ArrayList<>();
|
||||
aliases.add("addcal");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the info on the command (not sub command) to be used in help menus.
|
||||
*
|
||||
* @return The command info.
|
||||
*/
|
||||
@Override
|
||||
public CommandInfo getCommandInfo() {
|
||||
return new CommandInfo(
|
||||
"addCalendar",
|
||||
"Starts the process of adding an external calendar",
|
||||
"!addCalendar (calendar ID)"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues the command this Object is responsible for.
|
||||
*
|
||||
* @param args The command arguments.
|
||||
* @param event The event received.
|
||||
* @return {@code true} if successful, else {@code false}.
|
||||
*/
|
||||
@Override
|
||||
public Mono<Void> issueCommand(final String[] args, final MessageCreateEvent event, final GuildSettings settings) {
|
||||
if (!(settings.getDevGuild() || settings.getPatronGuild())) {
|
||||
return Messages.sendMessage(Messages.getMessage("Notification.Patron", settings), event).then();
|
||||
}
|
||||
|
||||
return PermissionChecker.hasManageServerRole(event).flatMap(hasManageRole -> {
|
||||
if (!hasManageRole) {
|
||||
return Messages.sendMessage(Messages.getMessage("Notification.Perm.MANAGE_SERVER", settings), event);
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
return DatabaseManager.INSTANCE.getMainCalendar(settings.getGuildID())
|
||||
.hasElement()
|
||||
.flatMap(hasCal -> {
|
||||
if (hasCal) {
|
||||
return Messages.sendMessage(
|
||||
Messages.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
} else {
|
||||
return GoogleExternalAuthHandler.INSTANCE.requestCode(event, settings)
|
||||
.then(Messages.sendMessage(
|
||||
Messages.getMessage("AddCalendar.Start", settings), event));
|
||||
}
|
||||
});
|
||||
} else if (args.length == 1) {
|
||||
return DatabaseManager.INSTANCE.getMainCalendar(settings.getGuildID())
|
||||
.flatMap(data -> {
|
||||
if (!"primary".equalsIgnoreCase(data.getCalendarAddress())) {
|
||||
return Messages.sendMessage(Messages.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
} else if ("N/a".equalsIgnoreCase(data.getEncryptedAccessToken())
|
||||
&& "N/a".equalsIgnoreCase(data.getEncryptedRefreshToken())) {
|
||||
return Messages.sendMessage(Messages.getMessage("AddCalendar.Select.NotAuth", settings), event);
|
||||
} else {
|
||||
return CalendarWrapper.INSTANCE.getUsersExternalCalendars(data)
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.any(c -> !c.isDeleted() && c.getId().equals(args[0]))
|
||||
.flatMap(valid -> {
|
||||
if (valid) {
|
||||
final CalendarData newData = new CalendarData(
|
||||
data.getGuildId(), 1, CalendarHost.GOOGLE, args[0], args[0], true, 0,
|
||||
data.getPrivateKey(), data.getEncryptedAccessToken(),
|
||||
data.getEncryptedRefreshToken(), data.getExpiresAt());
|
||||
|
||||
//combine db calls and message send to be executed together async
|
||||
final Mono<Boolean> calInsert = DatabaseManager.INSTANCE.updateCalendar(newData);
|
||||
final Mono<Message> sendMsg = Messages.sendMessage(
|
||||
Messages.getMessage("AddCalendar.Select.Success", settings), event);
|
||||
|
||||
return Mono.when(calInsert, sendMsg);
|
||||
} else {
|
||||
return Messages.sendMessage(Messages
|
||||
.getMessage("AddCalendar.Select.Failure.Invalid", settings), event);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//Invalid argument count...
|
||||
return Messages.sendMessage(Messages.getMessage("AddCalendar.Specify", settings), event);
|
||||
}
|
||||
}).then();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package org.dreamexposure.discal.client.module.command;
|
||||
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.command.CommandInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author NovaFox161
|
||||
* Date Created: 9/10/2018
|
||||
* For Project: DisCal-Discord-Bot
|
||||
* Author Website: https://www.novamaday.com
|
||||
* Company Website: https://www.dreamexposure.org
|
||||
* Contact: nova@dreamexposure.org
|
||||
*/
|
||||
public interface Command {
|
||||
default String getCommand() {
|
||||
return "COMMAND_NAME";
|
||||
}
|
||||
|
||||
default List<String> getAliases() {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
|
||||
aliases.add("ALIAS");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
default CommandInfo getCommandInfo() {
|
||||
final CommandInfo info = new CommandInfo(
|
||||
"COMMAND_NAME",
|
||||
"COMMAND_DESCRIPTION",
|
||||
"!command <sub> (sub2)"
|
||||
);
|
||||
|
||||
info.getSubCommands().put("a", "b");
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
Mono<Void> issueCommand(String[] args, MessageCreateEvent event, GuildSettings settings);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package org.dreamexposure.discal.client.module.command;
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.dreamexposure.discal.client
|
||||
|
||||
import org.dreamexposure.discal.Application
|
||||
import org.dreamexposure.discal.client.message.Messages
|
||||
import org.dreamexposure.discal.core.config.Config
|
||||
import org.dreamexposure.discal.core.logger.LOGGER
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT
|
||||
@@ -17,9 +16,6 @@ class DisCalClient {
|
||||
fun main(args: Array<String>) {
|
||||
Config.init()
|
||||
|
||||
//Load lang files
|
||||
Messages.reloadLangs().subscribe()
|
||||
|
||||
//Start Spring
|
||||
try {
|
||||
SpringApplicationBuilder(Application::class.java).run(*args)
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.dreamexposure.discal.client.listeners.discord
|
||||
import discord4j.core.event.domain.lifecycle.ReadyEvent
|
||||
import discord4j.rest.util.Image
|
||||
import kotlinx.coroutines.reactor.awaitSingle
|
||||
import kotlinx.coroutines.reactor.awaitSingleOrNull
|
||||
import org.dreamexposure.discal.client.message.Messages
|
||||
import org.dreamexposure.discal.core.logger.LOGGER
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.STATUS
|
||||
@@ -19,8 +17,6 @@ class ReadyEventListener : EventListener<ReadyEvent> {
|
||||
.map { it.getIconUrl(Image.Format.PNG).orElse("") }
|
||||
.awaitSingle()
|
||||
|
||||
Messages.reloadLangs().awaitSingleOrNull()
|
||||
|
||||
LOGGER.info(STATUS, "Ready event success!")
|
||||
} catch (e: Exception) {
|
||||
LOGGER.error(DEFAULT, "Failed to handle ready event", e)
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
package org.dreamexposure.discal.client.network.google
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent
|
||||
import discord4j.core.spec.EmbedCreateSpec
|
||||
import org.dreamexposure.discal.client.message.Messages
|
||||
import org.dreamexposure.discal.core.config.Config
|
||||
import org.dreamexposure.discal.core.crypto.AESEncryption
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager
|
||||
import org.dreamexposure.discal.core.enums.calendar.CalendarHost
|
||||
import org.dreamexposure.discal.core.exceptions.google.GoogleAuthCancelException
|
||||
import org.dreamexposure.discal.core.logger.LOGGER
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.`object`.calendar.CalendarData
|
||||
import org.dreamexposure.discal.core.`object`.google.ExternalGoogleAuthPoll
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.discalColor
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal.iconUrl
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper
|
||||
import org.dreamexposure.discal.core.wrapper.google.GoogleAuthWrapper
|
||||
import org.json.JSONObject
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import reactor.function.TupleUtils
|
||||
import java.time.Instant
|
||||
import java.util.function.Predicate
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
object GoogleExternalAuthHandler {
|
||||
fun requestCode(event: MessageCreateEvent, settings: GuildSettings): Mono<Void> {
|
||||
return GoogleAuthWrapper.requestDeviceCode().flatMap { response ->
|
||||
if (response.code == GlobalVal.STATUS_SUCCESS) {
|
||||
//Got code -- Send message with code, start auth poll
|
||||
val successJson = JSONObject(response.body!!.string())
|
||||
response.body?.close()
|
||||
response.close()
|
||||
|
||||
val embed = EmbedCreateSpec.builder()
|
||||
.author("DisCal", Config.URL_BASE.getString(), iconUrl)
|
||||
.title(Messages.getMessage("Embed.AddCalendar.Code.Title", settings))
|
||||
.addField(
|
||||
Messages.getMessage("Embed.AddCalendar.Code.Code", settings),
|
||||
successJson.getString("user_code"),
|
||||
true)
|
||||
.footer(Messages.getMessage("Embed.AddCalendar.Code.Footer", settings), null)
|
||||
.url(successJson.getString("verification_url"))
|
||||
.color(discalColor)
|
||||
.build()
|
||||
|
||||
event.message.authorAsMember.flatMap { user ->
|
||||
val poll = ExternalGoogleAuthPoll(
|
||||
user,
|
||||
settings,
|
||||
interval = successJson.getInt("interval"),
|
||||
expiresIn = successJson.getInt("expires_in"),
|
||||
remainingSeconds = successJson.getInt("expires_in"),
|
||||
deviceCode = successJson.getString("device_code")
|
||||
) { this.pollForAuth(it as ExternalGoogleAuthPoll) }
|
||||
|
||||
Messages.sendDirectMessage(
|
||||
Messages.getMessage("AddCalendar.Auth.Code.Request.Success", settings),
|
||||
embed,
|
||||
user
|
||||
).then(GoogleAuthWrapper.scheduleOAuthPoll(poll))
|
||||
}
|
||||
} else {
|
||||
//Bad response -- Log, send message
|
||||
val body = response.body?.string()
|
||||
response.body?.close()
|
||||
response.close()
|
||||
LOGGER.debug(DEFAULT, "Error request access token | Status code: ${response.code} | ${
|
||||
response
|
||||
.message
|
||||
} | $body")
|
||||
|
||||
event.message.authorAsMember.flatMap {
|
||||
Messages.sendDirectMessage(
|
||||
Messages.getMessage("AddCalendar.Auth.Code.Request.Failure.NotOkay", settings), it)
|
||||
}
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun pollForAuth(poll: ExternalGoogleAuthPoll): Mono<Void> {
|
||||
return GoogleAuthWrapper.requestPollResponse(poll).flatMap { response ->
|
||||
when (response.code) {
|
||||
GlobalVal.STATUS_FORBIDDEN -> {
|
||||
//Handle access denied -- Send message, cancel poll
|
||||
Messages.sendDirectMessage(Messages.getMessage("AddCalendar.Auth.Poll.Failure.Deny", poll
|
||||
.settings), poll.user)
|
||||
.then(Mono.error(GoogleAuthCancelException()))
|
||||
}
|
||||
GlobalVal.STATUS_BAD_REQUEST, GlobalVal.STATUS_PRECONDITION_REQUIRED -> {
|
||||
//See if auth is pending, if so, just reschedule...
|
||||
val errorJson = JSONObject(response.body!!.string())
|
||||
response.body?.close()
|
||||
response.close()
|
||||
when {
|
||||
"authorization_pending".equals(errorJson.getString("error"), true) -> {
|
||||
//Response pending
|
||||
Mono.empty()
|
||||
}
|
||||
"expired_token".equals(errorJson.getString("error"), true) -> {
|
||||
//Token is expired -- Send message, cancel poll
|
||||
Messages.sendDirectMessage(Messages.getMessage("AddCal.Auth.Poll.Failure.Expired", poll
|
||||
.settings), poll.user)
|
||||
.then(Mono.error(GoogleAuthCancelException()))
|
||||
}
|
||||
else -> {
|
||||
//Unknown error -- Log, send message, cancel poll
|
||||
LOGGER.debug(DEFAULT, "[E.GCA] Poll failure", "Status: ${response.code} | ${response.message} | $errorJson")
|
||||
|
||||
Messages.sendDirectMessage(Messages.getMessage("Notification.Error.Network", poll.settings),
|
||||
poll.user)
|
||||
.then(Mono.error(GoogleAuthCancelException()))
|
||||
}
|
||||
}
|
||||
}
|
||||
GlobalVal.STATUS_RATE_LIMITED -> {
|
||||
//We got rate limited. Oops. Let's just poll half as often.
|
||||
poll.interval = poll.interval * 2
|
||||
|
||||
//Nothing else needs to be done for this to be handled
|
||||
Mono.empty<Void>()
|
||||
}
|
||||
GlobalVal.STATUS_SUCCESS -> {
|
||||
//Access granted -- Save creds, get calendars, list for user, cancel auth
|
||||
val successJson = JSONObject(response.body!!.string())
|
||||
response.body?.close()
|
||||
response.close()
|
||||
|
||||
//Save creds
|
||||
val calData = CalendarData.emptyExternal(poll.settings.guildID, CalendarHost.GOOGLE)
|
||||
val encryption = AESEncryption(calData.privateKey)
|
||||
|
||||
|
||||
val accessMono = encryption.encrypt(successJson.getString("access_token"))
|
||||
val refreshMono = encryption.encrypt(successJson.getString("refresh_token"))
|
||||
|
||||
Mono.zip(accessMono, refreshMono).flatMap(TupleUtils.function { access, refresh ->
|
||||
calData.encryptedAccessToken = access
|
||||
calData.encryptedRefreshToken = refresh
|
||||
calData.expiresAt = Instant.now().plusSeconds(successJson.getLong("expires_in"))
|
||||
|
||||
|
||||
DatabaseManager.updateCalendar(calData)
|
||||
.then(CalendarWrapper.getUsersExternalCalendars(calData))
|
||||
.flatMapMany { Flux.fromIterable(it) }
|
||||
.map { cal ->
|
||||
EmbedCreateSpec.builder()
|
||||
.author("DisCal", Config.URL_BASE.getString(), iconUrl)
|
||||
.title(Messages.getMessage("Embed.AddCalendar.List.Title", poll.settings))
|
||||
.addField(
|
||||
Messages.getMessage("Embed.AddCalendar.List.Name", poll.settings),
|
||||
cal.summary,
|
||||
false)
|
||||
.addField(
|
||||
Messages.getMessage("Embed.AddCalendar.List.TimeZone", poll.settings),
|
||||
cal.timeZone,
|
||||
false)
|
||||
.addField(
|
||||
Messages.getMessage("Embed.AddCalendar.List.ID", poll.settings),
|
||||
cal.id,
|
||||
false)
|
||||
.color(discalColor)
|
||||
.build()
|
||||
}.flatMap { Messages.sendDirectMessage(it, poll.user) }
|
||||
.switchIfEmpty {
|
||||
Messages.sendDirectMessage(
|
||||
Messages.getMessage("AddCalendar.Auth.Poll.Failure.ListCalendars", poll.settings),
|
||||
poll.user
|
||||
)
|
||||
}.then(Mono.error(GoogleAuthCancelException()))
|
||||
})
|
||||
}
|
||||
else -> {
|
||||
//Unknown error -- Log, send message, cancel poll
|
||||
LOGGER.debug(DEFAULT, "Network error | poll failure" +
|
||||
" | Status code: ${response.code} | ${response.message} | ${response.body?.string()}")
|
||||
response.body?.close()
|
||||
response.close()
|
||||
|
||||
Messages.sendDirectMessage(
|
||||
Messages.getMessage("Notification.Error.Network", poll.settings), poll.user)
|
||||
.then(Mono.error(GoogleAuthCancelException()))
|
||||
}
|
||||
}
|
||||
}.onErrorResume(Predicate.not(GoogleAuthCancelException::class::isInstance)) {
|
||||
//Other error -- Log, send message, cancel poll
|
||||
LOGGER.error(DEFAULT, "Failed to poll for authorization to google account", it)
|
||||
|
||||
Messages.sendDirectMessage(Messages.getMessage("Notification.Error.Unknown", poll.settings), poll.user)
|
||||
.then(Mono.error(GoogleAuthCancelException()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.dreamexposure.discal.core.file;
|
||||
|
||||
import kotlin.text.Charsets;
|
||||
import org.dreamexposure.discal.core.utils.GlobalVal;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by Nova Fox on 11/10/17.
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
@Deprecated
|
||||
public class ReadFile {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReadFile.class);
|
||||
|
||||
public static Mono<JSONObject> readAllLangFiles() {
|
||||
return Mono.fromCallable(() -> {
|
||||
final JSONObject langs = new JSONObject();
|
||||
|
||||
try {
|
||||
var pathMatching = new PathMatchingResourcePatternResolver();
|
||||
|
||||
for (Resource res : pathMatching.getResources("languages/*.json")) {
|
||||
var reader = new InputStreamReader(res.getInputStream(), Charsets.UTF_8);
|
||||
|
||||
// Open the file
|
||||
final String contents = FileCopyUtils.copyToString(reader);
|
||||
|
||||
//Close reader
|
||||
reader.close();
|
||||
|
||||
//Parse json
|
||||
final JSONObject json = new JSONObject(contents);
|
||||
|
||||
if (!json.getString("Language").equalsIgnoreCase("TEMPLATE"))
|
||||
langs.put(json.getString("Language"), json);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOGGER.error(GlobalVal.getDEFAULT(), "Failed to load lang files", e);
|
||||
}
|
||||
return langs;
|
||||
}).subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package org.dreamexposure.discal.core.file;
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.dreamexposure.discal.core.utils;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.rest.util.Permission;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Created by Nova Fox on 1/19/17.
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal
|
||||
*/
|
||||
@Deprecated
|
||||
public class PermissionChecker {
|
||||
public static Mono<Boolean> hasManageServerRole(final MessageCreateEvent event) {
|
||||
return Mono.justOrEmpty(event.getMember())
|
||||
.flatMap(Member::getBasePermissions)
|
||||
.map(perms -> perms.contains(Permission.MANAGE_GUILD)
|
||||
|| perms.contains(Permission.ADMINISTRATOR))
|
||||
.defaultIfEmpty(false);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package org.dreamexposure.discal.core.utils;
|
||||
@@ -13,20 +13,14 @@ import org.slf4j.Marker
|
||||
import org.slf4j.MarkerFactory
|
||||
|
||||
object GlobalVal {
|
||||
@JvmStatic
|
||||
var iconUrl: String = ""
|
||||
|
||||
@JvmStatic
|
||||
@Deprecated(message = "Using linebreak char should be sufficient")
|
||||
val lineBreak: String = System.getProperty("line.separator")
|
||||
|
||||
@JvmStatic
|
||||
val devUserIds = listOf(
|
||||
Snowflake.of(130510525770629121L), //NovaFox161
|
||||
Snowflake.of(135995653095555073L), //Dannie <3
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
val discalColor: Color = Color.of(56, 138, 237)
|
||||
val errorColor: Color = Color.of(248, 38, 48)
|
||||
val warnColor: Color = Color.of(232, 150, 0)
|
||||
@@ -64,7 +58,6 @@ object GlobalVal {
|
||||
)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val DEFAULT: Marker = MarkerFactory.getMarker("DISCAL_WEBHOOK_DEFAULT")
|
||||
|
||||
val STATUS: Marker = MarkerFactory.getMarker("DISCAL_WEBHOOK_STATUS")
|
||||
|
||||
Reference in New Issue
Block a user