diff --git a/gradle.properties b/gradle.properties
index 6ae3faa..f8bd912 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
## Core
-VERSION = 0.4.2.8
+VERSION = 0.4.2.9
# dependencies
diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java
index a708d13..a2cdfd5 100644
--- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java
+++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java
@@ -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.4.2.8";
- public static final long COMPILE_TIMESTAMP = 1640153916855L;
+ public static final String VERSION = "0.4.2.9";
+ public static final long COMPILE_TIMESTAMP = 1640371604243L;
}
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java
index 6d10041..911cb4f 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java
@@ -10,7 +10,8 @@ import com.pengrad.telegrambot.model.request.ParseMode;
import com.pengrad.telegrambot.request.ForwardMessage;
import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.request.SendSticker;
-import org.jetbrains.annotations.NotNull;
+
+import javax.annotation.Nonnull;
/**
* 通过 bot 呼叫主人的事件监听管理类
@@ -34,7 +35,7 @@ public class OnCallMe extends EventListener {
* 如果匹配到呼叫,则返回{@code true},反之返回{@code false}
*/
@Override
- public boolean onMessage (@NotNull Update update) {
+ public boolean onMessage (@Nonnull Update update) {
if (update.message().text() == null)
return false;
if (update.message().chat().type() != Chat.Type.Private)
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
index 5c4bee4..8b9d052 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
@@ -7,6 +7,7 @@ import cc.sukazyo.cono.morny.bot.api.EventListener;
import cc.sukazyo.cono.morny.bot.api.InputCommand;
import cc.sukazyo.cono.morny.bot.event.on_commands.EventHack;
import cc.sukazyo.cono.morny.bot.event.on_commands.GetUsernameAndId;
+import cc.sukazyo.cono.morny.data.MornyJrrp;
import cc.sukazyo.cono.morny.data.TelegramStickers;
import cc.sukazyo.cono.morny.util.CommonFormatUtils;
import com.pengrad.telegrambot.model.Update;
@@ -52,6 +53,9 @@ public class OnCommandExecute extends EventListener {
case "/runtime":
onCommandRuntimeExec(event);
break;
+ case "/jrrp":
+ onCommandJrrpExec(event);
+ break;
default:
return nonCommandExecutable(event, command);
}
@@ -174,4 +178,17 @@ public class OnCommandExecute extends EventListener {
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
}
+ private void onCommandJrrpExec (Update event) {
+ final double jrrp = MornyJrrp.getJrrpFromTelegramUser(event.message().from(), System.currentTimeMillis());
+ final String endChar = jrrp>70 ? "!" : jrrp>30 ? ";" : "...";
+ MornyCoeur.getAccount().execute(new SendMessage(
+ event.message().chat().id(),
+ String.format(
+ "%s 在(utc的)今天的运气指数是———— %.2f%%
%s",
+ event.message().from().id(), event.message().from().firstName(),
+ jrrp, endChar
+ )
+ ).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
+ }
+
}
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java
index 5dfd54e..1867887 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java
@@ -8,7 +8,8 @@ import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
import com.pengrad.telegrambot.model.request.ParseMode;
import com.pengrad.telegrambot.request.AnswerInlineQuery;
-import org.jetbrains.annotations.NotNull;
+
+import javax.annotation.Nonnull;
/**
* telegram inlineQuery 功能的处理类,
@@ -22,7 +23,7 @@ public class OnInlineQuery extends EventListener {
* @since 0.4.1.3
*/
@Override
- public boolean onInlineQuery (@NotNull Update update) {
+ public boolean onInlineQuery (@Nonnull Update update) {
MornyCoeur.getAccount().execute(new AnswerInlineQuery(update.inlineQuery().id(), new InlineQueryResultArticle[]{
new InlineQueryResultArticle(
EncryptUtils.encryptByMD5(update.inlineQuery().query()),
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUpdateTimestampOffsetLock.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUpdateTimestampOffsetLock.java
index 4b96284..80eff7f 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUpdateTimestampOffsetLock.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUpdateTimestampOffsetLock.java
@@ -3,7 +3,6 @@ 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 org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
@@ -32,7 +31,7 @@ public class OnUpdateTimestampOffsetLock extends EventListener {
}
@Override
- public boolean onMessage (@NotNull Update update) {
+ public boolean onMessage (@Nonnull Update update) {
return isOutdated(update.message().date());
}
diff --git a/src/main/java/cc/sukazyo/cono/morny/data/MornyJrrp.java b/src/main/java/cc/sukazyo/cono/morny/data/MornyJrrp.java
new file mode 100644
index 0000000..eb80f66
--- /dev/null
+++ b/src/main/java/cc/sukazyo/cono/morny/data/MornyJrrp.java
@@ -0,0 +1,23 @@
+package cc.sukazyo.cono.morny.data;
+
+import cc.sukazyo.cono.morny.util.EncryptUtils;
+import com.pengrad.telegrambot.model.User;
+
+/**
+ * Morny 的 jrrp 运算类.
+ *
+ * @see #getJrrpFromTelegramUser(User,long)
+ * @see #calcJrrpXmomi(long,long)
+ * @since 0.4.2.9
+ */
+public class MornyJrrp {
+
+ public static double getJrrpFromTelegramUser (User user, long timestamp) {
+ return calcJrrpXmomi(user.id(), timestamp / (1000 * 60 * 60 * 24)) * 100.0;
+ }
+
+ public static double calcJrrpXmomi (long userId, long dayStamp) {
+ return (double)Long.parseLong(EncryptUtils.encryptByMD5(userId + "@" + dayStamp).substring(0, 4), 16) / (double)0xffff;
+ }
+
+}
diff --git a/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java b/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java
index 6d502f9..243389a 100644
--- a/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java
+++ b/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java
@@ -1,5 +1,6 @@
package cc.sukazyo.cono.morny.util;
+import javax.annotation.Nonnull;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -18,6 +19,7 @@ public class EncryptUtils {
/***
* 对指定的字符串进行MD5加密
*/
+ @Nonnull
public static String encryptByMD5(String originString) {
try {
//创建具有MD5算法的信息摘要
@@ -28,9 +30,8 @@ public class EncryptUtils {
String s = byteArrayToHex(bytes);
return s.toUpperCase();
} catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
+ throw new IllegalStateException();
}
- return null;
}
/**