[[[release 0.6.0.2]]]

## 📇功能

- @KuoHuanHuan 定制的睡觉禁止发言功能添加
- 斜线响应使其基本符合 t.me/hasutestbot 标准 (#26
This commit is contained in:
A.C.Sukazyo Eyre 2022-03-15 17:45:35 +08:00
commit 77337b4557
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
7 changed files with 96 additions and 26 deletions

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.5.1.1 VERSION = 0.6.0.2
# dependencies # dependencies

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.5.1.1"; public static final String VERSION = "0.6.0.2";
public static final long COMPILE_TIMESTAMP = 1644381533694L; public static final long COMPILE_TIMESTAMP = 1647237887029L;
} }

View File

@ -76,7 +76,8 @@ public class MornyCommands {
new 喵呜.抱抱(), new 喵呜.抱抱(),
new 喵呜.揉揉(), new 喵呜.揉揉(),
new 喵呜.蹭蹭(), new 喵呜.蹭蹭(),
new 喵呜.贴贴() new 喵呜.贴贴(),
new 私わね()
); );
} }

View File

@ -0,0 +1,38 @@
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.request.SendMessage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.ThreadLocalRandom;
@SuppressWarnings("NonAsciiCharacters")
public class 私わね implements ISimpleCommand {
@Nonnull
@Override public String getName () { return "/me"; }
@Nullable
@Override public String[] getAliases () { return null; }
@Override
public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
if (ThreadLocalRandom.current().nextInt(521) == 0) {
// 可以接入未来的心情系统如果有的话
final String text = switch (ThreadLocalRandom.current().nextInt(11)) {
case 0,7,8,9,10 -> "才不是";
case 1,2,3,6 -> "才不是!";
case 4,5 -> "才不是..";
default -> throw new IllegalStateException("Unexpected random value in 私わね command.");
};
MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(),
text
).replyToMessageId(event.message().messageId()));
}
}
}

View File

@ -11,11 +11,13 @@ public class EventListeners {
public static final OnInlineQueries INLINE_QUERY = new OnInlineQueries(); public static final OnInlineQueries INLINE_QUERY = new OnInlineQueries();
public static final OnCallMe CALL_ME = new OnCallMe(); public static final OnCallMe CALL_ME = new OnCallMe();
public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle(); public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle();
public static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep();
public static void registerAllListeners () { public static void registerAllListeners () {
EventListenerManager.addListener( EventListenerManager.addListener(
ACTIVITY_RECORDER, ACTIVITY_RECORDER,
UPDATE_TIMESTAMP_OFFSET_LOCK, UPDATE_TIMESTAMP_OFFSET_LOCK,
KUOHUANHUAN_NEED_SLEEP,
COMMANDS_LISTENER, COMMANDS_LISTENER,
USER_SLASH_ACTION, USER_SLASH_ACTION,
INLINE_QUERY, INLINE_QUERY,

View File

@ -0,0 +1,32 @@
package cc.sukazyo.cono.morny.bot.event;
import cc.sukazyo.cono.morny.MornyCoeur;
import cc.sukazyo.cono.morny.bot.api.EventListener;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.DeleteMessage;
import javax.annotation.Nonnull;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class OnKuohuanhuanNeedSleep extends EventListener {
@Override
public boolean onMessage (@Nonnull Update update) {
if (
update.message().from().id() == 786563752L && (
new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) >= 23 ||
new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) < 5
)
) {
MornyCoeur.extra().exec(
new DeleteMessage(update.message().chat().id(),
update.message().messageId())
);
return true;
}
return false;
}
}

View File

@ -38,25 +38,23 @@ public class OnUserSlashAction extends EventListener {
return false; return false;
} }
int prefixLength = 1; final String[] action = CommonCommand.format(text);
boolean useVerbSuffix = true; action[0] = action[0].substring(1);
boolean useObjectPrefix = true;
if (text.startsWith("//#") || text.startsWith("///")) { if (action[0].matches("^[a-zA-Z_]+$")) {
useVerbSuffix = false; return false; // 忽略掉 Telegram 命令格式的输入
useObjectPrefix = false; } else if (action[0].contains("/")) {
prefixLength = 3; return false; // 忽略掉疑似目录格式的输入
} else if (text.startsWith("/#")) {
useObjectPrefix = false;
prefixLength = 2;
} else if (text.startsWith("//")) {
useVerbSuffix = false;
prefixLength = 2;
} }
final String[] action = CommonCommand.format(text.substring(prefixLength)); final boolean isHardParse = "".equals(action[0]);
final String verb = action[0]; /* 忽略空数据 */ if (isHardParse && action.length < 2) { return false; }
final boolean hasObject = action.length != 1; final String verb = isHardParse ? action[1] : action[0];
final String object = StringArrays.connectStringArray(action, " ", 1, action.length-1); final boolean hasObject = action.length != (isHardParse?2:1);
final String object =
hasObject ?
StringArrays.connectStringArray(action, " ", isHardParse?2:1, action.length-1) :
"";
final User origin = event.message().from(); final User origin = event.message().from();
final User target = (event.message().replyToMessage() == null ? ( final User target = (event.message().replyToMessage() == null ? (
origin origin
@ -67,16 +65,15 @@ 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(
"%s %s%s %s%s%s", "%s %s%s %s %s!",
TGToString.as(origin).firstnameRefHtml(), TGToString.as(origin).firstnameRefHtml(),
verb, escapeHtml((useVerbSuffix?"":"")), escapeHtml(verb), escapeHtml((hasObject?"":"")),
origin==target ? origin==target ?
"<a href='tg://user?id="+target.id()+"'>自己</a>" : "<a href='tg://user?id="+target.id()+"'>自己</a>" :
TGToString.as(target).firstnameRefHtml(), TGToString.as(target).firstnameRefHtml(),
escapeHtml((hasObject ? (useObjectPrefix ?"": " ") : "")), escapeHtml(hasObject ? object+" " : "")
escapeHtml((hasObject ? object : ""))
) )
).parseMode(ParseMode.HTML)); ).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId()));
return true; return true;