Skip to content

Commit

Permalink
Merge pull request #226 from P3D-Legacy/219-refactoring-configs
Browse files Browse the repository at this point in the history
Closes #219
  • Loading branch information
dsbilling authored Dec 23, 2022
2 parents 0759522 + 169f8de commit 9fb735e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 37 deletions.
12 changes: 6 additions & 6 deletions app/Helpers/DiscordHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class DiscordHelper
public function __construct()
{
$this->discordClient =
config('discord.token') && config('discord.server_id')
? new DiscordClient(['token' => config('discord.token')])
config('services.discord.token') && config('services.discord.server_id')
? new DiscordClient(['token' => config('services.discord.token')])
: null;
}

public function getServer()
{
return $this->discordClient->guild->getGuild([
'guild.id' => config('discord.server_id'),
'guild.id' => config('services.discord.server_id'),
'with_counts' => true,
]);
}
Expand All @@ -39,7 +39,7 @@ public static function getServerRoles()
$client = new self();
try {
return $client->discordClient->guild->getGuildRoles([
'guild.id' => config('discord.server_id'),
'guild.id' => config('services.discord.server_id'),
]);
} catch (\Exception $exception) {
return $exception;
Expand All @@ -51,7 +51,7 @@ public static function getMemberRoles(int $user_id)
$client = new self();
try {
return $client->discordClient->guild->getGuildMember([
'guild.id' => config('discord.server_id'),
'guild.id' => config('services.discord.server_id'),
'user.id' => $user_id,
]);
} catch (\Exception $exception) {
Expand All @@ -64,7 +64,7 @@ public static function setMemberRole(int $user_id, int $role_id)
$client = new self();
try {
return $client->discordClient->guild->addGuildMemberRole([
'guild.id' => config('discord.server_id'),
'guild.id' => config('services.discord.server_id'),
'user.id' => $user_id,
'role.id' => $role_id,
]);
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/WikiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class WikiHelper
{
public static function sendRequest($endpoint)
{
if (config('wiki.api_url') === null) {
if (! config('services.wiki.api_url')) {
return 'Wiki API URL is not set';
}
$url = config('wiki.api_url').'?'.$endpoint;
$url = config('services.wiki.api_url').'?'.$endpoint;
$response = Http::withHeaders([
'Accept' => 'application/json',
])
Expand Down
10 changes: 5 additions & 5 deletions app/Helpers/XenForoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class XenForoHelper

public static function sendRequest($endpoint, $data = [], $method = self::METHOD_GET)
{
if (config('xenforo.apikey') == null) {
if (! config('services.xenforo.api_key')) {
return ['errors' => []];
}
if (is_string($data)) {
$method = $data;
$data = [];
}
$url = config('xenforo.base_url').$endpoint;
$url = config('services.xenforo.api_url').$endpoint;
$response = Http::withHeaders([
'XF-Api-Key' => config('xenforo.apikey'),
'XF-Api-Key' => config('services.xenforo.api_key'),
])->$method($url, $data);
$decodedResponse = json_decode($response, true);

Expand Down Expand Up @@ -52,14 +52,14 @@ public static function postAuth($login, $password)
];

$client = new Client([
'base_uri' => config('xenforo.base_url'),
'base_uri' => config('services.xenforo.api_url'),
]);

try {
$response = $client->post('/api/auth', [
'form_params' => $credentials,
'headers' => [
'XF-Api-Key' => config('xenforo.apikey'),
'XF-Api-Key' => config('services.xenforo.api_key'),
'Accept' => 'application/json',
],
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Spotlight/WikiSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function searchWiki($query)
*/
public function execute(Spotlight $spotlight, $wiki)
{
$spotlight->redirect(config('wiki.base_url').'/index.php?curid='.$wiki);
$spotlight->redirect(config('services.wiki.base_url').'/index.php?curid='.$wiki);
}

/**
Expand Down
7 changes: 0 additions & 7 deletions config/discord.php

This file was deleted.

8 changes: 8 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'client_id' => env('DISCORD_CLIENT_ID'),
'client_secret' => env('DISCORD_CLIENT_SECRET'),
'redirect' => env('DISCORD_REDIRECT_URI', '/login/discord/callback'),
'token' => env('DISCORD_TOKEN'),
'server_id' => env('DISCORD_SERVER_ID'),
'invite_url' => env('DISCORD_INVITE_URL', '#'),
],

'twitter' => [
Expand Down Expand Up @@ -64,4 +67,9 @@
'api_url' => config('services.xenforo.base_url').'/api',
],

'wiki' => [
'base_url' => env('WIKI_BASE_URL'),
'api_url' => config('services.wiki.base_url').'/api.php',
],

];
6 changes: 0 additions & 6 deletions config/wiki.php

This file was deleted.

7 changes: 0 additions & 7 deletions config/xenforo.php

This file was deleted.

4 changes: 2 additions & 2 deletions resources/views/profile/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
@livewire('profile.connect-gamejolt-account')
<x-jet-section-border />
@endif

@if(config("services.discord.client_id") && config("services.discord.client_secret"))
@livewire('profile.discord-account')
<x-jet-section-border />
@endif

@if(config("xenforo.apikey") && config("xenforo.base_url"))
@if(config("services.xenforo.api_key") && config("services.xenforo.api_url"))
@livewire('profile.xenforo-account')
<x-jet-section-border />
@endif
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
})->name('github');

Route::get('/discord', function () {
return redirect(config('discord.invite_url'));
return redirect(config('services.discord.invite_url'));
})->name('discord');
});

Expand Down

0 comments on commit 9fb735e

Please sign in to comment.