55 lines
1.9 KiB
Kotlin
55 lines
1.9 KiB
Kotlin
package nl.voidcorp.ottobot
|
|
|
|
import net.dv8tion.jda.api.entities.Activity
|
|
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder
|
|
import net.dv8tion.jda.api.sharding.ShardManager
|
|
import nl.voidcorp.ottobot.command.Command
|
|
import nl.voidcorp.ottobot.database.*
|
|
import nl.voidcorp.ottobot.events.CommandListener
|
|
import nl.voidcorp.ottobot.events.DisconnectListenerAdapter
|
|
import nl.voidcorp.ottobot.events.OttoListener
|
|
import org.jetbrains.exposed.sql.Database
|
|
import org.jetbrains.exposed.sql.SchemaUtils
|
|
import org.jetbrains.exposed.sql.selectAll
|
|
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
import org.slf4j.Logger
|
|
import org.slf4j.LoggerFactory
|
|
import java.sql.Connection
|
|
|
|
val logger: Logger = LoggerFactory.getLogger("OttoBot")
|
|
const val creator = 168743656738521088
|
|
lateinit var jda: ShardManager
|
|
|
|
fun main() {
|
|
val token: String = System.getenv("DISCORD_TOKEN") ?: throw RuntimeException("Missing DISCORD_TOKEN in env!")
|
|
Database.connect(
|
|
System.getenv("JDBC_URL") ?: "jdbc:sqlite:test.db",
|
|
System.getenv("JDBC_DRIVER") ?: "org.sqlite.JDBC",
|
|
System.getenv("JDBC_USER") ?: "",
|
|
System.getenv("JDBC_PASSWORD") ?: ""
|
|
)
|
|
TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
|
|
transaction {
|
|
SchemaUtils.createMissingTablesAndColumns(GuildStores)
|
|
SchemaUtils.createMissingTablesAndColumns(
|
|
GuildStoreAdminRoles,
|
|
GuildStoreBotChannels,
|
|
GuildStoreModeratorRoles,
|
|
GuildStoreRoleMap
|
|
)
|
|
}
|
|
startBot(token)
|
|
}
|
|
|
|
fun startBot(token: String) {
|
|
|
|
val builder = DefaultShardManagerBuilder.createDefault(token)
|
|
|
|
builder.addEventListeners(CommandListener(Command.allCommands), DisconnectListenerAdapter, OttoListener)
|
|
jda = builder.build()
|
|
jda.setActivityProvider {
|
|
Activity.playing("v3.0 ($it)")
|
|
}
|
|
|
|
} |