Initial Commit
This commit is contained in:
commit
d190beb7bf
13 changed files with 382 additions and 0 deletions
48
src/main/scala/db/schema/ScopesVersion.scala
Normal file
48
src/main/scala/db/schema/ScopesVersion.scala
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package unit_ca5.db.schema
|
||||
|
||||
import unit_ca5.twitch.TokenScope
|
||||
|
||||
trait ScopesVersion:
|
||||
val scopes: List[TokenScope]
|
||||
val version: Int
|
||||
|
||||
def toScopes(): List[TokenScope] = scopes
|
||||
|
||||
def toInt(): Int = version
|
||||
|
||||
def matches(version: Int): Boolean =
|
||||
this.version == version
|
||||
|
||||
def matches(scopes: List[TokenScope]): Boolean =
|
||||
this.scopes == scopes
|
||||
|
||||
|
||||
object ScopesVersion:
|
||||
val allScopesVersions: List[ScopesVersion] = List(
|
||||
scopesVersion1
|
||||
)
|
||||
|
||||
// Construct from a list of scopes
|
||||
def apply(scopes: List[TokenScope]): Option[ScopesVersion] =
|
||||
allScopesVersions.find(
|
||||
(candidate: ScopesVersion) =>
|
||||
candidate.matches(scopes)
|
||||
)
|
||||
|
||||
// Construct from a version number
|
||||
def apply(version: Int): Option[ScopesVersion] =
|
||||
allScopesVersions.find(
|
||||
(candidate: ScopesVersion) =>
|
||||
candidate.matches(version)
|
||||
)
|
||||
|
||||
val scopesVersion1: ScopesVersion =
|
||||
new ScopesVersion:
|
||||
val scopes = List(
|
||||
TokenScope.UserReadChat,
|
||||
TokenScope.BitsRead,
|
||||
TokenScope.ChannelManageRaids
|
||||
)
|
||||
val version = 1
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue