From cdd3053e1645f7435f6e10e493ee81a47d69deab Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 20 Feb 2020 16:40:40 +0800 Subject: [PATCH] Better --- docs/guide_getting_started.md | 61 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/docs/guide_getting_started.md b/docs/guide_getting_started.md index e8bd38801..b6299742a 100644 --- a/docs/guide_getting_started.md +++ b/docs/guide_getting_started.md @@ -36,7 +36,7 @@ JDK要求8以上 - 首先添加repositories - ``` + ```groovy //添加jcenter仓库 /* repositories { @@ -53,7 +53,7 @@ JDK要求8以上 - 添加依赖,将dependencies部分覆盖为 - ``` + ```groovy dependencies { implementation 'net.mamoe:mirai-core:0.16.0' implementation 'net.mamoe:mirai-core-qqandroid-jvm:0.16.0' @@ -72,38 +72,31 @@ JDK要求8以上 - 在包下新建kotlin文件```MyLoader.kt``` - ``` - package net.mamoe.mirai.simpleloader - - import kotlinx.coroutines.* - import net.mamoe.mirai.Bot - import net.mamoe.mirai.alsoLogin - import net.mamoe.mirai.event.subscribeMessages - - fun main(args: Array) { - runBlocking {//阻塞,直到Mirai退出 - coroutineScope() { - launch { - val qqId = 10000L//Bot的QQ号,需为Long类型,在结尾处添加大写L - val password = "your_password"//Bot的密码 - val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆 - miraiBot.subscribeMessages { - "你好" reply "你好!" - "profile" reply { sender.queryProfile() } - case("at me") { - reply(sender.at() + " 给爷爬 ") - } - - (contains("舔") or contains("刘老板")) { - "刘老板太强了".reply() - } - } - miraiBot.join() - } - } - } - } - ``` +```kotlin +package net.mamoe.mirai.simpleloader + +import kotlinx.coroutines.* +import net.mamoe.mirai.Bot +import net.mamoe.mirai.alsoLogin +import net.mamoe.mirai.event.subscribeMessages + +suspend fun main() { + val qqId = 10000L//Bot的QQ号,需为Long类型,在结尾处添加大写L + val password = "your_password"//Bot的密码 + val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆 + miraiBot.subscribeMessages { + "你好" reply "你好!" + case("at me") { + reply(sender.at() + " 给爷爬 ") + } + + (contains("舔") or contains("刘老板")) { + "刘老板太强了".reply() + } + } + miraiBot.join() +} +``` - 单击编辑器内第8行(```fun main```)左侧的run按钮(绿色三角),等待,MiraiBot成功登录。 - 本例的功能中,在任意群内任意成员发送包含“舔”字或“刘老板”字样的消息,MiraiBot会回复“刘老板太强了”