feat: add gravatar command
This commit is contained in:
3 files changed
+48
-2
No files matched your search
@@ -126,5 +126,6 @@ val commands = listOf(
|
|||||||
ZDJDCommand(), ScanQRCodeCommand(), TTSCommand(), SlimeChunkHelperCommand(),
|
ZDJDCommand(), ScanQRCodeCommand(), TTSCommand(), SlimeChunkHelperCommand(),
|
||||||
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
||||||
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand(),
|
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand(),
|
||||||
TodayEatCommand(), TodayDrinkCommand(), MCLoginCommand(), RCONCommand()
|
TodayEatCommand(), TodayDrinkCommand(), MCLoginCommand(), RCONCommand(),
|
||||||
|
GravatarCommand()
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/14
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.lookup
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
|
import cn.rtast.fancybot.util.misc.toURL
|
||||||
|
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||||
|
import cn.rtast.fancybot.util.str.getMD5
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
|
||||||
|
@CommandDescription("查询用户的Gravatar头像")
|
||||||
|
class GravatarCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/g", "/gravatar")
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val GRAVATAR_URL = "https://gravatar.rtast.cn/avatar"
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val emailMD5 = if (args.first().trim().lowercase().contains("@")) args.first().trim().lowercase().getMD5()
|
||||||
|
else args.first().trim().lowercase()
|
||||||
|
val avatarImage = "$GRAVATAR_URL/$emailMD5?size=256".toURL().readBytes().encodeToBase64()
|
||||||
|
val msg = MessageChain.Builder().addImage(avatarImage, true).build()
|
||||||
|
message.reply(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.util.str
|
|||||||
|
|
||||||
import java.awt.Graphics2D
|
import java.awt.Graphics2D
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
fun setTruncate(origin: String, g2d: Graphics2D, maxWidth: Int = 500): String {
|
fun setTruncate(origin: String, g2d: Graphics2D, maxWidth: Int = 500): String {
|
||||||
val fontMetrics = g2d.fontMetrics
|
val fontMetrics = g2d.fontMetrics
|
||||||
@@ -51,3 +52,13 @@ fun Int.formatToMinutes(): String {
|
|||||||
val String.proxy get() = this.replace("https://", "https://proxy.rtast.cn/https/")
|
val String.proxy get() = this.replace("https://", "https://proxy.rtast.cn/https/")
|
||||||
|
|
||||||
val String.uriEncode get() = URLEncoder.encode(this, "UTF-8")
|
val String.uriEncode get() = URLEncoder.encode(this, "UTF-8")
|
||||||
|
|
||||||
|
fun String.getMD5(): String {
|
||||||
|
return this.toByteArray().getMD5()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteArray.getMD5(): String {
|
||||||
|
val md = MessageDigest.getInstance("MD5")
|
||||||
|
val hashBytes = md.digest(this)
|
||||||
|
return hashBytes.joinToString("") { "%02x".format(it) }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user