|
@@ -11,6 +11,8 @@ import socket
|
|
import SocketServer
|
|
import SocketServer
|
|
import threading
|
|
import threading
|
|
|
|
|
|
|
|
+msgserver = None
|
|
|
|
+
|
|
# TODO: move into config file :)
|
|
# TODO: move into config file :)
|
|
msgserver_known_senders = {
|
|
msgserver_known_senders = {
|
|
"127.0.0.1": "localhost",
|
|
"127.0.0.1": "localhost",
|
|
@@ -42,19 +44,30 @@ class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
|
|
pass
|
|
pass
|
|
|
|
|
|
def setup(bot):
|
|
def setup(bot):
|
|
- host = "localhost"
|
|
|
|
- port = 4342
|
|
|
|
- if not bot.config.ffpb.msg_host is None: host = bot.config.ffpb.msg_host
|
|
|
|
- if not bot.config.ffpb.msg_port is None: port = int(bot.config.ffpb.msg_port)
|
|
|
|
-
|
|
|
|
- msgserver = ThreadingTCPServer((host,port), MsgHandler)
|
|
|
|
- msgserver.bot = bot
|
|
|
|
- ip, port = msgserver.server_address
|
|
|
|
- print("Messaging server listening on {}:{}".format(ip,port))
|
|
|
|
-
|
|
|
|
- msgserver_thread = threading.Thread(target=msgserver.serve_forever)
|
|
|
|
- msgserver_thread.daemon = True
|
|
|
|
- msgserver_thread.start()
|
|
|
|
|
|
+ global msgserver
|
|
|
|
+
|
|
|
|
+ if bot.config.has_section('ffpb') and bot.config.ffpb.msg_enable:
|
|
|
|
+ host = "localhost"
|
|
|
|
+ port = 4342
|
|
|
|
+ if not bot.config.ffpb.msg_host is None: host = bot.config.ffpb.msg_host
|
|
|
|
+ if not bot.config.ffpb.msg_port is None: port = int(bot.config.ffpb.msg_port)
|
|
|
|
+
|
|
|
|
+ msgserver = ThreadingTCPServer((host,port), MsgHandler)
|
|
|
|
+ msgserver.bot = bot
|
|
|
|
+ ip, port = msgserver.server_address
|
|
|
|
+ print("Messaging server listening on {}:{}".format(ip,port))
|
|
|
|
+
|
|
|
|
+ msgserver_thread = threading.Thread(target=msgserver.serve_forever)
|
|
|
|
+ msgserver_thread.daemon = True
|
|
|
|
+ msgserver_thread.start()
|
|
|
|
+
|
|
|
|
+def shutdown(bot):
|
|
|
|
+ global msgserver
|
|
|
|
+
|
|
|
|
+ if not msgserver is None:
|
|
|
|
+ msgserver.shutdown()
|
|
|
|
+ print("Closed messaging server.")
|
|
|
|
+ msgserver = None
|
|
|
|
|
|
@willie.module.commands('status')
|
|
@willie.module.commands('status')
|
|
def ffpb_status(bot, trigger):
|
|
def ffpb_status(bot, trigger):
|