项目 TG 对象转字符串使用 untitled 库,更新 untitled 类库导入方式,日常依赖更新

- groovy:untitled(String,String)
- dependencies
  - untitled:util-telegram-api-formatter +
  - spotbugs 4.5.2 -> 4.5.3
  - javaTelegramApi 5.5.0 -> 5.6.0
This commit is contained in:
A.C.Sukazyo Eyre 2022-01-24 12:25:08 +08:00
parent 8f2c63e300
commit 3762261cff
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
6 changed files with 49 additions and 51 deletions

View File

@ -17,14 +17,19 @@ repositories {
maven { name '-ws'; url 'https://mvn.sukazyo.cc' } maven { name '-ws'; url 'https://mvn.sukazyo.cc' }
} }
String untitled (String lib, String upd = null) {
int majorCode = Integer.parseInt(project.libUntitledVersionMajor)
return "cc.sukazyo.untitled:$lib:[$majorCode${upd==null?"":".$upd"}, ${majorCode+1}["
}
dependencies { dependencies {
compileOnlyApi "com.github.spotbugs:spotbugs-annotations:${libSpotbugsVersion}" compileOnlyApi "com.github.spotbugs:spotbugs-annotations:${libSpotbugsVersion}"
implementation "cc.sukazyo.untitled:util-string-commons:${libUntitledVersion}" implementation untitled("util-command-parser","1.0")
implementation "cc.sukazyo.untitled:util-telegram-commons:${libUntitledVersion}" implementation untitled("util-string-commons", "1.0")
implementation "cc.sukazyo.untitled:util-telegram-api:${libUntitledVersion}" implementation untitled("util-telegram-api", "2.1")
implementation untitled("util-telegram-api-formatter", "3.3")
implementation untitled("util-telegram-commons", "1.0")
api "cc.sukazyo:messiva:${libMessivaVersion}" api "cc.sukazyo:messiva:${libMessivaVersion}"
implementation "com.github.pengrad:java-telegram-bot-api:${libJavaTelegramBotApiVersion}" implementation "com.github.pengrad:java-telegram-bot-api:${libJavaTelegramBotApiVersion}"

View File

@ -1,15 +1,15 @@
## Core ## Core
VERSION = 0.4.3.6 VERSION = 0.4.3.7
# dependencies # dependencies
libSpotbugsVersion = 4.5.2 libSpotbugsVersion = 4.5.3
libUntitledVersion = 1.+ libUntitledVersionMajor = 1
libMessivaVersion = 0.1.0.1 libMessivaVersion = 0.1.0.1
libJavaTelegramBotApiVersion = 5.5.0 libJavaTelegramBotApiVersion = 5.6.0
libJunitVersion = 5.8.2 libJunitVersion = 5.8.2

View File

@ -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.4.3.6"; public static final String VERSION = "0.4.3.7";
public static final long COMPILE_TIMESTAMP = 1642747921571L; public static final long COMPILE_TIMESTAMP = 1642998030356L;
} }

View File

