mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
建立 InlineQuery 抽象层与管理器
This commit is contained in:
parent
6dbe214476
commit
a229ce9add
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.5.0.1
|
VERSION = 0.5.0.2
|
||||||
|
|
||||||
# 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.5.0.1";
|
public static final String VERSION = "0.5.0.2";
|
||||||
public static final long COMPILE_TIMESTAMP = 1643447337882L;
|
public static final long COMPILE_TIMESTAMP = 1643612350660L;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny;
|
|||||||
import cc.sukazyo.cono.morny.bot.api.OnUpdate;
|
import cc.sukazyo.cono.morny.bot.api.OnUpdate;
|
||||||
import cc.sukazyo.cono.morny.bot.command.MornyCommands;
|
import cc.sukazyo.cono.morny.bot.command.MornyCommands;
|
||||||
import cc.sukazyo.cono.morny.bot.event.EventListeners;
|
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.cono.morny.data.tracker.TrackerDataManager;
|
||||||
import cc.sukazyo.untitled.telegram.api.extra.ExtraAction;
|
import cc.sukazyo.untitled.telegram.api.extra.ExtraAction;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class MornyCoeur {
|
|||||||
private final MornyTrusted trusted;
|
private final MornyTrusted trusted;
|
||||||
/** 当前 Morny 的 telegram 命令管理器 */
|
/** 当前 Morny 的 telegram 命令管理器 */
|
||||||
private final MornyCommands commandManager = new MornyCommands();
|
private final MornyCommands commandManager = new MornyCommands();
|
||||||
|
private final MornyQueries queryManager = new MornyQueries();
|
||||||
|
|
||||||
/** morny 的 bot 账户 */
|
/** morny 的 bot 账户 */
|
||||||
private final TelegramBot account;
|
private final TelegramBot account;
|
||||||
@ -255,6 +257,11 @@ public class MornyCoeur {
|
|||||||
return INSTANCE.commandManager;
|
return INSTANCE.commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static MornyQueries queryManager () {
|
||||||
|
return INSTANCE.queryManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static ExtraAction extra () {
|
public static ExtraAction extra () {
|
||||||
return INSTANCE.extraActionInstance;
|
return INSTANCE.extraActionInstance;
|
||||||
|
@ -8,7 +8,7 @@ public class EventListeners {
|
|||||||
public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
||||||
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 OnInlineQueries INLINE_QUERY = new OnInlineQueries();
|
||||||
public static final OnCallMe CALL_ME = new OnCallMe();
|
public static final OnCallMe CALL_ME = new OnCallMe();
|
||||||
public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle();
|
public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle();
|
||||||
|
|
||||||
|
@ -2,14 +2,12 @@ package cc.sukazyo.cono.morny.bot.event;
|
|||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||||
import cc.sukazyo.cono.morny.util.EncryptUtils;
|
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
import com.pengrad.telegrambot.model.request.InlineQueryResult;
|
||||||
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
|
||||||
import com.pengrad.telegrambot.request.AnswerInlineQuery;
|
import com.pengrad.telegrambot.request.AnswerInlineQuery;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* telegram inlineQuery 功能的处理类,
|
* telegram inlineQuery 功能的处理类,
|
||||||
@ -17,21 +15,21 @@ import javax.annotation.Nonnull;
|
|||||||
*
|
*
|
||||||
* @since 0.4.1.3
|
* @since 0.4.1.3
|
||||||
*/
|
*/
|
||||||
public class OnInlineQuery extends EventListener {
|
public class OnInlineQueries extends EventListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.4.1.3
|
* @since 0.4.1.3
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onInlineQuery (@Nonnull Update update) {
|
public boolean onInlineQuery (@Nonnull Update update) {
|
||||||
MornyCoeur.extra().exec(new AnswerInlineQuery(update.inlineQuery().id(), new InlineQueryResultArticle[]{
|
|
||||||
new InlineQueryResultArticle(
|
List<InlineQueryResult<?>> results = MornyCoeur.queryManager().query(update);
|
||||||
EncryptUtils.encryptByMD5(update.inlineQuery().query()),
|
|
||||||
"Raw Input",
|
if (results.size() == 0) return false;
|
||||||
new InputTextMessageContent(update.inlineQuery().query()).parseMode(ParseMode.MarkdownV2)
|
|
||||||
)
|
MornyCoeur.extra().exec(new AnswerInlineQuery(update.inlineQuery().id(), results.toArray(InlineQueryResult[]::new)));
|
||||||
}));
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineQueryResult;
|
||||||
|
|
||||||
|
public interface ITelegramQuery <T extends InlineQueryResult<T>> {
|
||||||
|
|
||||||
|
T query (Update event);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineQueryResult;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MornyQueries {
|
||||||
|
|
||||||
|
private final List<ITelegramQuery<?>> queryInstances = new ArrayList<>();
|
||||||
|
|
||||||
|
public MornyQueries () {
|
||||||
|
queryInstances.add(new RawText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public List<InlineQueryResult<?>> query (@Nonnull Update event) {
|
||||||
|
final List<InlineQueryResult<?>> results = new ArrayList<>();
|
||||||
|
for (ITelegramQuery<?> instance : queryInstances) {
|
||||||
|
final InlineQueryResult<?> r = instance.query(event);
|
||||||
|
if (r!=null) results.add(r);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java
Normal file
21
src/main/java/cc/sukazyo/cono/morny/bot/query/RawText.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.EncryptUtils;
|
||||||
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
||||||
|
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
||||||
|
|
||||||
|
public class RawText implements ITelegramQuery<InlineQueryResultArticle> {
|
||||||
|
|
||||||
|
public static final String TITLE = "Raw Text";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InlineQueryResultArticle query (Update event) {
|
||||||
|
return new InlineQueryResultArticle(
|
||||||
|
"[morny/r/txt]" + EncryptUtils.encryptByMD5(event.inlineQuery().query()),
|
||||||
|
TITLE,
|
||||||
|
new InputTextMessageContent(event.inlineQuery().query())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user