Exemplo n.º 1
0
    def start(self):
        try:
            os.unlink(config['socket_filename'])
        except FileNotFoundError:
            pass
        self.loop.run_until_complete(
            self.rpc_server.start(config['socket_filename'],
                                  config['socket_port']))

        # Start background tasks
        chatlogtask = asyncio. async (chatlog.run_task(), loop=self.loop)

        self._connect()
        self.cardviewer.start()

        # Don't fall over if the server sends something that's not real UTF-8
        self.connection.buffer.errors = "replace"

        try:
            self.loop.run_forever()
        finally:
            log.info("Bot shutting down...")
            self.pubsub.close()
            self.loop.run_until_complete(self.rpc_server.close())
            chatlog.stop_task()
            tasks_waiting = [chatlogtask]
            if self.whisperconn:
                tasks_waiting.append(self.whisperconn.stop_task())
            tasks_waiting.append(self.cardviewer.stop())
            tasks_waiting.append(self.subs.stop_task())
            self.loop.run_until_complete(asyncio.wait(tasks_waiting))
Exemplo n.º 2
0
	def start(self):
		try:
			os.unlink(config['socket_filename'])
		except FileNotFoundError:
			pass
		self.loop.run_until_complete(self.rpc_server.start(config['socket_filename'], config['socket_port']))

		# Start background tasks
		chatlogtask = asyncio.ensure_future(chatlog.run_task(), loop=self.loop)

		self._connect()
		self.cardviewer.start()

		# Don't fall over if the server sends something that's not real UTF-8
		self.connection.buffer.errors = "replace"

		try:
			self.loop.run_forever()
		finally:
			log.info("Bot shutting down...")
			self.pubsub.close()
			self.loop.run_until_complete(self.rpc_server.close())
			chatlog.stop_task()
			tasks_waiting = [chatlogtask]
			if self.whisperconn:
				tasks_waiting.append(self.whisperconn.stop_task())
			tasks_waiting.append(self.cardviewer.stop())
			tasks_waiting.append(self.subs.stop_task())
			self.loop.run_until_complete(asyncio.wait(tasks_waiting))
Exemplo n.º 3
0
	def start(self):
		# Let us run on windows, without the socket
		if hasattr(self.loop, 'create_unix_server'):
			# TODO: To be more robust, the code really should have a way to shut this socket down
			# when the bot exits... currently, it's assuming that there'll only be one LRRBot
			# instance, that lasts the life of the program... which is true for now...
			try:
				os.unlink(config['socket_filename'])
			except OSError:
				if os.path.exists(config['socket_filename']):
					raise
			event_server = self.loop.create_unix_server(self.rpc_server, path=config['socket_filename'])
			self.loop.run_until_complete(event_server)
		else:
			event_server = None

		# Start background tasks
		substask = asyncio.async(twitchsubs.watch_subs(self), loop=self.loop)
		chatlogtask = asyncio.async(chatlog.run_task(), loop=self.loop)

		self._connect()
		if self.whisperconn:
			self.whisperconn._connect()

		# Don't fall over if the server sends something that's not real UTF-8
		self.connection.buffer.errors = "replace"
		if self.whisperconn:
			self.whisperconn.connection.buffer.errors = "replace"

		try:
			self.loop.run_forever()
		finally:
			log.info("Bot shutting down...")
			if event_server:
				event_server.close()
			substask.cancel()
			chatlog.stop_task()
			tasks_waiting = [substask, chatlogtask]
			if self.whisperconn:
				tasks_waiting.append(self.whisperconn.stop_task())
			self.loop.run_until_complete(asyncio.wait(tasks_waiting))
			self.loop.close()
Exemplo n.º 4
0
#!/usr/bin/env python3
import common
common.FRAMEWORK_ONLY = True
import lrrbot.main
from lrrbot.chatlog import run_task, rebuild_all, stop_task
import asyncio

loop = asyncio.get_event_loop()
task = asyncio. async (run_task(), loop=loop)
rebuild_all()
stop_task()
loop.run_until_complete(task)
loop.close()
Exemplo n.º 5
0
#!/usr/bin/env python3
import common
common.FRAMEWORK_ONLY = True
import lrrbot.main
from lrrbot.chatlog import run_task, rebuild_all, stop_task
import asyncio

loop = asyncio.get_event_loop()
task = asyncio.ensure_future(run_task(), loop=loop)
rebuild_all()
stop_task()
loop.run_until_complete(task)
loop.close()
Exemplo n.º 6
0
#!/usr/bin/env python3
import lrrbot.main
from lrrbot.chatlog import run_task, rebuild_all, stop_task
import asyncio

loop = asyncio.get_event_loop()
task = asyncio.async(run_task(), loop=loop)
rebuild_all()
stop_task()
loop.run_until_complete(task)
loop.close()