mirai/mirai-japt
2020-02-15 17:56:23 +08:00
..
.README_images Add Japt README 2020-02-15 15:25:13 +08:00
src/main Use Kotlin API over Java API 2020-02-15 16:14:13 +08:00
build.gradle.kts Publish mirai-japt 2020-02-15 15:25:23 +08:00
mirai-japt.postfixTemplates Update japt 2020-01-11 23:53:01 +08:00
README.md Add requirements 2020-02-15 17:56:23 +08:00

mirai-japt

Mirai Java Apt

提供阻塞API 来让 Java 调用 Mirai 的 API 更容易

Requirements

  • JDK 1.8+

开始

class Test{
    public static void main(String[] args){
        BlockingBot bot = BlockingBot.newInstance(123456, "");
        
        bot.login();
        
        bot.getFriendList().forEach(friend -> {
            System.out.println(friend.getNick());
        });
        
        Events.subscribeAlways(GroupMessage.class, (GroupMessage message) -> {
            final BlockingQQ sender = BlockingContacts.createBlocking(message.getSender());
        
            sender.sendMessage("Hello");
        });
        
        Thread.sleep(999999999);
    }
}

便捷开发

在 IntelliJ IDEA 或 Android Studio 中找到设置 Editor -> General -> Postfix Completion, 添加一个设置到 Java 分类中:

Applicable expression types:

net.mamoe.mirai.contact.Contact

转换后表达式:

net.mamoe.mirai.japt.BlockingContacts.createBlocking($EXPR$)

效果:

4SY8BC@J4ZKQM7OZ_~BC1I_1

722WEHTTXD6XFFH43