mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-25 12:37:39 +08:00
添加呼叫主人以进行某些事件请求的新功能,MornyTrusted 添加主人id记录与认证
This commit is contained in:
parent
ff428f76b2
commit
6219773ebc
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.4.2.0
|
VERSION = 0.4.2.1
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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 && (
|
||||||
|
@ -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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
74
src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java
Normal file
74
src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java
Normal 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user