xref: /plugin/aichat/AbstractCLI.php (revision 0de7e020fcc340c97acd36e48cdb20a9d43528b6)
1<?php
2
3namespace dokuwiki\plugin\aichat;
4
5use splitbrain\phpcli\Options;
6
7abstract class AbstractCLI extends \dokuwiki\Extension\CLIPlugin
8{
9    /** @var \helper_plugin_aichat */
10    protected $helper;
11
12    /** @inheritdoc */
13    public function __construct($autocatch = true)
14    {
15        parent::__construct($autocatch);
16        $this->helper = plugin_load('helper', 'aichat');
17        $this->helper->setLogger($this);
18        $this->loadConfig();
19        ini_set('memory_limit', -1);
20    }
21
22    /** @inheritdoc */
23    protected function setup(Options $options)
24    {
25        $options->useCompactHelp();
26
27        $options->registerOption(
28            'lang',
29            'When set to a language code, it overrides the the lang and preferUIlanguage settings and asks the ' .
30            'bot to always use this language instead. ' .
31            'When set to "auto" the bot is asked to detect the language of the input falling back to the wiki lang.',
32            '',
33            'lang'
34        );
35    }
36
37    /** @inheritDoc */
38    protected function main(Options $options)
39    {
40        if ($this->loglevel['debug']['enabled']) {
41            $this->helper->factory->setDebug(true);
42        }
43
44        $lc = $options->getOpt('lang');
45        if ($lc === 'auto') {
46            $this->helper->updateConfig(['preferUIlanguage' => 0]);
47        } else if ($lc) {
48            $this->helper->updateConfig(['preferUIlanguage' => 1]);
49            global $conf;
50            $conf['lang'] = $lc;
51        }
52
53    }
54}
55