mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
添加了 /info stickers 命令可以(通过反射)列出 morny 所定义的所有贴纸或是某贴纸名称所定义的贴纸
This commit is contained in:
parent
e947c3f239
commit
f195d5c1bb
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.8.0.5
|
VERSION = 0.8.0.6
|
||||||
|
|
||||||
CODENAME = fuzhou
|
CODENAME = fuzhou
|
||||||
|
|
||||||
|
@ -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.5";
|
public static final String VERSION = "0.8.0.6";
|
||||||
public static final String CODENAME = "fuzhou";
|
public static final String CODENAME = "fuzhou";
|
||||||
public static final long COMPILE_TIMESTAMP = 1665763018652L;
|
public static final long COMPILE_TIMESTAMP = 1665825000740L;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import java.util.Base64;
|
|||||||
|
|
||||||
import static cc.sukazyo.cono.morny.Log.logger;
|
import static cc.sukazyo.cono.morny.Log.logger;
|
||||||
|
|
||||||
public class EncUtils implements ITelegramCommand {
|
public class Encryptor implements ITelegramCommand {
|
||||||
|
|
||||||
@Nonnull @Override public String getName () { return "encrypt"; }
|
@Nonnull @Override public String getName () { return "encrypt"; }
|
||||||
@Nullable @Override public String[] getAliases () { return new String[0]; }
|
@Nullable @Override public String[] getAliases () { return new String[0]; }
|
@ -68,8 +68,9 @@ public class MornyCommands {
|
|||||||
new Nbnhhsh(),
|
new Nbnhhsh(),
|
||||||
new Ip186Query.Ip(),
|
new Ip186Query.Ip(),
|
||||||
new Ip186Query.Whois(),
|
new Ip186Query.Whois(),
|
||||||
new EncUtils(),
|
new Encryptor(),
|
||||||
new SaveData(),
|
new SaveData(),
|
||||||
|
new MornyInformations(),
|
||||||
new Version(),
|
new Version(),
|
||||||
new MornyRuntime(),
|
new MornyRuntime(),
|
||||||
new Jrrp(),
|
new Jrrp(),
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
|
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||||
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.request.SendSticker;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class MornyInformations implements ITelegramCommand {
|
||||||
|
|
||||||
|
private static final String ACT_STICKER = "stickers";
|
||||||
|
|
||||||
|
@Nonnull @Override public String getName () { return "info"; }
|
||||||
|
@Nullable @Override public String[] getAliases () { return new String[0]; }
|
||||||
|
@Nonnull @Override public String getParamRule () { return "[(stickers)|(stickers.)sticker_id]"; }
|
||||||
|
@Nonnull @Override public String getDescription () { return "输出 Morny 当前版本的一些预定义信息"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
|
||||||
|
|
||||||
|
if (!command.hasArgs() || command.getArgs().length > 1) {
|
||||||
|
MornyCoeur.extra().exec(new SendSticker(event.message().chat().id(), TelegramStickers.ID_404).replyToMessageId(event.message().messageId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String action = command.getArgs()[0];
|
||||||
|
|
||||||
|
if (action.startsWith("stickers")) {
|
||||||
|
if (action.equals("stickers"))
|
||||||
|
TelegramStickers.echoAllStickers(MornyCoeur.extra(), event.message().chat().id(), event.message().messageId());
|
||||||
|
else {
|
||||||
|
TelegramStickers.echoStickerByID(
|
||||||
|
action.substring((ACT_STICKER+".").length()),
|
||||||
|
MornyCoeur.extra(), event.message().chat().id(), event.message().messageId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MornyCoeur.extra().exec(new SendSticker(event.message().chat().id(), TelegramStickers.ID_404).replyToMessageId(event.message().messageId()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,12 @@
|
|||||||
package cc.sukazyo.cono.morny.data;
|
package cc.sukazyo.cono.morny.data;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.ExtraAction;
|
||||||
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
|
import com.pengrad.telegrambot.request.SendSticker;
|
||||||
|
import com.pengrad.telegrambot.response.SendResponse;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存放 bot 使用到的贴纸
|
* 存放 bot 使用到的贴纸
|
||||||
* @since 0.4.2.0
|
* @since 0.4.2.0
|
||||||
@ -17,4 +24,45 @@ public class TelegramStickers {
|
|||||||
public static final String ID_PROGYNOVA = "CAACAgUAAxkBAAICm2KEuL7UQqNP7vSPCg2DHJIND6UsAAKLAwACH4WSBszIo722aQ3jJAQ";
|
public static final String ID_PROGYNOVA = "CAACAgUAAxkBAAICm2KEuL7UQqNP7vSPCg2DHJIND6UsAAKLAwACH4WSBszIo722aQ3jJAQ";
|
||||||
public static final String ID_NETWORK_ERR = "CAACAgEAAxkBAAID0WNJgNEkD726KW4vZeFlw0FlVVyNAAIXJgACePzGBb50o7O1RbxoKgQ";
|
public static final String ID_NETWORK_ERR = "CAACAgEAAxkBAAID0WNJgNEkD726KW4vZeFlw0FlVVyNAAIXJgACePzGBb50o7O1RbxoKgQ";
|
||||||
|
|
||||||
|
public static void echoAllStickers (ExtraAction actionObject, long sentChat, int replyToMessageId) {
|
||||||
|
|
||||||
|
for (Field object : TelegramStickers.class.getFields()) {
|
||||||
|
if (object.getType()==String.class && object.getName().startsWith("ID_")) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
final String stickerId = (String)object.get("");
|
||||||
|
SendSticker echo = new SendSticker(sentChat, stickerId);
|
||||||
|
SendMessage echoName = new SendMessage(sentChat, object.getName());
|
||||||
|
if (replyToMessageId!=-1) echo.replyToMessageId(replyToMessageId);
|
||||||
|
SendResponse echoedName = actionObject.exec(echoName);
|
||||||
|
actionObject.exec(echo.replyToMessageId(echoedName.message().messageId()));
|
||||||
|
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void echoStickerByID (String stickerFieldID, ExtraAction actionObject, long sentChat, int replyToMessageId) {
|
||||||
|
try {
|
||||||
|
// normally get the sticker and echo
|
||||||
|
Field sticker = TelegramStickers.class.getField(stickerFieldID);
|
||||||
|
SendMessage echoName = new SendMessage(sentChat, sticker.getName());
|
||||||
|
SendSticker echo = new SendSticker(sentChat, (String)sticker.get(""));
|
||||||
|
if (replyToMessageId!=-1) echo.replyToMessageId(replyToMessageId);
|
||||||
|
SendResponse echoedName = actionObject.exec(echoName);
|
||||||
|
actionObject.exec(echo.replyToMessageId(echoedName.message().messageId()));
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// no such sticker found
|
||||||
|
SendSticker echo404 = new SendSticker(sentChat, TelegramStickers.ID_404);
|
||||||
|
if (replyToMessageId!=-1) echo404.replyToMessageId(replyToMessageId);
|
||||||
|
actionObject.exec(echo404);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// java-reflect get sticker FILE_ID failed
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user