ソースを参照

最初コミット

master
テクニカル諏訪子 5ヶ月前
コミット
fc3b5d6483
  1. 1
      .gitignore
  2. 7
      config.sample.php
  3. 18
      crontab
  4. 24
      post.php
  5. 61
      reply.php

1
.gitignore vendored

@ -0,0 +1 @@
config.php

7
config.sample.php

@ -0,0 +1,7 @@
<?php
$token = ''; // authトークン
$mess = ''; // メッセージ
$domain = 'https://'; // インスタンスのドメイン名
$source = '076 Pleroma Bot Engine';
$visibility = 'public';
?>

18
crontab

@ -0,0 +1,18 @@
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# 毎日9時
0 9 * * * root php /opt/bot/post.php
# 毎日21時
0 21 * * * root php /opt/bot/post.php
# 出来るだけ
* * * * * root php /opt/bot/reply.php
#

24
post.php

@ -0,0 +1,24 @@
<?php
// https://tinysubversions.com/notes/mastodon-bot/
include('config.php');
$param = [
'status' => $mess,
'source' => $source,
'visibility' => $visibility,
'content_type' => 'text/plain'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain.'/api/v1/statuses');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) return 400;
return 200;
?>

61
reply.php

@ -0,0 +1,61 @@
<?php
// https://tinysubversions.com/notes/mastodon-bot/
include('config.php');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain.'/api/v1/timelines/home');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) return 400;
$saveid = [];
foreach (json_decode($get) as $g) {
//if (is_null($g->in_reply_to_id)) continue;
if ($g->account->bot) continue;
if (in_array($g->id, $saveid)) continue;
if ($g->favourited) continue;
$param = [
'status' => $mess,
'source' => $source,
'visibility' => $visibility,
'content_type' => 'text/plain',
'in_reply_to_id' => $g->id
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain.'/api/v1/statuses');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) return 400;
$saveid[] = $g->id;
}
foreach ($saveid as $s) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain.'/api/v1/statuses/'.$s.'/favourite');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) return 400;
}
return 200;
?>
読み込み中…
キャンセル
保存