@mashiro 大佬,这个bili的bot运行报这个是还需要配置什么吗

@mashiro 那代码统计代码要加哪里啊,docker搭建的也能加吗

@mashiro 是只能这个统计平台吗,其他自建统计平台也行吗 :bili_emoji_xingxingyan:

@gjcloak 只做了plausible和matomo的,其他平台暂不考虑

Follow

@gjcloak 如果需要我开个我的plausible给你

· · Web · 2 · 0 · 0

@gjcloak PHP7

<?php

$token="xxxxxx";

$account_id="4";

$base_url="https://hello.2heng.xin";

$visibility="direct";

$welcome_message="你好!欢迎加入长毛象联邦,并成为小森林里的一员~我是本站的通知兼迎新机器人~ :catlaugh: \n
:icon_mastodon: 长毛象不仅是一个社交网络,更是一种全新的理念和社交的方式,请允许我简要介绍一下。\n
:icon_forest: 本站 #小森林 是众多长毛象实例中的一个([关于长毛象的详细说明](https://hello.2heng.xin/about/more)),在本实例开设账号,你不仅可以和本地用户交互,也可以无缝和所有其他站点的用户交流!\n
你现在就可以尝试打开 `<本地时间轴>` 及 `<跨站时间轴>` 来查看大家的嘟文。";

$language="zh";

define('ROOTPATH', __DIR__);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . '/api/v1/accounts/' . $account_id . '/followers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

$headers = array();
$headers[] = 'Authorization: Bearer ' . $token ;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

$json = json_decode($result, TRUE);
$newest_user_id=$json[0]['id'];
$newest_user_username=$json[0]['username'];

echo "last user: ".$newest_user_id ."\n";

$readstorage = fopen(ROOTPATH."/newest_user_id.txt", "r") or die("Unable to open file!");
$last_user_id = fread($readstorage,filesize(ROOTPATH."/newest_user_id.txt"));
echo "\n\nlast_user_id is: " . $last_user_id."\n";
fclose($readstorage);

if ($last_user_id == "") {
    $writestorage = fopen(ROOTPATH."/newest_user_id.txt", "w") or die("Unable to open file!");
    fwrite($writestorage, $newest_user_id);
    fclose($writestorage);
}

if (($last_user_id != $newest_user_id) && ($last_user_id != "") && ($newest_user_id != "")) {
    $writestorage = fopen(ROOTPATH."/newest_user_id.txt", "w") or die("Unable to open file!");
    fwrite($writestorage, $newest_user_id);
    fclose($writestorage);
                
    foreach ( array_reverse($json) as $user_json ) {
        $user_id = $user_json['id'];
        $user_username = $user_json['username'];
        
        if (($last_user_id < $user_id) && ($user_id != "")) {
          
            $headers = [
              'Authorization: Bearer ' . $token
            ];
          
            $post="";

            $status_data = array(
              "status" => "@" . $user_username . " " . $welcome_message ,
              "language" => $language,
              "visibility" => $visibility
            );

            $ch_status = curl_init();
            curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v1/statuses");
            curl_setopt($ch_status, CURLOPT_POST, 1);
            curl_setopt($ch_status, CURLOPT_POSTFIELDS, $status_data);
            curl_setopt($ch_status, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch_status, CURLOPT_HTTPHEADER, $headers);
            $output_status = json_decode(curl_exec($ch_status));
            curl_close ($ch_status);
            
            echo "\nWelcome new user: ".$user_id.": @".$user_username."\n";
            
        } else {
          
            echo "\nError handeling ".$user_id.": @".$user_username."\n";

        }
    }
} else {

    echo "\nNo new user\n";

}
Sign in to participate in the conversation
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。