mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-24 20:17:38 +08:00
添加 inline:myInformation 功能
- 更改使 inline:raw 功能在空 query message 时不触发 - 添加 inline:myInformation 作为 cmd:user 对自己使用的 inline 方式 - 将字符串化用户的信息的功能独立为 util method
This commit is contained in:
parent
a229ce9add
commit
b77194fef7
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.5.0.2
|
VERSION = 0.5.0.3
|
||||||
|
|
||||||
# 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.5.0.2";
|
public static final String VERSION = "0.5.0.3";
|
||||||
public static final long COMPILE_TIMESTAMP = 1643612350660L;
|
public static final long COMPILE_TIMESTAMP = 1643617049492L;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.command;
|
package cc.sukazyo.cono.morny.bot.command;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||||
|
import cc.sukazyo.cono.morny.util.TelegramUserInformation;
|
||||||
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
import cc.sukazyo.untitled.util.telegram.object.InputCommand;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.User;
|
import com.pengrad.telegrambot.model.User;
|
||||||
@ -63,59 +63,9 @@ public class GetUsernameAndId implements ITelegramCommand {
|
|||||||
|
|
||||||
final User user = response.chatMember().user();
|
final User user = response.chatMember().user();
|
||||||
|
|
||||||
final StringBuilder userInformation = new StringBuilder();
|
|
||||||
userInformation.append(String.format(
|
|
||||||
"""
|
|
||||||
userid :
|
|
||||||
- <code>%d</code>""",
|
|
||||||
userId
|
|
||||||
));
|
|
||||||
if (user.username() == null) {
|
|
||||||
userInformation.append("\nusername : <u>null</u>");
|
|
||||||
} else {
|
|
||||||
userInformation.append(String.format(
|
|
||||||
"""
|
|
||||||
|
|
||||||
username :
|
|
||||||
- <code>%s</code>""",
|
|
||||||
escapeHtml(user.username())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (user.firstName() == null) {
|
|
||||||
userInformation.append("\nfirstname : <u>null</u>");
|
|
||||||
} else {
|
|
||||||
userInformation.append(String.format(
|
|
||||||
"""
|
|
||||||
|
|
||||||
firstname :
|
|
||||||
- <code>%s</code>""",
|
|
||||||
escapeHtml(user.firstName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (user.lastName() == null) {
|
|
||||||
userInformation.append("\nlastname : <u>null</u>");
|
|
||||||
} else {
|
|
||||||
userInformation.append(String.format(
|
|
||||||
"""
|
|
||||||
|
|
||||||
lastname :
|
|
||||||
- <code>%s</code>""",
|
|
||||||
escapeHtml(user.lastName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (user.languageCode() != null) {
|
|
||||||
userInformation.append(String.format(
|
|
||||||
"""
|
|
||||||
|
|
||||||
language-code :
|
|
||||||
- <code>%s</code>""",
|
|
||||||
escapeHtml(user.languageCode())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
MornyCoeur.extra().exec(new SendMessage(
|
MornyCoeur.extra().exec(new SendMessage(
|
||||||
event.message().chat().id(),
|
event.message().chat().id(),
|
||||||
userInformation.toString()
|
TelegramUserInformation.informationOutputHTML(user)
|
||||||
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.query;
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.request.InlineQueryResult;
|
import com.pengrad.telegrambot.model.request.InlineQueryResult;
|
||||||
|
|
||||||
public interface ITelegramQuery <T extends InlineQueryResult<T>> {
|
public interface ITelegramQuery <T extends InlineQueryResult<T>> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
T query (Update event);
|
T query (Update event);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ public class MornyQueries {
|
|||||||
|
|
||||||
public MornyQueries () {
|
public MornyQueries () {
|
||||||
queryInstances.add(new RawText());
|
queryInstances.add(new RawText());
|
||||||
|
queryInstances.add(new MyInformation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
||||||
|
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
||||||
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.TelegramUserInformation;
|
||||||
|
|
||||||
|
public class MyInformation implements ITelegramQuery<InlineQueryResultArticle> {
|
||||||
|
|
||||||
|
public static final String ID_PREFIX = "[morny/info/me]";
|
||||||
|
public static final String TITLE = "My Account Information";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public InlineQueryResultArticle query(Update event) {
|
||||||
|
if (!(event.inlineQuery().query() == null || "".equals(event.inlineQuery().query()))) return null;
|
||||||
|
return new InlineQueryResultArticle(ID_PREFIX, TITLE, new InputTextMessageContent(
|
||||||
|
TelegramUserInformation.informationOutputHTML(event.inlineQuery().from())
|
||||||
|
).parseMode(ParseMode.HTML));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,18 +1,24 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.query;
|
package cc.sukazyo.cono.morny.bot.query;
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.util.EncryptUtils;
|
import cc.sukazyo.cono.morny.util.EncryptUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle;
|
||||||
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
import com.pengrad.telegrambot.model.request.InputTextMessageContent;
|
||||||
|
|
||||||
public class RawText implements ITelegramQuery<InlineQueryResultArticle> {
|
public class RawText implements ITelegramQuery<InlineQueryResultArticle> {
|
||||||
|
|
||||||
|
public static final String ID_PREFIX = "[morny/r/text]";
|
||||||
public static final String TITLE = "Raw Text";
|
public static final String TITLE = "Raw Text";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public InlineQueryResultArticle query (Update event) {
|
public InlineQueryResultArticle query (Update event) {
|
||||||
|
if (event.inlineQuery().query() == null || "".equals(event.inlineQuery().query())) return null;
|
||||||
return new InlineQueryResultArticle(
|
return new InlineQueryResultArticle(
|
||||||
"[morny/r/txt]" + EncryptUtils.encryptByMD5(event.inlineQuery().query()),
|
ID_PREFIX + EncryptUtils.encryptByMD5(event.inlineQuery().query()),
|
||||||
TITLE,
|
TITLE,
|
||||||
new InputTextMessageContent(event.inlineQuery().query())
|
new InputTextMessageContent(event.inlineQuery().query())
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
|
||||||
|
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||||
|
public class TelegramUserInformation {
|
||||||
|
|
||||||
|
public static String informationOutputHTML (User user) {
|
||||||
|
|
||||||
|
final StringBuilder userInformation = new StringBuilder();
|
||||||
|
userInformation.append(String.format(
|
||||||
|
"""
|
||||||
|
userid :
|
||||||
|
- <code>%d</code>""",
|
||||||
|
user.id()
|
||||||
|
));
|
||||||
|
if (user.username() == null) {
|
||||||
|
userInformation.append("\nusername : <u>null</u>");
|
||||||
|
} else {
|
||||||
|
userInformation.append(String.format(
|
||||||
|
"""
|
||||||
|
|
||||||
|
username :
|
||||||
|
- <code>%s</code>""",
|
||||||
|
escapeHtml(user.username())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (user.firstName() == null) {
|
||||||
|
userInformation.append("\nfirstname : <u>null</u>");
|
||||||
|
} else {
|
||||||
|
userInformation.append(String.format(
|
||||||
|
"""
|
||||||
|
|
||||||
|
firstname :
|
||||||
|
- <code>%s</code>""",
|
||||||
|
escapeHtml(user.firstName())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (user.lastName() == null) {
|
||||||
|
userInformation.append("\nlastname : <u>null</u>");
|
||||||
|
} else {
|
||||||
|
userInformation.append(String.format(
|
||||||
|
"""
|
||||||
|
|
||||||
|
lastname :
|
||||||
|
- <code>%s</code>""",
|
||||||
|
escapeHtml(user.lastName())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (user.languageCode() != null) {
|
||||||
|
userInformation.append(String.format(
|
||||||
|
"""
|
||||||
|
|
||||||
|
language-code :
|
||||||
|
- <code>%s</code>""",
|
||||||
|
escapeHtml(user.languageCode())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return userInformation.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user