Skip to content

Commit

Permalink
[pm_triggers] WIP extension to send PMs on certain events
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Jan 6, 2024
1 parent 02da924 commit b5feb88
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ext/pm_triggers/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Shimmie2;

class PMTriggerInfo extends ExtensionInfo
{
public const KEY = "pm_triggers";

public string $key = self::KEY;
public string $name = "PM triggers";
public string $url = self::SHIMMIE_URL;
public array $authors = self::SHISH_AUTHOR;
public string $license = self::LICENSE_GPLV2;
public string $description = "Send PMs in response to certain events (eg post deletion)";
public bool $beta = true;
}
29 changes: 29 additions & 0 deletions ext/pm_triggers/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Shimmie2;

class PMTrigger extends Extension
{
public function onImageDeletion(ImageDeletionEvent $event)
{
$this->send(
$event->image->owner_id,
"[System] A post you uploaded has been deleted",
"Post le gone~ (#{$event->image->id}, {$event->image->get_tag_list()})"
);
}

private function send($to_id, $subject, $body)
{
global $user;
send_event(new SendPMEvent(new PM(
$user->id,
get_real_ip(),
$to_id,
$subject,
$body
)));
}
}

0 comments on commit b5feb88

Please sign in to comment.