mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
将部分 util 移动至 untitled 项目,修复上个更新的 tracker 活动锁被误删的问题
This commit is contained in:
parent
413f734034
commit
2a34b576b6
@ -21,6 +21,10 @@ dependencies {
|
||||
|
||||
compileOnlyApi "com.github.spotbugs:spotbugs-annotations:${libSpotbugsVersion}"
|
||||
|
||||
implementation "cc.sukazyo.untitled:util-string-commons:${libUntitledVersion}"
|
||||
implementation "cc.sukazyo.untitled:util-telegram-commons:${libUntitledVersion}"
|
||||
implementation "cc.sukazyo.untitled:util-telegram-api:${libUntitledVersion}"
|
||||
|
||||
api "cc.sukazyo:messiva:${libMessivaVersion}"
|
||||
|
||||
implementation "com.github.pengrad:java-telegram-bot-api:${libJavaTelegramBotApiVersion}"
|
||||
|
@ -1,11 +1,13 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.4.3.0
|
||||
VERSION = 0.4.3.1
|
||||
|
||||
# dependencies
|
||||
|
||||
libSpotbugsVersion = 4.5.2
|
||||
|
||||
libUntitledVersion = 1.+
|
||||
|
||||
libMessivaVersion = 0.1.0.1
|
||||
|
||||
libJavaTelegramBotApiVersion = 5.5.0
|
||||
|
@ -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.4.3.0";
|
||||
public static final long COMPILE_TIMESTAMP = 1641056437585L;
|
||||
public static final String VERSION = "0.4.3.1";
|
||||
public static final long COMPILE_TIMESTAMP = 1641201595120L;
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
package cc.sukazyo.cono.morny.bot.api;
|
||||
|
||||
import cc.sukazyo.cono.morny.util.StringUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class InputCommand {
|
||||
|
||||
private final String target;
|
||||
private final String command;
|
||||
private final String[] args;
|
||||
|
||||
private InputCommand (@Nullable String target, @Nonnull String command, @Nonnull String[] args) {
|
||||
this.target = target;
|
||||
this.command = command;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public InputCommand (@Nonnull String[] inputArray) {
|
||||
this(parseInputArray(inputArray));
|
||||
}
|
||||
|
||||
public InputCommand (@Nonnull String input) {
|
||||
this(StringUtils.formatCommand(input));
|
||||
}
|
||||
|
||||
public InputCommand (@Nonnull InputCommand source) {
|
||||
this(source.target, source.command, source.args);
|
||||
}
|
||||
|
||||
public static InputCommand parseInputArray (@Nonnull String[] inputArray) {
|
||||
final String[] cx = inputArray[0].split("@", 2);
|
||||
final String[] args = new String[inputArray.length-1];
|
||||
System.arraycopy(inputArray, 1, args, 0, inputArray.length - 1);
|
||||
return new InputCommand(cx.length == 1 ? null : cx[1], cx[0], args);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTarget () {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getCommand () {
|
||||
return command;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String[] getArgs () {
|
||||
return args;
|
||||
}
|
||||
|
||||
public boolean hasArgs () {
|
||||
return args.length != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String toString() {
|
||||
return String.format("{{%s}@{%s}#{%s}}", command, target, Arrays.toString(args));
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ import com.pengrad.telegrambot.request.SendSticker;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.StringUtils.escapeHtmlTelegram;
|
||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||
|
||||
/**
|
||||
* 通过 bot 呼叫主人的事件监听管理类
|
||||
@ -76,7 +76,7 @@ public class OnCallMe extends EventListener {
|
||||
request <b>STEAM LIBRARY</b>
|
||||
from <a href="tg://user?id=%d">%s</a>""",
|
||||
event.message().from().id(),
|
||||
escapeHtmlTelegram(
|
||||
escapeHtml(
|
||||
event.message().from().firstName() + " " + event.message().from().lastName()
|
||||
)
|
||||
)
|
||||
@ -96,7 +96,7 @@ public class OnCallMe extends EventListener {
|
||||
request <b>Hana Paresu</b>
|
||||
from <a href="tg://user?id=%d">%s</a>""",
|
||||
event.message().from().id(),
|
||||
escapeHtmlTelegram(
|
||||
escapeHtml(
|
||||
event.message().from().firstName() + " " + event.message().from().lastName()
|
||||
)
|
||||
)
|
||||
@ -124,7 +124,7 @@ public class OnCallMe extends EventListener {
|
||||
request <u>[???]</u>
|
||||
from <a href="tg://user?id=%d">%s</a>""",
|
||||
event.message().from().id(),
|
||||
escapeHtmlTelegram(
|
||||
escapeHtml(
|
||||
event.message().from().firstName() + " " + event.message().from().lastName()
|
||||
)
|
||||
)
|
||||
|
@ -4,12 +4,13 @@ import cc.sukazyo.cono.morny.GradleProjectConfigures;
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.MornySystem;
|
||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import cc.sukazyo.cono.morny.bot.api.InputCommand;
|
||||
import cc.sukazyo.cono.morny.bot.event.on_commands.EventHack;
|
||||
import cc.sukazyo.cono.morny.bot.event.on_commands.GetUsernameAndId;
|
||||
import cc.sukazyo.cono.morny.bot.event.on_commands.Ip186Query;
|
||||
import cc.sukazyo.cono.morny.data.MornyJrrp;
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
||||
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
@ -20,7 +21,7 @@ import javax.annotation.Nonnull;
|
||||
import static cc.sukazyo.cono.morny.Log.logger;
|
||||
import static cc.sukazyo.cono.morny.util.CommonFormatUtils.formatDate;
|
||||
import static cc.sukazyo.cono.morny.util.CommonFormatUtils.formatDuration;
|
||||
import static cc.sukazyo.cono.morny.util.StringUtils.escapeHtmlTelegram;
|
||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||
|
||||
public class OnCommandExecute extends EventListener {
|
||||
|
||||
@ -131,10 +132,10 @@ public class OnCommandExecute extends EventListener {
|
||||
compile timestamp:
|
||||
- <code>%d</code>
|
||||
- <code>%s [UTC]</code>""",
|
||||
escapeHtmlTelegram(MornySystem.VERSION),
|
||||
escapeHtmlTelegram(MornySystem.getJarMd5()),
|
||||
escapeHtml(MornySystem.VERSION),
|
||||
escapeHtml(MornySystem.getJarMd5()),
|
||||
GradleProjectConfigures.COMPILE_TIMESTAMP,
|
||||
escapeHtmlTelegram(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0))
|
||||
escapeHtml(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0))
|
||||
)
|
||||
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
||||
}
|
||||
@ -166,24 +167,24 @@ public class OnCommandExecute extends EventListener {
|
||||
- <code>%s [UTC]</code>
|
||||
- [<code>%d</code>]""",
|
||||
// system
|
||||
escapeHtmlTelegram(System.getProperty("os.name")),
|
||||
escapeHtmlTelegram(System.getProperty("os.version")),
|
||||
escapeHtml(System.getProperty("os.name")),
|
||||
escapeHtml(System.getProperty("os.version")),
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
// java
|
||||
escapeHtmlTelegram(System.getProperty("java.vm.name")),
|
||||
escapeHtmlTelegram(System.getProperty("java.version")),
|
||||
escapeHtml(System.getProperty("java.vm.name")),
|
||||
escapeHtml(System.getProperty("java.version")),
|
||||
// memory
|
||||
Runtime.getRuntime().totalMemory() / 1024 / 1024,
|
||||
Runtime.getRuntime().maxMemory() / 1024 / 1024,
|
||||
// version
|
||||
escapeHtmlTelegram(MornySystem.VERSION),
|
||||
escapeHtmlTelegram(MornySystem.getJarMd5()),
|
||||
escapeHtmlTelegram(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0)),
|
||||
escapeHtml(MornySystem.VERSION),
|
||||
escapeHtml(MornySystem.getJarMd5()),
|
||||
escapeHtml(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0)),
|
||||
GradleProjectConfigures.COMPILE_TIMESTAMP,
|
||||
// continuous
|
||||
escapeHtmlTelegram(formatDuration(System.currentTimeMillis() - MornyCoeur.coeurStartTimestamp)),
|
||||
escapeHtml(formatDuration(System.currentTimeMillis() - MornyCoeur.coeurStartTimestamp)),
|
||||
System.currentTimeMillis() - MornyCoeur.coeurStartTimestamp,
|
||||
escapeHtmlTelegram(formatDate(MornyCoeur.coeurStartTimestamp, 0)),
|
||||
escapeHtml(formatDate(MornyCoeur.coeurStartTimestamp, 0)),
|
||||
MornyCoeur.coeurStartTimestamp
|
||||
)
|
||||
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
||||
@ -197,8 +198,8 @@ public class OnCommandExecute extends EventListener {
|
||||
String.format(
|
||||
"<a href='tg://user?id=%d'>%s</a> 在(utc的)今天的运气指数是———— <code>%.2f%%</code> %s",
|
||||
event.message().from().id(),
|
||||
escapeHtmlTelegram(event.message().from().firstName()),
|
||||
jrrp, escapeHtmlTelegram(endChar)
|
||||
escapeHtml(event.message().from().firstName()),
|
||||
jrrp, escapeHtml(endChar)
|
||||
)
|
||||
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ 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.StringUtils;
|
||||
import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
@ -66,7 +67,7 @@ public class OnEventHackHandle extends EventListener {
|
||||
logger.debug("hacked event by " + x);
|
||||
MornyCoeur.getAccount().execute(new SendMessage(x.fromChatId, String.format(
|
||||
"<code>%s</code>",
|
||||
StringUtils.escapeHtmlTelegram(new GsonBuilder().setPrettyPrinting().create().toJson(update))
|
||||
MsgEscape.escapeHtml(new GsonBuilder().setPrettyPrinting().create().toJson(update))
|
||||
)).parseMode(ParseMode.HTML).replyToMessageId((int)x.fromMessageId));
|
||||
return true;
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ 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.StringUtils;
|
||||
import cc.sukazyo.untitled.util.command.CommonCommand;
|
||||
import cc.sukazyo.untitled.util.string.StringArrays;
|
||||
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.User;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
@ -10,7 +12,7 @@ import com.pengrad.telegrambot.request.SendMessage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.StringUtils.escapeHtmlTelegram;
|
||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||
|
||||
public class OnUserSlashAction extends EventListener {
|
||||
|
||||
@ -35,10 +37,10 @@ public class OnUserSlashAction extends EventListener {
|
||||
prefixLength = 2;
|
||||
}
|
||||
|
||||
final String[] action = StringUtils.formatCommand(text.substring(prefixLength));
|
||||
final String[] action = CommonCommand.format(text.substring(prefixLength));
|
||||
final String verb = action[0];
|
||||
final boolean hasObject = action.length != 1;
|
||||
final String object = StringUtils.connectStringArray(action, " ", 1, action.length-1);
|
||||
final String object = StringArrays.connectStringArray(action, " ", 1, action.length-1);
|
||||
final User origin = event.message().from();
|
||||
final User target = (event.message().replyToMessage() == null ? (
|
||||
origin
|
||||
@ -50,11 +52,11 @@ public class OnUserSlashAction extends EventListener {
|
||||
event.message().chat().id(),
|
||||
String.format(
|
||||
"<a href='tg://user?id=%d'>%s</a> %s%s <a href='tg://user?id=%d'>%s</a>%s%s",
|
||||
origin.id(), escapeHtmlTelegram(origin.firstName()),
|
||||
verb, escapeHtmlTelegram((useVerbSuffix?"了":"")),
|
||||
target.id(), escapeHtmlTelegram((origin==target ? "自己" : target.firstName())),
|
||||
escapeHtmlTelegram((hasObject ? (useObjectPrefix ?" 的": " ") : "")),
|
||||
escapeHtmlTelegram((hasObject ? object : ""))
|
||||
origin.id(), escapeHtml(origin.firstName()),
|
||||
verb, escapeHtml((useVerbSuffix?"了":"")),
|
||||
target.id(), escapeHtml((origin==target ? "自己" : target.firstName())),
|
||||
escapeHtml((hasObject ? (useObjectPrefix ?" 的": " ") : "")),
|
||||
escapeHtml((hasObject ? object : ""))
|
||||
)
|
||||
).parseMode(ParseMode.HTML));
|
||||
|
||||
|
@ -2,9 +2,10 @@ package cc.sukazyo.cono.morny.bot.event.on_commands;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.MornyTrusted;
|
||||
import cc.sukazyo.cono.morny.bot.api.InputCommand;
|
||||
import cc.sukazyo.cono.morny.bot.event.OnEventHackHandle;
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
||||
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.request.SendSticker;
|
||||
|
||||
|
@ -10,7 +10,7 @@ import com.pengrad.telegrambot.response.GetChatMemberResponse;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.StringUtils.escapeHtmlTelegram;
|
||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||
|
||||
public class GetUsernameAndId {
|
||||
|
||||
@ -67,7 +67,7 @@ public class GetUsernameAndId {
|
||||
|
||||
username :
|
||||
- <code>%s</code>""",
|
||||
escapeHtmlTelegram(user.username())
|
||||
escapeHtml(user.username())
|
||||
));
|
||||
}
|
||||
if (user.firstName() == null) {
|
||||
@ -78,7 +78,7 @@ public class GetUsernameAndId {
|
||||
|
||||
firstname :
|
||||
- <code>%s</code>""",
|
||||
escapeHtmlTelegram(user.firstName())
|
||||
escapeHtml(user.firstName())
|
||||
));
|
||||
}
|
||||
if (user.lastName() == null) {
|
||||
@ -89,7 +89,7 @@ public class GetUsernameAndId {
|
||||
|
||||
lastname :
|
||||
- <code>%s</code>""",
|
||||
escapeHtmlTelegram(user.lastName())
|
||||
escapeHtml(user.lastName())
|
||||
));
|
||||
}
|
||||
if (user.languageCode() != null) {
|
||||
@ -98,7 +98,7 @@ public class GetUsernameAndId {
|
||||
|
||||
language-code :
|
||||
- <code>%s</code>""",
|
||||
escapeHtmlTelegram(user.languageCode())
|
||||
escapeHtml(user.languageCode())
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cc.sukazyo.cono.morny.bot.event.on_commands;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.bot.api.InputCommand;
|
||||
import cc.sukazyo.cono.morny.data.ip186.IP186QueryResponse;
|
||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
||||
import cc.sukazyo.cono.morny.data.ip186.IP186QueryHandler;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
@ -10,7 +10,7 @@ import com.pengrad.telegrambot.request.SendMessage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.StringUtils.escapeHtmlTelegram;
|
||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||
|
||||
/**
|
||||
* {@value IP186QueryHandler#SITE_URL} 查询的 telegram 命令前端
|
||||
@ -50,12 +50,12 @@ public class Ip186Query {
|
||||
};
|
||||
MornyCoeur.getAccount().execute(new SendMessage(
|
||||
event.message().chat().id(),
|
||||
escapeHtmlTelegram(response.url()) + "\n<code>" + escapeHtmlTelegram(response.body()) + "</code>"
|
||||
escapeHtml(response.url()) + "\n<code>" + escapeHtml(response.body()) + "</code>"
|
||||
).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId()));
|
||||
} catch (Exception e) {
|
||||
MornyCoeur.getAccount().execute(new SendMessage(
|
||||
event.message().chat().id(),
|
||||
"[Exception] in query:\n<code>" + escapeHtmlTelegram(e.getMessage()) + "</code>"
|
||||
"[Exception] in query:\n<code>" + escapeHtml(e.getMessage()) + "</code>"
|
||||
).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId()));
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ public class TrackerDataManager {
|
||||
|
||||
@Override
|
||||
public void run () {
|
||||
trackingLock.lock();
|
||||
long lastWaitTimestamp = System.currentTimeMillis();
|
||||
boolean postProcess = false;
|
||||
do {
|
||||
@ -46,6 +47,7 @@ public class TrackerDataManager {
|
||||
}
|
||||
else logger.info("nothing to do yet");
|
||||
} while (!postProcess);
|
||||
trackingLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
package cc.sukazyo.cono.morny.util;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
@Nonnull
|
||||
public static String[] formatCommand (@Nonnull String com) {
|
||||
|
||||
final ArrayList<String> arr = new ArrayList<>();
|
||||
|
||||
final StringBuilder tmp = new StringBuilder();
|
||||
final char[] coma = com.toCharArray();
|
||||
for (int i = 0; i < coma.length; i++) {
|
||||
if (coma[i] == ' ') {
|
||||
if (!tmp.toString().equals("")) { arr.add(tmp.toString()); }
|
||||
tmp.setLength(0);
|
||||
} else if (coma[i] == '"') {
|
||||
while (true) {
|
||||
i++;
|
||||
if (coma[i] == '"') {
|
||||
break;
|
||||
} else if (coma[i] == '\\' && (coma[i+1] == '"' || coma[i+1] == '\\')) {
|
||||
i++;
|
||||
tmp.append(coma[i]);
|
||||
} else {
|
||||
tmp.append(coma[i]);
|
||||
}
|
||||
}
|
||||
} else if (coma[i] == '\\' && (coma[i+1] == ' ' || coma[i+1] == '"' || coma[i+1] == '\\')) {
|
||||
i++;
|
||||
tmp.append(coma[i]);
|
||||
} else {
|
||||
tmp.append(coma[i]);
|
||||
}
|
||||
}
|
||||
if (!tmp.toString().equals("")) { arr.add(tmp.toString()); }
|
||||
tmp.setLength(0);
|
||||
|
||||
final String[] out = new String[arr.size()];
|
||||
arr.toArray(out);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String connectStringArray (
|
||||
@Nonnull String[] array, @Nonnull String connector, @Nonnegative int startIndex, @Nonnegative int stopIndex
|
||||
) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = startIndex; i < stopIndex; i++) {
|
||||
builder.append(array[i]);
|
||||
builder.append(connector);
|
||||
}
|
||||
builder.append(array[stopIndex]);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String escapeHtmlTelegram (String raw) {
|
||||
raw = raw.replaceAll("&", "&");
|
||||
raw = raw.replaceAll("<", "<");
|
||||
raw = raw.replaceAll(">", ">");
|
||||
return raw;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user