This commit is contained in:
2023-10-16 16:12:16 +03:00
parent 2abd435798
commit a14232a899
4 changed files with 188 additions and 356 deletions
+32
View File
@@ -99,6 +99,21 @@ class Chat
'rotate' => [0 => 'катается от смеха по полу', 1 => 'катается по полу от смеха над [*%l*]'],
];
public static function getLastMessageId(): int
{
return (int)Db::getValue('select max(id) from chat');
}
public static function setCurrentTimeById(int $messageId): void
{
Db::sql('update chat set time = unix_timestamp() where id = ?)', [$messageId]);
}
public static function setCurrentTimeAndIdById(int $messageId, int $newMessageId): void
{
Db::sql('update chat set time = unix_timestamp(), id = ? where id = ?', [$newMessageId, $messageId]);
}
public function expworld($txt, $vl): string
{
$words = explode(' ', $txt);
@@ -214,4 +229,21 @@ class Chat
];
Db::sql($q, $args);
}
/** Какая-то заумная выборка что отображать в чат.
* @param int $messageId
* @param string $login
* @return array
*/
public function getMessages(int $messageId, string $login): array
{
$query = "select * from chat
where
new = 1 and
(id > ? or spam > 0 or (time < 0 and time > -unix_timestamp() and (`to` = '' or `to` = ?))) and
(time > unix_timestamp() - 360 or time > unix_timestamp() - 120 or (time = -1 and (`to` = ? or type = 8)) or time < -1 and time > -unix_timestamp() and (`to` = ? or type = 8 or `to` = ''))
order by id";
return Db::getRows($query, [$messageId, $login, $login, $login]);
}
}