diff --git a/gradle.properties b/gradle.properties index 3c89bfe..5576ec9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.8.0.7 +VERSION = 0.8.0.8 CODENAME = putian diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index d6ac208..2c188e6 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,7 +4,7 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.8.0.7"; + public static final String VERSION = "0.8.0.8"; public static final String CODENAME = "putian"; - public static final long COMPILE_TIMESTAMP = 1665827278036L; + public static final long COMPILE_TIMESTAMP = 1665999835121L; } 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 b0fa978..c79ab37 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 @@ -4,11 +4,12 @@ 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 > { +import java.util.List; + +public interface ITelegramQuery { @Nullable - InlineQueryUnit query (Update event); + List> 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 a10f00d..a561303 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 @@ -9,19 +9,20 @@ import java.util.List; public class MornyQueries { - private final List> queryInstances = new ArrayList<>(); + private final List queryInstances = new ArrayList<>(); public MornyQueries () { queryInstances.add(new RawText()); queryInstances.add(new MyInformation()); + queryInstances.add(new ShareToolTwitter()); } @Nonnull public List> query (@Nonnull Update event) { final List> results = new ArrayList<>(); - for (ITelegramQuery instance : queryInstances) { - final InlineQueryUnit r = instance.query(event); - if (r!=null) results.add(r); + for (ITelegramQuery instance : queryInstances) { + final List> r = instance.query(event); + if (r!=null) results.addAll(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 53f666a..7921174 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 @@ -10,21 +10,26 @@ import com.pengrad.telegrambot.model.request.ParseMode; import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramUserInformation; -public class MyInformation implements ITelegramQuery { +import java.util.Collections; +import java.util.List; + +import static cc.sukazyo.cono.morny.util.tgapi.formatting.NamedUtils.inlineIds; + +public class MyInformation implements ITelegramQuery { public static final String ID_PREFIX = "[morny/info/me]"; public static final String TITLE = "My Account Information"; @Override @Nullable - public InlineQueryUnit query(Update event) { + public List> query(Update event) { if (!(event.inlineQuery().query() == null || "".equals(event.inlineQuery().query()))) return null; - return new InlineQueryUnit<>(new InlineQueryResultArticle( - ID_PREFIX, TITLE, + return Collections.singletonList(new InlineQueryUnit<>(new InlineQueryResultArticle( + inlineIds(ID_PREFIX), TITLE, new InputTextMessageContent( TelegramUserInformation.informationOutputHTML(event.inlineQuery().from()) ).parseMode(ParseMode.HTML) - )).isPersonal(true).cacheTime(10); + )).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 655d03a..a773f6b 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 @@ -8,23 +8,24 @@ import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.InlineQueryResultArticle; import com.pengrad.telegrambot.model.request.InputTextMessageContent; -import static cc.sukazyo.cono.morny.util.CommonConvert.byteArrayToHex; -import static cc.sukazyo.cono.morny.util.CommonEncrypt.hashMd5; +import java.util.Collections; +import java.util.List; -public class RawText implements ITelegramQuery { +import static cc.sukazyo.cono.morny.util.tgapi.formatting.NamedUtils.inlineIds; + +public class RawText implements ITelegramQuery { public static final String ID_PREFIX = "[morny/r/text]"; public static final String TITLE = "Raw Text"; @Override @Nullable - public InlineQueryUnit query (Update event) { + public List> query (Update event) { if (event.inlineQuery().query() == null || "".equals(event.inlineQuery().query())) return null; - return new InlineQueryUnit<>(new InlineQueryResultArticle( - ID_PREFIX + byteArrayToHex(hashMd5(event.inlineQuery().query())), - TITLE, + return Collections.singletonList(new InlineQueryUnit<>(new InlineQueryResultArticle( + inlineIds(ID_PREFIX, event.inlineQuery().query()), TITLE, new InputTextMessageContent(event.inlineQuery().query()) - )); + ))); } } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.java new file mode 100644 index 0000000..9c50d6f --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.java @@ -0,0 +1,50 @@ +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.InlineQueryResultArticle; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static cc.sukazyo.cono.morny.util.tgapi.formatting.NamedUtils.inlineIds; + +public class ShareToolTwitter implements ITelegramQuery { + + public static final String TITLE_VX = "[tweet] Share as VxTwitter"; + public static final String TITLE_VX_COMBINED = "[tweet] Share as VxTwitter(combination)"; + public static final String ID_PREFIX_VX = "[morny/share/twitter/vxtwi]"; + public static final String ID_PREFIX_VX_COMBINED = "[morny/share/twitter/vxtwi_combine]"; + + public static final Pattern REGEX_TWEET_LINK = Pattern.compile( + "^(?:https?://)?((?:(?:c\\.)?vx|fx|www\\.)?twitter\\.com)/((\\w+)/status/(\\d+)(?:/photo/(\\d+))?)/?(\\?[\\w&=-]+)?$"); + + @Nullable + @Override + public List> query (@Nonnull Update event) { + if (event.inlineQuery().query() == null) return null; + final Matcher regex = REGEX_TWEET_LINK.matcher(event.inlineQuery().query()); + if (regex.matches()) { + + List> result = new ArrayList<>(); + + result.add(new InlineQueryUnit<>(new InlineQueryResultArticle( + inlineIds(ID_PREFIX_VX+event.inlineQuery().query()), TITLE_VX, + String.format("https://vxtwitter.com/%s", regex.group(2)) + ))); + result.add(new InlineQueryUnit<>(new InlineQueryResultArticle( + inlineIds(ID_PREFIX_VX_COMBINED+event.inlineQuery().query()), TITLE_VX_COMBINED, + String.format("https://c.vxtwitter.com/%s", regex.group(2)) + ))); + + return result; + + } + return null; + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/util/tgapi/formatting/NamedUtils.java b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/formatting/NamedUtils.java new file mode 100644 index 0000000..b046f30 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/formatting/NamedUtils.java @@ -0,0 +1,18 @@ +package cc.sukazyo.cono.morny.util.tgapi.formatting; + +import cc.sukazyo.cono.morny.util.CommonConvert; +import cc.sukazyo.cono.morny.util.CommonEncrypt; + +import javax.annotation.Nonnull; + +public class NamedUtils { + + public static String inlineIds (@Nonnull String tag) { + return inlineIds(tag, ""); + } + + public static String inlineIds (@Nonnull String tag, @Nonnull String taggedData) { + return CommonConvert.byteArrayToHex(CommonEncrypt.hashMd5(tag+taggedData)); + } + +}