添加呼叫主人以进行某些事件请求的新功能,MornyTrusted 添加主人id记录与认证

This commit is contained in:
A.C.Sukazyo Eyre 2021-12-14 23:15:39 +08:00
parent ff428f76b2
commit 6219773ebc
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
6 changed files with 88 additions and 4 deletions

View File

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

View File

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

View File

@ -14,6 +14,12 @@ public class MornyTrusted {
*/ */
public static final long TRUSTED_CHAT_ID = -1001541451710L; public static final long TRUSTED_CHAT_ID = -1001541451710L;
/**
* morny 的主人<br>
* 这项值的对象总是会被认为是可信任的
*/
public static final long MASTER = 793274677L;
/** /**
* 用于检查一个 telegram-user 是否受信任<br> * 用于检查一个 telegram-user 是否受信任<br>
* <br> * <br>
@ -25,6 +31,7 @@ public class MornyTrusted {
* @return 所传递的用户id对应的用户是否受信任 * @return 所传递的用户id对应的用户是否受信任
*/ */
public static boolean isTrusted (long userId) { public static boolean isTrusted (long userId) {
if (userId == MASTER) return true;
final ChatMember chatMember = MornyCoeur.getAccount().execute(new GetChatMember(TRUSTED_CHAT_ID, userId)).chatMember(); final ChatMember chatMember = MornyCoeur.getAccount().execute(new GetChatMember(TRUSTED_CHAT_ID, userId)).chatMember();
return ( return (
chatMember != null && ( chatMember != null && (

View File

@ -9,6 +9,7 @@ public class EventListeners {
public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction(); public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction();
public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock(); public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock();
public static final OnInlineQuery INLINE_QUERY = new OnInlineQuery(); public static final OnInlineQuery INLINE_QUERY = new OnInlineQuery();
public static final OnCallMe CALL_ME = new OnCallMe();
public static void registerAllListeners () { public static void registerAllListeners () {
EventListenerManager.addListener( EventListenerManager.addListener(
@ -16,7 +17,8 @@ public class EventListeners {
UPDATE_TIMESTAMP_OFFSET_LOCK, UPDATE_TIMESTAMP_OFFSET_LOCK,
COMMANDS_LISTENER, COMMANDS_LISTENER,
USER_SLASH_ACTION, USER_SLASH_ACTION,
INLINE_QUERY INLINE_QUERY,
CALL_ME
); );
} }

View File

@ -0,0 +1,74 @@
package cc.sukazyo.cono.morny.bot.event;
import cc.sukazyo.cono.morny.MornyCoeur;
import cc.sukazyo.cono.morny.MornyTrusted;
import cc.sukazyo.cono.morny.bot.api.EventListener;
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.SendMessage;
import com.pengrad.telegrambot.request.SendSticker;
import org.jetbrains.annotations.NotNull;
/**
* @since 0.4.2.1
*/
public class OnCallMe extends EventListener {
/**
* @since 0.4.2.1
*/
private static final long ME = MornyTrusted.MASTER;
@Override
public boolean onMessage (@NotNull Update update) {
if (update.message().text() == null)
return false;
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:
return false;
}
MornyCoeur.getAccount().execute(new SendSticker(
update.message().chat().id(),
TelegramStickers.ID_SENT
).replyToMessageId(update.message().messageId())
);
return true;
}
private static void requestSteamJoin (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
ME, String.format("""
request <b>STEAM LIBRARY</b>
from <a href="tg://user?id=%d">%s</a>""",
event.message().from().id(),
event.message().from().firstName() + " " + event.message().from().lastName()
)
).parseMode(ParseMode.HTML));
}
private static void requestHanaParesuJoin (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
ME, String.format("""
request <b>Hana Paresu</b>
from <a href="tg://user?id=%d">%s</a>""",
event.message().from().id(),
event.message().from().firstName() + " " + event.message().from().lastName()
)
).parseMode(ParseMode.HTML));
}
}

View File

@ -12,5 +12,6 @@ public class TelegramStickers {
public static final String ID_403 = "CAACAgEAAxkBAAMqYYYa_7hpXH6hMOYMX4Nh8AVYd74AAnQnAAJ4_MYFRdmmsQKLDZgiBA"; public static final String ID_403 = "CAACAgEAAxkBAAMqYYYa_7hpXH6hMOYMX4Nh8AVYd74AAnQnAAJ4_MYFRdmmsQKLDZgiBA";
public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA"; public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA";
public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA"; public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA";
public static final String ID_SENT = "CAACAgEAAx0CSQh32gABA--zYbiyU_wOijEitp-0tSl_k7W6l3gAAgMmAAJ4_MYF4GrompjXPx4jBA";
} }