添加简单的 jrrp (#13),将项目的 NotNull 改为 Nonnull

This commit is contained in:
A.C.Sukazyo Eyre 2021-12-25 02:50:30 +08:00
parent a6040a6818
commit bd29b4355e
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
8 changed files with 53 additions and 11 deletions

View File

@ -1,6 +1,6 @@
## Core
VERSION = 0.4.2.8
VERSION = 0.4.2.9
# 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.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;
}

View File

@ -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)

View File

@ -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(
"<a href='tg://user?id=%d'>%s</a> 在(utc的)今天的运气指数是———— <code>%.2f%%</code> %s",
event.message().from().id(), event.message().from().firstName(),
jrrp, endChar
)
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
}
}

View File

@ -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()),

View File

@ -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());
}

View File

@ -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;
}
}

View File

@ -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;
}
/**