MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接
    1. Home
    2. MrXiaoM
    3. Posts
    • Profile
    • Following 9
    • Followers 39
    • Topics 37
    • Posts 865
    • Best 206
    • Controversial 0
    • Groups 5

    Posts made by MrXiaoM

    • RE: WifeYouWant —— 每天随机把群友当老婆

      @1024191579

      enable-groups:
        - 114514
        - 1919810
      
      posted in 插件发布
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      -4745ec2de012eef8.jpg

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      _20220803_182429.JPG
      我看了两遍才看懂

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      QQ图片20220729220557.gif
      猫:这是什么老鼠

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      QQ图片20220729130631.jpg
      QQ图片20220729130640.jpg
      QQ图片20220729130644.jpg

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      QQ图片20220728233841.jpg
      QQ图片20220728233849.jpg

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: WifeYouWant —— 每天随机把群友当老婆

      @QFLS 无

      posted in 插件发布
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      QQ图片20220727135231.jpg
      QQ图片20220727135157.jpg

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 求助:HTTP/1.1 404 Not Found

      mirai-api-http 2.x 是用 /verify 不是用 /auth,详见迁移文档

      posted in HTTP API和第三方SDK
      MrXiaoM
      MrXiaoM
    • mirai 消息变量替换工具类

      使用 kotlin 编写,但有 java 兼容。

      import kotlinx.coroutines.Dispatchers
      import kotlinx.coroutines.runBlocking
      import kotlinx.coroutines.withContext
      import net.mamoe.mirai.contact.Contact
      import net.mamoe.mirai.message.data.*
      import net.mamoe.mirai.utils.ExternalResource
      import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
      import java.net.URL
      
      /**
      * 消息助手
      * @author MrXiaoM
      */
      object MessageHelper {
         /**
          * 参见 [String.replace]
          * @author MrXiaoM
          */
         @JvmStatic
         fun replace(s: String, replacements: Map<String, SingleMessage>): MessageChain =
             runBlocking { s.replace(replacements) }
      }
      
      /**
      * 消息助手预处理消息接口
      * @author MrXiaoM
      */
      interface PrepareMessage : SingleMessage {
         /**
          * 该方法将会在该消息需要被处理时调用以生成消息。
          * 有时,用户可能会在单条消息多次使用同一变量,建议储存生成结果以便复用。
          * @author MrXiaoM
          */
         suspend fun generateMessage(): SingleMessage
         override fun contentToString(): String = ""
      }
      
      /**
      * 适用于 MessageHelper.replace 的预上传图片
      * @author MrXiaoM
      * @param contact 要上传到的联系人
      * @param handler 需要上传时用于生成 ExternalResource 的处理器,自行编写处理器时应自觉 toAutoCloseable()
      * @param failedText 上传失败时的代替文本
      */
      class PrepareUploadImage(
         private val contact: Contact,
         private val handler: suspend () -> ExternalResource?,
         private val failedText: String = ""
      ) : PrepareMessage {
         private var generated: SingleMessage? = null
         override suspend fun generateMessage(): SingleMessage {
             generated?.also { return it }
             return try {
                 contact.uploadImage(handler()!!).also { generated = it }
             } catch (_: Throwable) {
                 PlainText(failedText)
             }
         }
         override fun contentToString(): String = failedText
         override fun toString(): String = "PrepareUploadImage(contact=$contact)"
         companion object {
             /**
              * 生成预下载图片消息。
              * 图片将会在 replace 时发现需要用到该变量时下载。
              * @author MrXiaoM
              * @param contact 要上传到的联系人
              * @param link 图片下载链接
              * @param failedText 上传失败时的返回消息
              */
             @JvmStatic
             fun fromURL(contact: Contact, link: String, failedText: String = ""): PrepareUploadImage =
                 PrepareUploadImage(contact, {
                     try {
                         withContext(Dispatchers.IO) {
                             URL(link).openConnection().also { it.connect() }.getInputStream()
                         }.toExternalResource().toAutoCloseable()
                     } catch (t: Throwable) {
                         t.printStackTrace()
                         null
                     }
                 }, failedText)
      
             /**
              * 生成预下载图片消息。
              *
              * 参见 [fromURL]
              * @param link 要下载图片的链接
              * @param failedText 上传失败时的返回消息
              */
             @JvmStatic
             fun Contact.prepareUploadImage(link: String, failedText: String = ""): PrepareUploadImage =
                 fromURL(this, link, failedText)
      
             /**
              * 生成预下载头像图片消息。
              *
              * 参见 [prepareUploadImage]
              * @param failedText 上传失败时的返回消息
              */
             @JvmStatic
             fun Contact.prepareUploadAvatarImage(failedText: String = ""): PrepareUploadImage =
                 prepareUploadImage(avatarUrl, failedText)
         }
      }
      
      /**
      * 将字符串作为字符串模板,替换其中的变量为 SingleMessage 来生成 MessageChain
      *
      * 使用示例: @用户并发送他的头像
      * ```kotlin
      * val member = event.sender
      * "\$at 你好,你的头像是\n \$pic".replace(mapOf("at" to At(member), "pic" to member.prepareUploadAvatarImage()))
      * ```
      *
      * 在配置文件或者在 java 中不需要用 \ 将 $ 转义,这会对用户自定义机器人发送的消息的体验更加友好
      * @author MrXiaoM
      * @param replacements 变量对照表
      */
      suspend fun String.replace(replacements: Map<String, SingleMessage>): MessageChain {
         if (!this.contains("\$") || replacements.isEmpty()) return PlainText(this).toMessageChain()
         val message = MessageChainBuilder()
         val s = this.split("\$").toMutableList()
         message.add(s.removeAt(0))
         s.forEach { text ->
             var isOriginal = true
             for ((k, m) in replacements) {
                 if (!text.startsWith(k)) continue
                 if (m is PrepareMessage) message.add(m.generateMessage())
                 else message.add(m)
      
                 message.add(text.substring(k.length))
                 isOriginal = false
                 break
             }
             if (isOriginal) message.add("\$$text")
         }
         return message.build()
      }
      

      刚学 kt 不久,代码有点烂,但是能用就行。以下是使用例子,均会生成 @人间工作p 你好,2431208142

      // kotlin
      val msg = "\$at 你好,\$qq".replace(mapOf("qq" to PlainText(sender.id), "at" to At(sender)))
      
      // java
      Map<String, SingleMessage> replacements = new HashMap<>();
      replacements.put("qq", new PlainText(String.valueOf(sender.getId())));
      replacements.put("at", new At(sender.getId()));
      MessageChain msg = MessageHelper.replace("$at 你好,$qq", replacements);
      

      若要使用这份代码,你只需要在源代码中保留作者信息(即保留 @author MrXiaoM)即可。

      posted in 技术交流板块
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅



      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 【每日沙雕图】沙雕小别墅

      QQ图片20220720105301.jpg

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 来博客互换友情链接

      @MrXiaoM 氦嗨亥,移动端适配做好了

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 来博客互换友情链接

      @RainChan 确实,之前把密码忘了,自己写的主题还没来得及做适配(

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 来博客互换友情链接

      来晚了

      网站名称:MrXiaoM的博客
      地址:https://blog.mrxiaom.top
      头像地址:https://blog.mrxiaom.top/logo-64.png
      logo-64.png

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • WifeYouWant —— 每天随机把群友当老婆

      WifeYouWant

      项目地址:https://github.com/MrXiaoM/WifeYouWant

      「你想要的插件」系列作品

      本插件移植自 椛椛 ᴮᴼᵀ

      名场面
      WifeYouWant.png

      特性

      • 每天可以从群友里随机抽一次老婆 (渣男!)
      • 不想要的可以换 (渣男!!)
      • 可设置只能抽和自己性别相反的人,也可以无视性别
      • 可以设置能抽到自己
      • 可以设置能 NTR (重复抽到群友)

      安装

      到 Releases 下载插件并放入 plugins 文件夹进行安装

      2.11 或以上下载 WifeYouWant-*.mirai2.jar

      2.11 以下下载 WifeYouWant-legacy-*.mirai.jar
      安装完毕后,编辑配置文件作出你想要的修改。在控制台执行 /wuw reload 重载配置即可~

      配置文件内有详细的注释,详见 源码

      用法

      随机挑选一位群友,在明天之前,无论怎么抽都是那位群友

      抽老婆
      

      抛弃老婆,重新抽一位群友

      换老婆
      

      关键词可在配置文件中修改

      捐助

      前往 爱发电 捐助我。

      来自群组: SkyNet1748

      posted in 插件发布
      MrXiaoM
      MrXiaoM
    • RE: 简单的Rss订阅插件 已添加RssHub支持 番剧订阅Bt种子自动上传

      @Moon1995 噢我的上帝啊,为什么不使用开源免费还不用登录查看的 pastebin.pl 呢
      好吧我找的这个过不去验证码()
      啊,找到了,moz://a 在线剪贴板:https://pastebin.mozilla.org/

      posted in 插件发布
      MrXiaoM
      MrXiaoM
    • 和 mirai 娘贴贴!

      同人图这不就来了吗?(我真的不会画画,硬画的)

      pid 99557438

      图片

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • RE: 高数考试的逆天活

      放心,你和机器至少能跑一个🤔

      posted in 摸鱼区
      MrXiaoM
      MrXiaoM
    • 1
    • 2
    • 35
    • 36
    • 37
    • 38
    • 39
    • 43
    • 44
    • 37 / 44