From 8b83ef3ba8f9fc66372fb77d0987087452e49296 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 2 Dec 2023 00:28:59 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B8=D1=88=D0=B5=D0=BC=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20=D0=B2=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=BE.=20=D0=A2=D0=B8=D0=BF=20`10`=20=D0=B2=D0=B7=D1=8F?= =?UTF-8?q?=D1=82=20=D0=BD=D0=B0=D1=83=D0=B3=D0=B0=D0=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _incl_data/class/Moderation/Moderation.php | 107 +++++++++++++++------ 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/_incl_data/class/Moderation/Moderation.php b/_incl_data/class/Moderation/Moderation.php index c5ab6b47..350e107d 100644 --- a/_incl_data/class/Moderation/Moderation.php +++ b/_incl_data/class/Moderation/Moderation.php @@ -4,8 +4,8 @@ namespace Moderation; use Core\Db; use DateTime; +use Delo; -// todo Запись в личное дело или добавить или убрать остатки. // todo Заменить уродский костыль с тюремным сундуком. Возможен конфликт с автоудалением предметов! // todo Понять как мониторить переводы. @@ -14,7 +14,8 @@ class Moderation private const JAIL_ROOM = 274; private const CENTRAL_SQUARE_ROOM = 9; private const JAIL_STORAGE = 1357908642; /* Ух, костыль! */ - + private const NOT_SET = 'Не указано.'; + private const EXPIRATION_DATETIME_FORMAT = 'd M Y H:i'; private int $target; public function __construct(int $userid) @@ -24,87 +25,129 @@ class Moderation /** * Молчание - * @param DateTime $expiration срок истечения. - * @param string|null $reason причина применения. - */public function silence(DateTime $expiration, ?string $reason = null) + * @param DateTime $expiration срок истечения. + * @param string $reason причина применения. + */ + public function silence(DateTime $expiration, string $reason = self::NOT_SET): void { Db::sql('update users set molch1 = ? where id = ?', [$expiration->getTimestamp(), $this->target]); + Delo::add( + 10, + 'moderation.silence', + $this->target, + 'Молчанка в чате до ' . $expiration->format(self::EXPIRATION_DATETIME_FORMAT) . '. ' . $reason, + ); } /** * Снятие молчания */ - public function unsilence() + public function unsilence(): void { + if (Db::getValue('select count(molch1) from users where id = ? and molch1 != 0', [$this->target]) === 0) { + return; + } Db::sql('update users set molch1 = default where id = ?', [$this->target]); + Delo::add( + 10, + 'moderation.unsilence', + $this->target, + 'Отмена молчанки.', + ); } /** * Обезличивание - * @param DateTime $expiration срок истечения. - * @param string|null $reason причина применения. + * @param DateTime $expiration срок истечения. + * @param string $reason причина применения. */ - public function depersonalize(DateTime $expiration, ?string $reason = null) + public function depersonalize(DateTime $expiration, string $reason = self::NOT_SET): void { Db::sql('update users set info_delete = ? where id = ?', [$expiration->getTimestamp(), $this->target]); + Delo::add( + 10, + 'moderation.depersonalize', + $this->target, + 'Скрытие анкеты до ' . $expiration->format(self::EXPIRATION_DATETIME_FORMAT) . '. ' . $reason, + ); } /** * Снятие обезличивания */ - public function undepersonalize() + public function undepersonalize(): void { + if (Db::getValue('select count(info_delete) from users where id = ? and info_delete != 0', [$this->target]) === 0) { + return; + } Db::sql('update users set info_delete = default where id = ?', [$this->target]); + Delo::add( + 10, + 'moderation.undepersonalize', + $this->target, + 'Раскрытие анкеты.', + ); } /** * Тюрьма - * @param DateTime $expiration срок истечения. - * @param string|null $reason причина применения. + * @param DateTime $expiration срок истечения. + * @param string $reason причина применения. */ - public function prison(DateTime $expiration, ?string $reason = null) + public function prison(DateTime $expiration, string $reason = self::NOT_SET): void { - Db::sql('update users set jail = ?, room = ? where id = ?', [ - $expiration->getTimestamp(), - self::JAIL_ROOM, + Db::sql('update users set jail = ?, room = ? where id = ?', [$expiration->getTimestamp(), self::JAIL_ROOM, $this->target,]); + Db::sql('update items_users set `delete` = ? where `delete` = 0 and uid = ?', [self::JAIL_STORAGE, $this->target,]); + Delo::add( + 10, + 'moderation.prison', $this->target, - ]); - Db::sql('update items_users set `delete` = ? where `delete` = 0 and uid = ?', [ - self::JAIL_STORAGE, - $this->target, - ]); + 'Тюрьма до ' . $expiration->format(self::EXPIRATION_DATETIME_FORMAT) . '. ' . $reason, + ); } /** * Снятие тюрьмы */ - public function unprison() + public function unprison(): void { - Db::sql('update users set jail = default, room = ? where id = ?', [ - self::CENTRAL_SQUARE_ROOM, + Db::sql('update users set jail = default, room = ? where id = ?', [self::CENTRAL_SQUARE_ROOM, $this->target,]); + Db::sql('update items_users set `delete` = default where `delete` = ? and uid = ?', [self::JAIL_STORAGE, $this->target,]); + Delo::add( + 10, + 'moderation.unprison', $this->target, - ]); - Db::sql('update items_users set `delete` = default where `delete` = ? and uid = ?', [ - 1357908642, - $this->target, - ]); + 'Выпуск из тюрьмы.', + ); } /** * Блокировка - * @param string|null $reason причина применения. + * @param string $reason причина применения. */ - public function ban(?string $reason = null) + public function ban(string $reason = self::NOT_SET): void { Db::sql('update users set banned = unix_timestamp() where id = ?', [$this->target]); + Delo::add( + 10, + 'moderation.ban', + $this->target, + 'Блокировка. ' . $reason, + ); } /** * Снятие блокировки */ - public function unban() + public function unban(): void { Db::sql('update users set banned = default where id = ?', [$this->target]); + Delo::add( + 10, + 'moderation.unban', + $this->target, + 'Снятие блокировки.', + ); } /**