From f10c3726da4ef4ca81e8d880513f6d1fb8378e7c Mon Sep 17 00:00:00 2001 From: Jeff MacKinnon Date: Wed, 11 May 2022 17:12:37 -0300 Subject: [PATCH] It works --- MastodonBotPHP/LICENSE | 21 ++++++++ MastodonBotPHP/Mastodon.php | 5 ++ bot.php | 99 +++++++++++++++++++++++++++++++++++++ comment_record.txt | 0 readme.rst | 3 ++ 5 files changed, 128 insertions(+) create mode 100644 MastodonBotPHP/LICENSE create mode 100644 comment_record.txt create mode 100644 readme.rst diff --git a/MastodonBotPHP/LICENSE b/MastodonBotPHP/LICENSE new file mode 100644 index 0000000..6d658d5 --- /dev/null +++ b/MastodonBotPHP/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Gabriele Grillo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MastodonBotPHP/Mastodon.php b/MastodonBotPHP/Mastodon.php index 09b442e..97eb60d 100644 --- a/MastodonBotPHP/Mastodon.php +++ b/MastodonBotPHP/Mastodon.php @@ -1,4 +1,9 @@ $curl_file, + ]; + + $response = $mastodon->uploadMedia($body); + + $file_id = $response['id']; + + + // Step 2b - Create the status + $status_text = $postTitle. ' -> '.$postURL; + + $status_data = [ + 'status' => $status_text, + 'visibility' => $visibility, + 'language' => $language, + 'media_ids[]' => $file_id, + ]; + + $status_response = $mastodon->postStatus($status_data); + + // Step 3 - Update Text file + + $status_id = $status_response['id']; + + $f = fopen($comment_record, 'a'); + fputcsv($f, [$postURL, $status_id]); + fclose($f); + + // Step 4 - Send them to the post + + // 301 redirect to the mastodon status + http_response_code(301); + header('Location: '.$base_url.'/'.$instance_user.'/'.$status_id); + exit; +} + +?> \ No newline at end of file diff --git a/comment_record.txt b/comment_record.txt new file mode 100644 index 0000000..e69de29 diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..453a39b --- /dev/null +++ b/readme.rst @@ -0,0 +1,3 @@ +Here is the Bot for your Mastodon Comments +========================================== +