-
Notifications
You must be signed in to change notification settings - Fork 2
/
AbstractCLI.php
54 lines (46 loc) · 1.48 KB
/
AbstractCLI.php
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
45
46
47
48
49
50
51
52
53
54
<?php
namespace dokuwiki\plugin\aichat;
use dokuwiki\Extension\CLIPlugin;
use splitbrain\phpcli\Options;
abstract class AbstractCLI extends CLIPlugin
{
/** @var \helper_plugin_aichat */
protected $helper;
/** @inheritdoc */
public function __construct($autocatch = true)
{
parent::__construct($autocatch);
$this->helper = plugin_load('helper', 'aichat');
$this->helper->setLogger($this);
$this->loadConfig();
ini_set('memory_limit', -1);
}
/** @inheritdoc */
protected function setup(Options $options)
{
$options->useCompactHelp();
$options->registerOption(
'lang',
'When set to a language code, it overrides the the lang and preferUIlanguage settings and asks the ' .
'bot to always use this language instead. ' .
'When set to "auto" the bot is asked to detect the language of the input falling back to the wiki lang.',
'',
'lang'
);
}
/** @inheritDoc */
protected function main(Options $options)
{
if ($this->loglevel['debug']['enabled']) {
$this->helper->factory->setDebug(true);
}
$lc = $options->getOpt('lang');
if ($lc === 'auto') {
$this->helper->updateConfig(['preferUIlanguage' => 0]);
} elseif ($lc) {
$this->helper->updateConfig(['preferUIlanguage' => 1]);
global $conf;
$conf['lang'] = $lc;
}
}
}