10de7e020SAndreas Gohr<?php 20de7e020SAndreas Gohr 30de7e020SAndreas Gohrnamespace dokuwiki\plugin\aichat; 40de7e020SAndreas Gohr 5*8c08cb3fSAndreas Gohruse dokuwiki\Extension\CLIPlugin; 60de7e020SAndreas Gohruse splitbrain\phpcli\Options; 70de7e020SAndreas Gohr 8*8c08cb3fSAndreas Gohrabstract class AbstractCLI extends CLIPlugin 90de7e020SAndreas Gohr{ 100de7e020SAndreas Gohr /** @var \helper_plugin_aichat */ 110de7e020SAndreas Gohr protected $helper; 120de7e020SAndreas Gohr 130de7e020SAndreas Gohr /** @inheritdoc */ 140de7e020SAndreas Gohr public function __construct($autocatch = true) 150de7e020SAndreas Gohr { 160de7e020SAndreas Gohr parent::__construct($autocatch); 170de7e020SAndreas Gohr $this->helper = plugin_load('helper', 'aichat'); 180de7e020SAndreas Gohr $this->helper->setLogger($this); 190de7e020SAndreas Gohr $this->loadConfig(); 200de7e020SAndreas Gohr ini_set('memory_limit', -1); 210de7e020SAndreas Gohr } 220de7e020SAndreas Gohr 230de7e020SAndreas Gohr /** @inheritdoc */ 240de7e020SAndreas Gohr protected function setup(Options $options) 250de7e020SAndreas Gohr { 260de7e020SAndreas Gohr $options->useCompactHelp(); 270de7e020SAndreas Gohr 280de7e020SAndreas Gohr $options->registerOption( 290de7e020SAndreas Gohr 'lang', 300de7e020SAndreas Gohr 'When set to a language code, it overrides the the lang and preferUIlanguage settings and asks the ' . 310de7e020SAndreas Gohr 'bot to always use this language instead. ' . 320de7e020SAndreas Gohr 'When set to "auto" the bot is asked to detect the language of the input falling back to the wiki lang.', 330de7e020SAndreas Gohr '', 340de7e020SAndreas Gohr 'lang' 350de7e020SAndreas Gohr ); 360de7e020SAndreas Gohr } 370de7e020SAndreas Gohr 380de7e020SAndreas Gohr /** @inheritDoc */ 390de7e020SAndreas Gohr protected function main(Options $options) 400de7e020SAndreas Gohr { 410de7e020SAndreas Gohr if ($this->loglevel['debug']['enabled']) { 420de7e020SAndreas Gohr $this->helper->factory->setDebug(true); 430de7e020SAndreas Gohr } 440de7e020SAndreas Gohr 450de7e020SAndreas Gohr $lc = $options->getOpt('lang'); 460de7e020SAndreas Gohr if ($lc === 'auto') { 470de7e020SAndreas Gohr $this->helper->updateConfig(['preferUIlanguage' => 0]); 480de7e020SAndreas Gohr } elseif ($lc) { 490de7e020SAndreas Gohr $this->helper->updateConfig(['preferUIlanguage' => 1]); 500de7e020SAndreas Gohr global $conf; 510de7e020SAndreas Gohr $conf['lang'] = $lc; 520de7e020SAndreas Gohr } 530de7e020SAndreas Gohr } 540de7e020SAndreas Gohr} 55