mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 03:04:54 +08:00
fix input av/bv may be too long or too small to process
This commit is contained in:
parent
f990df70ea
commit
9c03a59512
1
_book
1
_book
@ -1 +0,0 @@
|
||||
Subproject commit 33e051fee5acb5118d6c023039ff9c1db6aa0c60
|
@ -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()
|
||||
|
@ -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 =
|
||||
|
@ -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) {
|
||||
|
@ -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 = "<a href='%s'>%s</a>";
|
||||
|
||||
|
@ -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 <a href="https://www.bilibili.com/">Bilibili</a> AV video id format to BV id format.
|
||||
* <p>
|
||||
@ -27,17 +43,26 @@ public class BiliTool {
|
||||
* <p>
|
||||
* for now , the BV id has 10 digits.
|
||||
* the method <b>available while the <u>av-id < 2^27</u></b>, while it theoretically available when the av-id < 2^30.
|
||||
* <p>
|
||||
* 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 <a href="https://www.zhihu.com/question/381784377/answer/1099438784">mcfx的回复: 如何看待 2020 年 3 月 23 日哔哩哔哩将稿件的「av 号」变更为「BV 号」?</a>
|
||||
*
|
||||
* @param bv the BV id, a string in (a special) base58 number format, <b>without "BV" prefix</b>.
|
||||
* @return the AV id corresponding to this bv id in <a href="https://www.bilibili.com/">Bilibili</a>, 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user