wikipedia suche erlaubt mehrere worte als argument
This commit is contained in:
parent
933eb8b3fc
commit
ce79ce07fb
1 changed files with 16 additions and 14 deletions
|
@ -49,31 +49,32 @@ class Plugin(Plugin):
|
||||||
|
|
||||||
def run(self, stanza):
|
def run(self, stanza):
|
||||||
'''
|
'''
|
||||||
|
Startfunktion des Plugins. Bekommt eine xmpp Stanza übergeben,
|
||||||
|
extrahiert daraus den Nick des Absenders und aus dem Body den
|
||||||
|
gewünschten Suchstring. Ist die Stringlänge ungleich Null oder
|
||||||
|
False, wird beides dem Thread zur Wikipedia-Anfrage übergeben und
|
||||||
|
eine Nachricht für den MUC zurück gegeben.
|
||||||
|
param 1: xmpp stanza objekt
|
||||||
|
returns: string
|
||||||
'''
|
'''
|
||||||
lang = 'de'
|
lang = 'de'
|
||||||
pattern = None
|
pattern = None
|
||||||
call_msg = 'Call "!help {}"'.format(self.get_command())
|
call_msg = 'Call "!help {}"'.format(self.get_command())
|
||||||
no_args_msg = ' '.join(('No search pattern!', call_msg))
|
|
||||||
|
|
||||||
muc_nick = common.get_nick_from_stanza(stanza)
|
muc_nick = common.get_nick_from_stanza(stanza)
|
||||||
arguments = common.get_arguments_from_body(stanza)
|
arguments = common.get_arguments_from_body(stanza)
|
||||||
logging.debug('Arguments: {}'.format(arguments))
|
logging.debug('Arguments: {}'.format(arguments))
|
||||||
|
|
||||||
if arguments is False:
|
if arguments is False or len(arguments) == 0:
|
||||||
logging.warning('No arguments for wp search. Abort.')
|
logging.warning('No arguments for wp search. Abort.')
|
||||||
self.callback(': '.join((muc_nick, no_args_msg)))
|
msg = ' '.join(('No search pattern!', call_msg))
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
if len(arguments) == 1:
|
pattern = ' '.join(arguments)
|
||||||
pattern = arguments[0]
|
api_thread = ApiThread(self.callback)
|
||||||
elif len(arguments) > 1:
|
api_thread.run(lang, pattern, muc_nick)
|
||||||
logging.warning('Not implemented yet.')
|
msg = ' '.join(('Search started for:', pattern))
|
||||||
self.callback('Not implemented yet')
|
self.callback(': '.join((muc_nick, msg)))
|
||||||
return
|
return
|
||||||
logging.debug('Start thread for wp search')
|
|
||||||
self.callback('Search started')
|
|
||||||
api_thread = ApiThread(self.callback)
|
|
||||||
api_thread.run(lang, pattern, muc_nick)
|
|
||||||
|
|
||||||
|
|
||||||
class ApiThread(threading.Thread):
|
class ApiThread(threading.Thread):
|
||||||
|
@ -88,6 +89,7 @@ class ApiThread(threading.Thread):
|
||||||
'''
|
'''
|
||||||
Starts the thread.
|
Starts the thread.
|
||||||
'''
|
'''
|
||||||
|
logging.debug('Start thread for wp search')
|
||||||
data = self.get_file(lang, pattern)
|
data = self.get_file(lang, pattern)
|
||||||
if data == False:
|
if data == False:
|
||||||
self.callback('Error while connecting WP')
|
self.callback('Error while connecting WP')
|
||||||
|
|
Loading…
Reference in a new issue