-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from P3D-Legacy/develop
Release 4.1.0
- Loading branch information
Showing
133 changed files
with
5,022 additions
and
2,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ jobs: | |
ref: ${{ github.head_ref }} | ||
- name: Install NPM dependencies | ||
run: npm install | ||
- name: Install Composer dependencies | ||
run: composer install | ||
- name: Prettify code | ||
uses: creyD/[email protected] | ||
with: | ||
prettier_options: --write **/*.{php,js} --config .prettierrc --ignore-path .prettierignore | ||
prettier_plugins: '@prettier/plugin-php prettier-plugin-tailwindcss' | ||
prettier_plugins: '@prettier/plugin-php prettier-plugin-tailwindcss' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Post; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use League\HTMLToMarkdown\HtmlConverter; | ||
|
||
class ImportFromTumblr extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:tumblr {blogname : The name of the Tumblr blog}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Import posts from a Tumblr blog'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
$blogName = $this->argument('blogname'); | ||
|
||
if ( | ||
env('TUMBLR_CONSUMER_KEY') == null || | ||
env('TUMBLR_CONSUMER_SECRET') == null || | ||
env('TUMBLR_OAUTH_TOKEN') == null || | ||
env('TUMBLR_OAUTH_TOKEN_SECRET') == null | ||
) { | ||
$this->error('Please set the tumblr environment variables.'); | ||
return 1; | ||
} | ||
|
||
try { | ||
$client = new \Tumblr\API\Client( | ||
env('TUMBLR_CONSUMER_KEY'), | ||
env('TUMBLR_CONSUMER_SECRET'), | ||
env('TUMBLR_OAUTH_TOKEN'), | ||
env('TUMBLR_OAUTH_TOKEN_SECRET') | ||
); | ||
|
||
$posts = $client->getBlogPosts($blogName); | ||
|
||
foreach ($posts->posts as $post) { | ||
$body = preg_replace("/\r|\n/", '', trim(strip_tags($post->body))); // Clean up the body | ||
$postedBy = substr($body, -30); // Get the last 30 characters of the body | ||
if (str_contains($postedBy, '-')) { | ||
// If the last 30 characters contain a dash, then it's probably the author | ||
$postedBy = substr($postedBy, strpos($postedBy, '-')); // Get the author | ||
$postedBy = trim(str_replace('-', '', $postedBy)); // Remove the dash | ||
$postedBy = explode('//', $postedBy)[0]; // Get the first part of the author | ||
} elseif (str_contains($postedBy, '//')) { | ||
// If the last 30 characters contain a double slash, then it's probably the author | ||
$postedBy = substr($postedBy, strpos($postedBy, '//')); // Get the author | ||
$postedBy = str_replace('/', '', $postedBy); // Remove the slash | ||
$postedBy = str_replace('‘', '', $postedBy); // Remove the left single quote | ||
$postedBy = str_replace('’', '', $postedBy); // Remove the right single quote | ||
} | ||
$postedBy = str_replace(' ', '', $postedBy); // Remove the spaces | ||
$user = User::where('username', $postedBy)->first() ?? User::first(); // Try to find the user by username or default to the first user | ||
$title = str_replace('Pokémon3D ', '', $post->title); // Remove the Pokémon3D prefix from the title | ||
$title = str_replace('!', '', $title); // Remove the exclamation mark | ||
$title = ucfirst($title); // Capitalize the first letter of the title | ||
$this->info('Title: ' . $title . ', Posted by: ' . $user->username); | ||
$converter = new HtmlConverter(); | ||
$markdown = $converter->convert($post->body); | ||
Post::create([ | ||
'title' => $title, | ||
'body' => $markdown, | ||
'slug' => $post->slug, | ||
'published_at' => Carbon::parse($post->date), | ||
'user_id' => $user->id, | ||
'active' => true, | ||
'sticky' => false, | ||
]); | ||
} | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\GameVersion; | ||
use App\Models\User; | ||
use App\Notifications\NewGameUpdateNotification; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use Notification; | ||
|
||
class NotifyGameUpdate extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'notify:gameupdate'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Notify users about a new game update'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
$latest = GameVersion::latest(); | ||
$rls_date = $latest->release_date; | ||
$yesterday = Carbon::yesterday(); | ||
$users = User::all()->filter(function ($user) { | ||
return $user->getConsent('email.newsletter'); | ||
}); | ||
if ($rls_date->isSameDay($yesterday)) { | ||
$this->info("New update found: {$latest->version}"); | ||
Notification::send($users, new NewGameUpdateNotification($latest)); | ||
} else { | ||
$this->info('No new update found to notify about.'); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class WikiHelper | ||
{ | ||
public static function sendRequest($endpoint) | ||
{ | ||
if (config('wiki.api_url') === null) { | ||
return 'Wiki API URL is not set'; | ||
} | ||
$url = config('wiki.api_url') . '?' . $endpoint; | ||
$response = Http::withHeaders([ | ||
'Accept' => 'application/json', | ||
]) | ||
->get($url) | ||
->body(); | ||
return json_decode($response); | ||
} | ||
|
||
public static function getSearchResults(string $query) | ||
{ | ||
if (empty($query)) { | ||
return collect([]); | ||
} | ||
$endpoint = | ||
'action=query&format=json&list=search&indexpageids=1&iwurl=1&srsearch=' . | ||
$query . | ||
'&srnamespace=0&srprop=size%7Cwordcount%7Ctimestamp%7Csnippet&srsort=relevance'; | ||
return self::sendRequest($endpoint); | ||
} | ||
|
||
public static function getAllPages(): Collection | ||
{ | ||
$endpoint = | ||
'action=query&format=json&list=allpages&indexpageids=1&iwurl=1&apnamespace=0&apfilterredir=nonredirects&aplimit=500&apdir=ascending'; | ||
return collect(self::sendRequest($endpoint)->query->allpages); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.