From 73a7b23bc25d7bcf86cba38198024837e00b4d23 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 4 May 2022 11:41:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=86=85=E8=81=94?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E7=9A=84=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=92=8C=E4=BB=85=E4=BE=9B=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E9=80=82=E9=85=8D=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20user-information=20=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98=20#32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +-- .../cono/morny/bot/api/InlineQueryUnit.java | 36 +++++++++++++++++++ .../cono/morny/bot/event/OnInlineQueries.java | 16 +++++++-- .../cono/morny/bot/query/ITelegramQuery.java | 3 +- .../cono/morny/bot/query/MornyQueries.java | 8 ++--- .../cono/morny/bot/query/MyInformation.java | 12 ++++--- .../sukazyo/cono/morny/bot/query/RawText.java | 7 ++-- 8 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/api/InlineQueryUnit.java diff --git a/gradle.properties b/gradle.properties index 5c06ab4..3c3e879 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.2.0 +VERSION = 0.6.3.0 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 05db217..da23614 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -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.6.2.0"; - public static final long COMPILE_TIMESTAMP = 1647533461453L; + public static final String VERSION = "0.6.3.0"; + public static final long COMPILE_TIMESTAMP = 1651635619528L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/api/InlineQueryUnit.java b/src/main/java/cc/sukazyo/cono/morny/bot/api/InlineQueryUnit.java new file mode 100644 index 0000000..43f0376 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/api/InlineQueryUnit.java @@ -0,0 +1,36 @@ +package cc.sukazyo.cono.morny.bot.api; + +import com.pengrad.telegrambot.model.request.InlineQueryResult; + +public class InlineQueryUnit> { + + public static final int DEFAULT_INLINE_CACHE_TIME = 300; + public static final boolean DEFAULT_INLINE_PERSONAL_RESP = false; + + private int cacheTime = DEFAULT_INLINE_CACHE_TIME; + private boolean isPersonal = DEFAULT_INLINE_PERSONAL_RESP; + public final T result; + + public InlineQueryUnit (T result) { + this.result = result; + } + + public int cacheTime () { + return cacheTime; + } + + public InlineQueryUnit cacheTime (int cacheTime) { + this.cacheTime = cacheTime; + return this; + } + + public boolean isPersonal () { + return isPersonal; + } + + public InlineQueryUnit isPersonal (boolean isPersonal) { + this.isPersonal = isPersonal; + return this; + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQueries.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQueries.java index 4e113c8..ed06f0b 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQueries.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQueries.java @@ -2,6 +2,7 @@ package cc.sukazyo.cono.morny.bot.event; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.bot.api.InlineQueryUnit; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.InlineQueryResult; import com.pengrad.telegrambot.request.AnswerInlineQuery; @@ -23,11 +24,22 @@ public class OnInlineQueries extends EventListener { @Override public boolean onInlineQuery (@Nonnull Update update) { - List> results = MornyCoeur.queryManager().query(update); + List> results = MornyCoeur.queryManager().query(update); + + int cacheTime = Integer.MAX_VALUE; + boolean isPersonal = InlineQueryUnit.DEFAULT_INLINE_PERSONAL_RESP; + InlineQueryResult[] inlineQueryResults = new InlineQueryResult[results.size()]; + for (int i = 0; i < results.size(); i++) { + inlineQueryResults[i] = results.get(i).result; + if (cacheTime > results.get(i).cacheTime()) cacheTime = results.get(i).cacheTime(); + if (results.get(i).isPersonal()) isPersonal = true; + } if (results.size() == 0) return false; - MornyCoeur.extra().exec(new AnswerInlineQuery(update.inlineQuery().id(), results.toArray(InlineQueryResult[]::new))); + MornyCoeur.extra().exec(new AnswerInlineQuery( + update.inlineQuery().id(), inlineQueryResults + ).cacheTime(cacheTime).isPersonal(isPersonal)); return true; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/ITelegramQuery.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/ITelegramQuery.java index 6f1d0da..b0fa978 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/query/ITelegramQuery.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/ITelegramQuery.java @@ -2,12 +2,13 @@ package cc.sukazyo.cono.morny.bot.query; import javax.annotation.Nullable; +import cc.sukazyo.cono.morny.bot.api.InlineQueryUnit; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.InlineQueryResult; public interface ITelegramQuery > { @Nullable - T query (Update event); + InlineQueryUnit query (Update event); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/MornyQueries.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/MornyQueries.java index 8bbbd30..a10f00d 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/query/MornyQueries.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/MornyQueries.java @@ -1,7 +1,7 @@ package cc.sukazyo.cono.morny.bot.query; +import cc.sukazyo.cono.morny.bot.api.InlineQueryUnit; import com.pengrad.telegrambot.model.Update; -import com.pengrad.telegrambot.model.request.InlineQueryResult; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -17,10 +17,10 @@ public class MornyQueries { } @Nonnull - public List> query (@Nonnull Update event) { - final List> results = new ArrayList<>(); + public List> query (@Nonnull Update event) { + final List> results = new ArrayList<>(); for (ITelegramQuery instance : queryInstances) { - final InlineQueryResult r = instance.query(event); + final InlineQueryUnit r = instance.query(event); if (r!=null) results.add(r); } return results; diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/MyInformation.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/MyInformation.java index 0140b6f..7d5dcb1 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/query/MyInformation.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/MyInformation.java @@ -2,6 +2,7 @@ package cc.sukazyo.cono.morny.bot.query; import javax.annotation.Nullable; +import cc.sukazyo.cono.morny.bot.api.InlineQueryUnit; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.InlineQueryResultArticle; import com.pengrad.telegrambot.model.request.InputTextMessageContent; @@ -16,11 +17,14 @@ public class MyInformation implements ITelegramQuery { @Override @Nullable - public InlineQueryResultArticle query(Update event) { + public InlineQueryUnit query(Update event) { if (!(event.inlineQuery().query() == null || "".equals(event.inlineQuery().query()))) return null; - return new InlineQueryResultArticle(ID_PREFIX, TITLE, new InputTextMessageContent( - TelegramUserInformation.informationOutputHTML(event.inlineQuery().from()) - ).parseMode(ParseMode.HTML)); + return new InlineQueryUnit<>(new InlineQueryResultArticle( + ID_PREFIX, TITLE, + new InputTextMessageContent( + TelegramUserInformation.informationOutputHTML(event.inlineQuery().from()) + ).parseMode(ParseMode.HTML) + )).isPersonal(true).cacheTime(10); } } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java index 2e3cceb..91333ed 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java @@ -1,5 +1,6 @@ package cc.sukazyo.cono.morny.bot.query; +import cc.sukazyo.cono.morny.bot.api.InlineQueryUnit; import cc.sukazyo.cono.morny.util.EncryptUtils; import javax.annotation.Nullable; @@ -15,13 +16,13 @@ public class RawText implements ITelegramQuery { @Override @Nullable - public InlineQueryResultArticle query (Update event) { + public InlineQueryUnit query (Update event) { if (event.inlineQuery().query() == null || "".equals(event.inlineQuery().query())) return null; - return new InlineQueryResultArticle( + return new InlineQueryUnit<>(new InlineQueryResultArticle( ID_PREFIX + EncryptUtils.encryptByMD5(event.inlineQuery().query()), TITLE, new InputTextMessageContent(event.inlineQuery().query()) - ); + )); } } From b252b3de51e2c6c23348760882b8b5059f3359c1 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Fri, 29 Apr 2022 17:44:34 +0800 Subject: [PATCH 2/4] #30 add support(warnlog) to /user command to channel identify --- gradle.properties | 2 +- .../cc/sukazyo/cono/morny/GradleProjectConfigures.java | 2 +- .../cono/morny/bot/command/GetUsernameAndId.java | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3c3e879..d270904 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.3.0 +VERSION = 0.6.3.1 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index da23614..cfd598d 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -5,5 +5,5 @@ package cc.sukazyo.cono.morny; */ public class GradleProjectConfigures { public static final String VERSION = "0.6.3.0"; - public static final long COMPILE_TIMESTAMP = 1651635619528L; + public static final long COMPILE_TIMESTAMP = 1651804975121L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java index f7d136f..627b6c3 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java @@ -32,7 +32,7 @@ public class GetUsernameAndId implements ITelegramCommand { long userId = event.message().from().id(); - if ( event.message().replyToMessage()!= null) { + if (event.message().replyToMessage()!= null) { userId = event.message().replyToMessage().from().id(); } if (args.length > 0) { @@ -61,6 +61,14 @@ public class GetUsernameAndId implements ITelegramCommand { final User user = response.chatMember().user(); + if (user.id() == 136817688) { + MornyCoeur.extra().exec(new SendMessage( + event.message().chat().id(), + "$__channel_identify" + )); + return; + } + MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), TelegramUserInformation.informationOutputHTML(user) From b5941494f69d9d18b2bb3e5097669fdc040302be Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Fri, 6 May 2022 11:27:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?#30=20=E4=BD=BF=20SlashAction=20=E7=9A=84?= =?UTF-8?q?=E5=9B=9E=E6=89=A7=E6=94=AF=E6=8C=81=E9=A2=91=E9=81=93=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 但由于API限制,链接无法导向至频道 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +-- .../morny/bot/event/OnUserSlashAction.java | 15 +++++----- .../util/tgapi/TGToStringFromMessage.java | 30 +++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java diff --git a/gradle.properties b/gradle.properties index d270904..5c9ffe4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.3.1 +VERSION = 0.6.3.2 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index cfd598d..d08ca5a 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -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.6.3.0"; - public static final long COMPILE_TIMESTAMP = 1651804975121L; + public static final String VERSION = "0.6.3.2"; + public static final long COMPILE_TIMESTAMP = 1651806802187L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java index bfb5da3..b624a23 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java @@ -2,12 +2,13 @@ package cc.sukazyo.cono.morny.bot.event; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.util.tgapi.TGToStringFromMessage; import cc.sukazyo.untitled.telegram.api.formatting.TGToString; import cc.sukazyo.untitled.util.command.CommonCommand; import cc.sukazyo.untitled.util.string.StringArrays; +import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; -import com.pengrad.telegrambot.model.User; import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.request.SendMessage; @@ -55,22 +56,22 @@ public class OnUserSlashAction extends EventListener { hasObject ? StringArrays.connectStringArray(action, " ", isHardParse?2:1, action.length-1) : ""; - final User origin = event.message().from(); - final User target = (event.message().replyToMessage() == null ? ( + final Message origin = event.message(); + final Message target = (event.message().replyToMessage() == null ? ( origin ): ( - event.message().replyToMessage().from() + event.message().replyToMessage() )); MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), String.format( "%s %s%s %s %s!", - TGToString.as(origin).firstnameRefHtml(), + TGToStringFromMessage.as(origin).getSenderFirstNameRefHtml(), escapeHtml(verb), escapeHtml((hasObject?"":"了")), origin==target ? - "自己" : - TGToString.as(target).firstnameRefHtml(), + "自己" : + TGToStringFromMessage.as(target).getSenderFirstNameRefHtml(), escapeHtml(hasObject ? object+" " : "") ) ).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId())); diff --git a/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java new file mode 100644 index 0000000..e4fac35 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java @@ -0,0 +1,30 @@ +package cc.sukazyo.cono.morny.util.tgapi; + +import cc.sukazyo.untitled.telegram.api.formatting.TGToString; +import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape; +import com.pengrad.telegrambot.model.Message; + +import javax.annotation.Nonnull; + +public class TGToStringFromMessage extends TGToString { + + @Nonnull + private final Message message; + + public TGToStringFromMessage (@Nonnull Message message) { this.message = message; } + public static TGToStringFromMessage as (@Nonnull Message message) { return new TGToStringFromMessage(message); } + + @Nonnull + public String getSenderFirstNameRefHtml () { + return message.senderChat()==null ? TGToString.as(message.from()).firstnameRefHtml() : String.format( + "%s", + message.senderChat().id(), + MsgEscape.escapeHtml(message.senderChat().title()) + ); + } + + public long getSenderId () { + return message.senderChat()==null ? message.from().id() : message.senderChat().id(); + } + +} From 7ce151b9bfe7302e72a3328e0b3eda9ca92f13c0 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 10 May 2022 23:10:38 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20calling"=E5=AE=89?= =?UTF-8?q?=E5=A6=AE=E4=BB=8A=E5=A4=A9=E5=90=83=E4=BB=80=E4=B9=88"=20?= =?UTF-8?q?=E5=92=8C=E5=85=B6=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > merged from major/0.6-hot-update/calling-last-dinner-get - 添加对私聊的 "安妮今天吃什么" 事件处理 - 添加 --trusted-reader-dinner 参数用于指定一个用户可以获取"安妮今天吃什么"的数据 - 参数可以重复指定,以便为多个账户授权 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../cc/sukazyo/cono/morny/MornyCoeur.java | 14 ++--- .../cc/sukazyo/cono/morny/MornyTrusted.java | 14 ++++- .../cc/sukazyo/cono/morny/ServerMain.java | 10 +++- .../cono/morny/bot/event/OnCallMe.java | 53 +++++++++++++++++++ 6 files changed, 86 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5c9ffe4..fb078c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.3.2 +VERSION = 0.6.3.3 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index d08ca5a..deefd90 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -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.6.3.2"; - public static final long COMPILE_TIMESTAMP = 1651806802187L; + public static final String VERSION = "0.6.3.3"; + public static final long COMPILE_TIMESTAMP = 1652195187089L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java index 07ff390..90ae3e1 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java @@ -6,13 +6,12 @@ import cc.sukazyo.cono.morny.bot.event.EventListeners; import cc.sukazyo.cono.morny.bot.query.MornyQueries; import cc.sukazyo.cono.morny.data.tracker.TrackerDataManager; import cc.sukazyo.untitled.telegram.api.extra.ExtraAction; - import com.pengrad.telegrambot.TelegramBot; -import com.pengrad.telegrambot.model.DeleteMyCommands; import com.pengrad.telegrambot.request.GetMe; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Set; import static cc.sukazyo.cono.morny.Log.logger; @@ -58,6 +57,8 @@ public class MornyCoeur { */ public static final long coeurStartTimestamp = System.currentTimeMillis(); + public static final long DINNER_CHAT_ID = -1001707106392L; + private record LogInResult(TelegramBot account, String username) { } /** @@ -74,7 +75,8 @@ public class MornyCoeur { */ private MornyCoeur ( @Nonnull String botKey, @Nullable String botUsername, - long master, long trustedChat, long latestEventTimestamp, + long master, long trustedChat, Set trustedRDinner, + long latestEventTimestamp, boolean isRemoveCommandListWhenExit ) { @@ -91,7 +93,7 @@ public class MornyCoeur { final LogInResult loginResult = login(botKey, botUsername); this.account = loginResult.account; this.username = loginResult.username; - this.trusted = new MornyTrusted(master, trustedChat); + this.trusted = new MornyTrusted(master, trustedChat, trustedRDinner); logger.info(String.format(""" trusted param set: - master (id) @@ -122,14 +124,14 @@ public class MornyCoeur { */ public static void main ( @Nonnull String botKey, @Nullable String botUsername, - long master, long trustedChat, long latestEventTimestamp, + long master, long trustedChat, Set trustedRDinner, long latestEventTimestamp, boolean isAutomaticResetCommandList, boolean isRemoveCommandListWhenExit ) { if (INSTANCE == null) { logger.info("System Starting"); INSTANCE = new MornyCoeur( botKey, botUsername, - master, trustedChat, + master, trustedChat, trustedRDinner, latestEventTimestamp, isRemoveCommandListWhenExit ); diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java b/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java index eb9305e..1c7009a 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java @@ -1,6 +1,8 @@ package cc.sukazyo.cono.morny; import com.pengrad.telegrambot.model.ChatMember.Status; +import java.util.HashSet; +import java.util.Set; /** * 对用户进行身份权限验证的管理类 @@ -19,9 +21,15 @@ public class MornyTrusted { */ public final long MASTER; - public MornyTrusted (long master, long trustedChatId) { + public final Set TRUSTED_READERS_OF_DINNER; + + public MornyTrusted (long master, long trustedChatId, Set trustedRDinner) { this.TRUSTED_CHAT_ID = trustedChatId; this.MASTER = master; + this.TRUSTED_READERS_OF_DINNER = new HashSet<>(){{ + this.add(master); + this.addAll(trustedRDinner); + }}; } /** @@ -39,4 +47,8 @@ public class MornyTrusted { return MornyCoeur.extra().isUserInGroup(userId, TRUSTED_CHAT_ID, Status.administrator); } + public boolean isTrustedForDinnerRead (long userId) { + return TRUSTED_READERS_OF_DINNER.contains(userId); + } + } diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java index b7d9d78..88a269c 100644 --- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java +++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java @@ -4,6 +4,9 @@ import cc.sukazyo.cono.morny.util.CommonFormatUtils; import javax.annotation.Nonnull; +import java.util.HashSet; +import java.util.Set; + import static cc.sukazyo.cono.morny.Log.logger; /** @@ -75,6 +78,7 @@ public class ServerMain { String username = null; boolean outdatedBlock = false; long master = 793274677L; + Set trustedReadersOfDinner = new HashSet<>(); long trustedChat = -1001541451710L; boolean autoCmdList = false; boolean autoCmdRemove = false; @@ -120,6 +124,10 @@ public class ServerMain { trustedChat = Long.parseLong(args[i]); continue; } + case "--trusted-reader-dinner" -> { + trustedReadersOfDinner.add(Long.parseLong(args[i])); + continue; + } case "--auto-cmd-list", "-ca" -> { autoCmdList = true; continue; @@ -165,7 +173,7 @@ public class ServerMain { } MornyCoeur.main( key, username, - master, trustedChat, + master, trustedChat, trustedReadersOfDinner, outdatedBlock?System.currentTimeMillis():0, autoCmdList, autoCmdRemove ); diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java index ef4e85b..1684d69 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java @@ -4,13 +4,18 @@ 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 cc.sukazyo.cono.morny.util.CommonFormatUtils; import cc.sukazyo.untitled.telegram.api.formatting.TGToString; +import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape; import com.pengrad.telegrambot.model.Chat; +import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.request.ForwardMessage; +import com.pengrad.telegrambot.request.GetChat; import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.request.SendSticker; +import com.pengrad.telegrambot.response.SendResponse; import javax.annotation.Nonnull; @@ -46,6 +51,8 @@ public class OnCallMe extends EventListener { requestSteamJoin(update); case "hana paresu", "花宫", "内群" -> requestHanaParesuJoin(update); + case "dinner", "lunch", "breakfast", "meal", "eating", "安妮今天吃什么" -> + requestLastDinner(update); default -> { if (update.message().text().startsWith("cc::")) { requestCustomCall(update); @@ -96,6 +103,52 @@ public class OnCallMe extends EventListener { ).parseMode(ParseMode.HTML)); } + /** + * 对访问最近一次的饭局的请求进行回复
+ * + * @param event 执行呼叫的tg事件 + */ + private static void requestLastDinner (Update event) { + boolean isAllowed = false; + Message lastDinnerData = null; + if (MornyCoeur.trustedInstance().isTrustedForDinnerRead(event.message().from().id())) { + lastDinnerData = MornyCoeur.extra().exec(new GetChat(MornyCoeur.DINNER_CHAT_ID)).chat().pinnedMessage(); + SendResponse sendResp = MornyCoeur.extra().exec(new ForwardMessage( + event.message().from().id(), + lastDinnerData.forwardFromChat().id(), + lastDinnerData.forwardFromMessageId() + )); + MornyCoeur.extra().exec(new SendMessage( + event.message().from().id(), + String.format("on %s [UTC+8]\n- %s before", + MsgEscape.escapeHtml( + CommonFormatUtils.formatDate((long)lastDinnerData.forwardDate()*1000, 8) + ), MsgEscape.escapeHtml( + CommonFormatUtils.formatDuration(System.currentTimeMillis()-(long)lastDinnerData.forwardDate()*1000) + ) + ) + ).replyToMessageId(sendResp.message().messageId()).parseMode(ParseMode.HTML)); + isAllowed = true; + } else { + MornyCoeur.extra().exec(new SendSticker( + event.message().from().id(), + TelegramStickers.ID_403 + ).replyToMessageId(event.message().messageId())); + } + MornyCoeur.extra().exec(new SendMessage( + ME, String.format( + """ + request Last Annie Dinner + from %s + %s""", + TGToString.as(event.message().from()).fullnameRefHtml(), + isAllowed ? "Allowed and returned " + String.format( + "https://t.me/c/%d/%d", Math.abs(lastDinnerData.forwardFromChat().id()+1000000000000L), lastDinnerData.forwardFromMessageId() + ) : "Forbidden by perm check." + ) + ).parseMode(ParseMode.HTML)); + } + /** * 执行自定义呼叫
* 将会向 {@link #ME} 发送一个 request 数据消息和转发的原始请求消息