mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-11 05:44:48 +08:00
to merge
This commit is contained in:
parent
6dd6162f78
commit
cebbceddcc
@ -22,37 +22,6 @@ import java.util.function.Function;
|
|||||||
* 事件处理
|
* 事件处理
|
||||||
*/
|
*/
|
||||||
public final class Events {
|
public final class Events {
|
||||||
|
|
||||||
private static void printDeprecated(){
|
|
||||||
System.err.println("Events.subscribe is deprecated, it will be remove soon");
|
|
||||||
System.err.println("Please use PluginBase.getEventListener");
|
|
||||||
System.err.println("Events.subscribe 即将在下个版本移除");
|
|
||||||
System.err.println("请更换为PluginBase.getEventListener");
|
|
||||||
System.err.println("Events.subscribe is deprecated, it will be remove soon");
|
|
||||||
System.err.println("Please use PluginBase.getEventListener");
|
|
||||||
System.err.println("Events.subscribe 即将在下个版本移除");
|
|
||||||
System.err.println("请更换为PluginBase.getEventListener");
|
|
||||||
System.err.println("Events.subscribe is deprecated, it will be remove soon");
|
|
||||||
System.err.println("Please use PluginBase.getEventListener");
|
|
||||||
System.err.println("Events.subscribe 即将在下个版本移除");
|
|
||||||
System.err.println("请更换为PluginBase.getEventListener");
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Deprecated()
|
|
||||||
public static <E extends Event> Listener<E> subscribe(@NotNull Class<E> eventClass, @NotNull Function<E, ListeningStatus> onEvent) {
|
|
||||||
printDeprecated();
|
|
||||||
return EventsImplKt.subscribeEventForJaptOnly(eventClass, GlobalScope.INSTANCE, onEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Deprecated()
|
|
||||||
public static <E extends Event> Listener<E> subscribeAlways(@NotNull Class<E> eventClass, @NotNull Consumer<E> onEvent) {
|
|
||||||
printDeprecated();
|
|
||||||
return EventsImplKt.subscribeEventForJaptOnly(eventClass, GlobalScope.INSTANCE, onEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阻塞地广播一个事件.
|
* 阻塞地广播一个事件.
|
||||||
*
|
*
|
||||||
|
@ -11,20 +11,20 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class BotManager {
|
public class BotManager {
|
||||||
|
|
||||||
static List<Long> getManagers(long botAccount) {
|
public static List<Long> getManagers(long botAccount) {
|
||||||
Bot bot = MiraiConsole.INSTANCE.getBotOrThrow(botAccount);
|
Bot bot = MiraiConsole.INSTANCE.getBotOrThrow(botAccount);
|
||||||
return getManagers(bot);
|
return getManagers(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Long> getManagers(Bot bot){
|
public static List<Long> getManagers(Bot bot){
|
||||||
return BotHelperKt.getBotManagers(bot);
|
return BotHelperKt.getBotManagers(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isManager(Bot bot, long target){
|
public static boolean isManager(Bot bot, long target){
|
||||||
return getManagers(bot).contains(target);
|
return getManagers(bot).contains(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isManager(long botAccount, long target){
|
public static boolean isManager(long botAccount, long target){
|
||||||
return getManagers(botAccount).contains(target);
|
return getManagers(botAccount).contains(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,113 @@
|
|||||||
|
package net.mamoe.mirai.console.utils
|
||||||
|
|
||||||
|
import net.mamoe.mirai.Bot
|
||||||
|
import net.mamoe.mirai.console.command.CommandSender
|
||||||
|
import net.mamoe.mirai.console.command.GroupContactCommandSender
|
||||||
|
import net.mamoe.mirai.contact.Group
|
||||||
|
import net.mamoe.mirai.contact.QQ
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this output type of that arg
|
||||||
|
* input is always String
|
||||||
|
*/
|
||||||
|
interface CommandArg<T:Any>{
|
||||||
|
operator fun invoke():T = get()
|
||||||
|
|
||||||
|
fun get():T
|
||||||
|
|
||||||
|
fun read(s:String, commandSender: CommandSender)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract class CommandArgImpl<T:Any>(
|
||||||
|
):CommandArg<T>{
|
||||||
|
|
||||||
|
lateinit var value:T
|
||||||
|
|
||||||
|
override fun get(): T = value
|
||||||
|
|
||||||
|
override fun read(s: String, commandSender: CommandSender) {
|
||||||
|
value = parse(s, commandSender)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun parse(s:String, commandSender: CommandSender):T
|
||||||
|
}
|
||||||
|
|
||||||
|
class IntArg:CommandArgImpl<Int>(){
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): Int {
|
||||||
|
return try{
|
||||||
|
s.toInt()
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("无法识别整数$s")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LongArg:CommandArgImpl<Long>(){
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): Long {
|
||||||
|
return try{
|
||||||
|
s.toLong()
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("无法识别长整数$s")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DoubleArg:CommandArgImpl<Double>(){
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): Double {
|
||||||
|
return try{
|
||||||
|
s.toDouble()
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("无法识别小数$s")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class StringArg:CommandArgImpl<String>(){
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): String {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* require a bot that already login in console
|
||||||
|
* input: Bot UIN
|
||||||
|
* output: Bot
|
||||||
|
* errors: String->Int convert, Bot Not Exist
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ExistBotArg:CommandArgImpl<Bot>(){
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): Bot {
|
||||||
|
val uin = try{
|
||||||
|
s.toLong()
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("无法识别QQ UIN$s")
|
||||||
|
}
|
||||||
|
return try{
|
||||||
|
Bot.getInstance(uin)
|
||||||
|
}catch (e:NoSuchElementException){
|
||||||
|
error("无法找到Bot $uin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ExistGroupArg:CommandArgImpl<Group>(){
|
||||||
|
|
||||||
|
override fun parse(s: String, commandSender: CommandSender): Group {
|
||||||
|
if((s === "" || s === "~") && commandSender is GroupContactCommandSender){
|
||||||
|
return commandSender.contact as Group
|
||||||
|
}
|
||||||
|
|
||||||
|
val code = try{
|
||||||
|
s.toLong()
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("无法识别Group Code$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
TODO()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package net.mamoe.mirai.console.utils
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Value
|
||||||
|
* the input type of this Value is T while the output is V
|
||||||
|
*/
|
||||||
|
abstract class Value<T,V>{
|
||||||
|
operator fun invoke():V = get()
|
||||||
|
|
||||||
|
abstract fun get():V
|
||||||
|
|
||||||
|
abstract fun set(t:T)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This value can be used as a Config Value
|
||||||
|
*/
|
||||||
|
interface ConfigValue
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple value
|
||||||
|
* the input type is same as output value
|
||||||
|
*/
|
||||||
|
|
||||||
|
open class SimpleValue<T>(
|
||||||
|
var value:T
|
||||||
|
):Value<T,T>() {
|
||||||
|
override fun get() = this.value
|
||||||
|
|
||||||
|
override fun set(t: T) {
|
||||||
|
this.value = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class NullableSimpleValue<T>(
|
||||||
|
value:T? = null
|
||||||
|
):SimpleValue<T?>(
|
||||||
|
value
|
||||||
|
){
|
||||||
|
fun isNull() = value == null
|
||||||
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ fun Bot.addManagerDeprecated(long: Long) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ToBeRemoved::class)
|
@OptIn(ToBeRemoved::class)
|
||||||
fun Bot.addManager(long: Long): Boolean {
|
internal fun Bot.addManager(long: Long): Boolean {
|
||||||
BOT_MANAGERS.putIfAbsent(this.id.toString(), mutableListOf<Long>())
|
BOT_MANAGERS.putIfAbsent(this.id.toString(), mutableListOf<Long>())
|
||||||
BOT_MANAGERS[this.id.toString()] =
|
BOT_MANAGERS[this.id.toString()] =
|
||||||
(BOT_MANAGERS.getLongList(this.id.toString()) as MutableList<Long>).apply {
|
(BOT_MANAGERS.getLongList(this.id.toString()) as MutableList<Long>).apply {
|
||||||
|
Loading…
Reference in New Issue
Block a user