mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
添加简单的 jrrp (#13),将项目的 NotNull 改为 Nonnull
This commit is contained in:
parent
a6040a6818
commit
bd29b4355e
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.4.2.8
|
VERSION = 0.4.2.9
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
|
@ -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.4.2.8";
|
public static final String VERSION = "0.4.2.9";
|
||||||
public static final long COMPILE_TIMESTAMP = 1640153916855L;
|
public static final long COMPILE_TIMESTAMP = 1640371604243L;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@ import com.pengrad.telegrambot.model.request.ParseMode;
|
|||||||
import com.pengrad.telegrambot.request.ForwardMessage;
|
import com.pengrad.telegrambot.request.ForwardMessage;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
import com.pengrad.telegrambot.request.SendSticker;
|
import com.pengrad.telegrambot.request.SendSticker;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 bot 呼叫主人的事件监听管理类
|
* 通过 bot 呼叫主人的事件监听管理类
|
||||||
@ -34,7 +35,7 @@ public class OnCallMe extends EventListener {
|
|||||||
* 如果匹配到呼叫,则返回{@code true},反之返回{@code false}
|
* 如果匹配到呼叫,则返回{@code true},反之返回{@code false}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onMessage (@NotNull Update update) {
|
public boolean onMessage (@Nonnull Update update) {
|
||||||
if (update.message().text() == null)
|
if (update.message().text() == null)
|
||||||
return false;
|
return false;
|
||||||
if (update.message().chat().type() != Chat.Type.Private)
|
if (update.message().chat().type() != Chat.Type.Private)
|
||||||
|
@ -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.api.InputCommand;
|
||||||
import cc.sukazyo.cono.morny.bot.event.on_commands.EventHack;
|
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.bot.event.on_commands.GetUsernameAndId;
|
||||||
|
import cc.sukazyo.cono.morny.data.MornyJrrp;
|
||||||
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
import cc.sukazyo.cono.morny.data.TelegramStickers;
|
||||||
import cc.sukazyo.cono.morny.util.CommonFormatUtils;
|
import cc.sukazyo.cono.morny.util.CommonFormatUtils;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
@ -52,6 +53,9 @@ public class OnCommandExecute extends EventListener {
|
|||||||
case "/runtime":
|
case "/runtime":
|
||||||
onCommandRuntimeExec(event);
|
onCommandRuntimeExec(event);
|
||||||
break;
|
break;
|
||||||
|
case "/jrrp":
|
||||||
|
onCommandJrrpExec(event);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return nonCommandExecutable(event, command);
|
return nonCommandExecutable(event, command);
|
||||||
}
|
}
|
||||||
@ -174,4 +178,17 @@ public class OnCommandExecute extends EventListener {
|
|||||||
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
).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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
|||||||
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
import com.pengrad.telegrambot.request.AnswerInlineQuery;
|
import com.pengrad.telegrambot.request.AnswerInlineQuery;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* telegram inlineQuery 功能的处理类,
|
* telegram inlineQuery 功能的处理类,
|
||||||
@ -22,7 +23,7 @@ public class OnInlineQuery extends EventListener {
|
|||||||
* @since 0.4.1.3
|
* @since 0.4.1.3
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onInlineQuery (@NotNull Update update) {
|
public boolean onInlineQuery (@Nonnull Update update) {
|
||||||
MornyCoeur.getAccount().execute(new AnswerInlineQuery(update.inlineQuery().id(), new InlineQueryResultArticle[]{
|
MornyCoeur.getAccount().execute(new AnswerInlineQuery(update.inlineQuery().id(), new InlineQueryResultArticle[]{
|
||||||
new InlineQueryResultArticle(
|
new InlineQueryResultArticle(
|
||||||
EncryptUtils.encryptByMD5(update.inlineQuery().query()),
|
EncryptUtils.encryptByMD5(update.inlineQuery().query()),
|
||||||
|
@ -3,7 +3,6 @@ package cc.sukazyo.cono.morny.bot.event;
|
|||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ public class OnUpdateTimestampOffsetLock extends EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMessage (@NotNull Update update) {
|
public boolean onMessage (@Nonnull Update update) {
|
||||||
return isOutdated(update.message().date());
|
return isOutdated(update.message().date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
src/main/java/cc/sukazyo/cono/morny/data/MornyJrrp.java
Normal file
23
src/main/java/cc/sukazyo/cono/morny/data/MornyJrrp.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cc.sukazyo.cono.morny.util;
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ public class EncryptUtils {
|
|||||||
/***
|
/***
|
||||||
* 对指定的字符串进行MD5加密
|
* 对指定的字符串进行MD5加密
|
||||||
*/
|
*/
|
||||||
|
@Nonnull
|
||||||
public static String encryptByMD5(String originString) {
|
public static String encryptByMD5(String originString) {
|
||||||
try {
|
try {
|
||||||
//创建具有MD5算法的信息摘要
|
//创建具有MD5算法的信息摘要
|
||||||
@ -28,9 +30,8 @@ public class EncryptUtils {
|
|||||||
String s = byteArrayToHex(bytes);
|
String s = byteArrayToHex(bytes);
|
||||||
return s.toUpperCase();
|
return s.toUpperCase();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user