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