├── gradle.properties ├── settings.gradle.kts ├── example ├── question │ └── 123456.lua ├── profile │ └── 123456.lua ├── bilibili │ └── 123456.lua ├── sponsor │ └── afdian.jpg ├── captcha │ └── screenshot.jpg └── afdian │ └── 123456.lua ├── src ├── main │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ ├── xyz.cssxsh.mirai.spi.ComparableService │ │ │ └── net.mamoe.mirai.console.plugin.jvm.JvmPlugin │ └── kotlin │ │ └── xyz │ │ └── cssxsh │ │ └── mirai │ │ └── auth │ │ ├── MiraiAuthStatus.kt │ │ ├── logger.kt │ │ ├── validator │ │ ├── afdian │ │ │ ├── AFDianApiException.kt │ │ │ ├── AFDianDataWrapper.kt │ │ │ ├── AFDianUser.kt │ │ │ ├── AFDianRequest.kt │ │ │ ├── AFDianQuery.kt │ │ │ ├── AFDianSponsor.kt │ │ │ ├── AFDianOrder.kt │ │ │ └── AFDianSponsorPlan.kt │ │ ├── bilibili │ │ │ ├── BiliBiliFansMedal.kt │ │ │ ├── BiliBiliResult.kt │ │ │ ├── BiliBiliFansMedalDetail.kt │ │ │ └── BiliBiliUserInfo.kt │ │ ├── sina │ │ │ └── SinaVerifyResult.kt │ │ ├── AbstractMiraiChecker.kt │ │ ├── MiraiValidator.kt │ │ ├── MiraiChecker.kt │ │ ├── MiraiQuestionChecker.kt │ │ ├── MiraiProfileChecker.kt │ │ ├── MiraiGuardChecker.kt │ │ ├── MiraiCaptchaValidator.kt │ │ └── MiraiSponsorChecker.kt │ │ ├── data │ │ └── MiraiAuthJoinConfig.kt │ │ ├── command │ │ ├── MiraiAuthCaptchaCommand.kt │ │ ├── MiraiAuthCheckCommand.kt │ │ └── MiraiAuthJoinCommand.kt │ │ ├── spi │ │ └── MiraiAuthApprover.kt │ │ ├── MiraiAuthenticatorPlugin.kt │ │ └── MiraiAuthenticator.kt └── test │ └── kotlin │ └── xyz │ └── cssxsh │ └── mirai │ └── auth │ └── MiraiAuthenticatorTest.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .github └── workflows │ └── test.yml ├── .run └── RunTerminal.run.xml ├── .gitignore ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "mirai-authenticator" -------------------------------------------------------------------------------- /example/question/123456.lua: -------------------------------------------------------------------------------- 1 | ---@return boolean 2 | return answer == "1919810"; -------------------------------------------------------------------------------- /example/profile/123456.lua: -------------------------------------------------------------------------------- 1 | ---@return boolean 2 | return fromProfile:getAge() > 0; -------------------------------------------------------------------------------- /example/bilibili/123456.lua: -------------------------------------------------------------------------------- 1 | ---@return boolean 2 | return medal:getTargetId() == 269415357 and medal:getLevel() >= 20; -------------------------------------------------------------------------------- /example/sponsor/afdian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cssxsh/mirai-authenticator/HEAD/example/sponsor/afdian.jpg -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/xyz.cssxsh.mirai.spi.ComparableService: -------------------------------------------------------------------------------- 1 | xyz.cssxsh.mirai.auth.spi.MiraiAuthApprover -------------------------------------------------------------------------------- /example/captcha/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cssxsh/mirai-authenticator/HEAD/example/captcha/screenshot.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cssxsh/mirai-authenticator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin: -------------------------------------------------------------------------------- 1 | xyz.cssxsh.mirai.auth.MiraiAuthenticatorPlugin -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/MiraiAuthStatus.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth 2 | 3 | /** 4 | * 认证状态 5 | * @property PASS 通过 6 | * @property FAIL 失败 7 | * @property BLACK 拉黑 8 | * @property IGNORE 忽略 9 | */ 10 | public enum class MiraiAuthStatus { 11 | PASS, FAIL, BLACK, IGNORE 12 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/logger.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth 2 | 3 | import net.mamoe.mirai.utils.* 4 | 5 | internal val logger by lazy { 6 | try { 7 | MiraiAuthenticatorPlugin.logger 8 | } catch (_: Throwable) { 9 | MiraiLogger.Factory.create(MiraiAuthenticator::class) 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianApiException.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | public class AFDianApiException(public val body: AFDianDataWrapper) : IllegalStateException() { 4 | override val message: String = "Error Code: ${body.code} Error Message: ${body.message} Data: ${body.data}" 5 | } -------------------------------------------------------------------------------- /example/afdian/123456.lua: -------------------------------------------------------------------------------- 1 | ---@return boolean 2 | 3 | -- print(answer); 4 | local list = query:getList(); 5 | for index = 1, list:size() do 6 | local sponsor = list:get(index - 1); 7 | local user = sponsor:getUser(); 8 | -- print(user); 9 | if user:getUserId() == answer or user:getName() == answer then 10 | return true; 11 | end 12 | end 13 | 14 | return false; -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianDataWrapper.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @Serializable 7 | public data class AFDianDataWrapper( 8 | @SerialName("data") 9 | val data: JsonElement = JsonNull, 10 | @SerialName("ec") 11 | val code: Int = 0, 12 | @SerialName("em") 13 | val message: String = "" 14 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianUser.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | 5 | @Serializable 6 | internal data class AFDianUser( 7 | @SerialName("avatar") 8 | val avatar: String = "", 9 | @SerialName("name") 10 | val name: String = "", 11 | @SerialName("user_id") 12 | val userId: String = "", 13 | @SerialName("user_private_id") 14 | val userPrivateId: String = "" 15 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianRequest.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | 5 | @PublishedApi 6 | @Serializable 7 | internal data class AFDianRequest( 8 | @SerialName("params") 9 | val params: String = "", 10 | @SerialName("sign") 11 | val sign: String = "", 12 | @SerialName("ts") 13 | val timestamp: Int = 0, 14 | @SerialName("user_id") 15 | val userId: String = "" 16 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/bilibili/BiliBiliFansMedal.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.bilibili 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @PublishedApi 7 | @Serializable 8 | internal data class BiliBiliFansMedal( 9 | @SerialName("medal") 10 | val medal: JsonElement = JsonNull, 11 | @SerialName("show") 12 | val show: Boolean = false, 13 | @SerialName("wear") 14 | val wear: Boolean = false 15 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianQuery.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | 5 | @PublishedApi 6 | @Serializable 7 | internal data class AFDianQuery( 8 | @SerialName("list") 9 | val list: List = emptyList(), 10 | @SerialName("request") 11 | val request: AFDianRequest = AFDianRequest(), 12 | @SerialName("total_count") 13 | val count: Int = 0, 14 | @SerialName("total_page") 15 | val page: Int = 0 16 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/bilibili/BiliBiliResult.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.bilibili 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @PublishedApi 7 | @Serializable 8 | internal data class BiliBiliResult( 9 | @SerialName("code") 10 | val code: Int = 0, 11 | @SerialName("data") 12 | val `data`: JsonElement = JsonNull, 13 | @SerialName("message") 14 | val message: String = "", 15 | @SerialName("ttl") 16 | val ttl: Int = 0 17 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/sina/SinaVerifyResult.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.sina 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @PublishedApi 7 | @Serializable 8 | internal data class SinaVerifyResult( 9 | @SerialName("errno") 10 | val errno: Int = 0, 11 | @SerialName("code") 12 | val code: Int = 0, 13 | @SerialName("data") 14 | val data: JsonElement = JsonNull, 15 | @SerialName("msg") 16 | val message: String = "", 17 | @SerialName("result") 18 | val result: Boolean = false 19 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianSponsor.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | 5 | @PublishedApi 6 | @Serializable 7 | internal data class AFDianSponsor( 8 | @SerialName("all_sum_amount") 9 | val allSumAmount: String = "", 10 | @SerialName("current_plan") 11 | val currentPlan: AFDianSponsorPlan = AFDianSponsorPlan(), 12 | @SerialName("first_pay_time") 13 | val firstPayTime: Int = 0, 14 | @SerialName("last_pay_time") 15 | val lastPayTime: Int = 0, 16 | @SerialName("sponsor_plans") 17 | val sponsorPlans: List = emptyList(), 18 | @SerialName("user") 19 | val user: AFDianUser = AFDianUser() 20 | ) -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: MiraiAuthenticator Test 2 | on: 3 | push: 4 | paths-ignore: 5 | - '**/*.md' 6 | pull_request: 7 | paths-ignore: 8 | - '**/*.md' 9 | 10 | jobs: 11 | check: 12 | environment: AFDIAN 13 | runs-on: ubuntu-latest 14 | steps: 15 | 16 | - name: Checkout 17 | uses: actions/checkout@v3 18 | 19 | - name: Setup JDK 11 20 | uses: actions/setup-java@v3 21 | with: 22 | distribution: 'adopt' 23 | java-version: '11' 24 | 25 | - name: chmod -R 777 * 26 | run: chmod -R 777 * 27 | 28 | - name: Init gradle project 29 | run: ./gradlew clean --scan 30 | 31 | - name: Assemble 32 | run: ./gradlew assemble --scan 33 | 34 | - name: MiraiAuthenticatorTest 35 | run: ./gradlew test --tests "xyz.cssxsh.mirai.auth.MiraiAuthenticatorTest" --scan --info 36 | env: 37 | AFDIAN_USER_ID: ${{ secrets.AFDIAN_USER_ID }} 38 | AFDIAN_USER_TOKEN: ${{ secrets.AFDIAN_USER_TOKEN }} 39 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/AbstractMiraiChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import net.mamoe.mirai.event.events.* 4 | import net.mamoe.mirai.utils.* 5 | import java.nio.file.* 6 | import javax.script.* 7 | 8 | /** 9 | * 校验接口 10 | */ 11 | public abstract class AbstractMiraiChecker : MiraiChecker { 12 | protected open val logger: MiraiLogger = MiraiLogger.Factory.create(this::class) 13 | protected val manager: ScriptEngineManager = ScriptEngineManager(this::class.java.classLoader) 14 | protected abstract val folder: Path 15 | 16 | /** 17 | * 装入基本 Bindings 18 | */ 19 | public override fun T.apply(event: MemberJoinRequestEvent): T = apply { 20 | this["bot"] = event.bot 21 | this["logger"] = logger 22 | this["eventId"] = event.eventId 23 | this["fromId"] = event.fromId 24 | this["fromNick"] = event.fromNick 25 | this["groupId"] = event.groupId 26 | this["groupName"] = event.groupName 27 | this["message"] = event.message 28 | this["invitorId"] = event.invitorId 29 | } 30 | } -------------------------------------------------------------------------------- /.run/RunTerminal.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/data/MiraiAuthJoinConfig.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.data 2 | 3 | import net.mamoe.mirai.console.data.* 4 | 5 | @PublishedApi 6 | internal object MiraiAuthJoinConfig : AutoSavePluginConfig("join") { 7 | @ValueName("timeout") 8 | @ValueDescription("等待问题提交时间") 9 | var timeout: Long by value(30_000L) 10 | 11 | @ValueName("count") 12 | @ValueDescription("问题允许的回答次数") 13 | var count: Int by value(3) 14 | 15 | @ValueName("tip") 16 | @ValueDescription("验证码的提示") 17 | var tip: String by value("请输入图片验证码的内容") 18 | 19 | @ValueName("place") 20 | @ValueDescription("加群请求将失败交由管理员处理") 21 | val place: MutableSet by value() 22 | 23 | @ValueName("checkers") 24 | @ValueDescription("检查内容配置") 25 | val checkers: MutableMap> by value() 26 | 27 | @ValueName("validators") 28 | @ValueDescription("验证内容配置") 29 | val validators: MutableMap> by value() 30 | 31 | @ValueName("official") 32 | @ValueDescription("官方机器人ID, 会自动放行") 33 | val official: MutableSet by value { 34 | add(2854196301) 35 | add(2854196306) 36 | add(2854196310) 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiValidator.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import net.mamoe.mirai.event.events.* 4 | import net.mamoe.mirai.message.data.* 5 | 6 | /** 7 | * 验证接口 8 | * @see MiraiCaptchaValidator 9 | */ 10 | public interface MiraiValidator { 11 | /** 12 | * 获取问题, 重复访问等于刷新状态 13 | */ 14 | public suspend fun question(event: MemberJoinEvent): Message 15 | 16 | /** 17 | * 提交答案 18 | */ 19 | public suspend fun auth(answer: String): Boolean 20 | 21 | public companion object { 22 | @PublishedApi 23 | internal val providers: MutableMap MiraiValidator> = HashMap() 24 | 25 | init { 26 | providers["captcha"] = ::MiraiCaptchaValidator 27 | } 28 | 29 | /** 30 | * 构建一个指定 id 的验证器 31 | */ 32 | public operator fun invoke(id: String): MiraiValidator { 33 | val block = providers[id] ?: throw NoSuchElementException("MiraiValidator ${id}.") 34 | return block() 35 | } 36 | 37 | /** 38 | * 设置一个新的验证器 39 | */ 40 | public operator fun set(id: String, provider: () -> MiraiValidator) { 41 | providers[id] = provider 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/command/MiraiAuthCaptchaCommand.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.command 2 | 3 | import net.mamoe.mirai.console.command.* 4 | import net.mamoe.mirai.event.* 5 | import net.mamoe.mirai.event.events.* 6 | import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource 7 | import xyz.cssxsh.mirai.auth.* 8 | import xyz.cssxsh.mirai.auth.data.* 9 | import xyz.cssxsh.mirai.auth.validator.* 10 | 11 | @PublishedApi 12 | internal object MiraiAuthCaptchaCommand : SimpleCommand( 13 | owner = MiraiAuthenticatorPlugin, 14 | primaryName = "auth-captcha", 15 | description = "测试验证码" 16 | ) { 17 | 18 | @Handler 19 | suspend fun UserCommandSender.handle() { 20 | val validator = MiraiCaptchaValidator() 21 | val image = validator.getCaptchaImage().toExternalResource().use { resource -> 22 | subject.uploadImage(resource) 23 | } 24 | sendMessage(message = image + MiraiAuthJoinConfig.tip) 25 | val next = subject.bot.eventChannel 26 | .nextEvent(priority = EventPriority.HIGH, intercept = true) { it.sender == user } 27 | 28 | val answer = next.message.contentToString() 29 | 30 | val result = validator.verifyCaptcha(code = answer) 31 | 32 | sendMessage(message = "验证结果: ${result.code != -102} (${result.code})") 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/bilibili/BiliBiliFansMedalDetail.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.bilibili 2 | 3 | import kotlinx.serialization.* 4 | 5 | @PublishedApi 6 | @Serializable 7 | internal data class BiliBiliFansMedalDetail( 8 | @SerialName("day_limit") 9 | val dayLimit: Int = 0, 10 | @SerialName("guard_level") 11 | val guardLevel: Int = 0, 12 | @SerialName("intimacy") 13 | val intimacy: Int = 0, 14 | @SerialName("is_lighted") 15 | val isLighted: Int = 0, 16 | @SerialName("level") 17 | val level: Int = 0, 18 | @SerialName("light_status") 19 | val lightStatus: Int = 0, 20 | @SerialName("medal_color") 21 | val medalColor: Long = 0, 22 | @SerialName("medal_color_border") 23 | val medalColorBorder: Long = 0, 24 | @SerialName("medal_color_end") 25 | val medalColorEnd: Long = 0, 26 | @SerialName("medal_color_start") 27 | val medalColorStart: Long = 0, 28 | @SerialName("medal_id") 29 | val medalId: Long = 0, 30 | @SerialName("medal_name") 31 | val medalName: String = "", 32 | @SerialName("next_intimacy") 33 | val nextIntimacy: Long = 0, 34 | @SerialName("score") 35 | val score: Long = 0, 36 | @SerialName("target_id") 37 | val targetId: Long = 0, 38 | @SerialName("uid") 39 | val uid: Long = 0, 40 | @SerialName("wearing_status") 41 | val wearingStatus: Int = 0 42 | ) -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import net.mamoe.mirai.event.events.* 4 | import javax.script.* 5 | 6 | /** 7 | * 校验接口 8 | */ 9 | public interface MiraiChecker { 10 | 11 | /** 12 | * 检查 13 | */ 14 | public suspend fun check(event: MemberJoinRequestEvent): Boolean 15 | 16 | /** 17 | * 装入基本 Bindings 18 | */ 19 | public fun T.apply(event: MemberJoinRequestEvent): T 20 | 21 | public companion object { 22 | @PublishedApi 23 | internal val providers: MutableMap MiraiChecker> = HashMap() 24 | 25 | init { 26 | providers["question"] = ::MiraiQuestionChecker 27 | providers["profile"] = ::MiraiProfileChecker 28 | providers["bilibili"] = ::MiraiGuardChecker 29 | providers["afdian"] = ::MiraiSponsorChecker 30 | } 31 | 32 | /** 33 | * 构建一个指定 id 的校验器 34 | */ 35 | public operator fun invoke(id: String): MiraiChecker { 36 | val block = providers[id] ?: throw NoSuchElementException("MiraiChecker $id") 37 | return block() 38 | } 39 | 40 | /** 41 | * 设置一个新的校验器 42 | */ 43 | public operator fun set(id: String, provider: () -> MiraiChecker) { 44 | providers[id] = provider 45 | } 46 | 47 | @PublishedApi 48 | internal val QA: Regex = """(?:问题|答案):(.+)""".toRegex() 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiQuestionChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import net.mamoe.mirai.event.events.* 4 | import kotlin.io.path.* 5 | 6 | /** 7 | * 校验加群问题 8 | */ 9 | @PublishedApi 10 | internal class MiraiQuestionChecker : MiraiChecker, AbstractMiraiChecker() { 11 | override val folder = Path(System.getProperty("xyz.cssxsh.mirai.auth.validator.question", "question")) 12 | 13 | override suspend fun check(event: MemberJoinRequestEvent): Boolean { 14 | val match = MiraiChecker.QA.find(event.message) ?: return true 15 | val question = match.groupValues[1] 16 | val answer = match.next()?.groupValues?.get(1) ?: return false 17 | val script = folder.listDirectoryEntries().firstOrNull { it.name.startsWith("${event.groupId}.") } 18 | ?: throw IllegalStateException("获取 ${event.groupId} Question 验证脚本失败") 19 | val engine = manager.getEngineByExtension(script.extension) 20 | ?: throw NoSuchElementException("获取 ${script.extension} 脚本引擎失败") 21 | 22 | val bindings = engine.createBindings() 23 | bindings["question"] = question 24 | bindings["answer"] = answer 25 | 26 | val result = try { 27 | (engine.eval(script.readText(), bindings) as org.luaj.vm2.LuaValue) 28 | .toboolean() 29 | } catch (cause: Exception) { 30 | throw IllegalStateException("验证 ${event.eventId} 失败", cause) 31 | } 32 | 33 | return result 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiProfileChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import net.mamoe.mirai.* 4 | import net.mamoe.mirai.event.events.* 5 | import kotlin.io.path.* 6 | 7 | /** 8 | * 校验简介信息 9 | */ 10 | @PublishedApi 11 | internal class MiraiProfileChecker : MiraiChecker, AbstractMiraiChecker() { 12 | override val folder = Path(System.getProperty("xyz.cssxsh.mirai.auth.validator.profile", "profile")) 13 | 14 | override suspend fun check(event: MemberJoinRequestEvent): Boolean { 15 | val script = folder.listDirectoryEntries().firstOrNull { it.name.startsWith("${event.groupId}.") } 16 | ?: throw IllegalStateException("获取 ${event.groupId} Profile 验证脚本失败") 17 | val engine = manager.getEngineByExtension(script.extension) 18 | ?: throw NoSuchElementException("获取 ${script.extension} 脚本引擎失败") 19 | 20 | val profile = try { 21 | Mirai.queryProfile(event.bot, event.fromId) 22 | } catch (cause: Exception) { 23 | throw IllegalStateException("查询 ${event.fromId} 信息失败", cause) 24 | } 25 | 26 | val bindings = engine.createBindings().apply(event = event) 27 | bindings["fromProfile"] = profile 28 | 29 | val result = try { 30 | (engine.eval(script.readText(), bindings) as org.luaj.vm2.LuaValue) 31 | .toboolean() 32 | } catch (cause: Exception) { 33 | throw IllegalStateException("验证 ${event.eventId} 失败", cause) 34 | } 35 | 36 | return result 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/spi/MiraiAuthApprover.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.spi 2 | 3 | import net.mamoe.mirai.event.events.* 4 | import xyz.cssxsh.mirai.auth.* 5 | import xyz.cssxsh.mirai.spi.* 6 | 7 | /** 8 | * SPI 接口 9 | * @see ComparableService 10 | */ 11 | public class MiraiAuthApprover : MemberApprover { 12 | // FriendApprover, GroupApprover, 13 | override val id: String = "mirai-authenticator" 14 | override val level: Int = 10 15 | 16 | // override suspend fun approve(event: NewFriendRequestEvent): ApproveResult = ApproveResult.Ignore 17 | // 18 | // override suspend fun approve(event: BotInvitedJoinGroupRequestEvent): ApproveResult = ApproveResult.Ignore 19 | 20 | override suspend fun approve(event: MemberJoinRequestEvent): ApproveResult { 21 | return when (MiraiAuthenticator.auth(event)) { 22 | MiraiAuthStatus.PASS -> ApproveResult.Accept 23 | MiraiAuthStatus.FAIL -> ApproveResult.Reject(black = false, message = "验证失败") 24 | MiraiAuthStatus.BLACK -> ApproveResult.Reject(black = true, message = "验证失败") 25 | MiraiAuthStatus.IGNORE -> ApproveResult.Ignore 26 | } 27 | } 28 | 29 | // override suspend fun approve(event: FriendAddEvent): ApproveResult = ApproveResult.Ignore 30 | // 31 | // override suspend fun approve(event: BotJoinGroupEvent): ApproveResult = ApproveResult.Ignore 32 | 33 | override suspend fun approve(event: MemberJoinEvent): ApproveResult { 34 | return when (MiraiAuthenticator.auth(event)) { 35 | MiraiAuthStatus.PASS -> ApproveResult.Accept 36 | MiraiAuthStatus.FAIL -> ApproveResult.Reject(black = false, message = "验证失败") 37 | MiraiAuthStatus.BLACK -> ApproveResult.Reject(black = true, message = "验证失败") 38 | MiraiAuthStatus.IGNORE -> ApproveResult.Ignore 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianOrder.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | 5 | @PublishedApi 6 | @Serializable 7 | internal data class AFDianOrder( 8 | @SerialName("address_address") 9 | val address: String = "", 10 | @SerialName("create_time") 11 | val createTime: Long = 0, 12 | @SerialName("address_person") 13 | val person: String = "", 14 | @SerialName("address_phone") 15 | val phone: String = "", 16 | @SerialName("discount") 17 | val discount: String = "", 18 | @SerialName("month") 19 | val month: Int = 0, 20 | @SerialName("out_trade_no") 21 | val trade: String = "", 22 | @SerialName("plan_id") 23 | val planId: String = "", 24 | @SerialName("plan_title") 25 | val planTitle: String = "", 26 | @SerialName("product_type") 27 | val productType: Int = 0, 28 | @SerialName("redeem_id") 29 | val redeemId: String = "", 30 | @SerialName("remark") 31 | val remark: String = "", 32 | @SerialName("show_amount") 33 | val showAmount: String = "", 34 | @SerialName("sku_detail") 35 | val skuDetail: List = emptyList(), 36 | @SerialName("status") 37 | val status: Int = 0, 38 | @SerialName("total_amount") 39 | val totalAmount: String = "", 40 | @SerialName("user_id") 41 | val userId: String = "", 42 | @SerialName("user_private_id") 43 | val userPrivateId: String = "" 44 | ) { 45 | @Serializable 46 | data class SkuDetail( 47 | @SerialName("album_id") 48 | val albumId: String = "", 49 | @SerialName("count") 50 | val count: Int = 0, 51 | @SerialName("name") 52 | val name: String = "", 53 | @SerialName("pic") 54 | val picture: String = "", 55 | @SerialName("post_id") 56 | val postId: String = "", 57 | @SerialName("sku_id") 58 | val skuId: String = "", 59 | @SerialName("stock") 60 | val stock: String = "" 61 | ) 62 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/MiraiAuthenticatorPlugin.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth 2 | 3 | import kotlinx.coroutines.* 4 | import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register 5 | import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister 6 | import net.mamoe.mirai.console.plugin.jvm.* 7 | import net.mamoe.mirai.event.* 8 | import xyz.cssxsh.mirai.admin.* 9 | import xyz.cssxsh.mirai.auth.command.* 10 | import xyz.cssxsh.mirai.auth.data.* 11 | import xyz.cssxsh.mirai.auth.validator.* 12 | import javax.script.* 13 | 14 | @PublishedApi 15 | internal object MiraiAuthenticatorPlugin : KotlinPlugin( 16 | JvmPluginDescription( 17 | id = "xyz.cssxsh.mirai.plugin.mirai-authenticator", 18 | name = "mirai-authenticator", 19 | version = "1.1.0" 20 | ) { 21 | author("cssxsh") 22 | 23 | dependsOn("xyz.cssxsh.mirai.plugin.mirai-administrator", true) 24 | dependsOn("xyz.cssxsh.mirai.plugin.mirai-script-plugin", true) 25 | } 26 | ) { 27 | override fun onEnable() { 28 | MiraiAuthJoinConfig.reload() 29 | try { 30 | MiraiAdministrator 31 | } catch (_: NoClassDefFoundError) { 32 | MiraiAuthenticator.registerTo(globalEventChannel()) 33 | } 34 | val lua = ScriptEngineManager(jvmPluginClasspath.pluginClassLoader).getEngineByName("lua") 35 | if (lua == null) { 36 | jvmPluginClasspath.downloadAndAddToPath( 37 | jvmPluginClasspath.pluginIndependentLibrariesClassLoader, 38 | listOf("org.luaj:luaj-jse:3.0.1") 39 | ) 40 | } 41 | 42 | for ((key, _) in MiraiChecker.providers) { 43 | val profile = resolveDataFile(key) 44 | profile.mkdirs() 45 | System.setProperty("xyz.cssxsh.mirai.auth.validator.${key}", profile.path) 46 | } 47 | 48 | MiraiAuthJoinCommand.register() 49 | MiraiAuthCaptchaCommand.register() 50 | MiraiAuthCheckCommand.register() 51 | } 52 | 53 | override fun onDisable() { 54 | MiraiAuthJoinCommand.unregister() 55 | MiraiAuthCaptchaCommand.unregister() 56 | MiraiAuthCheckCommand.unregister() 57 | MiraiAuthenticator.cancel() 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/kotlin/xyz/cssxsh/mirai/auth/MiraiAuthenticatorTest.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth 2 | 3 | import kotlinx.coroutines.* 4 | import net.mamoe.mirai.event.* 5 | import net.mamoe.mirai.mock.* 6 | import org.junit.jupiter.api.* 7 | import xyz.cssxsh.mirai.auth.data.* 8 | import xyz.cssxsh.mirai.auth.validator.* 9 | import java.io.File 10 | 11 | internal class MiraiAuthenticatorTest { 12 | private val bot = MockBotFactory.newMockBotBuilder().create() 13 | private val group = bot.addGroup(123456, "mock") 14 | 15 | init { 16 | MiraiAuthenticator.registerTo(GlobalEventChannel) 17 | for ((key, _) in MiraiChecker.providers) { 18 | val folder = File("example/${key}") 19 | folder.mkdirs() 20 | System.setProperty("xyz.cssxsh.mirai.auth.validator.${key}", folder.path) 21 | } 22 | } 23 | 24 | @Test 25 | fun profile(): Unit = runBlocking { 26 | MiraiAuthJoinConfig.checkers[123456] = listOf("profile") 27 | group.broadcastNewMemberJoinRequestEvent( 28 | requester = 123456789, 29 | requesterName = "...", 30 | message = "" 31 | ) 32 | } 33 | 34 | @Test 35 | fun question(): Unit = runBlocking { 36 | MiraiAuthJoinConfig.checkers[123456] = listOf("question") 37 | group.broadcastNewMemberJoinRequestEvent( 38 | requester = 123456789, 39 | requesterName = "...", 40 | message = """ 41 | 问题:114514 42 | 答案:1919810 43 | """.trimIndent() 44 | ) 45 | } 46 | 47 | @Test 48 | fun bilibili(): Unit = runBlocking { 49 | MiraiAuthJoinConfig.checkers[123456] = listOf("bilibili") 50 | group.broadcastNewMemberJoinRequestEvent( 51 | requester = 123456789, 52 | requesterName = "...", 53 | message = """ 54 | 问题:你的UID 55 | 答案:730732 56 | """.trimIndent() 57 | ) 58 | } 59 | 60 | @Test 61 | fun afdian(): Unit = runBlocking { 62 | MiraiAuthJoinConfig.checkers[123456] = listOf("afdian") 63 | group.broadcastNewMemberJoinRequestEvent( 64 | requester = 123456789, 65 | requesterName = "...", 66 | message = """ 67 | 问题:你的爱发电ID 68 | 答案:730732 69 | """.trimIndent() 70 | ) 71 | } 72 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | # mpeltonen/sbt-idea plugin 11 | .idea_modules/ 12 | 13 | # JIRA plugin 14 | atlassian-ide-plugin.xml 15 | 16 | # Compiled class file 17 | *.class 18 | 19 | # Log file 20 | *.log 21 | 22 | # BlueJ files 23 | *.ctxt 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | 37 | *~ 38 | 39 | # temporary files which can be created if a process still has a handle open of a deleted file 40 | .fuse_hidden* 41 | 42 | # KDE directory preferences 43 | .directory 44 | 45 | # Linux trash folder which might appear on any partition or disk 46 | .Trash-* 47 | 48 | # .nfs files are created when an open file is removed but is still being accessed 49 | .nfs* 50 | 51 | # General 52 | .DS_Store 53 | .AppleDouble 54 | .LSOverride 55 | 56 | # Icon must end with two \r 57 | Icon 58 | 59 | # Thumbnails 60 | ._* 61 | 62 | # Files that might appear in the root of a volume 63 | .DocumentRevisions-V100 64 | .fseventsd 65 | .Spotlight-V100 66 | .TemporaryItems 67 | .Trashes 68 | .VolumeIcon.icns 69 | .com.apple.timemachine.donotpresent 70 | 71 | # Directories potentially created on remote AFP share 72 | .AppleDB 73 | .AppleDesktop 74 | Network Trash Folder 75 | Temporary Items 76 | .apdisk 77 | 78 | # Windows thumbnail cache files 79 | Thumbs.db 80 | Thumbs.db:encryptable 81 | ehthumbs.db 82 | ehthumbs_vista.db 83 | 84 | # Dump file 85 | *.stackdump 86 | 87 | # Folder config file 88 | [Dd]esktop.ini 89 | 90 | # Recycle Bin used on file shares 91 | $RECYCLE.BIN/ 92 | 93 | # Windows Installer files 94 | *.cab 95 | *.msi 96 | *.msix 97 | *.msm 98 | *.msp 99 | 100 | # Windows shortcuts 101 | *.lnk 102 | 103 | .gradle 104 | build/ 105 | 106 | # Ignore Gradle GUI config 107 | gradle-app.setting 108 | 109 | # Cache of project 110 | .gradletasknamecache 111 | 112 | **/build/ 113 | 114 | # Common working directory 115 | run/ 116 | 117 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 118 | !gradle-wrapper.jar 119 | 120 | 121 | # Local Test Launch point 122 | src/test/kotlin/RunTerminal.kt 123 | 124 | # Mirai console files with direct bootstrap 125 | /config 126 | /data 127 | /plugins 128 | /bots 129 | 130 | # Local Test Launch Point working directory 131 | /debug-sandbox 132 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/bilibili/BiliBiliUserInfo.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.bilibili 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @PublishedApi 7 | @Serializable 8 | internal data class BiliBiliUserInfo( 9 | @SerialName("birthday") 10 | val birthday: String = "", 11 | @SerialName("coins") 12 | val coins: Int = 0, 13 | @SerialName("contract") 14 | val contract: JsonElement = JsonNull, 15 | @SerialName("elec") 16 | val elec: JsonElement = JsonNull, 17 | @SerialName("face") 18 | val face: String = "", 19 | @SerialName("face_nft") 20 | val faceNft: Int = 0, 21 | @SerialName("face_nft_type") 22 | val faceNftType: Int = 0, 23 | @SerialName("fans_badge") 24 | val fansBadge: Boolean = false, 25 | @SerialName("fans_medal") 26 | val fansMedal: JsonElement = JsonNull, 27 | @SerialName("ga_data") 28 | val gaData: JsonElement = JsonNull, 29 | @SerialName("gaia_data") 30 | val gaiaData: JsonElement = JsonNull, 31 | @SerialName("gaia_res_type") 32 | val gaiaResType: Int = 0, 33 | @SerialName("is_followed") 34 | val isFollowed: Boolean = false, 35 | @SerialName("is_risk") 36 | val isRisk: Boolean = false, 37 | @SerialName("is_senior_member") 38 | val isSeniorMember: Int = 0, 39 | @SerialName("jointime") 40 | val jointime: Long = 0, 41 | @SerialName("level") 42 | val level: Int = 0, 43 | @SerialName("live_room") 44 | val liveRoom: JsonElement = JsonNull, 45 | @SerialName("mcn_info") 46 | val mcnInfo: JsonElement = JsonNull, 47 | @SerialName("mid") 48 | val mid: Long = 0, 49 | @SerialName("moral") 50 | val moral: Int = 0, 51 | @SerialName("name") 52 | val name: String = "", 53 | @SerialName("nameplate") 54 | val nameplate: JsonElement = JsonNull, 55 | @SerialName("official") 56 | val official: JsonElement = JsonNull, 57 | @SerialName("pendant") 58 | val pendant: JsonElement = JsonNull, 59 | @SerialName("profession") 60 | val profession: JsonElement = JsonNull, 61 | @SerialName("rank") 62 | val rank: Int = 0, 63 | @SerialName("school") 64 | val school: JsonElement = JsonNull, 65 | @SerialName("series") 66 | val series: JsonElement = JsonNull, 67 | @SerialName("sex") 68 | val sex: String = "", 69 | @SerialName("sign") 70 | val sign: String = "", 71 | @SerialName("silence") 72 | val silence: Int = 0, 73 | @SerialName("sys_notice") 74 | val sysNotice: JsonElement = JsonNull, 75 | @SerialName("tags") 76 | val tags: JsonElement = JsonNull, 77 | @SerialName("theme") 78 | val theme: JsonElement = JsonNull, 79 | @SerialName("top_photo") 80 | val topPhoto: String = "", 81 | @SerialName("user_honour_info") 82 | val userHonourInfo: JsonElement = JsonNull, 83 | @SerialName("vip") 84 | val vip: JsonElement = JsonNull, 85 | ) -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiGuardChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.call.* 5 | import io.ktor.client.engine.okhttp.* 6 | import io.ktor.client.plugins.* 7 | import io.ktor.client.plugins.compression.* 8 | import io.ktor.client.request.* 9 | import io.ktor.http.* 10 | import kotlinx.serialization.json.* 11 | import net.mamoe.mirai.event.events.* 12 | import xyz.cssxsh.mirai.auth.validator.bilibili.* 13 | import kotlin.io.path.* 14 | 15 | /** 16 | * 校验 b站粉丝牌 17 | */ 18 | @PublishedApi 19 | internal class MiraiGuardChecker : MiraiChecker, AbstractMiraiChecker() { 20 | override val folder = Path(System.getProperty("xyz.cssxsh.mirai.auth.validator.bilibili", "bilibili")) 21 | private val http: HttpClient = HttpClient(OkHttp) { 22 | BrowserUserAgent() 23 | ContentEncoding() 24 | } 25 | 26 | override suspend fun check(event: MemberJoinRequestEvent): Boolean { 27 | val script = folder.listDirectoryEntries().firstOrNull { it.name.startsWith("${event.groupId}.") } 28 | ?: throw IllegalStateException("获取 ${event.groupId} Guard 验证脚本失败") 29 | val engine = manager.getEngineByExtension(script.extension) 30 | ?: throw NoSuchElementException("获取 ${script.extension} 脚本引擎失败") 31 | 32 | val match = MiraiChecker.QA.find(event.message) ?: return true 33 | val question = match.groupValues[1] 34 | val answer = match.next()?.groupValues?.get(1) ?: return false 35 | val mid = answer.trim().toLong() 36 | 37 | val medal = try { 38 | fetchFansMedal(mid = mid) 39 | } catch (cause: Exception) { 40 | throw IllegalStateException("查询 ${event.fromId}-${mid} 信息失败", cause) 41 | } 42 | 43 | val bindings = engine.createBindings().apply(event = event) 44 | bindings["question"] = question 45 | bindings["answer"] = answer 46 | bindings["mid"] = mid 47 | bindings["medal"] = medal 48 | 49 | val result = try { 50 | (engine.eval(script.readText(), bindings) as org.luaj.vm2.LuaValue) 51 | .toboolean() 52 | } catch (cause: Exception) { 53 | throw IllegalStateException("验证 ${event.eventId} 失败", cause) 54 | } 55 | 56 | return result 57 | } 58 | 59 | @PublishedApi 60 | internal suspend fun fetchFansMedal(mid: Long): BiliBiliFansMedalDetail { 61 | val statement = http.prepareGet("https://api.bilibili.com/x/space/acc/info") { 62 | parameter("mid", mid) 63 | parameter("platform", "web") 64 | parameter("jsonp", "jsonp") 65 | } 66 | 67 | return statement.execute { response -> 68 | val text = response.body() 69 | if (response.status != HttpStatusCode.OK) throw ResponseException(response, text) 70 | try { 71 | val result = Json.decodeFromString(BiliBiliResult.serializer(), text) 72 | val info = Json.decodeFromJsonElement(BiliBiliUserInfo.serializer(), result.data) 73 | val medal = Json.decodeFromJsonElement(BiliBiliFansMedal.serializer(), info.fansMedal) 74 | Json.decodeFromJsonElement(BiliBiliFansMedalDetail.serializer(), medal.medal) 75 | } catch (cause: Exception) { 76 | throw ResponseException(response, text) 77 | .initCause(cause) 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiCaptchaValidator.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.call.* 5 | import io.ktor.client.engine.okhttp.* 6 | import io.ktor.client.plugins.* 7 | import io.ktor.client.plugins.compression.* 8 | import io.ktor.client.plugins.cookies.* 9 | import io.ktor.client.request.* 10 | import io.ktor.client.request.forms.* 11 | import io.ktor.client.statement.* 12 | import io.ktor.http.* 13 | import io.ktor.utils.io.charsets.* 14 | import kotlinx.serialization.json.* 15 | import net.mamoe.mirai.event.events.* 16 | import net.mamoe.mirai.message.data.* 17 | import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource 18 | import xyz.cssxsh.mirai.auth.data.* 19 | import xyz.cssxsh.mirai.auth.validator.sina.* 20 | 21 | /** 22 | * 验证器,验证码实现 23 | */ 24 | @PublishedApi 25 | internal class MiraiCaptchaValidator : MiraiValidator { 26 | private val http: HttpClient = HttpClient(OkHttp) { 27 | BrowserUserAgent() 28 | ContentEncoding() 29 | Charsets { 30 | responseCharsetFallback = Charset.forName("GBK") 31 | } 32 | install(HttpCookies) { 33 | storage = AcceptAllCookiesStorage() 34 | } 35 | } 36 | 37 | @PublishedApi 38 | internal suspend fun getCaptchaImage(): ByteArray { 39 | val html = http.get("https://mail.sina.com.cn/register/regmail.php").bodyAsText() 40 | val id = """(?<=accessid=).{42}""".toRegex().find(html)?.value 41 | ?: throw IllegalStateException("Not Found Access Id") 42 | val statement = http.prepareGet("https://mail.sina.com.cn/cgi-bin/imgcode.php") { 43 | parameter("t", 1) 44 | parameter("accessid", id) 45 | header(HttpHeaders.Referrer, "https://mail.sina.com.cn/register/regmail.php") 46 | header(HttpHeaders.Origin, "https://mail.sina.com.cn") 47 | } 48 | return statement.execute { response -> 49 | if (response.contentType() != ContentType.Image.JPEG) { 50 | throw ResponseException(response, response.bodyAsText()) 51 | } 52 | response.body() 53 | } 54 | } 55 | 56 | @PublishedApi 57 | internal suspend fun verifyCaptcha(code: String): SinaVerifyResult { 58 | val statement = http.prepareForm("https://mail.sina.com.cn/cgi-bin/RegPhoneCode.php", Parameters.build { 59 | append("phonenumber", "15874523695") 60 | append("email", "fgsj842376tysd@sina.com") 61 | append("imgvcode", code) 62 | }) { 63 | header(HttpHeaders.Referrer, "https://mail.sina.com.cn/register/regmail.php") 64 | header(HttpHeaders.Origin, "https://mail.sina.com.cn") 65 | } 66 | return statement.execute { response -> 67 | val text = response.body() 68 | if (response.status != HttpStatusCode.OK) throw ResponseException(response, text) 69 | try { 70 | Json.decodeFromString(SinaVerifyResult.serializer(), text) 71 | } catch (cause: Exception) { 72 | throw ResponseException(response, text) 73 | .initCause(cause) 74 | } 75 | } 76 | } 77 | 78 | override suspend fun question(event: MemberJoinEvent): Message { 79 | val bytes = getCaptchaImage() 80 | return bytes.toExternalResource().use { event.group.uploadImage(it) } + MiraiAuthJoinConfig.tip 81 | } 82 | 83 | override suspend fun auth(answer: String): Boolean { 84 | return when (verifyCaptcha(code = answer.trim()).code) { 85 | -102 -> false 86 | else -> true 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/command/MiraiAuthCheckCommand.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.command 2 | 3 | import net.mamoe.mirai.* 4 | import net.mamoe.mirai.console.command.* 5 | import net.mamoe.mirai.event.* 6 | import net.mamoe.mirai.event.events.* 7 | import net.mamoe.mirai.utils.* 8 | import xyz.cssxsh.mirai.auth.* 9 | import xyz.cssxsh.mirai.auth.validator.* 10 | import kotlin.random.* 11 | 12 | @PublishedApi 13 | @OptIn(MiraiInternalApi::class) 14 | internal object MiraiAuthCheckCommand : CompositeCommand( 15 | owner = MiraiAuthenticatorPlugin, 16 | primaryName = "auth-check", 17 | description = "测试校验器" 18 | ) { 19 | 20 | @SubCommand 21 | @Description("测试 question 校验器") 22 | suspend fun UserCommandSender.question(group: Long, question: String, answer: String) { 23 | val request = MemberJoinRequestEvent( 24 | bot = bot, 25 | eventId = Random.Default.nextLong(), 26 | message = """ 27 | 问题:$question 28 | 答案:$answer 29 | """.trimIndent(), 30 | fromId = 0, 31 | fromNick = "", 32 | groupId = group, 33 | groupName = "", 34 | invitorId = user.id 35 | ) 36 | 37 | val checker = MiraiQuestionChecker() 38 | val result = checker.check(event = request) 39 | 40 | sendMessage(message = "验证结果: $result") 41 | } 42 | 43 | @SubCommand 44 | @Description("测试 profile 校验器") 45 | suspend fun UserCommandSender.profile(group: Long, target: Long) { 46 | val request = MemberJoinRequestEvent( 47 | bot = bot, 48 | eventId = Random.Default.nextLong(), 49 | message = "", 50 | fromId = target, 51 | fromNick = "", 52 | groupId = group, 53 | groupName = "", 54 | invitorId = user.id 55 | ) 56 | 57 | sendMessage("${target}-${Mirai.queryProfile(bot, target)}") 58 | val checker = MiraiProfileChecker() 59 | val result = checker.check(event = request) 60 | 61 | sendMessage(message = "验证结果: $result") 62 | } 63 | 64 | @SubCommand 65 | @Description("测试 bilibili 校验器") 66 | suspend fun UserCommandSender.bilibili(group: Long, uid: Long) { 67 | val request = MemberJoinRequestEvent( 68 | bot = bot, 69 | eventId = Random.Default.nextLong(), 70 | message = """ 71 | 问题:请输入你的UID, (注意挂上舰长粉丝牌) 72 | 答案:$uid 73 | """.trimIndent(), 74 | fromId = 0, 75 | fromNick = "", 76 | groupId = group, 77 | groupName = "", 78 | invitorId = user.id 79 | ) 80 | 81 | val checker = MiraiGuardChecker() 82 | val result = checker.check(event = request) 83 | 84 | sendMessage(message = "验证结果: $result") 85 | } 86 | 87 | @SubCommand 88 | @Description("测试 afdian 校验器") 89 | suspend fun UserCommandSender.afdian(group: Long, uid: String) { 90 | val request = MemberJoinRequestEvent( 91 | bot = bot, 92 | eventId = Random.Default.nextLong(), 93 | message = """ 94 | 问题:请输入你的爱发电 ID 95 | 答案:$uid 96 | """.trimIndent(), 97 | fromId = 0, 98 | fromNick = "", 99 | groupId = group, 100 | groupName = "", 101 | invitorId = user.id 102 | ) 103 | 104 | val checker = MiraiSponsorChecker() 105 | val result = checker.check(event = request) 106 | 107 | sendMessage(message = "验证结果: $result") 108 | } 109 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/command/MiraiAuthJoinCommand.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.command 2 | 3 | import net.mamoe.mirai.console.command.* 4 | import net.mamoe.mirai.contact.* 5 | import xyz.cssxsh.mirai.auth.* 6 | import xyz.cssxsh.mirai.auth.data.* 7 | import xyz.cssxsh.mirai.auth.validator.* 8 | import kotlin.io.path.* 9 | 10 | @PublishedApi 11 | internal object MiraiAuthJoinCommand : CompositeCommand( 12 | owner = MiraiAuthenticatorPlugin, 13 | primaryName = "auth-join", 14 | description = "加群请求验证配置" 15 | ) { 16 | 17 | @SubCommand 18 | @Description("进群前检查配置") 19 | suspend fun CommandSender.check(group: Long, vararg types: String) { 20 | if (types.any { it !in MiraiChecker.providers }) { 21 | sendMessage("当前支持的类型 ${MiraiChecker.providers.keys}") 22 | return 23 | } 24 | for (type in types) { 25 | val script = Path(System.getProperty("xyz.cssxsh.mirai.auth.validator.$type", type), "${group}.lua") 26 | if (script.isReadable()) continue 27 | when (type) { 28 | "profile" -> script.writeText("""return fromProfile:getQLevel() > 4;""") 29 | "question" -> script.writeText("""return answer == "114514";""") 30 | "bilibili" -> script.writeText("""return medal:getTargetId() == 11153765 and medal:getLevel() >= 20;""") 31 | "afdian" -> script.writeText( 32 | """ 33 | local list = query:getList(); 34 | for index = 1, list:size() do 35 | local sponsor = list:get(index - 1); 36 | local user = sponsor:getUser(); 37 | if user:getUserId() == answer or user:getName() == answer then 38 | return true; 39 | end 40 | end 41 | 42 | return false; 43 | """.trimIndent() 44 | ) 45 | } 46 | sendMessage("之后,请编辑确认 $script") 47 | } 48 | 49 | MiraiAuthJoinConfig.checkers[group] = types.asList() 50 | sendMessage("群 $group 当前检查设置: ${types.joinToString()}") 51 | } 52 | 53 | @SubCommand 54 | @Description("进群后验证配置") 55 | suspend fun CommandSender.validator(group: Long, vararg types: String) { 56 | if (types.all { it in MiraiValidator.providers }) { 57 | MiraiAuthJoinConfig.validators[group] = types.asList() 58 | sendMessage("群 $group 当前验证设置: ${types.joinToString()}") 59 | } else { 60 | sendMessage("当前支持的类型 ${MiraiValidator.providers.keys}") 61 | } 62 | } 63 | 64 | @SubCommand 65 | @Description("设置自动放行的QQ号") 66 | suspend fun CommandSender.official(id: Long) { 67 | MiraiAuthJoinConfig.official.add(id) 68 | 69 | sendMessage("当前自动放行 ${MiraiAuthJoinConfig.official}") 70 | } 71 | 72 | @SubCommand 73 | @Description("问题回答等待时间") 74 | suspend fun CommandSender.timeout(mills: Long) { 75 | if (mills < 1_000) { 76 | sendMessage("单位是 毫秒 !") 77 | return 78 | } 79 | MiraiAuthJoinConfig.timeout = mills 80 | sendMessage("目前 等待时间 ${mills}ms") 81 | } 82 | 83 | @SubCommand 84 | @Description("问题允许回答次数") 85 | suspend fun CommandSender.count(value: Int) { 86 | if (value < 0) { 87 | sendMessage("至少 1 次") 88 | return 89 | } 90 | MiraiAuthJoinConfig.count = value 91 | sendMessage("目前 回答次数 $value 次") 92 | } 93 | 94 | @SubCommand 95 | @Description("验证码的提示") 96 | suspend fun CommandSender.tip(message: String) { 97 | MiraiAuthJoinConfig.tip = message 98 | sendMessage("目前 验证码的提示 $message") 99 | } 100 | 101 | @SubCommand 102 | @Description("加群请求失败交由管理员处理") 103 | suspend fun CommandSender.place(group: Long) { 104 | if (MiraiAuthJoinConfig.place.add(group)) { 105 | sendMessage("加群请求将失败交由管理员处理") 106 | } else { 107 | MiraiAuthJoinConfig.place.remove(group) 108 | sendMessage("取消加群请求失败交由管理员处理") 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/afdian/AFDianSponsorPlan.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator.afdian 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.json.* 5 | 6 | @Serializable 7 | internal data class AFDianSponsorPlan( 8 | @SerialName("bundle_sku_select_count") 9 | val bundleSkuSelectCount: Int = 0, 10 | @SerialName("bundle_stock") 11 | val bundleStock: Int = 0, 12 | @SerialName("can_buy_hide") 13 | val canBuyHide: Int = 0, 14 | @SerialName("can_ali_agreement") 15 | val canAliAgreement: Int = 0, 16 | @SerialName("config") 17 | val config: Config = Config(), 18 | @SerialName("coupon") 19 | val coupon: List = emptyList(), 20 | @SerialName("desc") 21 | val description: String = "", 22 | @SerialName("expire_time") 23 | val expireTime: Int = 0, 24 | @SerialName("favorable_price") 25 | val favorablePrice: Int = 0, 26 | @SerialName("has_coupon") 27 | val hasCoupon: Int = 0, 28 | @SerialName("has_plan_config") 29 | val hasPlanConfig: Int = 0, 30 | @SerialName("independent") 31 | val independent: Int = 0, 32 | @SerialName("name") 33 | val name: String = "", 34 | @SerialName("need_address") 35 | val needAddress: Int = 0, 36 | @SerialName("need_invite_code") 37 | val needInviteCode: Boolean = false, 38 | @SerialName("pay_month") 39 | val payMonth: Int = 0, 40 | @SerialName("permanent") 41 | val permanent: Int = 0, 42 | @SerialName("pic") 43 | val picture: String = "", 44 | @SerialName("plan_id") 45 | val planId: String = "", 46 | @SerialName("price") 47 | val price: String = "", 48 | @SerialName("product_type") 49 | val productType: Int = 0, 50 | @SerialName("rank") 51 | val rank: Int = 0, 52 | @SerialName("rankType") 53 | val rankType: Int = 0, 54 | @SerialName("sale_limit_count") 55 | val saleLimitCount: Int = 0, 56 | @SerialName("shipping_fee_info") 57 | val shippingFeeInfo: JsonElement = JsonNull, 58 | @SerialName("show_price") 59 | val showPrice: String = "", 60 | @SerialName("show_price_after_adjust") 61 | val showPriceAfterAdjust: String = "", 62 | @SerialName("sku_processed") 63 | val skuProcessed: List = emptyList(), 64 | @SerialName("status") 65 | val status: Int = 0, 66 | @SerialName("timing") 67 | val timing: Timing = Timing(), 68 | @SerialName("update_time") 69 | val updateTime: Int = 0, 70 | @SerialName("user_id") 71 | val userId: String = "" 72 | ) { 73 | @Serializable 74 | data class Config( 75 | @SerialName("create_time") 76 | val createTime: Int = 0, 77 | @SerialName("id") 78 | val id: Int = 0, 79 | @SerialName("plan_id") 80 | val planId: String = "", 81 | @SerialName("remark_name") 82 | val remarkName: String = "", 83 | @SerialName("remark_placeholder") 84 | val remarkPlaceholder: String = "", 85 | @SerialName("remark_required") 86 | val remarkRequired: Int = 0, 87 | @SerialName("status") 88 | val status: Int = 0, 89 | @SerialName("update_time") 90 | val updateTime: Int = 0, 91 | @SerialName("user_id") 92 | val userId: String = "" 93 | ) 94 | 95 | @Serializable 96 | data class SkuProcessed( 97 | @SerialName("album_id") 98 | val albumId: String = "", 99 | @SerialName("count") 100 | val count: Int = 0, 101 | @SerialName("name") 102 | val name: String = "", 103 | @SerialName("pic") 104 | val picture: String = "", 105 | @SerialName("post_id") 106 | val postId: String = "", 107 | @SerialName("price") 108 | val price: Double = 0.0, 109 | @SerialName("sku_id") 110 | val skuId: String = "", 111 | @SerialName("stock") 112 | val stock: String = "" 113 | ) 114 | 115 | @Serializable 116 | data class Timing( 117 | @SerialName("timing_off") 118 | val timingOff: Int = 0, 119 | @SerialName("timing_on") 120 | val timingOn: Int = 0, 121 | @SerialName("timing_sell_off") 122 | val timingSellOff: Int = 0, 123 | @SerialName("timing_sell_on") 124 | val timingSellOn: Int = 0 125 | ) 126 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mirai Authenticator 2 | 3 | > 基于 Mirai Console 的 加群/好友 验证插件 4 | 5 | [![Release](https://img.shields.io/github/v/release/cssxsh/mirai-authenticator)](https://github.com/cssxsh/mirai-authenticator/releases) 6 | [![Downloads](https://img.shields.io/github/downloads/cssxsh/mirai-authenticator/total)](https://repo1.maven.org/maven2/xyz/cssxsh/mirai/mirai-authenticator/) 7 | [![maven-central](https://img.shields.io/maven-central/v/xyz.cssxsh.mirai/mirai-authenticator)](https://search.maven.org/artifact/xyz.cssxsh.mirai/mirai-authenticator) 8 | [![MiraiAuthenticator Test](https://github.com/cssxsh/mirai-authenticator/actions/workflows/test.yml/badge.svg)](https://github.com/cssxsh/mirai-authenticator/actions/workflows/test.yml) 9 | 10 | **使用前应该查阅的相关文档或项目** 11 | 12 | * [User Manual](https://github.com/mamoe/mirai/blob/dev/docs/UserManual.md) 13 | * [Permission Command](https://github.com/mamoe/mirai/blob/dev/mirai-console/docs/BuiltInCommands.md#permissioncommand) 14 | * [Chat Command](https://github.com/project-mirai/chat-command) 15 | 16 | **目前只实现了加群验证的功能** 17 | 18 | ## MCL 指令安装 19 | 20 | **请确认 mcl.jar 的版本是 2.1.0+** 21 | `./mcl --update-package xyz.cssxsh.mirai:mirai-authenticator --channel maven-stable --type plugin` 22 | 23 | ## 指令 24 | 25 | ### auth-join 26 | 27 | 配置验证条件, 目前 check 中 可选的 type 有 `profile`, `question`, `bilibili`, `afdian` 28 | 配置验证条件, 目前 validator 中 可选的 type 有 `captcha` 29 | 30 | * `/auth-join check [group] {types}` 进群前检查 31 | 例如: `/auth-join check 123456 profile question` 32 | 33 | * `/auth-join validator [group] {types}` 进群后验证 34 | 例如: `/auth-join validator 123456 captcha` 35 | 36 | * `/auth-join official [id]` 设置自动放行的QQ号 37 | 例如: `/auth-join official 123456789` 38 | 39 | * `/auth-join timeout [mills]` 问题回答等待时间 40 | 例如: `/auth-join timeout 180000` 41 | 42 | * `/auth-join count [value]` 问题允许回答次数 43 | 例如: `/auth-join count 5` 44 | 45 | * `/auth-join tip [message]` 验证码的提示 46 | 例如: `/auth-join tip 请输入图片验证码的内容(不区分大小写)` 47 | 48 | * `/auth-join place [group]` 加群请求失败交由管理员处理 49 | 例如: `/auth-join place 123456` 50 | 51 | ### auth-captcha 52 | 53 | 测试验证码功能 54 | 55 | * `/auth-captcha` 会发送一张验证码并接受回答,以供测试 56 | 57 | ### auth-check 58 | 59 | 测试进群前检查功能 60 | 61 | * `/auth-check question [group] [question] [answer]` 测试群的 question 验证脚本 62 | `group` 是群号, `question` 是问题, `answer` 是答案 63 | 例如: `/auth-check question 123456 天王盖地虎 宝塔镇河妖` 64 | 65 | * `/auth-check profile [group] [target]` 测试群的 profile 验证脚本 66 | `group` 是群号, `target` 是被测试的qq号 67 | 例如: `/auth-check profile 123456 789566` 68 | 69 | * `/auth-check bilibili [group] [uid]` 测试群的 bilibili 验证脚本 70 | `group` 是群号, `uid` 是入群提交的 uid 71 | 例如: `/auth-check bilibili 123456 789566` 72 | 73 | * `/auth-check afdian [group] [uid]` 测试群的 afdian 验证脚本 74 | `group` 是群号, `uid` 是入群提交的 uid 75 | 例如: `/auth-check afdian 123456 dousha99` 76 | 77 | #### 效果 78 | 79 | 进群后验证: 80 | ![captcha](example/captcha/screenshot.jpg) 81 | 82 | ## 配置 Lua 校验脚本 83 | 84 | 自定义验证分别在以下文件夹中 85 | * `data/xyz.cssxsh.mirai.plugin.mirai-authenticator/profile` 86 | * `data/xyz.cssxsh.mirai.plugin.mirai-authenticator/question` 87 | * `data/xyz.cssxsh.mirai.plugin.mirai-authenticator/bilibili` 88 | 89 | 脚本文件名对应群号, 例如 `123456.lua` 90 | 91 | `Global variable` (bindings) 支持的属性和方法有以下 92 | 93 | * `bot` bot 对象 94 | * `eventId` 事件id 95 | * `groupId` 群ID 96 | * `groupName` 群名 97 | * `message` 请求消息 98 | * `invitorId` 邀请人 99 | * `fromId` 请求者ID 100 | * `fromNick` 请求者NICK 101 | 102 | ### Profile 校验脚本 103 | 104 | `Profile` 校验脚本主要用于校验用户的 `Profile` 信息 105 | 所以对于 `Profile` 校验脚本, 将支持 106 | 107 | * `fromProfile` 请求者profile 108 | * `getAge` 获取年龄 109 | * `getQLevel` 获取QQ等级 110 | * `getEmail` 获取右键 111 | * `getNickname` 获取昵称 112 | 113 | 例如,检查申请入群者的QQ等级是否大于4: 114 | ```lua 115 | return fromProfile:getQLevel() > 4; 116 | ``` 117 | 118 | ### Question 校验脚本 119 | 120 | `Question` 校验脚本主要用于校验用户提交的加群问题答案 121 | 所以对于 `Question` 校验脚本, 将支持 122 | 123 | * `question` 问题 124 | * `answer` 回答 125 | 126 | 例如,检查答案是否满足要求: 127 | ```lua 128 | return answer == "114514" or answer == "......"; 129 | ``` 130 | 131 | ### BiliBili 校验脚本 132 | 133 | `BiliBili` 校验脚本主要用于校验用户提交的 `UID` 当前配置的粉丝牌详情 134 | 对于 `BiliBili` 校验脚本, 将支持 135 | 136 | * `medal` 粉丝牌详情 137 | * `getTargetId` 获取主播UID 138 | * `getScore` 获取积分 139 | * `getLevel` 获取等级 140 | * `getGuardLevel` 获取舰长类型 (0 是非舰长) 141 | 142 | 例如, 检查是否佩戴了 [哔哩哔哩音悦台#11153765](https://space.bilibili.com/11153765) 的粉丝牌,且为舰长 (等级大等于20) : 143 | ```lua 144 | return medal:getTargetId() == 11153765 and medal:getLevel() >= 20; 145 | ``` 146 | 147 | ### AFDian 校验脚本 148 | 149 | `AFDian` 校验脚本主要用于校验用户提交的 `UID` 是否在捐助者列表中 150 | 对于 `AFDian` 校验脚本, 将支持 151 | 152 | * `query` 查询结果 153 | * `getList` 获取捐助者列表 154 | * `getUser` 获取捐助者信息 155 | * `getUserId` 获取捐助者 ID 156 | * `getName` 获取捐助者 NAME 157 | * `getCurrentPlan` 获取当前捐助计划 158 | * `getName` 获取捐助计划 Name 159 | * `getStatus` 获取捐助状态 160 | * `getPrice` 获取捐助价格 161 | * ... 162 | * `getFirstPayTime` 第一次支付时间 163 | * `getLastPayTime` 最后一次支付时间 164 | * `getAllSumAmount` 总计金额 165 | * `getCount` 获取总数量 166 | * `getPage` 获取当前查询数量 167 | 168 | ## [爱发电](https://afdian.net/@cssxsh) 169 | 170 | ![afdian](example/sponsor/afdian.jpg) 171 | -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/validator/MiraiSponsorChecker.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth.validator 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.engine.okhttp.* 5 | import io.ktor.client.plugins.* 6 | import io.ktor.client.plugins.compression.* 7 | import io.ktor.client.request.* 8 | import io.ktor.http.* 9 | import kotlinx.coroutines.* 10 | import kotlinx.serialization.* 11 | import kotlinx.serialization.json.* 12 | import net.mamoe.mirai.event.events.* 13 | import xyz.cssxsh.mirai.auth.validator.afdian.* 14 | import java.security.* 15 | import kotlin.io.path.* 16 | import kotlin.random.* 17 | 18 | /** 19 | * 校验爱发电 20 | */ 21 | @PublishedApi 22 | internal class MiraiSponsorChecker : MiraiChecker, AbstractMiraiChecker() { 23 | override val folder = Path(System.getProperty("xyz.cssxsh.mirai.auth.validator.afdian", "afdian")) 24 | private val http: HttpClient = HttpClient(OkHttp) { 25 | BrowserUserAgent() 26 | ContentEncoding() 27 | } 28 | private val uid: String = System.getenv("AFDIAN_USER_ID") 29 | ?: System.getProperty("xyz.cssxsh.mirai.auth.validator.afdian.uid") 30 | ?: throw NoSuchElementException("AFDIAN_USER_ID") 31 | private val token: String = System.getenv("AFDIAN_USER_TOKEN") 32 | ?: System.getProperty("xyz.cssxsh.mirai.auth.validator.afdian.token") 33 | ?: throw NoSuchElementException("AFDIAN_USER_TOKEN") 34 | 35 | override suspend fun check(event: MemberJoinRequestEvent): Boolean { 36 | val match = MiraiChecker.QA.find(event.message) ?: return true 37 | val question = match.groupValues[1] 38 | val answer = match.next()?.groupValues?.get(1) ?: return false 39 | val script = folder.listDirectoryEntries().firstOrNull { it.name.startsWith("${event.groupId}.") } 40 | ?: throw IllegalStateException("获取 ${event.groupId} Sponsor 验证脚本失败") 41 | val engine = manager.getEngineByExtension(script.extension) 42 | ?: throw NoSuchElementException("获取 ${script.extension} 脚本引擎失败") 43 | 44 | val bindings = engine.createBindings().apply(event = event) 45 | bindings["question"] = question 46 | bindings["answer"] = answer 47 | 48 | return supervisorScope { 49 | var page = 1 50 | var total = 0 51 | while (isActive) { 52 | val query = sponsor(uid = uid, token = token, page = page++) 53 | 54 | bindings["query"] = query 55 | val result = try { 56 | (engine.eval(script.readText(), bindings) as org.luaj.vm2.LuaValue) 57 | .toboolean() 58 | } catch (cause: Exception) { 59 | throw IllegalStateException("验证 ${event.eventId} 失败", cause) 60 | } 61 | if (result) return@supervisorScope true 62 | 63 | if (total++ >= query.count || query.list.isEmpty()) break 64 | } 65 | 66 | false 67 | } 68 | } 69 | 70 | private fun sign(token: String, params: String, timestamp: Long, uid: String): String { 71 | val digest = MessageDigest.getInstance("md5") 72 | digest.update(token.toByteArray()) 73 | digest.update("params".toByteArray()) 74 | digest.update(params.toByteArray()) 75 | digest.update("ts".toByteArray()) 76 | digest.update(timestamp.toString().toByteArray()) 77 | digest.update("user_id".toByteArray()) 78 | digest.update(uid.toByteArray()) 79 | val bytes = digest.digest() 80 | 81 | return "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x".format(args = bytes.toTypedArray()) 82 | 83 | } 84 | 85 | private fun HttpRequestBuilder.body(uid: String, token: String, builder: JsonObjectBuilder.() -> Unit) { 86 | val timestamp = System.currentTimeMillis() / 1_000 87 | val params = buildJsonObject(builder).toString() 88 | val sign = sign(token = token, params = params, timestamp = timestamp, uid = uid) 89 | contentType(ContentType.Application.Json) 90 | setBody(buildJsonObject { 91 | put("user_id", uid) 92 | put("params", params) 93 | put("ts", timestamp) 94 | put("sign", sign) 95 | }.toString()) 96 | } 97 | 98 | @PublishedApi 99 | internal suspend fun ping(uid: String, token: String): JsonObject { 100 | val statement = http.preparePost("https://afdian.com/api/open/ping") { 101 | body(uid, token) { 102 | put("page", Random.Default.nextInt()) 103 | } 104 | } 105 | 106 | val json = statement.body() 107 | val wrapper = Json.decodeFromString(json) 108 | if (wrapper.code != 200) throw AFDianApiException(body = wrapper) 109 | return Json.decodeFromJsonElement(wrapper.data) 110 | } 111 | 112 | @PublishedApi 113 | internal suspend fun order(uid: String, token: String, page: Int): AFDianQuery { 114 | val statement = http.preparePost("https://afdian.com/api/open/query-order") { 115 | body(uid, token) { 116 | put("page", page) 117 | } 118 | } 119 | 120 | val json = statement.body() 121 | val wrapper = Json.decodeFromString(json) 122 | if (wrapper.code != 200) throw AFDianApiException(body = wrapper) 123 | return Json.decodeFromJsonElement(wrapper.data) 124 | } 125 | 126 | @PublishedApi 127 | internal suspend fun sponsor(uid: String, token: String, page: Int): AFDianQuery { 128 | val statement = http.preparePost("https://afdian.com/api/open/query-sponsor") { 129 | body(uid, token) { 130 | put("page", page) 131 | } 132 | } 133 | 134 | val json = statement.body() 135 | val wrapper = Json.decodeFromString(json) 136 | if (wrapper.code != 200) throw AFDianApiException(body = wrapper) 137 | return Json.decodeFromJsonElement(wrapper.data) 138 | } 139 | } -------------------------------------------------------------------------------- /src/main/kotlin/xyz/cssxsh/mirai/auth/MiraiAuthenticator.kt: -------------------------------------------------------------------------------- 1 | package xyz.cssxsh.mirai.auth 2 | 3 | import kotlinx.coroutines.* 4 | import net.mamoe.mirai.contact.* 5 | import net.mamoe.mirai.event.* 6 | import net.mamoe.mirai.event.events.* 7 | import net.mamoe.mirai.message.data.* 8 | import net.mamoe.mirai.utils.* 9 | import xyz.cssxsh.mirai.auth.validator.* 10 | import xyz.cssxsh.mirai.auth.data.* 11 | import kotlin.coroutines.* 12 | 13 | /** 14 | * 认证插件核心监听器 15 | */ 16 | public object MiraiAuthenticator : SimpleListenerHost() { 17 | 18 | override fun handleException(context: CoroutineContext, exception: Throwable) { 19 | when (exception) { 20 | is CancellationException -> { 21 | // ... 22 | } 23 | is ExceptionInEventHandlerException -> { 24 | logger.warning({ "MiraiAuthenticator with ${exception.event}" }, exception.cause) 25 | } 26 | else -> { 27 | logger.warning({ "MiraiAuthenticator" }, exception) 28 | } 29 | } 30 | } 31 | 32 | @PublishedApi 33 | @EventHandler(priority = EventPriority.HIGH) 34 | internal suspend fun MemberJoinRequestEvent.handle() { 35 | if ((group?.botPermission ?: MemberPermission.MEMBER) < MemberPermission.ADMINISTRATOR) return 36 | when (auth(event = this)) { 37 | MiraiAuthStatus.PASS -> accept() 38 | MiraiAuthStatus.FAIL -> reject(blackList = false, message = "验证失败") 39 | MiraiAuthStatus.BLACK -> reject(blackList = true, message = "验证失败") 40 | MiraiAuthStatus.IGNORE -> return 41 | } 42 | intercept() 43 | } 44 | 45 | @PublishedApi 46 | @EventHandler(priority = EventPriority.HIGH) 47 | internal suspend fun MemberJoinEvent.handle() { 48 | if (group.botPermission < MemberPermission.ADMINISTRATOR) return 49 | when (auth(event = this)) { 50 | MiraiAuthStatus.PASS -> return 51 | MiraiAuthStatus.FAIL -> member.kick(block = false, message = "验证失败") 52 | MiraiAuthStatus.BLACK -> member.kick(block = true, message = "验证失败") 53 | MiraiAuthStatus.IGNORE -> return 54 | } 55 | intercept() 56 | } 57 | 58 | private fun Group.checkers(): Sequence? { 59 | val ids = MiraiAuthJoinConfig.checkers[id] ?: return null 60 | return sequence { 61 | for (id in ids) { 62 | val validator = try { 63 | MiraiChecker(id) 64 | } catch (cause: Exception) { 65 | logger.warning({ "$name 获取校验器 $id 失败" }, cause) 66 | continue 67 | } 68 | yield(validator) 69 | } 70 | } 71 | } 72 | 73 | private fun Group.validators(): Sequence? { 74 | val ids = MiraiAuthJoinConfig.validators[id] ?: return null 75 | return sequence { 76 | for (id in ids) { 77 | val validator = try { 78 | MiraiValidator(id) 79 | } catch (cause: Exception) { 80 | logger.warning({ "$name 获取验证器 $id 失败" }, cause) 81 | continue 82 | } 83 | yield(validator) 84 | } 85 | } 86 | } 87 | 88 | /** 89 | * 加群前验证 90 | * @param event 被验证成员的申请事件 91 | * @see MiraiChecker 92 | */ 93 | public suspend fun auth(event: MemberJoinRequestEvent): MiraiAuthStatus { 94 | val group = event.group ?: return MiraiAuthStatus.IGNORE 95 | val checkers = group.checkers() ?: return MiraiAuthStatus.IGNORE 96 | 97 | for (checker in checkers) { 98 | try { 99 | if (checker.check(event = event).not()) { 100 | return if (group.id in MiraiAuthJoinConfig.place) { 101 | group.sendMessage(message = "${event.fromNick}(${event.fromId}) 加群请求检查失败, 请管理员处理") 102 | MiraiAuthStatus.IGNORE 103 | } else { 104 | MiraiAuthStatus.FAIL 105 | } 106 | } 107 | } catch (cause: IllegalStateException) { 108 | logger.warning({ "检查<入群答案>失败" }, cause) 109 | return MiraiAuthStatus.IGNORE 110 | } 111 | } 112 | 113 | return MiraiAuthStatus.PASS 114 | } 115 | 116 | /** 117 | * 加群后验证 118 | * @param event 被验证成员的入群事件 119 | * @see MiraiValidator 120 | */ 121 | public suspend fun auth(event: MemberJoinEvent): MiraiAuthStatus { 122 | if (event.member.id in MiraiAuthJoinConfig.official) return MiraiAuthStatus.PASS 123 | val validators = event.group.validators() ?: return MiraiAuthStatus.IGNORE 124 | 125 | for (validator in validators) { 126 | var count = MiraiAuthJoinConfig.count 127 | while (count-- > 0) { 128 | val question = try { 129 | validator.question(event = event) 130 | } catch (cause: IllegalStateException) { 131 | logger.warning({ "生成<验证问题>失败" }, cause) 132 | continue 133 | } 134 | try { 135 | event.group.sendMessage(message = At(event.member) + question) 136 | } catch (cause: IllegalStateException) { 137 | logger.warning({ "发送<验证问题>失败" }, cause) 138 | continue 139 | } 140 | val response = withTimeoutOrNull(timeMillis = MiraiAuthJoinConfig.timeout) { 141 | globalEventChannel().nextEvent(priority = EventPriority.HIGH, intercept = true) { 142 | it.group == event.group && it.sender == event.member 143 | } 144 | } ?: kotlin.run { 145 | try { 146 | event.group.sendMessage(message = At(event.member) + "回答超时") 147 | } catch (cause: IllegalStateException) { 148 | logger.warning({ "发送<回答超时>失败" }, cause) 149 | } 150 | return MiraiAuthStatus.FAIL 151 | } 152 | 153 | val content = response.message.contentToString() 154 | 155 | logger.info("summit answer <${content}>") 156 | 157 | val result = try { 158 | validator.auth(answer = content) 159 | } catch (cause: IllegalStateException) { 160 | logger.warning({ "提交<验证答案>失败" }, cause) 161 | continue 162 | } 163 | 164 | try { 165 | event.group.sendMessage(message = At(event.member) + if (result) "验证成功" else "验证失败") 166 | } catch (cause: IllegalStateException) { 167 | logger.warning({ "发送<验证结果>失败" }, cause) 168 | } 169 | 170 | if (result) return MiraiAuthStatus.PASS 171 | } 172 | } 173 | 174 | return MiraiAuthStatus.FAIL 175 | } 176 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to mirai it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) mirai the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to mirai the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, mirai and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | mirai a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to mirai, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise mirai, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------