Exemplo n.º 1
0
 def run_forever(self):
     while True:
         raw_data = self.ws.recv()
         # one might think that after sending "compress": true, we can expect to only receive
         # compressed data. one would be underestimating discord's incompetence
         if isinstance(raw_data, bytes):
             raw_data = zlib.decompress(raw_data).decode('utf-8')
         if not raw_data:
             break
         if config.bot.debug:
             print('<-', raw_data)
         data = json.loads(raw_data)
         self.seq = data['s']
         handler = self.handlers.get(data['op'])
         if handler:
             try:
                 handler(data['t'], data['d'])
             except:
                 tb = traceback.format_exc()
                 log.write(data)
                 log.write(tb)
                 if config.bot.err_channel:
                     try:
                         # messages can be up to 2000 characters
                         self.send_message(
                             config.bot.err_channel,
                             '```\n%s\n```\n```\n%s\n```' %
                             (raw_data[:800], tb[:1000]))
                     except Exception:
                         log.write('error sending to err_channel:\n' +
                                   traceback.format_exc())
         log.flush()
Exemplo n.º 2
0
 def _output_line(line, exe, prefix, out, count):
     #exe.lock.acquire()
     #exe.outputting = True
     #exe.lock.release()
     if out:
         out(prefix + line)
     else:
         log.output(prefix + line)
         if count > 10:
             log.flush()
Exemplo n.º 3
0
 def _output_line(line, exe, prefix, out, count):
     #exe.lock.acquire()
     #exe.outputting = True
     #exe.lock.release()
     if out:
         out(prefix + line)
     else:
         log.output(prefix + line)
         if count > 10:
             log.flush()
Exemplo n.º 4
0
 def _output_line(line, exe, prefix, out, count):
     #print 'LINE:%d: %s' % (count, line)
     exe.lock.acquire()
     #exe.outputting = True
     exe.lock.release()
     if out:
         out(prefix + line)
     else:
         log.output(prefix + line)
         if count > 10:
             log.flush()
Exemplo n.º 5
0
def run():
	conn = yield tornado.websocket.websocket_connect('wss://ws.eve-kill.net/kills', connect_timeout=5)
	msg = yield conn.read_message()
	assert(isinstance(json.loads(msg), list)) # server info line

	while True:
		msg = yield conn.read_message()
		if msg is None:
			log.write('websocket disconnected')
			log.flush()
			break
		handle_message(msg)
Exemplo n.º 6
0
def main():
	rs = requests.Session()
	while True:
		try:
			data = rs.get('http://redisq.zkillboard.com/listen.php').json()
			handle_package(data['package'])
		except KeyboardInterrupt:
			break
		except (ValueError, requests.exceptions.RequestException):
			log.write('redisq error; waiting 5 minutes\n%s' % traceback.format_exc())
			time.sleep(300)
		log.flush()
 def _readthread(fh, out, prefix = ''):
     """Read from a file handle and write to the output handler
     until the file closes."""
     count = 0
     while True:
         line = fh.readline()
         count += 1
         if len(line) == 0:
             break
         if out:
             out(prefix + line)
         else:
             log.output(prefix + line)
             if count > 10:
                 log.flush()
                 count = 0
Exemplo n.º 8
0
 def _readthread(fh, out, prefix = ''):
     """Read from a file handle and write to the output handler
     until the file closes."""
     count = 0
     while True:
         line = fh.readline()
         # str and bytes are the same type in Python2
         if type(line) is not str and type(line) is bytes:
             line = line.decode(sys.stdout.encoding)
         count += 1
         if len(line) == 0:
             break
         if out:
             out(prefix + line)
         else:
             log.output(prefix + line)
             if count > 10:
                 log.flush()
                 count = 0
Exemplo n.º 9
0
def mainloop(sta_if):
    telsession = telemetry.TelemetrySession()
    recentgoodssids = datastr.RecentStrings(60)
    try:
        recentgoodssids.load(SSIDS_FILE)
    except OSError:
        pass # Unable to load ssids file, but that's ok,
        # maybe we haven't created it yet.
    # Now search for a valid API.
    last_clock_save_time = 0
    while True:
        sta_if.disconnect()
        ok = search_for_ap(sta_if, telsession, recentgoodssids)
        if ok:
            use_working_ap(telsession)
        log.flush()   
        if recentgoodssids.modified:
            recentgoodssids.save(SSIDS_FILE)
        if clock_is_set and ((time.time() - last_clock_save_time) > 120):
            save_clock()
            last_clock_save_time = time.time()
