Giter VIP home page Giter VIP logo

Comments (2)

rubyuu avatar rubyuu commented on May 24, 2024 1

感激不尽

from chatgpt-yourchatrobot.

ashinnotfound avatar ashinnotfound commented on May 24, 2024

如果你想实现**在群聊里只有当别人@机器人时,才会回复。**可以考虑将获取到的消息元素进行筛选,若筛选到@机器人的消息,再向ChatGPT提问并回复,比如:

@EventHandler
    public void onMessage(@NotNull MessageEvent event) {
        ChatBO chatBO = new ChatBO();
        chatBO.setSessionId(String.valueOf(event.getSender().getId()));
        chatBO.setQuestion(event.getMessage().contentToString());
        if(event.getBot().getGroups().contains(event.getSubject().getId())) {
            //如果是在群聊
            //遍历收到的消息元素
            for (SingleMessage singleMessage : event.getMessage()) {
                if (singleMessage.equals(new At(event.getBot().getId()))) {
                    //存在@机器人的消息就向ChatGPT提问
                    event.getSubject().sendMessage(interactService.chat(chatBO));
                    break;
                }
            }
        }else
            //不是在群聊 则直接回复
            event.getSubject().sendMessage(interactService.chat(chatBO));
    }

你可以将以上代码copy到项目里替换原来的onMessage函数来直接使用。
其他的设定可以参考mirai的文档,后续我也会增加这类设定功能,谢谢你的提问🌹

from chatgpt-yourchatrobot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.