@ -4,6 +4,7 @@ import cc.sukazyo.cono.morny.MornyCoeur;
import cc.sukazyo.cono.morny.MornyTrusted; import cc.sukazyo.cono.morny.MornyTrusted;
import cc.sukazyo.cono.morny.bot.api.EventListener; import cc.sukazyo.cono.morny.bot.api.EventListener;
import cc.sukazyo.cono.morny.data.TelegramStickers; import cc.sukazyo.cono.morny.data.TelegramStickers;
import cc.sukazyo.untitled.telegram.api.formatting.TGToString;
import com.pengrad.telegrambot.model.Chat; import com.pengrad.telegrambot.model.Chat;
import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.model.request.ParseMode;
@ -13,8 +14,6 @@ import com.pengrad.telegrambot.request.SendSticker;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
/** /**
* 通过 bot 呼叫主人的事件监听管理类 * 通过 bot 呼叫主人的事件监听管理类
* @since 0.4.2.1 * @since 0.4.2.1
@ -74,11 +73,8 @@ public class OnCallMe extends EventListener {
ME, String.format( ME, String.format(
""" """
request <b>STEAM LIBRARY</b> request <b>STEAM LIBRARY</b>
from <a href="tg://user?id=%d">%s</a>""", from %s""",
event.message().from().id(), TGToString.as(event.message().from()).fullnameRefHtml()
escapeHtml(
event.message().from().firstName() + " " + event.message().from().lastName()
)
) )
).parseMode(ParseMode.HTML)); ).parseMode(ParseMode.HTML));
} }
@ -94,11 +90,8 @@ public class OnCallMe extends EventListener {
ME, String.format( ME, String.format(
""" """
request <b>Hana Paresu</b> request <b>Hana Paresu</b>
from <a href="tg://user?id=%d">%s</a>""", from %s""",
event.message().from().id(), TGToString.as(event.message().from()).fullnameRefHtml()
escapeHtml(
event.message().from().firstName() + " " + event.message().from().lastName()
)
) )
).parseMode(ParseMode.HTML)); ).parseMode(ParseMode.HTML));
} }
@ -122,11 +115,8 @@ public class OnCallMe extends EventListener {
ME, String.format( ME, String.format(
""" """
request <u>[???]</u> request <u>[???]</u>
from <a href="tg://user?id=%d">%s</a>""", from %s""",
event.message().from().id(), TGToString.as(event.message().from()).fullnameRefHtml()
escapeHtml(
event.message().from().firstName() + " " + event.message().from().lastName()
)
) )
).parseMode(ParseMode.HTML)); ).parseMode(ParseMode.HTML));
MornyCoeur.extra().exec(new ForwardMessage( MornyCoeur.extra().exec(new ForwardMessage(

View File

@ -10,6 +10,7 @@ import cc.sukazyo.cono.morny.bot.event.on_commands.Ip186Query;
import cc.sukazyo.cono.morny.bot.event.on_commands.Nbnhhsh; import cc.sukazyo.cono.morny.bot.event.on_commands.Nbnhhsh;
import cc.sukazyo.cono.morny.data.MornyJrrp; import cc.sukazyo.cono.morny.data.MornyJrrp;
import cc.sukazyo.cono.morny.data.TelegramStickers; import cc.sukazyo.cono.morny.data.TelegramStickers;
import cc.sukazyo.untitled.telegram.api.formatting.TGToString;
import cc.sukazyo.untitled.util.telegram.object.InputCommand; import cc.sukazyo.untitled.util.telegram.object.InputCommand;
import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.Update;
@ -112,7 +113,7 @@ public class OnCommandExecute extends EventListener {
TelegramStickers.ID_EXIT TelegramStickers.ID_EXIT
).replyToMessageId(event.message().messageId()) ).replyToMessageId(event.message().messageId())
); );
logger.info("Morny exited by user @" + event.message().from().username()); logger.info("Morny exited by user " + TGToString.as(event.message().from()).toStringLogTag());
System.exit(0); System.exit(0);
} else { } else {
MornyCoeur.extra().exec(new SendSticker( MornyCoeur.extra().exec(new SendSticker(
@ -120,7 +121,7 @@ public class OnCommandExecute extends EventListener {
TelegramStickers.ID_403 TelegramStickers.ID_403
).replyToMessageId(event.message().messageId()) ).replyToMessageId(event.message().messageId())
); );
logger.info("403 exited tag from user @" + event.message().from().username()); logger.info("403 exited tag from user " + TGToString.as(event.message().from()).toStringLogTag());
} }
} }
@ -200,9 +201,8 @@ public class OnCommandExecute extends EventListener {
MornyCoeur.extra().exec(new SendMessage( MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(), event.message().chat().id(),
String.format( String.format(
"<a href='tg://user?id=%d'>%s</a> 在(utc的)今天的运气指数是———— <code>%.2f%%</code> %s", "%s 在(utc的)今天的运气指数是———— <code>%.2f%%</code> %s",
event.message().from().id(), TGToString.as(event.message().from()).fullnameRefHtml(),
escapeHtml(event.message().from().firstName()),
jrrp, escapeHtml(endChar) jrrp, escapeHtml(endChar)
) )
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML)); ).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
@ -213,7 +213,7 @@ public class OnCommandExecute extends EventListener {
*/ */
private void onSaveDataExec (Update event) { private void onSaveDataExec (Update event) {
if (MornyCoeur.trustedInstance().isTrusted(event.message().from().id())) { if (MornyCoeur.trustedInstance().isTrusted(event.message().from().id())) {
logger.info(String.format("called save from command by @%s.", event.message().from().username())); logger.info("called save from command by " + TGToString.as(event.message().from()).toStringLogTag());
MornyCoeur.callSaveData(); MornyCoeur.callSaveData();
MornyCoeur.extra().exec(new SendSticker( MornyCoeur.extra().exec(new SendSticker(
event.message().chat().id(), event.message().chat().id(),
@ -226,7 +226,7 @@ public class OnCommandExecute extends EventListener {
TelegramStickers.ID_403 TelegramStickers.ID_403
).replyToMessageId(event.message().messageId()) ).replyToMessageId(event.message().messageId())
); );
logger.info("403 call save tag from user @" + event.message().from().username()); logger.info("403 call save tag from user " + TGToString.as(event.message().from()).toStringLogTag());
} }
} }

View File

@ -2,6 +2,7 @@ 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.untitled.telegram.api.formatting.TGToString;
import cc.sukazyo.untitled.util.command.CommonCommand; import cc.sukazyo.untitled.util.command.CommonCommand;
import cc.sukazyo.untitled.util.string.StringArrays; import cc.sukazyo.untitled.util.string.StringArrays;
@ -22,21 +23,21 @@ public class OnUserSlashAction extends EventListener {
final String text = event.message().text(); final String text = event.message().text();
if (text == null) return false; if (text == null) return false;
// Due to @Lapis_Apple, we stopped slash action function at .DP7 groups. if (text.startsWith("/")) {
// It may be enabled after some of updates when the function will not be conflicted to other bots.
/// Due to @Lapis_Apple, we stopped slash action function at .DP7 groups.
/// It may be enabled after some updates when the function will not be conflicted to other bots.
// if (event.message().chat().id() == ) return false; // if (event.message().chat().id() == ) return false;
if (event.message().chat().title() != null && event.message().chat().title().contains(".DP7")) { if (event.message().chat().title() != null && event.message().chat().title().contains(".DP7")) {
logger.info(String.format(""" logger.info(String.format("""
Chat slash action ignored due to keyword \".DP7\". Chat slash action ignored due to the following keyword.
- %s - %s
- [%d]""", - ".DP7\"""",
event.message().chat().title(), TGToString.as(event.message().chat()).toStringFullNameId()
event.message().chat().id()
)); ));
return false; return false;
} }
if (text.startsWith("/")) {
int prefixLength = 1; int prefixLength = 1;
boolean useVerbSuffix = true; boolean useVerbSuffix = true;
boolean useObjectPrefix = true; boolean useObjectPrefix = true;
@ -66,10 +67,12 @@ public class OnUserSlashAction extends EventListener {
MornyCoeur.extra().exec(new SendMessage( MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(), event.message().chat().id(),
String.format( String.format(
"<a href='tg://user?id=%d'>%s</a> %s%s <a href='tg://user?id=%d'>%s</a>%s%s", "%s %s%s %s%s%s",
origin.id(), escapeHtml(origin.firstName()), TGToString.as(origin).firstnameRefHtml(),
verb, escapeHtml((useVerbSuffix?"":"")), verb, escapeHtml((useVerbSuffix?"":"")),
target.id(), escapeHtml((origin==target ? "自己" : target.firstName())), origin==target ?
"<a href='tg://user?id="+target.id()+"'>自己</a>" :
TGToString.as(target).firstnameRefHtml(),
escapeHtml((hasObject ? (useObjectPrefix ?"": " ") : "")), escapeHtml((hasObject ? (useObjectPrefix ?"": " ") : "")),
escapeHtml((hasObject ? object : "")) escapeHtml((hasObject ? object : ""))
) )