From fc3b5d6483126236f331aaa32ab44d28da2670b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Tue, 28 Dec 2021 18:05:58 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=88=9D=E3=82=B3=E3=83=9F=E3=83=83?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + config.sample.php | 7 ++++++ crontab | 18 ++++++++++++++ post.php | 24 +++++++++++++++++++ reply.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 .gitignore create mode 100644 config.sample.php create mode 100644 crontab create mode 100644 post.php create mode 100644 reply.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f4773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/config.sample.php b/config.sample.php new file mode 100644 index 0000000..f257fa8 --- /dev/null +++ b/config.sample.php @@ -0,0 +1,7 @@ + diff --git a/crontab b/crontab new file mode 100644 index 0000000..096c01a --- /dev/null +++ b/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 +# diff --git a/post.php b/post.php new file mode 100644 index 0000000..d9762e7 --- /dev/null +++ b/post.php @@ -0,0 +1,24 @@ + $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; +?> diff --git a/reply.php b/reply.php new file mode 100644 index 0000000..6cd75ea --- /dev/null +++ b/reply.php @@ -0,0 +1,61 @@ +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; +?>