|
@@ -1,19 +1,8 @@
|
|
|
-import hashlib
|
|
|
-from datetime import datetime
|
|
|
import config
|
|
|
-import jsonAndRequest as jsreq
|
|
|
from EchoBot import JabberBot
|
|
|
-
|
|
|
+import sys
|
|
|
import logging
|
|
|
-from getpass import getpass
|
|
|
from argparse import ArgumentParser
|
|
|
-import asyncio
|
|
|
-
|
|
|
-botname = "open_basic_bot"
|
|
|
-operating_status = 0
|
|
|
-
|
|
|
-JID = botname + "@" + config.JSERVER
|
|
|
-PASSWORD = hashlib.md5((botname + config.PASSWORD).encode('utf-8')).hexdigest()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# Setup the command line arguments.
|
|
@@ -28,8 +17,8 @@ if __name__ == '__main__':
|
|
|
const=logging.DEBUG, default=logging.INFO)
|
|
|
|
|
|
# JID and password options.
|
|
|
- # parser.add_argument("-b", "--bot", dest="bot",
|
|
|
- # help="Bot name")
|
|
|
+ parser.add_argument("-b", "--bot", dest="bot",
|
|
|
+ help="Bot name")
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
@@ -37,17 +26,25 @@ if __name__ == '__main__':
|
|
|
logging.basicConfig(level=args.loglevel,
|
|
|
format='%(levelname)-8s %(message)s')
|
|
|
|
|
|
- # if args.jid is None:
|
|
|
- # args.jid = input("Username: ")
|
|
|
- # if args.password is None:
|
|
|
- # args.password = getpass("Password: ")
|
|
|
|
|
|
- # Setup the EchoBot and register plugins. Note that while plugins may
|
|
|
- # have interdependencies, the order in which you register them does
|
|
|
- # not matter.
|
|
|
+ if args.bot and args.bot in config.BOTLIST:
|
|
|
+ module = __import__("handlers." + args.bot)
|
|
|
+
|
|
|
+ print(module.JID)
|
|
|
+
|
|
|
+ JID = module.JID
|
|
|
+ PASSWORD = module.PASSWORD
|
|
|
|
|
|
- xmpp = JabberBot(JID, PASSWORD)
|
|
|
+ fn_start_handler = module.start_handler
|
|
|
+ fn_message = module.message
|
|
|
|
|
|
- xmpp.send_message(JID, f"message send: {datetime.now()}")
|
|
|
|
|
|
- asyncio.get_event_loop().run_forever()
|
|
|
+ bot = JabberBot(JID, PASSWORD)
|
|
|
+ bot.add_event_handler("message", fn_message)
|
|
|
+ bot.run()
|
|
|
+ fn_start_handler(bot)
|
|
|
+ bot.stop()
|
|
|
+ else:
|
|
|
+ print("Select using -n flag for select availible bot from botlist:\n")
|
|
|
+ for botname in config.BOTLIST:
|
|
|
+ print(f"- {botname}")
|