Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from herpaderpaldent/dev
Browse files Browse the repository at this point in the history
Version 1.0.5
  • Loading branch information
herpaderpaldent authored Jan 5, 2019
2 parents 8421f0f + 4044e61 commit fce6fbb
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Channels/Discord/DiscordChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DiscordChannel

public function __construct()
{
$this->discord = app('discord');
$this->discord = app('seatnotifications-discord');
}

public function send($notifiable, Notification $notification)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getChannels()
$response = cache('herpaderp.seatnotifications.discord.channels');

if(is_null($response)){
$channels = app('discord')
$channels = app('seatnotifications-discord')
->guild
->getGuildChannels([
'guild.id' => (int) setting('herpaderp.seatnotifications.discord.credentials.guild_id', true),
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Discord/DiscordServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function callback(Request $request)
setting(['herpaderp.seatnotifications.discord.credentials.guild_id', $request->input('guild_id')], true);

// update Discord container
app()->singleton('discord', function () {
app()->singleton('seatnotifications-discord', function () {
return new DiscordClient([
'tokenType' => 'Bot',
'token' => setting('herpaderp.seatnotifications.discord.credentials.bot_token', true),
Expand Down
51 changes: 51 additions & 0 deletions src/Jobs/RefreshTokenDeletionDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Created by PhpStorm.
* User: felix
* Date: 05.01.2019
* Time: 22:53.
*/

namespace Herpaderpaldent\Seat\SeatNotifications\Jobs;

use Herpaderpaldent\Seat\SeatNotifications\Models\RefreshTokenNotification;
use Herpaderpaldent\Seat\SeatNotifications\Notifications\RefreshTokenDeletedNotification;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Redis;
use Seat\Eveapi\Models\RefreshToken;

class RefreshTokenDeletionDispatcher extends SeatNotificationsJobBase
{
/**
* @var array
*/
protected $tags = ['refresh_token_deletion'];

/**
* @var \Seat\Eveapi\Models\RefreshToken
*/
private $refresh_token;

public function __construct(RefreshToken $refresh_token)
{
$this->refresh_token = $refresh_token;
}

public function handle()
{
Redis::funnel('soft_delete:refresh_token_' . $this->refresh_token->user->name)->limit(1)->then(function () {
logger()->info('SoftDelete detected of ' . $this->refresh_token->user->name);

$recipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
return $recepient->shouldReceive();
});

Notification::send($recipients, (new RefreshTokenDeletedNotification($this->refresh_token)));
}, function () {

logger()->info('A Soft-Delete job is already running for ' . $this->refresh_token->user->name);
$this->delete();
});
}
}
58 changes: 58 additions & 0 deletions src/Jobs/SeatNotificationsJobBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Created by PhpStorm.
* User: felix
* Date: 01.09.2018
* Time: 13:33.
*/

namespace Herpaderpaldent\Seat\SeatNotifications\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

abstract class SeatNotificationsJobBase implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* @var array
*/
protected $tags = [];

/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 1;

/**
* Assign this job a tag so that Horizon can categorize and allow
* for specific tags to be monitored.
*
* If a job specifies the tags property, that is added.
*
* @return array
*/
public function tags(): array
{

$tags = ['seatnotifications', 'dispatcher'];

if (property_exists($this, 'tags'))
return array_merge($this->tags, $tags);

return $tags;
}

/**
* Execute the job.
*
* @return void
*/
abstract public function handle();
}
4 changes: 2 additions & 2 deletions src/Models/RefreshTokenNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public function recipient() : string
if(is_null($this->group()))
return 'channel';

$main_character = $this->group()->main_character;
$main_character = $this->group()->main_character->name;

if (is_null($main_character)) {
logger()->warning('Group has no main character set. Attempt to make assignation based on first attached character.', [
'group_id' => $this->group()->id,
]);
$main_character = $group->users->first()->character;
$main_character = $group->users->first()->character->name;
}

return $main_character;
Expand Down
11 changes: 9 additions & 2 deletions src/Notifications/RefreshTokenDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class RefreshTokenDeletedNotification extends BaseNotification

public $corporation;

private $refresh_token;

public function __construct(RefreshToken $refresh_token)
{
parent::__construct();

$this->refresh_token = $refresh_token;
$this->user_name = $refresh_token->user->name;
$this->image = 'https://imageserver.eveonline.com/Character/' . $refresh_token->character_id . '_128.jpg';
$this->main_character = $this->getMainCharacter($refresh_token->user->group)->name;
Expand Down Expand Up @@ -74,13 +77,17 @@ public function via($notifiable)

public function toDiscord($notifiable)
{
$character = sprintf('[%s](%s)',
$this->user_name,
route('configuration.users.edit', ['user_id' => $this->refresh_token->character_id]));

return (new DiscordMessage)
->embed(function ($embed) {
->embed(function ($embed) use ($character) {

$embed->title('**A SeAT users refresh token was removed!**')
->thumbnail($this->image)
->color('16711680')
->field('Character', $this->user_name, true)
->field('Character', $character, true)
->field('Corporation', $this->corporation, true)
->field('Main Character', $this->main_character, false);
});
Expand Down
34 changes: 7 additions & 27 deletions src/Observers/RefreshTokenObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,27 @@

namespace Herpaderpaldent\Seat\SeatNotifications\Observers;

use Herpaderpaldent\Seat\SeatNotifications\Models\RefreshTokenNotification;
use Herpaderpaldent\Seat\SeatNotifications\Notifications\RefreshTokenDeletedNotification;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Redis;
use Herpaderpaldent\Seat\SeatNotifications\Jobs\RefreshTokenDeletionDispatcher;
use Seat\Eveapi\Models\RefreshToken;

class RefreshTokenObserver
{
public function deleting(RefreshToken $refresh_token)
{
Redis::funnel('soft_delete:refresh_token_' . $refresh_token->user->name)->limit(1)->then(function () use ($refresh_token) {
logger()->info('SoftDelete detected of ' . $refresh_token->user->name);

$receipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
return $recepient->shouldReceive();
});

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));
}, function () use ($refresh_token) {
logger()->info('A Soft-Delete job is already running for ' . $refresh_token->user->name);
});

$job = new RefreshTokenDeletionDispatcher($refresh_token);

dispatch($job)->onQueue('high');
}

public function test()
{

$refresh_token = RefreshToken::find(95725047);

Redis::funnel('soft_delete:refresh_token_' . $refresh_token->user->name)->limit(1)->then(function () use ($refresh_token) {
logger()->info('SoftDelete detected of ' . $refresh_token->user->name);

$receipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
return $recepient->shouldReceive();
});
$job = new RefreshTokenDeletionDispatcher($refresh_token);

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));
}, function () use ($refresh_token) {
logger()->info('A Soft-Delete job is already running for ' . $refresh_token->user->name);
});
dispatch($job)->onQueue('high');

}
}
4 changes: 2 additions & 2 deletions src/SeatNotificationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function addDiscordContainer()
$bot_token = setting('herpaderp.seatnotifications.discord.credentials.bot_token', true);

if (! is_null($bot_token)) {
$this->app->singleton('discord', function () {
$this->app->singleton('seatnotifications-discord', function () {
return new DiscordClient([
'tokenType' => 'Bot',
'token' => setting('herpaderp.seatnotifications.discord.credentials.bot_token', true),
Expand All @@ -98,7 +98,7 @@ private function addDiscordContainer()
}

// bind discord alias to DiscordClient
$this->app->alias('discord', DiscordClient::class);
$this->app->alias('seatnotifications-discord', DiscordClient::class);
}

private function addSlackContainer()
Expand Down
2 changes: 1 addition & 1 deletion src/config/seatnotifications.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Time: 10:24.
*/
return [
'version' => '1.0.3',
'version' => '1.0.5',
];
16 changes: 16 additions & 0 deletions src/resources/views/seatnotifications/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

</div>
<!-- /.box -->
<div class="box-footer">
<div class="col-md-3">
Installed version: <b>{{ config('seatnotifications.config.version') }}</b>
</div>
<div class="col-md-3">
Latest version:
<a href="https://packagist.org/packages/herpaderpaldent/seat-notifications">
<img src="https://poser.pugx.org/herpaderpaldent/seat-notifications/v/stable" alt="SeAT Notifications version" />
</a>
</div>
<div class="col-md-6"></div>
</div>
</div>
</div>
</div>
Expand All @@ -31,5 +43,9 @@
@endforeach
</div>

<div class="row">

<div>


@endsection

0 comments on commit fce6fbb

Please sign in to comment.