添加了无 tg 扩展信息的简单命令类型,添加 [喵呜] 命令类

This commit is contained in:
A.C.Sukazyo Eyre 2022-02-09 11:46:56 +08:00
parent 7ad7913a3c
commit 32d7fa7374
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
6 changed files with 97 additions and 22 deletions

View File

@ -1,6 +1,6 @@
## Core
VERSION = 0.5.0.5
VERSION = 0.5.0.6
# dependencies

View File

@ -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.5.0.5";
public static final long COMPILE_TIMESTAMP = 1644309862037L;
public static final String VERSION = "0.5.0.6";
public static final long COMPILE_TIMESTAMP = 1644378359640L;
}

View File

@ -0,0 +1,19 @@
package cc.sukazyo.cono.morny.bot.command;
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
import com.pengrad.telegrambot.model.Update;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public interface ISimpleCommand {
@Nonnull
String getName();
@Nullable
String[] getAliases();
void execute (@Nonnull InputCommand command, @Nonnull Update event);
}

View File

@ -1,23 +1,12 @@
package cc.sukazyo.cono.morny.bot.command;
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
import com.pengrad.telegrambot.model.Update;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public interface ITelegramCommand {
public interface ITelegramCommand extends ISimpleCommand {
@Nonnull
String getName();
@Nullable
String[] getAliases();
@Nonnull
String getParamRule();
@Nonnull
String getDescription();
void execute (@Nonnull InputCommand command, @Nonnull Update event);
}

View File

@ -29,9 +29,9 @@ import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
public class MornyCommands {
private final Map<String, ITelegramCommand> commands = new LinkedHashMap<>();
private final Map<String, ISimpleCommand> commands = new LinkedHashMap<>();
private void pushCommandTo (@Nonnull String name, @Nonnull ITelegramCommand instance) {
private void pushCommandTo (@Nonnull String name, @Nonnull ISimpleCommand instance) {
if (commands.containsKey(name)) {
logger.warn(String.format("""
Telegram command instance named "%s" already exists and will be override by another command instance
@ -45,8 +45,8 @@ public class MornyCommands {
commands.put(name, instance);
}
public void register (@Nonnull ITelegramCommand... list) {
for (ITelegramCommand instance : list) {
public void register (@Nonnull ISimpleCommand... list) {
for (ISimpleCommand instance : list) {
final String[] aliases = instance.getAliases();
pushCommandTo(instance.getName(), instance);
if (aliases!=null) for (String alias : aliases) pushCommandTo(alias, instance);
@ -70,6 +70,14 @@ public class MornyCommands {
new Exit()
);
// 统一注册这些奇怪的东西&.&
register(
new 喵呜.抱抱(),
new 喵呜.揉揉(),
new 喵呜.蹭蹭(),
new 喵呜.贴贴()
);
}
public boolean execute (@Nonnull InputCommand command, @Nonnull Update event) {
@ -99,11 +107,11 @@ public class MornyCommands {
public BotCommand[] getCommandListTelegram () {
final List<BotCommand> telegramFormatListing = new ArrayList<>();
commands.forEach((regKey, command) -> {
if (regKey.equals(command.getName())) {
if (command instanceof ITelegramCommand && regKey.equals(command.getName())) {
telegramFormatListing.add(formatTelegramCommandListLine(
command.getName(),
command.getParamRule(),
command.getDescription()
((ITelegramCommand)command).getParamRule(),
((ITelegramCommand)command).getDescription()
));
if (command.getAliases() != null) for (String alias : command.getAliases()) {
telegramFormatListing.add(formatTelegramCommandListLine(alias, "", ""));

View File

@ -0,0 +1,59 @@
package cc.sukazyo.cono.morny.bot.command;
import cc.sukazyo.cono.morny.MornyCoeur;
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;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@SuppressWarnings("NonAsciiCharacters")
public class 喵呜 {
public static class 抱抱 implements ISimpleCommand {
@Nonnull @Override public String getName () { return "/抱抱"; }
@Nullable @Override public String[] getAliases () { return new String[0]; }
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(),
"抱抱——"
));
}
}
public static class 揉揉 implements ISimpleCommand {
@Nonnull @Override public String getName () { return "/揉揉"; }
@Nullable @Override public String[] getAliases () { return new String[0]; }
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(),
"蹭蹭w"
));
}
}
public static class 蹭蹭 implements ISimpleCommand {
@Nonnull @Override public String getName () { return "/蹭蹭"; }
@Nullable @Override public String[] getAliases () { return new String[0]; }
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(),
"喵呜~-"
));
}
}
public static class 贴贴 implements ISimpleCommand {
@Nonnull @Override public String getName () { return "/贴贴"; }
@Nullable @Override public String[] getAliases () { return new String[0]; }
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(),
"<tg-spoiler>(贴贴喵呜&amp;.&amp;)</tg-spoiler>"
).parseMode(ParseMode.HTML));
}
}
}