Skip to content

Commit

Permalink
Merge pull request #153 from P3D-Legacy/develop
Browse files Browse the repository at this point in the history
Release 4.1.0
  • Loading branch information
dsbilling authored May 22, 2022
2 parents 588c118 + 7d461be commit c254cac
Show file tree
Hide file tree
Showing 133 changed files with 5,022 additions and 2,844 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ LANG_CONTRIBUTION_URL=null
POSTMARK_TOKEN=null

IPGEOLOCATION_KEY=null

WIKI_BASE_URL="https://wiki.pokemon3d.net"

PLAUSIBLE_API_KEY=null

TUMBLR_CONSUMER_KEY=null
TUMBLR_CONSUMER_SECRET=null
TUMBLR_OAUTH_TOKEN=null
TUMBLR_OAUTH_TOKEN_SECRET=null
4 changes: 3 additions & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
94 changes: 94 additions & 0 deletions app/Console/Commands/ImportFromTumblr.php
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('&lsquo;', '', $postedBy); // Remove the left single quote
$postedBy = str_replace('&rsquo;', '', $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;
}
}
49 changes: 49 additions & 0 deletions app/Console/Commands/NotifyGameUpdate.php
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;
}
}
7 changes: 7 additions & 0 deletions app/Console/Commands/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use anlutro\LaravelSettings\Facade as Setting;
use App\Models\DiscordBotSetting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

Expand Down Expand Up @@ -70,6 +71,12 @@ public function handle(): int
Artisan::call('discord:syncroles');
$this->info('Getting Discord user roles...');
Artisan::call('discord:syncuserroles');
$this->info('Saving DiscordBotSetting...');
if (DiscordBotSetting::first() === null) {
DiscordBotSetting::create([
'hide_events' => '{}',
]);
}
$this->info('Done.');
return 0;
}
Expand Down
25 changes: 16 additions & 9 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

namespace App\Console;

use App\Console\Commands\DiscordRoleSync;
use App\Console\Commands\DiscordUserRoleSync;
use App\Console\Commands\NotifyGameUpdate;
use App\Console\Commands\PingAllServers;
use App\Console\Commands\SkinUserUpdate;
use App\Console\Commands\SyncGameVersion;
use App\Console\Commands\UpdateGamejoltAccountTrophies;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Activitylog\CleanActivitylogCommand;

class Kernel extends ConsoleKernel
{
Expand All @@ -16,14 +23,14 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('p3d:skinuserupdate')->hourlyAt(10);
$schedule->command('server:pingall')->hourly();
$schedule->command('gj:update-trophies')->hourly();
$schedule->command('github:syncrelease')->daily();
$schedule->command('discord:syncroles')->dailyAt('12:00');
$schedule->command('discord:syncuserroles')->dailyAt('12:10');
$schedule->command('activity:cleanup')->dailyAt('01:00');
$schedule->command(RunHealthChecksCommand::class)->everyMinute();
$schedule->command(SkinUserUpdate::class)->hourlyAt(10);
$schedule->command(PingAllServers::class)->hourly();
$schedule->command(UpdateGamejoltAccountTrophies::class)->hourly();
$schedule->command(SyncGameVersion::class)->dailyAt('00:00');
$schedule->command(DiscordRoleSync::class)->dailyAt('12:00');
$schedule->command(DiscordUserRoleSync::class)->dailyAt('12:10');
$schedule->command(CleanActivitylogCommand::class)->dailyAt('01:00');
$schedule->command(NotifyGameUpdate::class)->dailyAt('00:30');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions app/Helpers/StatsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public static function countPlayers()
{
try {
$data = self::sendRequest('/server/status');

return count($data['players']);
if (isset($data['players'])) {
return count($data['players']);
}
return 0;
} catch (\Exception $exception) {
report($exception);
return 0;
Expand Down
42 changes: 42 additions & 0 deletions app/Helpers/WikiHelper.php
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);
}
}
23 changes: 6 additions & 17 deletions app/Helpers/XenForoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class XenForoHelper

const METHOD_POST = 'post';

const NEWS_BOARD_ID = '4';

public static function sendRequest($endpoint, $data = [], $method = self::METHOD_GET)
{
if (config('xenforo.apikey') == null) {
Expand All @@ -32,25 +30,16 @@ public static function sendRequest($endpoint, $data = [], $method = self::METHOD
return $decodedResponse;
}

public static function getNewsItems()
{
$data = self::sendRequest('/forums/' . self::NEWS_BOARD_ID . '/threads');

if (array_key_exists('errors', $data)) {
return ['threads' => []];
}

return $data;
}

public static function getUserCount()
{
$data = self::sendRequest('/users');
if (array_key_exists('errors', $data)) {
throw new \Exception('CAN NOT COUNT USERS!');
if ($data) {
if (array_key_exists('errors', $data)) {
return 0;
}
return $data['pagination']['total'];
}

return $data['pagination']['total'];
return 0;
}

public static function postAuth($login, $password)
Expand Down
Loading

0 comments on commit c254cac

Please sign in to comment.