-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
605 additions
and
45 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/top/wsure/warframe/cache/ConstantObject.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,18 @@ | ||
package top.wsure.warframe.cache | ||
|
||
import java.util.* | ||
import kotlin.collections.HashMap | ||
|
||
/** | ||
* FileName: TaskCache | ||
* Author: wsure | ||
* Date: 2021/3/31 10:31 上午 | ||
* Description: | ||
*/ | ||
object ConstantObject { | ||
val taskMap: MutableMap<String, Pair<Timer,TimerTask>> = HashMap() | ||
|
||
const val TASK_HOLDER = "updateTaskLoop" | ||
|
||
const val INITIATIVE_NOTIFY = "INITIATIVE_NOTIFY_ALL_GROUP" | ||
} |
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
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,46 @@ | ||
package top.wsure.warframe.command | ||
|
||
import net.mamoe.mirai.console.command.CommandSender | ||
import net.mamoe.mirai.console.command.CompositeCommand | ||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors | ||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi | ||
import net.mamoe.mirai.contact.User | ||
import net.mamoe.mirai.message.data.PlainText | ||
import top.wsure.warframe.WorldState | ||
import top.wsure.warframe.data.WorldStateData | ||
import top.wsure.warframe.utils.PromiseUtils | ||
|
||
object EditMaster : CompositeCommand( | ||
WorldState, | ||
"master", | ||
"主人", "骂死他", | ||
description = "bot-master-tools插件设置" | ||
) { | ||
@ExperimentalCommandDescriptors | ||
@ConsoleExperimentalApi | ||
override val prefixOptional = true | ||
|
||
@SubCommand("list", "show", "列表") | ||
@Description("master列表") | ||
suspend fun CommandSender.list() { | ||
sendMessage(PlainText(WorldStateData.masters.joinToString("\n"))) | ||
} | ||
|
||
@SubCommand("add", "加", "plus","增加","添加") | ||
@Description("+ master") | ||
suspend fun CommandSender.add(user: User) { | ||
if (PromiseUtils.isMaster(this.user)) { | ||
val isSuccess = WorldStateData.masters.add(user.id) | ||
sendMessage(PlainText("添加${user.id}${if (isSuccess) "成功" else "失败"}")) | ||
} | ||
} | ||
|
||
@SubCommand("del", "remove", "rm","delete","删","减","删除","去除","移除") | ||
@Description("- master") | ||
suspend fun CommandSender.del(user: User) { | ||
if (PromiseUtils.isMaster(this.user)) { | ||
val isSuccess = WorldStateData.masters.remove(user.id) | ||
sendMessage(PlainText("删除${user.id}${if (isSuccess) "成功" else "失败"}")) | ||
} | ||
} | ||
} |
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,119 @@ | ||
package top.wsure.warframe.command | ||
|
||
import net.mamoe.mirai.Bot | ||
import net.mamoe.mirai.console.command.CommandSender | ||
import net.mamoe.mirai.console.command.CompositeCommand | ||
import net.mamoe.mirai.console.command.ConsoleCommandSender | ||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors | ||
import net.mamoe.mirai.console.command.isConsole | ||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi | ||
import net.mamoe.mirai.message.data.PlainText | ||
import top.wsure.warframe.WorldState | ||
import top.wsure.warframe.data.RemoteTask | ||
import top.wsure.warframe.data.TaskEnum | ||
import top.wsure.warframe.data.WorldStateData | ||
import top.wsure.warframe.utils.PromiseUtils | ||
|
||
/** | ||
* FileName: EditTask | ||
* Author: wsure | ||
* Date: 2021/4/1 8:39 下午 | ||
* Description: | ||
*/ | ||
object EditTask : CompositeCommand( | ||
WorldState, | ||
"task", | ||
"任务", "定时任务", | ||
description = "定时任务设置" | ||
) { | ||
@ExperimentalCommandDescriptors | ||
@ConsoleExperimentalApi | ||
override val prefixOptional = true | ||
|
||
|
||
@SubCommand("list", "show", "列表") | ||
@Description("task list") | ||
suspend fun CommandSender.list() { | ||
if(isConsole()){ | ||
sendMessage(PlainText(WorldStateData.taskList.filter { it.type == TaskEnum.NOTIFY_GROUP }.joinToString("\n") { task -> | ||
"${task.name} - 间隔${(task.period / 60 / 1000).toDouble()}分钟" | ||
})) | ||
} else { | ||
val groupId = PromiseUtils.getGroupId(this) | ||
if (groupId != null) { | ||
var groupSetting = WorldStateData.groupTaskSetting[groupId] | ||
if (groupSetting == null) { | ||
groupSetting = HashMap() | ||
WorldStateData.groupTaskSetting[groupId] = groupSetting | ||
} | ||
sendMessage(PlainText(getGroupTaskSetting(groupSetting))) | ||
} | ||
} | ||
} | ||
|
||
@SubCommand("add", "加", "plus", "增加", "添加", "enable", "open", "开", "启用", "使用") | ||
@Description("+task") | ||
suspend fun CommandSender.add(task: String) { | ||
if(isConsole()){ | ||
setAllGroupTaskList(task,this,true) | ||
} else { | ||
setGroupTaskList(task, this,true) | ||
} | ||
} | ||
|
||
@SubCommand("del", "remove", "rm", "delete", "删", "减", "删除", "去除", "移除", "关", "关闭", "禁用", "停用", "disable", "close") | ||
@Description("-task") | ||
suspend fun CommandSender.del(task: String) { | ||
if(isConsole()){ | ||
setAllGroupTaskList(task,this,false) | ||
} else { | ||
setGroupTaskList(task, this,false) | ||
} | ||
} | ||
|
||
suspend fun setGroupTaskList( | ||
task: String, | ||
sender: CommandSender, | ||
enabled:Boolean | ||
) { | ||
val remoteTask = WorldStateData.taskList.find { it.name == task } | ||
val groupId = PromiseUtils.getGroupId(sender) | ||
if (remoteTask != null && groupId != null) { | ||
var groupSetting = WorldStateData.groupTaskSetting[groupId] | ||
if (groupSetting == null) { | ||
groupSetting = HashMap() | ||
WorldStateData.groupTaskSetting[groupId] = groupSetting | ||
} | ||
setOperator(sender,groupId, remoteTask,enabled) | ||
} | ||
} | ||
|
||
suspend fun setOperator(sender: CommandSender,groupId: Long, task: RemoteTask,enabled:Boolean){ | ||
if (PromiseUtils.isManage(sender)) { | ||
WorldStateData.groupTaskSetting[groupId]?.set(task.name, enabled) | ||
sender.sendMessage(PlainText("群${groupId} ${if (enabled) "启用" else "禁用" } ${task.name} 成功")) | ||
} | ||
} | ||
|
||
suspend fun setAllGroupTaskList( | ||
task: String, | ||
sender: CommandSender, | ||
enabled:Boolean | ||
) { | ||
val remoteTask = WorldStateData.taskList.find { it.name == task } | ||
if (remoteTask != null) { | ||
val groups = Bot.instances.map { it.groups }.flatten().distinct() | ||
groups.forEach { | ||
setOperator(sender,it.id , remoteTask,enabled) | ||
} | ||
} | ||
} | ||
|
||
fun getGroupTaskSetting(groupSetting: MutableMap<String, Boolean>): String { | ||
return WorldStateData.taskList.filter { it.type == TaskEnum.NOTIFY_GROUP }.joinToString("\n") { task -> | ||
"${task.name} - 间隔${(task.period / 60 / 1000).toDouble()}分钟 - 状态: ${ | ||
if (groupSetting.getOrDefault(task.name, false)) "开启" else "关闭" | ||
} " | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/top/wsure/warframe/command/SendToAllGroup.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,35 @@ | ||
package top.wsure.warframe.command | ||
|
||
import net.mamoe.mirai.console.MiraiConsole | ||
import net.mamoe.mirai.console.command.CommandSender | ||
import net.mamoe.mirai.console.command.RawCommand | ||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors | ||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi | ||
import net.mamoe.mirai.message.data.MessageChain | ||
import net.mamoe.mirai.utils.MiraiLogger | ||
import top.wsure.warframe.WorldState | ||
import top.wsure.warframe.cache.ConstantObject.INITIATIVE_NOTIFY | ||
import top.wsure.warframe.utils.NotifyUtils.Companion.notifyAllGroup | ||
import top.wsure.warframe.utils.PromiseUtils.Companion.isMaster | ||
|
||
@ConsoleExperimentalApi | ||
object SendToAllGroup : RawCommand( | ||
WorldState, | ||
"发送全部群", | ||
"sendToAllGroup" | ||
) { | ||
private val logger: MiraiLogger = MiraiConsole.createLogger(this.javaClass.canonicalName) | ||
|
||
@ExperimentalCommandDescriptors | ||
override val prefixOptional = true | ||
|
||
override suspend fun CommandSender.onCommand(args: MessageChain) { | ||
if (isMaster(this.user)) { | ||
val msg = args.joinToString(" ") { it.contentToString() } | ||
logger.info("发送全部群 :${msg}") | ||
sendMessage("发送全部群 完成,耗时:${notifyAllGroup(this.bot, args,INITIATIVE_NOTIFY)}ms") | ||
logger.info("发送全部群 :完成") | ||
} | ||
} | ||
|
||
} |
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,12 @@ | ||
package top.wsure.warframe.data | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* FileName: RemoteQueue | ||
* Author: wsure | ||
* Date: 2021/3/30 10:23 上午 | ||
* Description: | ||
*/ | ||
@Serializable | ||
data class RemoteQueue(val key:String,val timeout:Long) : java.io.Serializable |
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 |
---|---|---|
|
@@ -18,8 +18,8 @@ data class RemoteTask( | |
) | ||
|
||
enum class TaskEnum{ | ||
NOTIFY, | ||
UPDATE, | ||
NOTIFY_GROUP, | ||
NOTIFY_MASTER, | ||
REFRESH, | ||
PULL, | ||
} |
Oops, something went wrong.