添加自定义呼叫功能,添加 event_hack 命令与呼叫功能的 javadoc

This commit is contained in:
A.C.Sukazyo Eyre 2021-12-15 12:06:55 +08:00
parent 6219773ebc
commit 12b4c91829
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
5 changed files with 77 additions and 14 deletions

View File

@ -1,6 +1,6 @@
## Core
VERSION = 0.4.2.1
VERSION = 0.4.2.2
# dependencies

View File

@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
* the final field that will be updated by gradle automatically.
*/
public class GradleProjectConfigures {
public static final String VERSION = "0.4.2.1";
public static final long COMPILE_TIMESTAMP = 1639494688933L;
public static final String VERSION = "0.4.2.2";
public static final long COMPILE_TIMESTAMP = 1639541150226L;
}

View File

@ -7,20 +7,32 @@ import cc.sukazyo.cono.morny.data.TelegramStickers;
import com.pengrad.telegrambot.model.Chat;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.model.request.ParseMode;
import com.pengrad.telegrambot.request.ForwardMessage;
import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.request.SendSticker;
import org.jetbrains.annotations.NotNull;
/**
* 通过 bot 呼叫主人的事件监听管理类
* @since 0.4.2.1
*/
public class OnCallMe extends EventListener {
/**
* 主人的 telegram user id同时被用于 chat id<br>
* 跟随 {@link MornyTrusted#MASTER} 的值
* @since 0.4.2.1
*/
private static final long ME = MornyTrusted.MASTER;
/**
* 监听私聊 bot 的消息进行呼叫关键字匹配
* 如果成功将会执行呼叫函数并向呼叫者回显{@link TelegramStickers#ID_WAITING "已呼叫"贴纸}
*
* @param update 事件基础参数消息事件所属的 tgapi:update 对象
* @return 事件基础返回值是否已完成处理事件<br>
* 如果匹配到呼叫则返回{@code true}反之返回{@code false}
*/
@Override
public boolean onMessage (@NotNull Update update) {
if (update.message().text() == null)
@ -28,18 +40,17 @@ public class OnCallMe extends EventListener {
if (update.message().chat().type() != Chat.Type.Private)
return false;
switch (update.message().text().toLowerCase()) {
case "steam":
case "sbeam":
case "sdeam":
requestSteamJoin(update);
break;
case "hana paresu":
case "花宫":
case "内群":
requestHanaParesuJoin(update);
break;
default:
case "steam", "sbeam", "sdeam" ->
requestSteamJoin(update);
case "hana paresu", "花宫", "内群" ->
requestHanaParesuJoin(update);
default -> {
if (update.message().text().startsWith("cc::")) {
requestCustomCall(update);
break;
}
return false;
}
}
MornyCoeur.getAccount().execute(new SendSticker(
update.message().chat().id(),
@ -49,6 +60,12 @@ public class OnCallMe extends EventListener {
return true;
}
/**
* 执行 steam library 呼叫<br>
* 将会向 {@link #ME} 发送
*
* @param event 执行呼叫的tg事件
*/
private static void requestSteamJoin (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
ME, String.format("""
@ -60,6 +77,12 @@ public class OnCallMe extends EventListener {
).parseMode(ParseMode.HTML));
}
/**
* 执行花宫呼叫<br>
* 将会向 {@link #ME} 发送
*
* @param event 执行呼叫的tg事件
*/
private static void requestHanaParesuJoin (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
ME, String.format("""
@ -71,4 +94,31 @@ public class OnCallMe extends EventListener {
).parseMode(ParseMode.HTML));
}
/**
* 执行自定义呼叫<br>
* 将会向 {@link #ME} 发送一个 request 数据消息和转发的原始请求消息<br>
* <br>
* <u>known issue</u><ul>
* <li>无法处理与转发带有媒体的消息</li>
* </ul>
*
* @param event 执行呼叫的tg事件
* @since 0.4.2.2
*/
private static void requestCustomCall (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
ME, String.format("""
request <u>[???]</u>
from <a href="tg://user?id=%d">%s</a>""",
event.message().from().id(),
event.message().from().firstName() + " " + event.message().from().lastName()
)
).parseMode(ParseMode.HTML));
MornyCoeur.getAccount().execute(new ForwardMessage(
ME,
event.message().chat().id(),
event.message().messageId()
));
}
}

View File

@ -9,11 +9,20 @@ import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.SendSticker;
/**
* {@link OnEventHackHandle} 的命令行前端
* @since 0.4.2.0
*/
public class EventHack {
/**
* {@link OnEventHackHandle} 的命令行前端<br>
* <br>
* 实现了通过命令行进行 EventHack 功能<br>
* 支持三种模式默认为 {@link OnEventHackHandle.HackType#USER USER}
* {@link OnEventHackHandle.HackType#ANY ANY} 将会通过 {@link MornyTrusted#isTrusted(long)} 检查触发用户的权限
*
* @param event 命令基础参数触发的事件对象本身
* @param command 命令基础参数解析出的命令对象
* @since 0.4.2.0
*/
public static void exec (Update event, InputCommand command) {

View File

@ -0,0 +1,4 @@
package cc.sukazyo.cono.morny.bot.event.on_commands;
public class Roll {
}