commit fc3b5d6483126236f331aaa32ab44d28da2670b9 Author: テクニカル諏訪子 Date: Tue Dec 28 18:05:58 2021 +0900 最初コミット 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; +?>