mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-25 20:47:38 +08:00
脱离 unititled 模块依赖,将工具类全部移动至 util 包
This commit is contained in:
parent
459470be02
commit
afef4f0345
@ -17,19 +17,10 @@ repositories {
|
|||||||
maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' }
|
maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' }
|
||||||
}
|
}
|
||||||
|
|
||||||
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 untitled("util-command-parser","1.0")
|
|
||||||
implementation untitled("util-string-commons", "1.0")
|
|
||||||
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}"
|
||||||
|
@ -4,7 +4,7 @@ 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.8.0.1";
|
public static final String VERSION = "0.8.0.2";
|
||||||
public static final String CODENAME = "fuzhou";
|
public static final String CODENAME = "fuzhou";
|
||||||
public static final long COMPILE_TIMESTAMP = 1664648280419L;
|
public static final long COMPILE_TIMESTAMP = 1664867846222L;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import cc.sukazyo.cono.morny.bot.event.EventListeners;
|
|||||||
import cc.sukazyo.cono.morny.bot.query.MornyQueries;
|
import cc.sukazyo.cono.morny.bot.query.MornyQueries;
|
||||||
import cc.sukazyo.cono.morny.daemon.MornyDaemons;
|
import cc.sukazyo.cono.morny.daemon.MornyDaemons;
|
||||||
import cc.sukazyo.cono.morny.daemon.TrackerDataManager;
|
import cc.sukazyo.cono.morny.daemon.TrackerDataManager;
|
||||||
import cc.sukazyo.untitled.telegram.api.extra.ExtraAction;
|
import cc.sukazyo.cono.morny.util.tgapi.ExtraAction;
|
||||||
import com.pengrad.telegrambot.TelegramBot;
|
import com.pengrad.telegrambot.TelegramBot;
|
||||||
import com.pengrad.telegrambot.impl.FileApi;
|
import com.pengrad.telegrambot.impl.FileApi;
|
||||||
import com.pengrad.telegrambot.model.User;
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.api;
|
package cc.sukazyo.cono.morny.bot.api;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.event.EventRuntimeException;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
|
||||||
import cc.sukazyo.untitled.telegram.api.event.EventRuntimeException;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
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.request.DeleteMessage;
|
import com.pengrad.telegrambot.request.DeleteMessage;
|
||||||
|
@ -4,8 +4,8 @@ import cc.sukazyo.cono.morny.MornyCoeur;
|
|||||||
import cc.sukazyo.cono.morny.MornyTrusted;
|
import cc.sukazyo.cono.morny.MornyTrusted;
|
||||||
import cc.sukazyo.cono.morny.bot.event.OnEventHackHandle;
|
import cc.sukazyo.cono.morny.bot.event.OnEventHackHandle;
|
||||||
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.request.SendSticker;
|
import com.pengrad.telegrambot.request.SendSticker;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.cono.morny.util.TelegramUserInformation;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramUserInformation;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.User;
|
import com.pengrad.telegrambot.model.User;
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -2,8 +2,8 @@ package cc.sukazyo.cono.morny.bot.command;
|
|||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.cono.morny.data.ip186.IP186QueryResponse;
|
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 cc.sukazyo.cono.morny.data.ip186.IP186QueryHandler;
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
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;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
@ -12,7 +12,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@value IP186QueryHandler#SITE_URL} 查询的 telegram 命令前端
|
* {@value IP186QueryHandler#SITE_URL} 查询的 telegram 命令前端
|
||||||
|
@ -5,8 +5,8 @@ import cc.sukazyo.cono.morny.MornyCoeur;
|
|||||||
import cc.sukazyo.cono.morny.MornySystem;
|
import cc.sukazyo.cono.morny.MornySystem;
|
||||||
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.cono.morny.util.tgapi.InputCommand;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.TGToString;
|
||||||
import com.pengrad.telegrambot.model.BotCommand;
|
import com.pengrad.telegrambot.model.BotCommand;
|
||||||
import com.pengrad.telegrambot.model.DeleteMyCommands;
|
import com.pengrad.telegrambot.model.DeleteMyCommands;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
@ -29,7 +29,7 @@ import java.util.Map;
|
|||||||
import static cc.sukazyo.cono.morny.Log.logger;
|
import static cc.sukazyo.cono.morny.Log.logger;
|
||||||
import static cc.sukazyo.cono.morny.util.CommonFormat.formatDate;
|
import static cc.sukazyo.cono.morny.util.CommonFormat.formatDate;
|
||||||
import static cc.sukazyo.cono.morny.util.CommonFormat.formatDuration;
|
import static cc.sukazyo.cono.morny.util.CommonFormat.formatDuration;
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
public class MornyCommands {
|
public class MornyCommands {
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
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;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.cono.morny.data.NbnhhshQuery;
|
import cc.sukazyo.cono.morny.data.NbnhhshQuery;
|
||||||
import cc.sukazyo.untitled.util.string.StringArrays;
|
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.CommonConvert.stringsConnecting;
|
||||||
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
public class Nbnhhsh implements ITelegramCommand {
|
public class Nbnhhsh implements ITelegramCommand {
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class Nbnhhsh implements ITelegramCommand {
|
|||||||
if (event.message().replyToMessage() != null && event.message().replyToMessage().text() != null)
|
if (event.message().replyToMessage() != null && event.message().replyToMessage().text() != null)
|
||||||
queryTarget = event.message().replyToMessage().text();
|
queryTarget = event.message().replyToMessage().text();
|
||||||
if (command.hasArgs())
|
if (command.hasArgs())
|
||||||
queryTarget = StringArrays.connectStringArray(command.getArgs(), " ", 0, command.getArgs().length-1);
|
queryTarget = stringsConnecting(command.getArgs(), " ", 0, command.getArgs().length-1);
|
||||||
|
|
||||||
NbnhhshQuery.GuessResult response = NbnhhshQuery.sendGuess(queryTarget);
|
NbnhhshQuery.GuessResult response = NbnhhshQuery.sendGuess(queryTarget);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
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;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ 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.cono.morny.util.CommonFormat;
|
import cc.sukazyo.cono.morny.util.CommonFormat;
|
||||||
import cc.sukazyo.untitled.telegram.api.formatting.TGToString;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape;
|
||||||
import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.TGToString;
|
||||||
import com.pengrad.telegrambot.model.Chat;
|
import com.pengrad.telegrambot.model.Chat;
|
||||||
import com.pengrad.telegrambot.model.Message;
|
import com.pengrad.telegrambot.model.Message;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
@ -22,7 +22,8 @@ import cc.sukazyo.cono.morny.data.TelegramStickers;
|
|||||||
import com.pengrad.telegrambot.response.GetChatResponse;
|
import com.pengrad.telegrambot.response.GetChatResponse;
|
||||||
import com.pengrad.telegrambot.response.SendResponse;
|
import com.pengrad.telegrambot.response.SendResponse;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
|
|
||||||
public class OnCallMsgSend extends EventListener {
|
public class OnCallMsgSend extends EventListener {
|
||||||
|
|
||||||
|
@ -2,7 +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.util.telegram.formatting.MsgEscape;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
@ -2,7 +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.util.telegram.object.InputCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
|
||||||
|
@ -2,7 +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.util.command.CommonCommand;
|
import cc.sukazyo.cono.morny.util.UniversalCommand;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -22,7 +22,7 @@ public class OnUserRandoms extends EventListener {
|
|||||||
if (update.message().text() == null) return false;
|
if (update.message().text() == null) return false;
|
||||||
if (!update.message().text().startsWith("/")) return false;
|
if (!update.message().text().startsWith("/")) return false;
|
||||||
|
|
||||||
final String[] preProcess = CommonCommand.format(update.message().text());
|
final String[] preProcess = UniversalCommand.format(update.message().text());
|
||||||
if (preProcess.length > 1) return false;
|
if (preProcess.length > 1) return false;
|
||||||
final String query = preProcess[0];
|
final String query = preProcess[0];
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@ 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.cono.morny.util.tgapi.TGToStringFromMessage;
|
import cc.sukazyo.cono.morny.util.UniversalCommand;
|
||||||
import cc.sukazyo.untitled.util.command.CommonCommand;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.TGToString;
|
||||||
import cc.sukazyo.untitled.util.string.StringArrays;
|
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.Message;
|
import com.pengrad.telegrambot.model.Message;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
@ -13,7 +12,8 @@ import com.pengrad.telegrambot.request.SendMessage;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.CommonConvert.stringsConnecting;
|
||||||
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
public class OnUserSlashAction extends EventListener {
|
public class OnUserSlashAction extends EventListener {
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public class OnUserSlashAction extends EventListener {
|
|||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
final String[] action = CommonCommand.format(text);
|
final String[] action = UniversalCommand.format(text);
|
||||||
action[0] = action[0].substring(1);
|
action[0] = action[0].substring(1);
|
||||||
|
|
||||||
if (action[0].matches("^\\w+(@\\w+)?$")) {
|
if (action[0].matches("^\\w+(@\\w+)?$")) {
|
||||||
@ -53,7 +53,7 @@ public class OnUserSlashAction extends EventListener {
|
|||||||
final boolean hasObject = action.length != (isHardParse?2:1);
|
final boolean hasObject = action.length != (isHardParse?2:1);
|
||||||
final String object =
|
final String object =
|
||||||
hasObject ?
|
hasObject ?
|
||||||
StringArrays.connectStringArray(action, " ", isHardParse?2:1, action.length-1) :
|
stringsConnecting(action, " ", isHardParse?2:1, action.length-1) :
|
||||||
"";
|
"";
|
||||||
final Message origin = event.message();
|
final Message origin = event.message();
|
||||||
final Message target = (event.message().replyToMessage() == null ? (
|
final Message target = (event.message().replyToMessage() == null ? (
|
||||||
@ -66,11 +66,11 @@ public class OnUserSlashAction extends EventListener {
|
|||||||
event.message().chat().id(),
|
event.message().chat().id(),
|
||||||
String.format(
|
String.format(
|
||||||
"%s %s%s %s %s!",
|
"%s %s%s %s %s!",
|
||||||
TGToStringFromMessage.as(origin).getSenderFirstNameRefHtml(),
|
TGToString.as(origin).getSenderFirstNameRefHtml(),
|
||||||
escapeHtml(verb), escapeHtml((hasObject?"":"了")),
|
escapeHtml(verb), escapeHtml((hasObject?"":"了")),
|
||||||
origin==target ?
|
origin==target ?
|
||||||
"<a href='tg://user?id="+TGToStringFromMessage.as(target).getSenderId()+"'>自己</a>" :
|
"<a href='tg://user?id="+TGToString.as(target).getSenderId()+"'>自己</a>" :
|
||||||
TGToStringFromMessage.as(target).getSenderFirstNameRefHtml(),
|
TGToString.as(target).getSenderFirstNameRefHtml(),
|
||||||
escapeHtml(hasObject ? object+" " : "")
|
escapeHtml(hasObject ? object+" " : "")
|
||||||
)
|
)
|
||||||
).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId()));
|
).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId()));
|
||||||
|
@ -8,7 +8,7 @@ import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
|||||||
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.util.TelegramUserInformation;
|
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramUserInformation;
|
||||||
|
|
||||||
public class MyInformation implements ITelegramQuery<InlineQueryResultArticle> {
|
public class MyInformation implements ITelegramQuery<InlineQueryResultArticle> {
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cc.sukazyo.cono.morny.util;
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,4 +34,28 @@ public class CommonConvert {
|
|||||||
return hex.length()<2?"0"+hex:hex;
|
return hex.length()<2?"0"+hex:hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个字符串数组按照一定规则连接.
|
||||||
|
* <p>
|
||||||
|
* 连接的方式类似于"数据1+分隔符+数据2+分隔符+...+数据n-1+分隔符+数据n"
|
||||||
|
*
|
||||||
|
* @param array 需要进行连接的字符串数组,数组中每一个元素会是一个数据
|
||||||
|
* @param connector 在每两个传入数据中插入的分隔符
|
||||||
|
* @param startIndex 从传入的数据组中的哪一个位置开始(第一个元素的位置是 {@code 0})
|
||||||
|
* @param stopIndex 从传入的数据组中的哪一个位置停止(元素位置计算方式同上)
|
||||||
|
* @return 连接好的字符串
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static String stringsConnecting (
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class UniversalCommand {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static String[] format (@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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.event.EventRuntimeException;
|
||||||
|
import com.pengrad.telegrambot.TelegramBot;
|
||||||
|
import com.pengrad.telegrambot.model.Chat;
|
||||||
|
import com.pengrad.telegrambot.model.ChatMember;
|
||||||
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
import com.pengrad.telegrambot.request.BaseRequest;
|
||||||
|
import com.pengrad.telegrambot.request.GetChatMember;
|
||||||
|
import com.pengrad.telegrambot.response.BaseResponse;
|
||||||
|
|
||||||
|
public class ExtraAction {
|
||||||
|
|
||||||
|
private final TelegramBot bot;
|
||||||
|
|
||||||
|
public ExtraAction (TelegramBot bot) {
|
||||||
|
this.bot = bot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExtraAction as (TelegramBot bot) {
|
||||||
|
return new ExtraAction(bot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserInGroup (User user, Chat chat) {
|
||||||
|
return isUserInGroup(user.id(), chat.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends BaseRequest<T, R>, R extends BaseResponse> R exec (T req) {
|
||||||
|
return exec(req, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends BaseRequest<T, R>, R extends BaseResponse> R exec (T req, String errorMessage) {
|
||||||
|
final R resp = bot.execute(req);
|
||||||
|
if (!resp.isOk()) throw new EventRuntimeException.ActionFailed(
|
||||||
|
(errorMessage.equals("") ? String.valueOf(resp.errorCode()) : errorMessage),
|
||||||
|
resp
|
||||||
|
);
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserInGroup (User user, Chat chat, ChatMember.Status permissionLevel) {
|
||||||
|
return isUserInGroup(user.id(), chat.id(), permissionLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserInGroup (long userId, long chatId) {
|
||||||
|
return isUserInGroup(userId, chatId, ChatMember.Status.restricted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserInGroup (long userId, long chatId, ChatMember.Status permissionLevel) {
|
||||||
|
final ChatMember chatMember = exec(new GetChatMember(chatId, userId)).chatMember();
|
||||||
|
return
|
||||||
|
chatMember != null &&
|
||||||
|
UserPermissionLevel.as(chatMember.status()).hasPermission(UserPermissionLevel.as(permissionLevel));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum UserPermissionLevel {
|
||||||
|
|
||||||
|
CREATOR(3),
|
||||||
|
ADMINISTRATOR(2),
|
||||||
|
MEMBER(1),
|
||||||
|
RESTRICTED(0),
|
||||||
|
LEFT(-1),
|
||||||
|
KICKED(-2);
|
||||||
|
|
||||||
|
final int permissionLevel;
|
||||||
|
|
||||||
|
UserPermissionLevel (int permissionLevel) {
|
||||||
|
this.permissionLevel = permissionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static UserPermissionLevel as (ChatMember.Status status) {
|
||||||
|
return switch (status) {
|
||||||
|
case creator -> CREATOR;
|
||||||
|
case administrator -> ADMINISTRATOR;
|
||||||
|
case member -> MEMBER;
|
||||||
|
case restricted -> RESTRICTED;
|
||||||
|
case left -> LEFT;
|
||||||
|
case kicked -> KICKED;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasPermission (UserPermissionLevel required) {
|
||||||
|
return this.permissionLevel >= required.permissionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.UniversalCommand;
|
||||||
|
|
||||||
|
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(UniversalCommand.format(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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi.event;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.response.BaseResponse;
|
||||||
|
|
||||||
|
public class EventRuntimeException extends RuntimeException {
|
||||||
|
|
||||||
|
public EventRuntimeException () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventRuntimeException (String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ActionFailed extends EventRuntimeException {
|
||||||
|
|
||||||
|
private final BaseResponse response;
|
||||||
|
|
||||||
|
public ActionFailed (BaseResponse response) {
|
||||||
|
super();
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFailed (String message, BaseResponse response) {
|
||||||
|
super(message);
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseResponse getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class MsgEscape {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static String escapeHtml (@Nonnull String raw) {
|
||||||
|
raw = raw.replaceAll("&", "&");
|
||||||
|
raw = raw.replaceAll("<", "<");
|
||||||
|
raw = raw.replaceAll(">", ">");
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.Chat;
|
||||||
|
import com.pengrad.telegrambot.model.Message;
|
||||||
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
|
||||||
|
public class TGToString {
|
||||||
|
|
||||||
|
public static TGToStringFromChat as (Chat chat) {
|
||||||
|
return new TGToStringFromChat(chat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TGToStringFromUser as (User user) {
|
||||||
|
return new TGToStringFromUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TGToStringFromMessage as (Message message) {
|
||||||
|
return new TGToStringFromMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.Chat;
|
||||||
|
|
||||||
|
public class TGToStringFromChat {
|
||||||
|
|
||||||
|
private final Chat data;
|
||||||
|
|
||||||
|
public TGToStringFromChat(Chat chat) {
|
||||||
|
this.data = chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStringFullNameId() {
|
||||||
|
if (data.title() == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot format private chat to group Name+Id format.");
|
||||||
|
}
|
||||||
|
return (data.username() == null) ?
|
||||||
|
(String.format("%s [%d]", data.title(), data.id())) :
|
||||||
|
(String.format("%s {%s}[%d]", data.title(), data.username(), data.id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package cc.sukazyo.cono.morny.util.tgapi;
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
import cc.sukazyo.untitled.telegram.api.formatting.TGToString;
|
|
||||||
import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape;
|
|
||||||
import com.pengrad.telegrambot.model.Message;
|
import com.pengrad.telegrambot.model.Message;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -12,7 +10,6 @@ public class TGToStringFromMessage extends TGToString {
|
|||||||
private final Message message;
|
private final Message message;
|
||||||
|
|
||||||
public TGToStringFromMessage (@Nonnull Message message) { this.message = message; }
|
public TGToStringFromMessage (@Nonnull Message message) { this.message = message; }
|
||||||
public static TGToStringFromMessage as (@Nonnull Message message) { return new TGToStringFromMessage(message); }
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getSenderFirstNameRefHtml () {
|
public String getSenderFirstNameRefHtml () {
|
@ -0,0 +1,53 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
|
||||||
|
public class TGToStringFromUser {
|
||||||
|
|
||||||
|
private final User data;
|
||||||
|
|
||||||
|
public TGToStringFromUser (User user) {
|
||||||
|
this.data = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String fullname () {
|
||||||
|
return data.firstName() + (data.lastName()==null ? "" : " "+data.lastName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String fullnameRefHtml () {
|
||||||
|
return String.format(
|
||||||
|
"<a href='tg://user?id=%d'>%s</a>",
|
||||||
|
data.id(),
|
||||||
|
MsgEscape.escapeHtml(fullname())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String fullnameRefMarkdown () {
|
||||||
|
return String.format(
|
||||||
|
"[%s](tg://user?id=%d)",
|
||||||
|
fullname(),
|
||||||
|
data.id()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String firstnameRefHtml () {
|
||||||
|
return String.format(
|
||||||
|
"<a href='tg://user?id=%d'>%s</a>",
|
||||||
|
data.id(),
|
||||||
|
MsgEscape.escapeHtml(data.firstName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String firstnameRefMarkdown () {
|
||||||
|
return String.format(
|
||||||
|
"[%s](tg://user?id=%d)",
|
||||||
|
data.firstName(),
|
||||||
|
data.id()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStringLogTag () {
|
||||||
|
return (data.username()==null ? fullname()+" " : "@"+data.username()) + "[" + data.id() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cc.sukazyo.cono.morny.util;
|
package cc.sukazyo.cono.morny.util.tgapi.formatting;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.User;
|
import com.pengrad.telegrambot.model.User;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
@ -11,7 +11,7 @@ import java.io.IOException;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.cono.morny.util.tgapi.formatting.MsgEscape.escapeHtml;
|
||||||
|
|
||||||
public class TelegramUserInformation {
|
public class TelegramUserInformation {
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package cc.sukazyo.cono.morny;
|
package cc.sukazyo.cono.morny;
|
||||||
|
|
||||||
import cc.sukazyo.untitled.util.command.CommonCommand;
|
import cc.sukazyo.cono.morny.util.UniversalCommand;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ public class MornyCLI {
|
|||||||
Scanner line = new Scanner(System.in);
|
Scanner line = new Scanner(System.in);
|
||||||
System.out.print("$ java -jar morny-coeur-"+GradleProjectConfigures.VERSION+".jar " );
|
System.out.print("$ java -jar morny-coeur-"+GradleProjectConfigures.VERSION+".jar " );
|
||||||
String x = line.nextLine();
|
String x = line.nextLine();
|
||||||
ServerMain.main(CommonCommand.format(x));
|
ServerMain.main(UniversalCommand.format(x));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user