Пишем действия в дело. Тип 10 взят наугад.

This commit is contained in:
Ivor Barhansky 2023-12-02 00:28:59 +02:00 committed by Ivor Barhansky
parent 9b243ec729
commit 8b83ef3ba8

View File

@ -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,
'Снятие блокировки.',
);
}
/**