Exemplo n.º 10
0
def mainloop(sta_if):
    telsession = telemetry.TelemetrySession()
    recentgoodssids = datastr.RecentStrings(60)
    try:
        recentgoodssids.load(SSIDS_FILE)
    except OSError:
        pass  # Unable to load ssids file, but that's ok,
        # maybe we haven't created it yet.
    # Now search for a valid API.
    last_clock_save_time = 0
    while True:
        sta_if.disconnect()
        ok = search_for_ap(sta_if, telsession, recentgoodssids)
        if ok:
            use_working_ap(telsession)
        log.flush()
        if recentgoodssids.modified:
            recentgoodssids.save(SSIDS_FILE)
        if clock_is_set and ((time.time() - last_clock_save_time) > 120):
            save_clock()
            last_clock_save_time = time.time()
Exemplo n.º 11
0
def main():
    log.log("Starting main")
    log.log("machine.reset_cause = ", machine.reset_cause())
    global blueled
    blueled = machine.Pin(2, machine.Pin.OUT)
    set_clock_from_file()
    # If there is a AP active, let's turn it off.
    network.WLAN(network.AP_IF).active(False)
    # Now activate the STA interface.
    sta_if = network.WLAN(network.STA_IF)
    sta_if.active(True)
    log.log("Interfaces active")
    # In case we are already connected, disconnect.
    sta_if.disconnect()
    try:
        mainloop(sta_if)
    except Exception as e:
        log.log("Unexpected exception:", e)
    log.log("Bye bye")
    log.flush()
    time.sleep(10)
    machine.reset()
Exemplo n.º 12
0
def main():
    log.log("Starting main")
    log.log("machine.reset_cause = ", machine.reset_cause())
    global blueled
    blueled = machine.Pin(2, machine.Pin.OUT)
    set_clock_from_file()
    # If there is a AP active, let's turn it off.
    network.WLAN(network.AP_IF).active(False)
    # Now activate the STA interface.
    sta_if = network.WLAN(network.STA_IF)
    sta_if.active(True)
    log.log("Interfaces active")
    # In case we are already connected, disconnect.
    sta_if.disconnect()
    try:
        mainloop(sta_if)
    except Exception as e:
        log.log("Unexpected exception:", e)
    log.log("Bye bye")
    log.flush()
    time.sleep(10)
    machine.reset()
Exemplo n.º 13
0
Arquivo: pbot.py Projeto: raylu/pbot
import threading
import time

from bot import Bot
import config
import log


def quit(signum, frame):
    for bot in bots:
        bot.disconnect()
    log.close()
    sys.exit()


for s in [signal.SIGTERM, signal.SIGINT]:
    signal.signal(s, quit)
    signal.siginterrupt(s, False)

bots = []
for c in config.bots:
    if not c.autoconnect:
        continue
    bot = Bot(c)
    bots.append(bot)
    threading.Thread(target=bot.connect, daemon=True).start()

while True:
    time.sleep(60)
    log.flush()
Exemplo n.º 14
0
Arquivo: stomp.py Projeto: raylu/ykill
	def on_error(self, headers, message):
		log.write('stomp error: {}, {}'.format(headers, message))
		log.flush()
Exemplo n.º 15
0
Arquivo: stomp.py Projeto: raylu/ykill
	def on_disconnected(self):
		log.write('stomp disconnected')
		log.flush()
Exemplo n.º 16
0
	daemonize()

import signal
import threading
import time

from bot import Bot
import config
import log

def quit(signum, frame):
	for bot in bots:
		bot.disconnect()
	log.close()
	sys.exit()
for s in [signal.SIGTERM, signal.SIGINT]:
	signal.signal(s, quit)
	signal.siginterrupt(s, False)

bots = []
for c in config.bots:
	if not c.autoconnect:
		continue
	bot = Bot(c)
	bots.append(bot)
	threading.Thread(target=bot.connect, daemon=True).start()

while True:
	time.sleep(60)
	log.flush()
Exemplo n.º 17
0
 def play_game(self):
     try:
         self.play_one_game()
     except constants.UserQuit:
         log.info("User quit, exitting")
     log.flush()