Skip to content

Commit

Permalink
:octocat:
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jul 17, 2023
1 parent 9f8fbc9 commit 61fcc6d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- clone this repository
- create a mastodon account for your bot, e.g. on https://botsin.space/
- when your account is approved, go to the [development settings](https://botsin.space/settings/applications) and create a new application
- copy [`/config/.env_example`](./config/.env_example) to `/config/.env`
- copy [`/config/.env_example`](./config/.env_example) to `/config/.env` (for local test, **do not upload the .env to GitHub!**)
- copy the access token from the mastodon application and save it in the `.env` as `MASTODON_TOKEN`, go to the repository settings on GitHub under `{repo_url}/settings/secrets/actions` and save it there too (not necessary if you plan to run the bot on your own webserver)
- save the mastodon instance URL in the `.env` as `MASTODON_INSTANCE`, save it as GitHub repository secret as well
- if you plan to use remote authentication with the mastodon app, you will need to do the same for the client key, secret and callback-URL
Expand Down Expand Up @@ -69,14 +69,22 @@ jobs:

# please note that this requires read/write permissions for the actions runner!
- name: "Commit log"
run: |
git config user.name github-actions
git config user.email [email protected]
git add data/posted.json
git commit -m "posted toot"
git push
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: ":octocat: posted toot"
file_pattern: 'data/posted.json'
```
## related projects
- [php-tootbot/php-tootbot](https://github.com/php-tootbot/php-tootbot)
- [php-tootbot/tootbot-template](https://github.com/php-tootbot/tootbot-template)
- [chillerlan/php-httpinterface](https://github.com/chillerlan/php-httpinterface)
- [chillerlan/php-http-message-utils](https://github.com/chillerlan/php-http-message-utils)
- [chillerlan/php-oauth-core](https://github.com/chillerlan/php-oauth-core)
- [chillerlan/php-oauth-providers](https://github.com/chillerlan/php-oauth-providers)
- [chillerlan/php-settings-container](https://github.com/chillerlan/php-settings-container)
- [chillerlan/php-dotenv](https://github.com/chillerlan/php-dotenv)
## disclaimer
WE'RE TOTALLY NOT RUNNING A PRODUCTION-LIKE ENVIRONMENT ON GITHUB.<br>
Expand Down
27 changes: 10 additions & 17 deletions cli/run.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* common.php
* TootBot CLI runner
*
* @created 03.12.2022
* @author smiley <[email protected]>
Expand All @@ -14,22 +14,15 @@
use Psr\Log\LogLevel;

ini_set('date.timezone', 'UTC');
#mb_internal_encoding('UTF-8');

require_once __DIR__.'/../vendor/autoload.php';

// if we're running on gh-actions, we're going to fetch the variables from gh.secrets,
if(isset($_SERVER['GITHUB_ACTIONS'])){
$instance = getenv('MASTODON_INSTANCE');
$apiToken = getenv('MASTODON_TOKEN');
// otherwise we'll load them from the local .env file into the global environment
if(!isset($_SERVER['GITHUB_ACTIONS'])){
(new DotEnv(__DIR__.'/../config', '.env', true))->load();
}
// otherwise we're loading them from the local .env file
else{
$env = (new DotEnv(__DIR__.'/../config', '.env', false))->load();

$instance = $env->get('MASTODON_INSTANCE');
$apiToken = $env->get('MASTODON_TOKEN');
}


// invoke the options instance
$options = new TootBotOptions;
Expand All @@ -41,14 +34,14 @@

// OAuthOptionsTrait
// these settings are only required for authentication/remote token acquisition
#$options->key = $env->get('MASTODON_KEY') ?? '';
#$options->secret = $env->get('MASTODON_SECRET') ?? '';
#$options->callbackURL = $env->get('MASTODON_CALLBACK_URL') ?? '';
#$options->key = getenv('MASTODON_KEY');
#$options->secret = getenv('MASTODON_SECRET');
#$options->callbackURL = getenv('MASTODON_CALLBACK_URL');
#$options->sessionStart = true;

// TootBotOptions
$options->instance = $instance;
$options->apiToken = $apiToken;
$options->instance = getenv('MASTODON_INSTANCE');
$options->apiToken = getenv('MASTODON_TOKEN');
$options->loglevel = LogLevel::INFO;
#$options->buildDir = __DIR__.'/../.build';
$options->dataDir = __DIR__.'/../data';
Expand Down
Empty file added data/.gitkeep
Empty file.
9 changes: 5 additions & 4 deletions src/MyTootBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
/**
* Class MyTootBot
*
* @todo: update/change docblock
*
* @created 03.02.2023
* @author smiley <[email protected]>
* @copyright 2023 smiley
* @author you
* @copyright 2023 you
* @license MIT
*/

namespace PHPTootBot\MyTootBot;

use PHPTootBot\PHPTootBot\TootBot;
use PHPTootBot\PHPTootBot\TootBotInterface;

/**
*
*/
class MyTootBot extends TootBot{

public function post():TootBotInterface{
public function post():static{
// TODO: Implement post() method.

return $this;
Expand Down
6 changes: 4 additions & 2 deletions tests/MyTootBotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
/**
* Class MyTootBotTest
*
* @todo: update/change docblock
*
* @created 03.02.2023
* @author smiley <[email protected]>
* @copyright 2023 smiley
* @author you
* @copyright 2023 you
* @license MIT
*/

Expand Down

0 comments on commit 61fcc6d

Please sign in to comment.