feat: started working on Status, added TokenManager

Changes by Redtronics123
This commit is contained in:
limited_dev 2023-03-26 00:41:34 +01:00
parent 0c3cee73a1
commit e01f5be61e
2 changed files with 98 additions and 0 deletions

View file

@ -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 <https://www.gnu.org/licenses/>.
*
*/
package de.limited_dev.botendo.util
import de.limited_dev.botendo.Bot
object Status {
suspend fun updateStatus() {
Bot.kord!!.editPresence {
this.playing("")
}
}
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*
*/
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()
}
}
}