mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
吃药提醒改为向频道发送文本消息,取消pin,添加了提醒被编辑的轮子 #36
This commit is contained in:
parent
c63217f0c6
commit
072a37b49b
@ -1,6 +1,6 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.7.1.1
|
||||
VERSION = 0.7.1.2
|
||||
|
||||
CODENAME = fuzhou
|
||||
|
||||
|
@ -4,7 +4,7 @@ package cc.sukazyo.cono.morny;
|
||||
* the final field that will be updated by gradle automatically.
|
||||
*/
|
||||
public class GradleProjectConfigures {
|
||||
public static final String VERSION = "0.7.1.1";
|
||||
public static final String VERSION = "0.7.1.2";
|
||||
public static final String CODENAME = "fuzhou";
|
||||
public static final long COMPILE_TIMESTAMP = 1654430498871L;
|
||||
public static final long COMPILE_TIMESTAMP = 1654487392325L;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public class EventListeners {
|
||||
@SuppressWarnings("unused") static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep();
|
||||
public static final OnUserRandoms USER_RANDOMS = new OnUserRandoms();
|
||||
public static final OnCallMsgSend CALL_MSG_SEND = new OnCallMsgSend();
|
||||
public static final OnMedicationNotifyApply MEDICATION_NOTIFY_APPLY = new OnMedicationNotifyApply();
|
||||
|
||||
public static void registerAllListeners () {
|
||||
EventListenerManager.addListener(
|
||||
@ -26,6 +27,7 @@ public class EventListeners {
|
||||
INLINE_QUERY,
|
||||
CALL_ME,
|
||||
CALL_MSG_SEND,
|
||||
MEDICATION_NOTIFY_APPLY,
|
||||
EVENT_HACK_HANDLE
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package cc.sukazyo.cono.morny.bot.event;
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import cc.sukazyo.cono.morny.daemon.MedicationTimer;
|
||||
import cc.sukazyo.cono.morny.daemon.MornyDaemons;
|
||||
import com.pengrad.telegrambot.model.Message;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class OnMedicationNotifyApply extends EventListener {
|
||||
|
||||
@Override
|
||||
public boolean onEditedChannelPost (@NotNull Update update) {
|
||||
return editedMessageProcess(update.editedChannelPost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditedMessage (@NotNull Update update) {
|
||||
return editedMessageProcess(update.editedMessage());
|
||||
}
|
||||
|
||||
private boolean editedMessageProcess (Message edited) {
|
||||
if (edited.chat().id() != MedicationTimer.NOTIFY_CHAT) return false;
|
||||
MornyDaemons.medicationTimerInstance.refreshNotificationWrite(edited);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,31 @@
|
||||
package cc.sukazyo.cono.morny.daemon;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||
import com.pengrad.telegrambot.request.PinChatMessage;
|
||||
import com.pengrad.telegrambot.request.SendSticker;
|
||||
import cc.sukazyo.cono.morny.util.CommonFormatUtils;
|
||||
import com.pengrad.telegrambot.model.Message;
|
||||
import com.pengrad.telegrambot.model.MessageEntity;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
import com.pengrad.telegrambot.request.EditMessageText;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import com.pengrad.telegrambot.response.SendResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.sukazyo.cono.morny.Log.logger;
|
||||
|
||||
public class MedicationTimer extends Thread {
|
||||
|
||||
public static final long NOTIFY_RECEIVE_CHAT = 5028252995L;
|
||||
public static final long NOTIFY_CHAT = -1001729016815L;
|
||||
public static final String NOTIFY_MESSAGE = "\uD83C\uDF65⏲";
|
||||
private static final String DAEMON_THREAD_NAME = "TIMER_Medication";
|
||||
|
||||
private static final long LAST_NOTIFY_ID_NULL = -1L;
|
||||
private long lastNotify = LAST_NOTIFY_ID_NULL;
|
||||
|
||||
|
||||
MedicationTimer () {
|
||||
super("TIMER_Medication");
|
||||
super(DAEMON_THREAD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,9 +46,25 @@ public class MedicationTimer extends Thread {
|
||||
logger.info("MedicationTimer stopped");
|
||||
}
|
||||
|
||||
private static void sendNotification () {
|
||||
SendResponse m = MornyCoeur.extra().exec(new SendSticker(NOTIFY_RECEIVE_CHAT, TelegramStickers.ID_PROGYNOVA));
|
||||
if (m.isOk()) MornyCoeur.extra().exec(new PinChatMessage(NOTIFY_RECEIVE_CHAT, m.message().messageId()));
|
||||
private void sendNotification () {
|
||||
final SendResponse resp = MornyCoeur.extra().exec(new SendMessage(NOTIFY_CHAT, NOTIFY_MESSAGE));
|
||||
if (resp.isOk()) lastNotify = resp.message().messageId();
|
||||
else lastNotify = LAST_NOTIFY_ID_NULL;
|
||||
}
|
||||
|
||||
public void refreshNotificationWrite (Message edited) {
|
||||
if (edited.messageId() != lastNotify) return;
|
||||
final String editTime = CommonFormatUtils.formatDate(edited.editDate()*1000, 8);
|
||||
ArrayList<MessageEntity> entities = new ArrayList<>();
|
||||
if (edited.entities() != null) entities.addAll(List.of(edited.entities()));
|
||||
entities.add(new MessageEntity(MessageEntity.Type.italic, edited.text().length() + "\n-- ".length(), editTime.length()));
|
||||
EditMessageText sending = new EditMessageText(
|
||||
NOTIFY_CHAT,
|
||||
edited.messageId(),
|
||||
edited.text() + "\n-- " + editTime + " --"
|
||||
).parseMode(ParseMode.HTML).entities(entities.toArray(MessageEntity[]::new));
|
||||
MornyCoeur.extra().exec(sending);
|
||||
lastNotify = LAST_NOTIFY_ID_NULL;
|
||||
}
|
||||
|
||||
private static long calcNextRoutineTimestamp () {
|
||||
|
@ -4,12 +4,11 @@ import static cc.sukazyo.cono.morny.Log.logger;
|
||||
|
||||
public class MornyDaemons {
|
||||
|
||||
static MedicationTimer medicationTimerInstance;
|
||||
public static final MedicationTimer medicationTimerInstance = new MedicationTimer();
|
||||
|
||||
public static void start () {
|
||||
logger.info("ALL Morny Daemons starting...");
|
||||
TrackerDataManager.init();
|
||||
medicationTimerInstance = new MedicationTimer();
|
||||
medicationTimerInstance.start();
|
||||
logger.info("Morny Daemons started.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user