-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessLog.php
More file actions
30 lines (24 loc) · 965 Bytes
/
AccessLog.php
File metadata and controls
30 lines (24 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace kjBotModule\kj415j45\CoreModule;
use DateTime;
use kjBot\Framework\DataStorage;
use kjBot\Framework\Event\MessageEvent;
class AccessLog{
const BaseDir = 'CoreModule.AccessLog/';
public static function Log($instance, MessageEvent $event, string $note = ''){
$className = get_class($instance);
$groupId = $event->fromGroup()?" (In {$event->groupId})":'';
$senderId = $event->getId();
$time = (new DateTime('now'))->format('Y-m-d H:i:s');
return DataStorage::SetData(static::BaseDir.$senderId,
"[{$time}]{$groupId} {$className}: {$note}\n"
, true);
}
public static function LogForModule($instance, string $note = ''){
$className = str_replace('\\', '.', get_class($instance));
$time = (new DateTime('now'))->format('Y-m-d H:i:s');
return DataStorage::SetData(static::BaseDir.$className,
"[{$time}] {$note}\n"
, true);
}
}