diff --git a/_book b/_book deleted file mode 160000 index 33e051f..0000000 --- a/_book +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 33e051fee5acb5118d6c023039ff9c1db6aa0c60 diff --git a/build.gradle b/build.gradle index 1629e2c..7c34aa5 100644 --- a/build.gradle +++ b/build.gradle @@ -102,11 +102,11 @@ java { } -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.encoding = proj_file_encoding.name() } -tasks.withType(Javadoc) { +tasks.withType(Javadoc).configureEach { options.encoding = proj_file_encoding.name() options.docEncoding = proj_file_encoding.name() options.charSet = proj_file_encoding.name() diff --git a/gradle.properties b/gradle.properties index c80d4ad..cdc89ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s -VERSION = 1.0.0-RC3.4 +VERSION = 1.0.0-RC3.5 USE_DELTA = false VERSION_DELTA = 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 bcc2bcf..553b14f 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 @@ -25,16 +25,20 @@ public class GetUsernameAndId implements ITelegramCommand { final String[] args = command.getArgs(); + // 不支持大于一个参数 if (args.length > 1) { MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), "[Unavailable] Too much arguments." ).replyToMessageId(event.message().messageId())); return; } + // 发送者自己的 id long userId = event.message().from().id(); + // 如果有回复某个人,则使用被回复人的 id if (event.message().replyToMessage()!= null) { userId = event.message().replyToMessage().from().id(); } + // 如果有指定 id,则使用指定的 id if (args.length > 0) { try { userId = Long.parseLong(args[0]); @@ -47,6 +51,7 @@ public class GetUsernameAndId implements ITelegramCommand { } } + // 重新获取用户对象 final GetChatMemberResponse response = MornyCoeur.getAccount().execute( new GetChatMember(event.message().chat().id(), userId) ); @@ -59,6 +64,7 @@ public class GetUsernameAndId implements ITelegramCommand { return; } + // 获取并发送用户信息 final User user = response.chatMember().user(); if (user.id() == 136817688) { diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.java b/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.java index a5e1ced..68652bd 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -//import static cc.sukazyo.cono.morny.Log.logger; import static cc.sukazyo.cono.morny.util.tgapi.formatting.NamedUtils.inlineIds; public class ShareToolBilibili implements ITelegramQuery { @@ -22,7 +21,7 @@ public class ShareToolBilibili implements ITelegramQuery { public static final String TITLE_BILI_BV = "[bilibili] Share video / BV"; public static final String ID_PREFIX_BILI_AV = "[morny/share/bili/av]"; public static final String ID_PREFIX_BILI_BV = "[morny/share/bili/bv]"; - public static final Pattern REGEX_BILI_VIDEO = Pattern.compile("^(?:(?:https?://)?(?:www\\.)?bilibili\\.com(?:/s)?/video/((?:av|AV)(\\d+)|(?:bv|BV)([A-HJ-NP-Za-km-z1-9]+))/?(\\?(?:p=(\\d+))?.*)?|(?:av|AV)(\\d+)|(?:bv|BV)([A-HJ-NP-Za-km-z1-9]+))$"); + public static final Pattern REGEX_BILI_VIDEO = Pattern.compile("^(?:(?:https?://)?(?:www\\.)?bilibili\\.com(?:/s)?/video/((?:av|AV)(\\d{1,12})|(?:bv|BV)([A-HJ-NP-Za-km-z1-9]{10}))/?(\\?(?:p=(\\d+))?.*)?|(?:av|AV)(\\d{1,12})|(?:bv|BV)([A-HJ-NP-Za-km-z1-9]{10}))$"); private static final String SHARE_FORMAT_HTML = "%s"; diff --git a/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java b/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java index ef36993..a7df8bc 100644 --- a/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java +++ b/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java @@ -16,6 +16,22 @@ public class BiliTool { private static final char[] BV_TEMPLATE = "1 4 1 7 ".toCharArray(); private static final int[] BV_TEMPLATE_FILTER = new int[]{9, 8, 1, 6, 2, 4}; + public static class IllegalFormatException extends RuntimeException { + + private IllegalFormatException (String bv, String reason) { + super("`%s` is not a valid 10 digits base58 BV id: %s".formatted(bv, reason)); + } + + private IllegalFormatException (String bv, int length) { + this(bv, "length is %d.".formatted(length)); + } + + private IllegalFormatException (String bv, char c, int location) { + this(bv, "char `%s` is not in base58 char table (in position %d)".formatted(c, location)); + } + + } + /** * Convert a Bilibili AV video id format to BV id format. *

@@ -27,17 +43,26 @@ public class BiliTool { *

* for now , the BV id has 10 digits. * the method available while the av-id < 2^27, while it theoretically available when the av-id < 2^30. + *

+ * this method allows input only 10 digits base58 BV id, if the input is not formatted by this method, it will throw + * an Exception. * * @see mcfx的回复: 如何看待 2020 年 3 月 23 日哔哩哔哩将稿件的「av 号」变更为「BV 号」? * * @param bv the BV id, a string in (a special) base58 number format, without "BV" prefix. * @return the AV id corresponding to this bv id in Bilibili, formatted as a number. + * @throws IllegalFormatException if the input BV id is not the 10 digits base58 String. */ @Nonnegative - public static long toAv (@Nonnull String bv) { + public static long toAv (@Nonnull String bv) throws IllegalFormatException { long av = 0; + if (bv.length() != 10) + throw new IllegalFormatException(bv, bv.length()); for (int i = 0; i < BV_TEMPLATE_FILTER.length; i++) { - av += BV_TABLE_REVERSED.get(bv.charAt(BV_TEMPLATE_FILTER[i])) * Math.pow(TABLE_INT,i); + final Integer tableToken = BV_TABLE_REVERSED.get(bv.charAt(BV_TEMPLATE_FILTER[i])); + if (tableToken == null) + throw new IllegalFormatException(bv, bv.charAt(BV_TEMPLATE_FILTER[i]), BV_TEMPLATE_FILTER[i]); + av += tableToken * Math.pow(TABLE_INT,i); } return (av-V_CONV_ADD)^V_CONV_XOR; }