diff options
author | nico <nico@magicbroccoli.de> | 2018-10-03 23:24:36 +0200 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2018-10-03 23:24:36 +0200 |
commit | 825167b8aa69ddcf3261b8a81c6e09c2d01baa71 (patch) | |
tree | 2e2d650caf8e6bdcd1e068cc4388c729f5e8da52 /main.py | |
parent | bfef4f1025591c7a89013b650e761cd474824090 (diff) |
Squashed commit of the following:
commit 91cf4b74105f69f16a80825581a0d2d34d15d155
Merge: 30ceaea 90b42ed
Author: nico <nico.wellpott@uni-oldenburg.de>
Date: Wed Oct 3 22:34:42 2018 +0200
Merge remote-tracking branch 'origin/xep' into xep
commit 30ceaea56a77ed95deba30c4fe65e238ea5960ac
Author: nico <nico.wellpott@uni-oldenburg.de>
Date: Wed Oct 3 22:34:33 2018 +0200
Initial Version XEP query
+ added initial version of xep query class
Init Implementation
+ added xep plugin to bot class
* reworked validation function
* updated .gitignore file
+ added xep plugin
commit 90b42edb9b8e92eba3bb67030d5f919b1e71d0bc
Author: nico <nico.wellpott@uni-oldenburg.de>
Date: Wed Oct 3 22:34:21 2018 +0200
* reworked validation function
* updated .gitignore file
+ added xep plugin
commit 25c78807731417867840d6fe4abf598e64aded28
Author: nico <nico@magicbroccoli.de>
Date: Wed Oct 3 10:54:02 2018 +0200
Init Implementation
+ added xep plugin to bot class
commit fe711f44d40671d927e9b946fb66679b297272c8
Author: nico <nico@magicbroccoli.de>
Date: Tue Oct 2 21:20:08 2018 +0200
Initial Version XEP query
+ added initial version of xep query class
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -19,6 +19,7 @@ from slixmpp.exceptions import XMPPError from classes.strings import StaticAnswers from classes.functions import Version, LastActivity, ContactInfo, HandleError +from classes.xep import XEPRequest class QueryBot(slixmpp.ClientXMPP): @@ -36,7 +37,7 @@ class QueryBot(slixmpp.ClientXMPP): def start(self, event): """ - :param str event -- An empty dictionary. The session_start event does not provide any additional data. + :param event -- An empty dictionary. The session_start event does not provide any additional data. """ self.send_presence() self.get_roster() @@ -47,27 +48,41 @@ class QueryBot(slixmpp.ClientXMPP): def validate_domain(self, wordlist, index): """ - validation method to reduce connection attemps to unvalid domains - :param wordlist: words seperated by " " from the message + validation method to reduce malformed querys and unnecessary connection attempts + :param wordlist: words separated by " " from the message :param index: keyword index inside the message :return: true if valid """ # keyword inside the message argument = wordlist[index] - # if the argument is not inside the no_arg_keywords target is index + 1 - if argument not in StaticAnswers().keys(arg='list', keyword="no_arg_keywords"): - try: - target = wordlist[index + 1] - if validators.domain(target): + # check if argument is in the argument list + if argument in StaticAnswers().keys(arg='list'): + # if argument uses a domain check for occurence in list and check domain + if argument in StaticAnswers().keys(arg='list', keyword='domain_keywords'): + try: + target = wordlist[index + 1] + if validators.domain(target): + return True + except IndexError: + # except an IndexError if a keywords is the last word in the message + return False + + # check if number keyword is used if true check if target is assignable + elif argument in StaticAnswers().keys(arg='list', keyword='number_keywords'): + try: + target = wordlist[index + 1] return True - except IndexError: - # except an IndexError if a keywords is the last word in the message + except IndexError: + # except an IndexError if target is not assignable + return False + # check if argument is inside no_arg list + elif argument in StaticAnswers().keys(arg='list', keyword="no_arg_keywords"): + return True + else: return False - elif argument in StaticAnswers().keys(arg='list', keyword="no_arg_keywords"): - return True else: - return + return False def deduplicate(self, reply): """ @@ -136,6 +151,9 @@ class QueryBot(slixmpp.ClientXMPP): contact = yield from self['xep_0030'].get_info(jid=target, cached=False) reply.append(ContactInfo(contact, msg, target).format_contact()) + elif keyword == "!xep": + reply.append(XEPRequest(msg, target).format()) + except XMPPError as error: reply.append(HandleError(error, msg, key, target).build_report()) |