@gjcloak 安装依赖
@mashiro mastodon能加统计代码吗
@mashiro 那代码统计代码要加哪里啊,docker搭建的也能加吗
@mashiro 是只能这个统计平台吗,其他自建统计平台也行吗
@gjcloak 只做了plausible和matomo的,其他平台暂不考虑
@mashiro 大佬迎新机器人的能再发下吗
@gjcloak PHP7
<?php
$token="xxxxxx";
$account_id="4";
$base_url="https://hello.2heng.xin";
$visibility="direct";
$welcome_message="你好!欢迎加入长毛象联邦,并成为小森林里的一员~我是本站的通知兼迎新机器人~
\n
长毛象不仅是一个社交网络,更是一种全新的理念和社交的方式,请允许我简要介绍一下。\n
本站 #小森林 是众多长毛象实例中的一个([关于长毛象的详细说明](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";
}
@mashiro 好的,谢谢了
@mashiro 这个account_id怎么看
@gjcloak 你打开用户管理页,在URL上
@mashiro 看到了,谢谢
@mashiro 谢谢了,我先研究下