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