-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from SkyNet1748/MrXiaoM-patch-2
添加经济接口
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/io/github/skynet1748/mirai/economy/IEconomyService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |