-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAliasPlugin.php
More file actions
44 lines (39 loc) · 1.46 KB
/
AliasPlugin.php
File metadata and controls
44 lines (39 loc) · 1.46 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace kjBotModule\kj415j45\CoreModule;
use kjBot\Framework\Plugin;
use kjBot\Framework\Event\MessageEvent;
class AliasPlugin extends Plugin{
public $handleDepth = 1;
public function message(MessageEvent $event){
if(!Access::Control($event)->hasLevel(AccessLevel::Supporter))return;
$alias = new Alias($event->getId());
$aliasList = $alias->getAlias();
if($aliasList==NULL)return;
if(array_search(NULL, $aliasList))return;
$matches = parseCommand($event->getMsg());
$command = rtrim($matches[0]);
if($matches==NULL){
$command = $event->getMsg();
$matches = [$command];
}
$aliasTarget = $aliasList[$command];
if($aliasTarget==NULL)return;
$str = $event->getMsg();
d('Before alias: '.$str);
$str = $aliasTarget;
$argCount = count($matches);
$pending = [];
for($i = 1; $i<$argCount; $i++){
if(strpos($str, ':arg'.$i)===false){
$pending[]= $matches[$i]; //FIXME 这里没有重新给含空格的参数补回引号,存在隐患,现阶段未触发
d(':arg'.$i.' not set, will be appended to tail');
}else{
$str = str_replace_once(':arg'.$i, $matches[$i], $str);
d('Replace :arg'.$i.': '.$str);
}
}
$str.= ' '.implode(' ', $pending);
d('After alias: '.$str);
$event->setMsg($str);
}
}