feat: add send mail command
This commit is contained in:
9 files changed
+104
-10
No files matched your search
@@ -31,9 +31,11 @@ val DEFAULT_CONFIG = Config(
|
||||
githubKey = "1919810",
|
||||
imageType = ImageType.PNG,
|
||||
openAIAPIHost = "https://api.moonshot.cn",
|
||||
openAIAPIKey = "114514"
|
||||
)
|
||||
|
||||
val ADMINS = listOf(
|
||||
3458671395L
|
||||
openAIAPIKey = "114514",
|
||||
smtpHost = "127.0.0.1",
|
||||
smtpPort = 25,
|
||||
smtpUser = "114514",
|
||||
smtpPassword = "1919810",
|
||||
smtpFromAddress = "fancybot@repo.rtast.cn",
|
||||
admins = listOf(3458671395L)
|
||||
)
|
||||
@@ -152,7 +152,8 @@ val commands = listOf(
|
||||
JiJianCommand(), LikeMeCommand(),
|
||||
CompilerCommand(), GPTCommand(),
|
||||
GithubUserCommand(), AboutCommand(),
|
||||
MusicPlayUrlCommand(), DomainPriceCommand()
|
||||
MusicPlayUrlCommand(), DomainPriceCommand(),
|
||||
SendMailCommand()
|
||||
)
|
||||
|
||||
suspend fun main() {
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/17
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.fancybot.configManager
|
||||
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.OBMessage
|
||||
import org.simplejavamail.api.mailer.config.TransportStrategy
|
||||
import org.simplejavamail.email.EmailBuilder
|
||||
import org.simplejavamail.mailer.MailerBuilder
|
||||
|
||||
class SendMailCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/mail")
|
||||
|
||||
private val smtpHost = configManager.smtpHost
|
||||
private val smtpPort = configManager.smtpPort
|
||||
private val smtpUser = configManager.smtpUser
|
||||
private val smtpPassword = configManager.smtpPassword
|
||||
private val smtpFromAddress = configManager.smtpFromAddress
|
||||
private val mailer = MailerBuilder.withSMTPServer(smtpHost, smtpPort, smtpUser, smtpPassword)
|
||||
.withTransportStrategy(TransportStrategy.SMTP_TLS)
|
||||
.clearEmailValidator()
|
||||
.async()
|
||||
.buildMailer()
|
||||
|
||||
private fun sendMail(target: String) {
|
||||
val email = EmailBuilder.startingBlank()
|
||||
.from(smtpFromAddress)
|
||||
.to(target)
|
||||
.withSubject("Test email from FancyBot")
|
||||
.withPlainText("Test email~")
|
||||
.buildEmail()
|
||||
this.mailer.sendMail(email)
|
||||
}
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("发送`/mail <收件人地址>`即可发送测试邮件~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
if (message.sender.userId !in configManager.admins) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addReply(message.messageId)
|
||||
.addText("你不许发邮件")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val target = args.first()
|
||||
this.sendMail(target)
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("正在发送邮件, 请查收~(可能会出现在垃圾桶中~)")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.ADMINS
|
||||
import cn.rtast.fancybot.configManager
|
||||
import cn.rtast.fancybot.signManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.enums.UserRole
|
||||
@@ -20,7 +20,7 @@ class MyPointCommand : BaseCommand() {
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
// query target's point
|
||||
if (args.isNotEmpty() && (message.sender.role == UserRole.admin || message.sender.userId in ADMINS)) {
|
||||
if (args.isNotEmpty() && (message.sender.role == UserRole.admin || message.sender.userId in configManager.admins)) {
|
||||
val targetId = args.first().toLong()
|
||||
val targetData = signManager.getStatus(targetId)
|
||||
val msg = MessageChain.Builder().addAt(message.sender.userId)
|
||||
|
||||
@@ -21,5 +21,11 @@ data class Config(
|
||||
val githubKey: String,
|
||||
val imageType: ImageType,
|
||||
val openAIAPIHost: String,
|
||||
val openAIAPIKey: String
|
||||
val openAIAPIKey: String,
|
||||
val smtpHost: String,
|
||||
val smtpPort: Int,
|
||||
val smtpUser: String,
|
||||
val smtpPassword: String,
|
||||
val smtpFromAddress: String,
|
||||
val admins: List<Long>
|
||||
)
|
||||
@@ -22,4 +22,10 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
val imageType get() = this.read<Config>().imageType
|
||||
val openAIAPIHost get() = this.read<Config>().openAIAPIHost
|
||||
val openAIAPIKey get() = this.read<Config>().openAIAPIKey
|
||||
val smtpHost get() = this.read<Config>().smtpHost
|
||||
val smtpPort get() = this.read<Config>().smtpPort
|
||||
val smtpUser get() = this.read<Config>().smtpUser
|
||||
val smtpPassword get() = this.read<Config>().smtpPassword
|
||||
val smtpFromAddress get() = this.read<Config>().smtpFromAddress
|
||||
val admins get() = this.read<Config>().admins
|
||||
}
|
||||
@@ -12,5 +12,13 @@
|
||||
"githubKey": "1919810",
|
||||
"imageType": "PNG",
|
||||
"openAIAPIHost": "https://api.moonshot.cn",
|
||||
"openAIAPIKey": "114514"
|
||||
"openAIAPIKey": "114514",
|
||||
"smtpHost": "127.0.0.1",
|
||||
"smtpPort": 25,
|
||||
"smtpUser": "114514",
|
||||
"smtpPassword": "1919810",
|
||||
"smtpFromAddress": "fancybot@repo.rtast.cn",
|
||||
"admins": [
|
||||
3458671395
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user