测试 至此我不在孤单前行
object Application {
private val logger = LoggerFactory.getLogger(this.javaClass)
@JvmStatic
fun main(args: Array<String>): Unit = runBlocking {
1 #include <windows.h>
2 #include <mmsystem.h>
3 #include <stdio.h>
4
5 #pragma comment(lib, "winmm.lib")
6
7
8 #define DATAFILE "BADAPPLE.txt"
9
10 #define FRAME_WIDTH 80
11 #define FRAME_HEIGHT 32
12
13 #define DATA_TOKEN_SIZE ( 5 + 1 ) // $0000\n
14 #define DATA_PITCH_SIZE ( FRAME_WIDTH + 1 ) // ###...\n
15 #define DATA_FRAME_SIZE ( DATA_TOKEN_SIZE + ( DATA_PITCH_SIZE * FRAME_HEIGHT ) )
16
17 #define FRAME_COUNT 3271
18
19 #define VIDEO_TIME 218000.0f // 3:38 (218000ms)
20
21
22 void main(void)
23 {
24 HANDLE hOutput;
25
26 hOutput = GetStdHandle( STD_OUTPUT_HANDLE );
27
28 CONSOLE_CURSOR_INFO coc = { 1, FALSE };
29 COORD co = { FRAME_WIDTH, FRAME_HEIGHT };
30 SMALL_RECT rc = { 0, 0, FRAME_WIDTH - 1, FRAME_HEIGHT - 1 };
31
32 SetConsoleCursorInfo( hOutput, &coc );
33 SetConsoleScreenBufferSize( hOutput, co );
34 SetConsoleWindowInfo( hOutput, TRUE, &rc );
35
36 SetConsoleTitle( "Bad Apple By Crsky @2016" );
37
38 FILE *fp;
39 int size;
40 char *buf;
41 char *cur;
42 int start;
43
44 buf = NULL;
45
46 fp = fopen( DATAFILE, "rb" );
47
48 if ( !fp )
49 {
50 printf( "%s not found.\n", DATAFILE );
51 goto err;
52 }
53
54 size = DATA_FRAME_SIZE * FRAME_COUNT;
55
56 buf = new char[ size ];
57
58 if ( fread( buf, size - 1, 1, fp ) != 1 )
59 {
60 printf( "Failed to read in data file.\n" );
61 goto err;
62 }
63
64 buf[ size - 1 ] = '\0';
65
66 fclose( fp );
67
68 mciSendString( "open BADAPPLE.wma alias BGM", NULL, 0, NULL );
69 mciSendString( "play BGM", NULL, 0, NULL );
70
71 start = GetTickCount();
72
73 while ( 1 )
74 {
75 int time;
76 float percen;
77 int frame;
78 COORD xy = { 0, 0 };
79 DWORD written;
80
81 if ( GetKeyState( VK_SPACE ) )
82 {
83 printf( "Stop play.\n" );
84 break;
85 }
86
87 time = GetTickCount();
88 percen = ( time - start ) / VIDEO_TIME;
89
90 if ( percen > 1 )
91 {
92 printf( "End of play.\n" );
93 break;
94 }
95
96 frame = percen * FRAME_COUNT;
97 cur = &buf[ ( DATA_FRAME_SIZE * frame ) + DATA_TOKEN_SIZE ];
98
99 for ( ; xy.Y < FRAME_HEIGHT; xy.Y++, cur += DATA_PITCH_SIZE )
100 WriteConsoleOutputCharacter( hOutput, cur, DATA_PITCH_SIZE - 1, xy, &written );
101
102 Sleep( 60 );
103 }
104
105 mciSendString( "stop", NULL, 0, NULL );
106 mciSendString( "close", NULL, 0, NULL );
107
108 err:
109 if ( buf )
110 delete[] buf;
111
112 Sleep( 500 );
113 }
$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) 4
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) 2
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4)
Project name (default: demo): 随你
Source package (default: demo): me.bot
BUILD SUCCESSFUL
2 actionable tasks: 2 executed
打开自己喜欢的编辑器,当然,开发 Java , IDEA 天下第一!
编辑 build.gradle.kts
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
plugins {
application
kotlin("jvm") version "1.7.20"
kotlin("plugin.serialization") version "1.7.20"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
group = "robot"
version = "0.1.0"
repositories {
mavenCentral()
}
tasks.withType(KotlinJvmCompile::class.java) {
kotlinOptions.jvmTarget = "1.8"
}
dependencies {
// Mirai 库
api("net.mamoe:mirai-core-api:2.12.3")
runtimeOnly("net.mamoe:mirai-core:2.12.3")
// 日志库
implementation("org.slf4j:slf4j-log4j12:2.0.3")
// Json 序列化
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
}
tasks.jar {
manifest {
attributes(
"Main-Class" to "me.bot.Application",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version
)
}
}
object Application {
private val logger = LoggerFactory.getLogger(this.javaClass)
@JvmStatic
fun main(args: Array<String>): Unit = runBlocking {
// 配置日志,为了不报错,可以不搞
logger.asMiraiLogger()
// 账号、密码
val bot = BotFactory.newBot(100001L, "MaHuaTengSiMa") {
// 设备消息,以文本形式自动生成 `device.json`
fileBasedDeviceInfo()
// 协议,我这里使用的是 安卓平板 协议
protocol = BotConfiguration.MiraiProtocol.ANDROID_PAD
}.alsoLogin()
}
}
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
plugins {
application
kotlin("jvm") version "1.7.20"
kotlin("plugin.serialization") version "1.7.20"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
group = "robot"
version = "0.1.0"
repositories {
mavenCentral()
}
tasks.withType(KotlinJvmCompile::class.java) {
kotlinOptions.jvmTarget = "1.8"
}
dependencies {
// Mirai 库
api("net.mamoe:mirai-core-api:2.12.3")
runtimeOnly("net.mamoe:mirai-core:2.12.3")
// 日志库
implementation("org.slf4j:slf4j-log4j12:2.0.3")
// Json 序列化
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
}
tasks.jar {
manifest {
attributes(
"Main-Class" to "me.bot.Application",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version
)
}
先发个图吧
这一楼我们实现机器人的登录和发消息
要启动QQ机器人,当然需要一个QQ号,然后登录就一句话
object Application {
private val logger = LoggerFactory.getLogger(this.javaClass)
@JvmStatic
fun main(args: Array<String>): Unit = runBlocking {
// 配置日志,为了不报错,可以不搞
logger.asMiraiLogger()
// 账号、密码
val bot = BotFactory.newBot(100001L, "MaHuaTengSiMa") {
// 设备消息,以文本形式自动生成 `device.json`
fileBasedDeviceInfo()
// 协议,我这里使用的是 安卓平板 协议
protocol = BotConfiguration.MiraiProtocol.ANDROID_PAD
}.alsoLogin()
}
}
页:
[1]