zl程序教程

您现在的位置是:首页 >  工具

当前栏目

AutoJs学习-QQ聊天机器人

QQ机器人学习 聊天 AutoJs
2023-09-14 09:04:16 时间
往期文章分享

👉关于作者

众所周知,人生是一个漫长的流程,不断克服困难,不断反思前进的过程。在这个过程中会产生很多对于人生的质疑和思考,于是我决定将自己的思考,经验和故事全部分享出来,以此寻找共鸣 !!!
专注于Android/Unity和各种游戏开发技巧,以及各种资源分享(网站、工具、素材、源码、游戏等)
有什么需要欢迎私我,交流群让学习不再孤单

在这里插入图片描述

本文约5千字,新手阅读需要7分钟,复习需要2分钟收藏随时查阅不再迷路

👉实践过程

脚本一


// 本脚本是根据白酒煮饭的图灵脚本改编的
// 功能, 打开手机QQ,打开QQ群聊天窗口,脚本自动回复新产生的聊天记录
"auto";
console.show();

launchApp("QQ");
threads.start(function() {
  while (true) {
    toast("你的QQ被图灵附身啦,不要打扰他!");
    sleep(5000);
  }
});
上一句话="图灵在哪里啊图灵在哪里"
while(1){

    chatBounds=[136,1500,909,1720]
    chat=id("chat_item_content_layout").className("android.widget.TextView").textMatches(/.+/).boundsInside(chatBounds[0], chatBounds[1], chatBounds[2], chatBounds[3]).findOne(300)
    // log(chat)
    if(chat && chat.text().length>0 && chat.text()!==上一句话){
        // log("聊天内容=",chat.text())
        chatText=chat.text()
        输入=chatText
        图灵机器人(输入)
        上一句话=chatText
    }else{
        // log("没找到聊天内容或者没有新的聊天")
    }
    sleep(1000)
}

function 图灵机器人(输入) {
    var 链接 = "http://www.tuling123.com/openapi/api";
    //toastLog(info);
    var 获取 = http.post(链接, {
        "key": "f48dd9f7a5284994bddcc546ae66cbd4",
        "info": 输入,
        "userid": "80000"
    });
    var 源码 = 获取.body.string();
    eval("b=" + 源码);
    log("\n图灵收到 ",输入,"\n图灵返回",b.text)
    // log("图灵说......",b.text)
    QQsendMessage(b.text)
}


function QQsendMessage(message){
    inputText(message)
    sleep(100)
    send()
}

function inputText(message) {
    className("EditText").untilFind().setText(message);
}

function send() {
    className("Button").text("发送").clickable().click();
}

脚本二

//打开QQ聊天界面就能自动聊天了
"auto"
t = 0; //延迟
toast("打开QQ消息界面自动聊天");
//threads.start(notificationmsg);
while (true) {
    other = "";
    findMessage();
    othersay = getMessage();
    if (othersay != null) {
        var info = othersay;
        log("\n\nTa:\n" + ":" + othersay);
        i = "";
        i += Me();
        i += "";
        sendMessage(i);
        log("\n\n我:\n" + i);
        sleep(t)
    }
    findboxmsg();
}

function Me() {
    var url = "http://www.tuling123.com/openapi/api";
    id1 = "llmjk";
    var res = http.post(url, {
        //key: "65458a5df537443b89b31f1c03202a80", //图灵
        key: "e0fcda33be9847c8b8534abe51b4b095", //唐嫣
        // key: "b4438ca194064134afa28f686fbd04a5", //my图灵
        info: info,
        userid: "1",
    });
    var html = res.body.string();
    eval("b=" + html);
    return b.text;
}

function getMessage() {
    var information = null;
    if (id("listView1").exists() && id("chat_item_head_icon").exists() && id("chat_item_content_layout").exists()) {
        num = msgnum();
        icon = id("chat_item_head_icon").findOnce(num - 1);
        toastt = id("chat_item_content_layout").findOnce(num - 1);
        if (toastt != null && icon != null) {
            x = icon.bounds().centerX();
            y = icon.bounds().centerY();
            if (x < 500) {
                information = toastt.text();
                other = icon.text();
            }
        }
    }
    return information;
}

function sendMessage(i) {
    if (id("input").exists()) {
        id("input").setText(i);
        className("android.widget.Button").text("发送").click();
    }
}

function findMessage() {
    if (id("unreadmsg").exists()) {
        unreadmsg = id("unreadmsg").findOnce(0);
        x1 = unreadmsg.bounds().centerX();
        y1 = unreadmsg.bounds().centerY();
        //click(x1 - 200, y1 - 50);
        press(x1 - 200, y1 - 50, 50);
        if (id("input").findOne(2000) == null) {
            back();
            if (currentActivity() != "com.tencent.mobileqq.activity.SplashActivity") {
                app.launch("com.tencent.mobileqq");
            }
        }
    } else {
        ismsg = className("android.widget.RelativeLayout").depth("4").drawingOrder("2").clickable(true).selected(true).findOne(100);
        if (ismsg != null && ismsg.childCount() == 3) {
            ismsg.click();
        }
    }
}

function findboxmsg() {
    if (id("msgbox").exists()) {
        id("msgbox").findOne(500).click();
    }
}

function notificationmsg() {
    var notifi;
    events.observeNotification();
    events.on("notification", function(n) {
        if ("com.tencent.mobileqq" == n.getPackageName()) {
            app.launch("com.tencent.mobileqq");
        }
    });
}


function msgnum() {
    i = 0;
    id("listView1").findOne().children()
        .forEach(function(child) {
            if (child.className() == "android.widget.RelativeLayout");
            i++;
        });
    return i;
}

脚本三

"auto";
console.show();
launchApp("QQ");
sleep(1000);

Text = "";
while (true) {
    var UIOB = className("android.widget.AbsListView").findOne();
    if (getEnd(UIOB) != "" && getEnd(UIOB) != Text) {
        Text = getEnd(UIOB);
        log(Text);
        var txt = TuringRobot(Text);
        input(txt);
        while (!click("发送"));
    };
};


function getEnd(UiObject) {
    try {
        var sum = UiObject.childCount();
        if (sum) {
            var Object = UiObject.child(sum - 1);
            if (Object.className() == "android.widget.TextView") {
                return Object.text();
            } else {
               if(getEnd(Object)){
                   return getEnd(Object);
                   }else{
                    return getEnd(UiObject.child(sum - 2));  
                       };
            };
        } else {
            return "";
        };
    } catch (e) {
        return "";
    };
};

function TuringRobot(message, id) {
    var url = "http://www.tuling123.com/openapi/api";
    var res = http.postJson(url, {
        key: "1c2514d9c9884931985b5bef1232fa24",
        info: message,
        userid: "1"
    });
    var txt = res.body.json().text;
    return txt;
};

👉其他

📢作者:小空和小芝中的小空
📢转载说明-务必注明来源:https://zhima.blog.csdn.net/
📢这位道友请留步☁️,我观你气度不凡,谈吐间隐隐有王者霸气💚,日后定有一番大作为📝!!!旁边有点赞👍收藏🌟今日传你,点了吧,未来你成功☀️,我分文不取,若不成功⚡️,也好回来找我。

温馨提示点击下方卡片获取更多意想不到的资源。
空名先生