From e01f5be61e36505bfed0dadf9ecc49de84def240 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Sun, 26 Mar 2023 00:41:34 +0100 Subject: [PATCH] feat: started working on Status, added TokenManager Changes by Redtronics123 --- .../de/limited_dev/botendo/util/Status.kt | 30 ++++++++ .../limited_dev/botendo/util/TokenManager.kt | 68 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/kotlin/de/limited_dev/botendo/util/Status.kt create mode 100644 src/main/kotlin/de/limited_dev/botendo/util/TokenManager.kt diff --git a/src/main/kotlin/de/limited_dev/botendo/util/Status.kt b/src/main/kotlin/de/limited_dev/botendo/util/Status.kt new file mode 100644 index 0000000..23203bf --- /dev/null +++ b/src/main/kotlin/de/limited_dev/botendo/util/Status.kt @@ -0,0 +1,30 @@ +/* + * Botendo + * Copyright (C) 2023 limited_dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package de.limited_dev.botendo.util + +import de.limited_dev.botendo.Bot + +object Status { + suspend fun updateStatus() { + Bot.kord!!.editPresence { + this.playing("") + } + } +} diff --git a/src/main/kotlin/de/limited_dev/botendo/util/TokenManager.kt b/src/main/kotlin/de/limited_dev/botendo/util/TokenManager.kt new file mode 100644 index 0000000..0763a4a --- /dev/null +++ b/src/main/kotlin/de/limited_dev/botendo/util/TokenManager.kt @@ -0,0 +1,68 @@ +/* + * Botendo + * Copyright (C) 2023 limited_dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package de.limited_dev.botendo.util + +import java.io.* +import java.util.* + +object TokenManager { + private const val filename = "token.nils" + var token: String = "empty" + + ///Load the bot token, generate a config if there is none + fun load() { + val configFile = File(filename) + if (!configFile.exists()) { + save() + return + } + try { + val input: InputStream = FileInputStream(filename) + val prop = Properties() + prop.load(input) + token = if (prop.getProperty("token").equals("empty")) "empty" else prop.getProperty("token") + input.close() + } catch (e: IOException) { + e.printStackTrace() + } + } + + ///generate a new sample config + private fun save() { + val configFile = File(filename) + if (!configFile.exists()) { + try { + configFile.createNewFile() + } catch (e: IOException) { + e.printStackTrace() + } + } + try { + val output: OutputStream = FileOutputStream(filename) + val prop = Properties() + prop.setProperty("token", "empty") + prop.store(output, null) + output.close() + } catch (e: IOException) { + e.printStackTrace() + } + } + +}