Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loritta's Lorituber #2666

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.perfectdreams.loritta.common.lorituber

enum class LoriTuberVideoContentCategory {
ANIMATION,
GAMES,
COMEDY,
BEAUTY,
EDUCATION,
TECHNOLOGY,
REAL_LIFE,
DOCUMENTARY,
FINANCE,
POLITICS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.perfectdreams.loritta.common.lorituber

enum class LoriTuberVideoContentVibes {
VIBE1,
VIBE2,
VIBE3,
VIBE4,
VIBE5,
VIBE6,
VIBE7
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.perfectdreams.loritta.common.lorituber

enum class LoriTuberVideoResolution {
RESOLUTION_240P,
RESOLUTION_360P,
RESOLUTION_720P,
RESOLUTION_1080P,
RESOLUTION_1440P,
RESOLUTION_2160P
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.perfectdreams.loritta.common.lorituber

enum class LoriTuberVideoStage {
RECORDING,
EDITING,
RENDERING,
THUMBNAIL,
FINISHED
}
2 changes: 2 additions & 0 deletions loritta-bot-discord/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(project(":discord-chat-message-renderer-entities"))
implementation(project(":lori-public-http-api-common"))
implementation(project(":yokye"))
implementation(project(":lorituber-rpc"))

// Kotlin Serialization
implementation(libs.kotlinx.serialization.json)
Expand Down Expand Up @@ -45,6 +46,7 @@ dependencies {
implementation("dev.kord:kord-core:0.8.x-lori-fork-20221109.172532-14")
implementation("dev.kord:kord-voice:0.8.x-lori-fork-20221109.172532-15")

// Exposed & Databases
// Exposed & Databases
implementation(libs.postgresqljdbcdriver)
implementation(libs.hikaricp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.perfectdreams.loritta.lorituber

import kotlinx.serialization.Serializable

@Serializable
sealed class LoriTuberEngagementType {
// Changing the engagementStartTick causes the easing simulation to change
abstract val engagementStartTick: Long
abstract val engagementEndTick: Long
abstract val startViews: Int
abstract val startLikes: Int
abstract val startDislikes: Int
abstract val targetViews: Int
abstract val targetLikes: Int
abstract val targetDislikes: Int

abstract fun simulateEngagement(currentTick: Long, engagementCycleProgress: Double): SimulatedEngagement

@Serializable
class EaseOutQuint(
override val engagementStartTick: Long,
override val engagementEndTick: Long,
override val startViews: Int,
override val startLikes: Int,
override val startDislikes: Int,
override val targetViews: Int,
override val targetLikes: Int,
override val targetDislikes: Int
): LoriTuberEngagementType() {
override fun simulateEngagement(currentTick: Long, engagementCycleProgress: Double): SimulatedEngagement {
val engagementCycleViews = targetViews - startViews
val engagementCycleLikes = targetLikes - startLikes
val engagementCycleDislikes = targetDislikes - startDislikes

val easedEngagement = easeOutQuint(engagementCycleProgress)

return SimulatedEngagement(
(engagementCycleViews * easedEngagement).toInt(),
(engagementCycleLikes * easedEngagement).toInt(),
(engagementCycleDislikes * easedEngagement).toInt()
)
}

private fun easeOutQuint(x: Double): Double {
return 1 - Math.pow(1 - x, 5.0)
}
}

@Serializable
class Linear(
override val engagementStartTick: Long,
override val engagementEndTick: Long,
override val startViews: Int,
override val startLikes: Int,
override val startDislikes: Int,
override val targetViews: Int,
override val targetLikes: Int,
override val targetDislikes: Int
): LoriTuberEngagementType() {
override fun simulateEngagement(currentTick: Long, engagementCycleProgress: Double): SimulatedEngagement {
val engagementCycleViews = targetViews - startViews
val engagementCycleLikes = targetLikes - startLikes
val engagementCycleDislikes = targetDislikes - startDislikes

return SimulatedEngagement(
(engagementCycleViews * engagementCycleProgress).toInt(),
(engagementCycleLikes * engagementCycleProgress).toInt(),
(engagementCycleDislikes * engagementCycleProgress).toInt()
)
}
}

data class SimulatedEngagement(
val views: Int,
val likes: Int,
val dislikes: Int
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.perfectdreams.loritta.lorituber

import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
import java.util.*
import kotlin.time.measureTime
import kotlin.time.measureTimedValue

data class TestVideo(
val title: String,
var views: Int,
var likes: Int,
var dislikes: Int
)

fun main() {
val videos = mutableListOf<TestVideo>()

repeat(1_000_000) {
if (it % 5_000 == 0) {
println(it)
}

videos.add(TestVideo(UUID.randomUUID().toString(), 0, 0, 0))
}

repeat(10) {
val d = measureTimedValue {
videos.forEach {
it.views++
it.likes++
it.dislikes++
}

videos.size
}

println(d)
}

File("test_fm.db").delete()

// We want to always create a database, no matter if it exists or not
val cfg: HikariConfig = HikariConfig().apply {
jdbcUrl = "jdbc:sqlite:test_fm.db"
maximumPoolSize = 1
}

val dataSource = HikariDataSource(cfg)

val videosDatabase = Database.connect(dataSource)

val d = measureTime {
transaction(videosDatabase) {
SchemaUtils.createMissingTablesAndColumns(
LoriTuberVideosTest
)

LoriTuberVideosTest.batchInsert(
videos
) {
this[LoriTuberVideosTest.name] = it.title
this[LoriTuberVideosTest.likes] = it.likes
this[LoriTuberVideosTest.dislikes] = it.dislikes
this[LoriTuberVideosTest.views] = it.views
}
}
}

println("${d}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.perfectdreams.loritta.lorituber

data class LoriTuberGroceryItem(
val item: LoriTuberItem,
val inStock: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.perfectdreams.loritta.lorituber

data class LoriTuberItem(
val id: String,
val name: String,
val description: String,
val price: Long,
val foodAttributes: FoodAttributes?
) {
data class FoodAttributes(
val hunger: Long,
val ticks: Long
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package net.perfectdreams.loritta.lorituber

object LoriTuberItems {
private val items = mutableMapOf<String, LoriTuberItem>()
val allItems
get() = items.values

val SLICED_BREAD = register(
"sliced_bread",
"Pão de Forma",
"Apenas um simples Pão de Forma",
100,
LoriTuberItem.FoodAttributes(
3,
20
)
)

// TODO: Update the name + description
val GESSY_CEREAL = register(
"gessy_cereal",
"Cereal do Gessy",
"Apenas um simples Pão de Forma",
100,
LoriTuberItem.FoodAttributes(
2,
20
)
)

// TODO: Update the name + description
val MILK = register(
"milk",
"Leite",
"Apenas um simples Pão de Forma",
100,
LoriTuberItem.FoodAttributes(
2,
20
)
)

val STRAWBERRY_YOGURT = register(
"strawberry_yogurt",
"Iogurte de Morango",
"Apenas um simples Iogurte delisia",
150,
LoriTuberItem.FoodAttributes(
3,
20
)
)

// TODO: Update the name + description
val GESSY_CEREAL_WITH_MILK = register(
"gessy_cereal_with_milk",
"Cereal do Gessy com Leite",
"Cereal com leite delícia",
100,
LoriTuberItem.FoodAttributes(
2,
20
)
)

val GESSY_CEREAL_WITH_STRAWBERRY_YOGURT = register(
"gessy_cereal_with_strawberry_yogurt",
"Cereal do Gessy com Iogurte de Morango",
"Cereal com iogurte delícia",
100,
LoriTuberItem.FoodAttributes(
2,
20
)
)

// TODO: Update the name + description
val SLOP = register(
"slop",
"Gororoba",
"Uma Gororoba",
0,
LoriTuberItem.FoodAttributes(
2,
100
)
)

fun register(
id: String,
name: String,
description: String,
price: Long,
foodAttributes: LoriTuberItem.FoodAttributes? = null
): LoriTuberItem {
val itemWithNamespace = "lorituber:${id}"

val item = LoriTuberItem(
itemWithNamespace,
name,
description,
price,
foodAttributes
)

items[itemWithNamespace] = item
return item
}

fun getByIdOrNull(id: String): LoriTuberItem? = items[id]
fun getById(id: String) = getByIdOrNull(id) ?: error("Unknown item \"$id\"!")
}
Loading