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

添加经济接口 #5

Merged
merged 5 commits into from Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions build.gradle.kts
@@ -1,9 +1,13 @@
import net.mamoe.mirai.console.gradle.BuildMiraiPluginTask

MrXiaoM marked this conversation as resolved.
Show resolved Hide resolved
plugins {
kotlin("jvm") version "1.6.21"
kotlin("plugin.serialization") version "1.6.21"

id("net.mamoe.mirai-console") version "2.11.1"
id("net.mamoe.maven-central-publish") version "0.7.1"

id("me.him188.kotlin-jvm-blocking-bridge") version "2.0.0-162.1"
}

group = "io.github.skynet1748"
Expand Down Expand Up @@ -47,3 +51,8 @@ tasks {
useJUnitPlatform()
}
}

// buildPluginLegacy
tasks.withType<BuildMiraiPluginTask>() {
archiveBaseName.set("[Legacy]" + archiveBaseName.get())
}
8 changes: 8 additions & 0 deletions settings.gradle.kts
@@ -1 +1,9 @@
pluginManagement {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

rootProject.name = "mirai-economy-core"
@@ -0,0 +1,73 @@
package io.github.skynet1748.mirai.economy

/**
* 经济服务,用于存取数据和获取经济上下文
*/
public interface IEconomyService {
public fun getGlobalContext(): IEconomyContextGlobal
public fun getGroupContext(groupId: Long): IEconomyContextGroup
}

/**
* 经济上下文,用于区分当前环境分开存取用户数据
*/
public interface IEconomyContext {
/**
* 该上下文的显示名称
*/
public val name: String
public val service: IEconomyService

/**
* 创建账户
*/
public fun createAccount(userId: Long, money: Double = 0.0)

/**
* 查询是否有该账户
*/
public fun hasAccount(userId: Long): Boolean

/**
* 列出账户列表
* @param count 列出的数量,0为无限制
*/
public fun listAccounts(count: Int = 0): List<Long>

/**
* 查询账户是否有足够的钱 (余额 >= money)
*/
public fun has(userId: Long, money: Double): Boolean

/**
* 获取账户余额
*/
public fun get(userId: Long): Double

/**
* 设置账户余额
*/
public fun set(userId: Long, money: Double)

/**
* 将钱存入账户
*/
public fun increase(userId: Long, money: Double): Double

/**
* 从账户中取钱
*/
public fun decrease(userId: Long, money: Double): Double
}

/**
* 全局上下文,适用于好友等非群聊环境
*/
public interface IEconomyContextGlobal : IEconomyContext

/**
* 群聊上下文,适用于群聊环境
*/
public interface IEconomyContextGroup : IEconomyContext {
public val groupId: Long
}