diff --git a/build.gradle.kts b/build.gradle.kts index cdc0831..5d08ed2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,14 +20,14 @@ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1") implementation("com.github.pemistahl:lingua:1.2.2") - implementation("com.google.protobuf:protobuf-java:4.27.0") - implementation("com.google.protobuf:protobuf-kotlin:4.27.0") + implementation("com.google.protobuf:protobuf-java:4.27.1") + implementation("com.google.protobuf:protobuf-kotlin:4.27.1") implementation("com.ibm.icu:icu4j:75.1") implementation("com.lmax:disruptor:4.0.0") implementation("com.sun.mail:jakarta.mail:2.0.1") implementation("commons-codec:commons-codec:1.17.0") implementation("commons-io:commons-io:2.16.1") - implementation("io.netty:netty-all:4.1.110.Final") + implementation("io.netty:netty-all:4.1.111.Final") implementation("jakarta.mail:jakarta.mail-api:2.1.3") implementation("net.dv8tion:JDA:5.0.0-beta.24") implementation("org.apache.commons:commons-compress:1.26.2") @@ -36,13 +36,13 @@ implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1") implementation("org.apache.logging.log4j:log4j-core:2.23.1") implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1") - implementation("org.jline:jline:3.26.1") - implementation("org.jline:jline-terminal-jansi:3.26.1") + implementation("org.jline:jline:3.26.2") + implementation("org.jline:jline-terminal-jansi:3.26.2") implementation("org.jsoup:jsoup:1.17.2") implementation("org.mariadb.jdbc:mariadb-java-client:3.4.0") implementation("org.python:jython-standalone:2.7.3") - implementation("org.seleniumhq.selenium:selenium-edge-driver:4.21.0") - implementation("org.seleniumhq.selenium:selenium-java:4.21.0") + implementation("org.seleniumhq.selenium:selenium-edge-driver:4.22.0") + implementation("org.seleniumhq.selenium:selenium-java:4.22.0") implementation("org.tukaani:xz:1.9") implementation(kotlin("stdlib-jdk8")) testImplementation(kotlin("test")) diff --git a/src/main/kotlin/net/taehui/twilight/Twilight.kt b/src/main/kotlin/net/taehui/twilight/Twilight.kt index bb35e69..1edd2cc 100644 --- a/src/main/kotlin/net/taehui/twilight/Twilight.kt +++ b/src/main/kotlin/net/taehui/twilight/Twilight.kt @@ -19,10 +19,14 @@ import javax.net.ssl.KeyManagerFactory import javax.net.ssl.SSLContext import kotlin.io.path.absolute +import kotlin.system.exitProcess object Twilight { @JvmStatic fun main(args: Array) { + AnsiConsole.systemInstall() + PIDClass.doHaveIt() + try { Files.createDirectories(TwilightComponent.NOTE_ENTRY_PATH) Files.createDirectories(TwilightComponent.COMMENT_ENTRY_PATH) @@ -36,12 +40,13 @@ Files.createDirectories(TwilightComponent.EDGE_ENTRY_PATH) } catch (e: IOException) { System.err.println("Cannot run Twilight from ${Paths.get(".").absolute()}") - Runtime.getRuntime().exit(1) + exitProcess(1) } (if (SystemUtils.IS_OS_LINUX) EpollEventLoopGroup() else NioEventLoopGroup()).use { eventLoopGroup -> + val eventChannel: Class = + if (SystemUtils.IS_OS_LINUX) EpollServerSocketChannel::class.java else NioServerSocketChannel::class.java try { - AnsiConsole.systemInstall() Configure.loadConfigure() DB.loadDB() AbilityClassSystem.loadAbilityClass() @@ -54,20 +59,19 @@ TitleSystem.loadTitle() VoteSystem.loadVote() AutoSystem.handleSystem() - Files.newInputStream(Paths.get("Twilight.jks")).use { + val sslContext = Files.newInputStream(Paths.get("Twilight.jks")).use { val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) keyStore.load(it, Configure.javaCipherStore.pw0) val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()) keyManagerFactory.init(keyStore, Configure.javaCipherStore.pw1) val sslContext = SSLContext.getInstance("TLS") sslContext.init(keyManagerFactory.keyManagers, null, null) - val eventChannel: Class = - if (SystemUtils.IS_OS_LINUX) EpollServerSocketChannel::class.java else NioServerSocketChannel::class.java - QwilightBoot(eventLoopGroup, eventChannel, sslContext).run() - SiteBoot(eventLoopGroup, eventChannel).run() - WwwBoot(eventLoopGroup, eventChannel).run() - TaehuiBoot(eventLoopGroup, eventChannel).run() + sslContext } + val qwilightChannel = QwilightBoot(eventLoopGroup, eventChannel, sslContext).run() + val siteChannel = SiteBoot(eventLoopGroup, eventChannel).run() + val wwwChannel = WwwBoot(eventLoopGroup, eventChannel).run() + val taehuiChannel = TaehuiBoot(eventLoopGroup, eventChannel).run() TVSystem.handleSystem() NoteFilesSystem.loadNoteFiles() PlatformIDSystem.loadPlatformID() @@ -77,6 +81,10 @@ AwilightHandler.eventLoopGroup = eventLoopGroup AwilightHandler.setAwilightCount(Configure.awilightCount) AvatarHandler.sendClose(IO.handleSystem()) + qwilightChannel.close() + siteChannel.close() + wwwChannel.close() + taehuiChannel.close() } finally { WitSystem.dispose() PlatformIDSystem.savePlatformID() @@ -87,6 +95,7 @@ BannedIP.saveBannedIP() BannedNote.saveBannedNote() Configure.saveConfigure() + PIDClass.dispose() } } } diff --git a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt index 73c40cc..27cc53d 100644 --- a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt @@ -1,6 +1,7 @@ package net.taehui.twilight.qwilight import io.netty.bootstrap.ServerBootstrap +import io.netty.channel.Channel import io.netty.channel.ChannelInitializer import io.netty.channel.EventLoopGroup import io.netty.channel.socket.ServerSocketChannel @@ -17,7 +18,7 @@ eventLoopGroup: EventLoopGroup, eventChannel: Class, sslContext: SSLContext -) : Logger, Runnable { +) : Logger { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -33,9 +34,11 @@ } }) - override fun run() { + fun run(): Channel { logInfo("Loading Qwilight") - mainBootstrap.bind(6101).channel().closeFuture() - .addListener { logInfo("Closed Qwilight") } + return mainBootstrap.bind(6101).channel().closeFuture() + .addListener { + logInfo("Closed Qwilight") + }.channel() } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/site/SiteAvatar.kt b/src/main/kotlin/net/taehui/twilight/site/SiteAvatar.kt index 4efb69d..28157a7 100644 --- a/src/main/kotlin/net/taehui/twilight/site/SiteAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/site/SiteAvatar.kt @@ -1,5 +1,6 @@ package net.taehui.twilight.site +import EventOuterClass import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import com.google.protobuf.ByteString @@ -16,8 +17,8 @@ import net.taehui.twilight.Utility import net.taehui.twilight.qwilight.QwilightAvatar import net.taehui.twilight.system.AvatarHandler -import net.taehui.twilight.system.Configure import net.taehui.twilight.system.AvatarIPSystem +import net.taehui.twilight.system.Configure import net.taehui.twilight.system.SiteHandler import org.apache.commons.lang3.RandomStringUtils import org.slf4j.LoggerFactory @@ -139,7 +140,11 @@ EventOuterClass.Event.EventID.NOT_LOG_IN -> wantLoggedIn { handleNotLogIn() } EventOuterClass.Event.EventID.SITE_YELL -> wantEstablished { - SiteHandler.putSiteYell(this, jm.readValue(eventText, JSON.QwilightSiteYell::class.java), true) + SiteHandler.putSiteYell( + this, + jm.readValue(eventText, JSON.QwilightSiteYell::class.java), + true + ) } EventOuterClass.Event.EventID.GET_SITE_YELLS -> wantEstablished { diff --git a/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt b/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt index a6b4d92..8f64d32 100644 --- a/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt @@ -1,6 +1,7 @@ package net.taehui.twilight.site import io.netty.bootstrap.ServerBootstrap +import io.netty.channel.Channel import io.netty.channel.ChannelInitializer import io.netty.channel.EventLoopGroup import io.netty.channel.socket.ServerSocketChannel @@ -11,7 +12,7 @@ import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler import net.taehui.twilight.Logger -class SiteBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, Runnable { +class SiteBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -24,9 +25,11 @@ } }) - override fun run() { + fun run(): Channel { logInfo("Loading Site") - mainBootstrap.bind(6704).channel().closeFuture() - .addListener { logInfo("Closed Site") } + return mainBootstrap.bind(6704).channel().closeFuture() + .addListener { + logInfo("Closed Site") + }.channel() } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/AbilityClassSystem.kt b/src/main/kotlin/net/taehui/twilight/system/AbilityClassSystem.kt index b764d84..6ea1a1e 100644 --- a/src/main/kotlin/net/taehui/twilight/system/AbilityClassSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/AbilityClassSystem.kt @@ -33,49 +33,70 @@ return if (abilityClass > 0) drawings[drawings.size - 2] else drawings[drawings.size - 1] } - fun getText(abilityClassVariety: AbilityClassVariety, abilityClass: Double): String { + fun getValue(abilityClassVariety: AbilityClassVariety, abilityClass: Double): Int { val abilityClasses = abilityClasses[abilityClassVariety.value] for (i in abilityClasses.indices) { if (abilityClass >= abilityClasses[i]) { - when (i) { - 0 -> return "GRAND MASTERⅠ" - 1 -> return "GRAND MASTERⅡ" - 2 -> return "GRAND MASTERⅢ" - 3 -> return "GRAND MASTERⅣ" - 4 -> return "GRAND MASTERⅤ" - 5 -> return "MASTERⅠ" - 6 -> return "MASTERⅡ" - 7 -> return "MASTERⅢ" - 8 -> return "MASTERⅣ" - 9 -> return "MASTERⅤ" - 10 -> return "DIAMONDⅠ" - 11 -> return "DIAMONDⅡ" - 12 -> return "DIAMONDⅢ" - 13 -> return "DIAMONDⅣ" - 14 -> return "DIAMONDⅤ" - 15 -> return "PLATINUMⅠ" - 16 -> return "PLATINUMⅡ" - 17 -> return "PLATINUMⅢ" - 18 -> return "PLATINUMⅣ" - 19 -> return "PLATINUMⅤ" - 20 -> return "GOLDⅠ" - 21 -> return "GOLDⅡ" - 22 -> return "GOLDⅢ" - 23 -> return "GOLDⅣ" - 24 -> return "GOLDⅤ" - 25 -> return "SILVERⅠ" - 26 -> return "SILVERⅡ" - 27 -> return "SILVERⅢ" - 28 -> return "SILVERⅣ" - 29 -> return "SILVERⅤ" - 30 -> return "BRONZEⅠ" - 31 -> return "BRONZEⅡ" - 32 -> return "BRONZEⅢ" - 33 -> return "BRONZEⅣ" - } + return i } } - return if (abilityClass > 0) "BRONZEⅤ" else "UNRANKED" + return if (abilityClass > 0) 34 else 35 + } + + fun getText(abilityClassVariety: AbilityClassVariety, abilityClass: Double): String { + return when (val value = getValue(abilityClassVariety, abilityClass)) { + 0 -> "GRAND MASTERⅠ" + 1 -> "GRAND MASTERⅡ" + 2 -> "GRAND MASTERⅢ" + 3 -> "GRAND MASTERⅣ" + 4 -> "GRAND MASTERⅤ" + 5 -> "MASTERⅠ" + 6 -> "MASTERⅡ" + 7 -> "MASTERⅢ" + 8 -> "MASTERⅣ" + 9 -> "MASTERⅤ" + 10 -> "DIAMONDⅠ" + 11 -> "DIAMONDⅡ" + 12 -> "DIAMONDⅢ" + 13 -> "DIAMONDⅣ" + 14 -> "DIAMONDⅤ" + 15 -> "PLATINUMⅠ" + 16 -> "PLATINUMⅡ" + 17 -> "PLATINUMⅢ" + 18 -> "PLATINUMⅣ" + 19 -> "PLATINUMⅤ" + 20 -> "GOLDⅠ" + 21 -> "GOLDⅡ" + 22 -> "GOLDⅢ" + 23 -> "GOLDⅣ" + 24 -> "GOLDⅤ" + 25 -> "SILVERⅠ" + 26 -> "SILVERⅡ" + 27 -> "SILVERⅢ" + 28 -> "SILVERⅣ" + 29 -> "SILVERⅤ" + 30 -> "BRONZEⅠ" + 31 -> "BRONZEⅡ" + 32 -> "BRONZEⅢ" + 33 -> "BRONZEⅣ" + 34 -> "BRONZEⅤ" + 35 -> "UNRANKED" + else -> throw IllegalArgumentException(value.toString()) + } + } + + fun getPlatformAbilityText(value: Int): String { + return when (value) { + 0, 1, 2, 3, 4 -> "GRAND MASTER" + 5, 6, 7, 8, 9 -> "MASTER" + 10, 11, 12, 13, 14 -> "DIAMOND" + 15, 16, 17, 18, 19 -> "PLATINUM" + 20, 21, 22, 23, 24 -> "GOLD" + 25, 26, 27, 28, 29 -> "SILVER" + 30, 31, 32, 33, 34 -> "BRONZE" + 35 -> "UNRANKED" + else -> throw IllegalArgumentException(value.toString()) + } } fun getStatus(abilityClassVariety: AbilityClassVariety, abilityClass: Double): Double { diff --git a/src/main/kotlin/net/taehui/twilight/system/AwilightHandler.kt b/src/main/kotlin/net/taehui/twilight/system/AwilightHandler.kt index 72b24ce..5384b0e 100644 --- a/src/main/kotlin/net/taehui/twilight/system/AwilightHandler.kt +++ b/src/main/kotlin/net/taehui/twilight/system/AwilightHandler.kt @@ -36,7 +36,7 @@ HttpClients.createDefault().use { UnsafeByteOperations.unsafeWrap( it.execute( - HttpGet("https://source.unsplash.com/random?twilight"), + HttpGet("https://source.unsplash.com/random"), HCDataHandler() ) ) diff --git a/src/main/kotlin/net/taehui/twilight/system/DB.kt b/src/main/kotlin/net/taehui/twilight/system/DB.kt index c77d0ee..22541fc 100644 --- a/src/main/kotlin/net/taehui/twilight/system/DB.kt +++ b/src/main/kotlin/net/taehui/twilight/system/DB.kt @@ -2981,6 +2981,40 @@ } } + fun getMaxAbilityName(avatarID: String): String { + val rawAbilities5K = getAbilities5K() + val targetAbilities5K = getAbilities(rawAbilities5K).toList() + val targetAbility5K = + targetAbilities5K.stream().filter { it.first.first == avatarID }.map { it.second }.findAny().orElse( + Pair(0.0, false) + ).first + + val rawAbilities7K = getAbilities7K() + val targetAbilities7K = getAbilities(rawAbilities7K).toList() + val targetAbility7K = + targetAbilities7K.stream().filter { it.first.first == avatarID }.map { it.second }.findAny().orElse( + Pair(0.0, false) + ).first + + val rawAbilities9K = getAbilities9K() + val targetAbilities9K = getAbilities(rawAbilities9K).toList() + val targetAbility9K = + targetAbilities9K.stream().filter { it.first.first == avatarID }.map { it.second }.findAny().orElse( + Pair(0.0, false) + ).first + + return AbilityClassSystem.getPlatformAbilityText( + maxOf( + AbilityClassSystem.getValue( + AbilityClassSystem.AbilityClassVariety.INPUT_MODE_5K, + targetAbility5K + ), + AbilityClassSystem.getValue(AbilityClassSystem.AbilityClassVariety.INPUT_MODE_7K, targetAbility7K), + AbilityClassSystem.getValue(AbilityClassSystem.AbilityClassVariety.INPUT_MODE_9K, targetAbility9K) + ) + ) + } + fun getHandled(avatarID: String, noteID: String): Component.Handled { return pool.connection.use { db -> db.prepareStatement( diff --git a/src/main/kotlin/net/taehui/twilight/system/IO.kt b/src/main/kotlin/net/taehui/twilight/system/IO.kt index af043fa..8f86daa 100644 --- a/src/main/kotlin/net/taehui/twilight/system/IO.kt +++ b/src/main/kotlin/net/taehui/twilight/system/IO.kt @@ -404,22 +404,29 @@ continue } + "handle" -> { + PlatformSystem.handleSystem() + continue + } + "dispose" -> { PlatformSystem.dispose() continue } - "handle" -> { - PlatformSystem.handleSystem() - continue + "ability" -> { + if (w.size > 3) { + PlatformSystem.setAbility(w[2], w[3]) + continue + } } } } - logInfo("platform avatar : Handle Avatar") + logInfo("platform avatar : Put or Wipe Avatar") logInfo("platform view: View Platform") - logInfo("platform dispose: Close Platform") logInfo("platform handle: Handle Platform") + logInfo("platform dispose: Close Platform") } "ram" -> { @@ -485,20 +492,20 @@ continue } - "dispose" -> { - TVSystem.dispose() + "handle" -> { + TVSystem.handleSystem() continue } - "handle" -> { - TVSystem.handleSystem() + "dispose" -> { + TVSystem.dispose() continue } } } logInfo("tv view: View TV") - logInfo("tv dispose: Close TV") logInfo("tv handle: Handle TV") + logInfo("tv dispose: Close TV") } else -> { diff --git a/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt b/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt new file mode 100644 index 0000000..8d6ac15 --- /dev/null +++ b/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt @@ -0,0 +1,35 @@ +package net.taehui.twilight.system + +import net.taehui.twilight.Logger +import java.io.IOException +import java.nio.channels.FileChannel +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.StandardOpenOption +import kotlin.system.exitProcess + +object PIDClass : Logger { + private val FILE_PATH: Path = Path.of("Twilight.#") + private var fc: FileChannel? = null + + fun doHaveIt() { + try { + fc = FileChannel.open( + FILE_PATH, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ + ) + try { + fc?.lock() + } catch (e: IOException) { + logFault(e) + } + } catch (e: IOException) { + logInfo("Twilight is already running") + exitProcess(1) + } + } + + fun dispose() { + fc?.close() + Files.deleteIfExists(FILE_PATH) + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt index fa59916..244e2e0 100644 --- a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt @@ -6,20 +6,27 @@ import net.dv8tion.jda.api.JDABuilder import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.Member -import net.dv8tion.jda.api.entities.UserSnowflake import net.dv8tion.jda.api.entities.channel.concrete.TextChannel import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent import net.dv8tion.jda.api.events.guild.member.GuildMemberUpdateEvent import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateAvatarEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.events.message.MessageDeleteEvent import net.dv8tion.jda.api.events.message.MessageReceivedEvent import net.dv8tion.jda.api.events.message.MessageUpdateEvent import net.dv8tion.jda.api.hooks.ListenerAdapter +import net.dv8tion.jda.api.interactions.commands.OptionType +import net.dv8tion.jda.api.interactions.commands.build.Commands import net.dv8tion.jda.api.requests.GatewayIntent import net.taehui.twilight.* +import org.apache.hc.client5.http.HttpResponseException import org.apache.hc.client5.http.classic.methods.HttpGet +import org.apache.hc.client5.http.classic.methods.HttpPost +import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler import org.apache.hc.client5.http.impl.classic.HttpClients +import org.apache.hc.core5.http.ContentType +import org.apache.hc.core5.http.io.entity.StringEntity import java.text.NumberFormat import java.util.* import java.util.concurrent.CompletableFuture @@ -75,7 +82,11 @@ } platform = JDABuilder.createDefault(platformClient.platform) - .enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS) + .enableIntents( + GatewayIntent.MESSAGE_CONTENT, + GatewayIntent.GUILD_MEMBERS, + GatewayIntent.GUILD_PRESENCES + ) .addEventListeners(object : ListenerAdapter() { override fun onMessageReceived(event: MessageReceivedEvent) { event.member?.let { @@ -119,8 +130,72 @@ override fun onGuildMemberUpdate(event: GuildMemberUpdateEvent) { doCallPlatformAvatars() } + + override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) { + event.deferReply().queue() + println(Thread.currentThread().threadId()) + + when (event.name) { + "role" -> { + val platformID = event.id + if (PlatformIDSystem.hasAvatarID(platformID)) { + val abilityName = DB.getMaxAbilityName( + PlatformIDSystem.getAvatarID(platformID) + ) + setAbility( + platformID, + abilityName + ) + event.hook.sendMessage("Your role is $abilityName").setEphemeral(true).queue() + } else { + event.hook.sendMessage("You didn't log in").setEphemeral(true).queue() + } + } + + "login" -> { + val avatarID = + event.getOption("avatar")?.asString ?: throw IllegalArgumentException("avatar") + val avatarCipher = + event.getOption("pw")?.asString ?: throw IllegalArgumentException("pw") + + HttpClients.createDefault().use { + val jm = ObjectMapper() + val dataPost = HttpPost(Configure.www.taehui + "/avatar/getTotem") + dataPost.setHeader("millis", System.currentTimeMillis()) + dataPost.entity = StringEntity( + jm.writeValueAsString( + object { + val avatarID = avatarID + val avatarCipher = avatarCipher + }), ContentType.APPLICATION_JSON + ) + try { + val taehuiGetTotem = jm.readValue( + it.execute(dataPost, BasicHttpClientResponseHandler()), + JSON.TaehuiGetTotem::class.java + ) + + PlatformIDSystem.putPlatformID(event.id, avatarID) + event.hook.sendMessage("You logged in as ${taehuiGetTotem.avatarName} to Qwilight Channel") + .setEphemeral(true).queue() + } catch (e: HttpResponseException) { + event.hook.sendMessage("Failed to log in").setEphemeral(true).queue() + } + } + } + } + } }).build().awaitReady() + platform?.updateCommands()?.addCommands( + Commands.slash("login", "Log in to Qwilight Channel") + .addOption(OptionType.STRING, "avatar", "ID of 불로그", true) + .addOption(OptionType.STRING, "pw", "PW of 불로그", true) + )?.queue() + qwilightPlatform = platform?.getGuildById(platformClient.qwilight) + qwilightPlatform?.updateCommands()?.addCommands(Commands.slash("role", "Set role to Qwilight tier")) + ?.queue() + doCallPlatformAvatars() qwilightPlatform?.audioManager?.openAudioConnection(qwilightPlatform?.getVoiceChannelById(platformClient.siteAudio)) @@ -269,9 +344,12 @@ return drawingStore[avatarID] } - fun putAbility(platformID: String, abilityName: String) { - qwilightPlatform?.getRolesByName(abilityName, true)?.forEach { - qwilightPlatform?.addRoleToMember(UserSnowflake.fromId(platformID), it) + fun setAbility(platformID: String, abilityName: String) { + qwilightPlatform?.retrieveMemberById(platformID)?.queue { avatar -> + qwilightPlatform?.modifyMemberRoles( + avatar, + *(qwilightPlatform?.getRolesByName(abilityName, true)?.toTypedArray() ?: emptyArray()) + )?.queue() } } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt b/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt index cbaeb66..5115560 100644 --- a/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt @@ -1,6 +1,7 @@ package net.taehui.twilight.taehui import io.netty.bootstrap.ServerBootstrap +import io.netty.channel.Channel import io.netty.channel.ChannelInitializer import io.netty.channel.EventLoopGroup import io.netty.channel.socket.ServerSocketChannel @@ -10,7 +11,7 @@ import io.netty.handler.codec.http.HttpServerCodec import net.taehui.twilight.Logger -class TaehuiBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, Runnable { +class TaehuiBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -22,9 +23,11 @@ } }) - override fun run() { + fun run(): Channel { logInfo("Loading Taehui") - mainBootstrap.bind(8300).channel().closeFuture() - .addListener { logInfo("Closed Taehui") } + return mainBootstrap.bind(8300).channel().closeFuture() + .addListener { + logInfo("Closed Taehui") + }.channel() } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt b/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt index 093ce74..8423f22 100644 --- a/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt @@ -1,6 +1,7 @@ package net.taehui.twilight.www import io.netty.bootstrap.ServerBootstrap +import io.netty.channel.Channel import io.netty.channel.ChannelInitializer import io.netty.channel.EventLoopGroup import io.netty.channel.socket.ServerSocketChannel @@ -10,7 +11,7 @@ import io.netty.handler.codec.http.HttpServerCodec import net.taehui.twilight.Logger -class WwwBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, Runnable { +class WwwBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -22,9 +23,11 @@ } }) - override fun run() { + fun run(): Channel { logInfo("Loading Www") - mainBootstrap.bind(7301).channel().closeFuture() - .addListener { logInfo("Closed Www") } + return mainBootstrap.bind(7301).channel().closeFuture() + .addListener { + logInfo("Closed Www") + }.channel() } } \ No newline at end of file