Пример #1
0
def init():
    global conn, c, last_match
    dbexists = isfile("database.sqlite3")
    conn = sqlite3.connect("database.sqlite3")
    conn.row_factory = sqlite3.Row
    c = conn.cursor()
    #set up trueskill here:
    ts.setup(draw_probability=0.01)
    if dbexists:
        try:
            check_db()
        except Exception as e:
            console.display(e)
            console.terminate()
            return
    else:
        console.display("DATATBASE| Creating new database...")
        create_tables()

    c.execute("SELECT pickup_id from pickups ORDER BY pickup_id DESC LIMIT 1")
    result = c.fetchone()
    if result:
        last_match = result[0]
    else:
        last_match = -1
Пример #2
0
def init(dirname=""):
    global cfg

    #load config
    try:
        cfg = SourceFileLoader('cfg', 'config.cfg').load_module()
    except Exception as e:
        console.display("ERROR| ERROR PARSING config.cfg FILE!!! {0}".format(
            str(e)))
        console.terminate()

    #check if we need to update from previous stats system
    if os.path.isdir('channels'):
        console.display(
            "OLD DATABASE FOLDER FOUND! PLEASE RUN 'updater.py' OR DELETE/RENAME 'channels' FOLDER."
        )
        os._exit(0)
Пример #3
0
def bot_run():
	while not c.is_closed and console.alive:
		frametime = time.time()
		bot.run(frametime)
		scheduler.run(frametime)
		console.run()
		if not c.is_closed:
			if len(client.send_queue) > 0:
				data = client.send_queue.pop(0)
				if data[0] == 'msg':
					destination, content = data[1], data[2]
					console.display('SEND| /{0}: {1}'.format(destination, content))
					if not client.silent:
						try:
							yield from c.send_message(destination, content)
						except:
							console.display("ERROR| Could not send the message. "+str(sys.exc_info()))
				elif data[0] == 'topic':
					content = data[1]
					if not client.silent:
						try:
							yield from c.edit_channel(client.channel, topic=content)
						except:
							console.display("ERROR| Could not change topic."+str(sys.exc_info()))
				elif data[0] == 'leave_server':
					for serv in c.servers:
						if serv.id == data[1]:
							console.display("Leaving {0}...".format(serv.name))
							yield from c.leave_server(serv)
							break
		else:
			console.display("ERROR| Connection to server has been closed unexpectedly.")
			console.terminate()
		yield from asyncio.sleep(0.5) # task runs every 0.5 seconds
	#quit gracefully
	try:
		yield from Client.logout()
	except:
		pass
	console.log.close()
	print("QUIT NOW.")
	os._exit(0)
Пример #4
0
def run():
    while True:
        try:
            if config.cfg.DISCORD_TOKEN != "":
                console.display("SYSTEM| logging in with token...")
                c.loop.run_until_complete(c.start(config.cfg.DISCORD_TOKEN))
            else:
                console.display(
                    "SYSTEM| logging in with username and password...")
                c.loop.run_until_complete(
                    c.start(config.cfg.USERNAME, config.cfg.PASSWORD))
            c.loop.run_until_complete(c.connect())
        except KeyboardInterrupt:
            console.display("ERROR| Keyboard interrupt.")
            console.terminate()
            c.loop.run_until_complete(close())
            print("QUIT NOW.")
            break
        except Exception as e:
            console.display("ERROR| Disconnected from the server: " + str(e) +
                            "\nReconnecting in 15 seconds...")
            time.sleep(15)
Пример #5
0
					channel.processmsg(message.content, message.author)
				except:
					console.display("ERROR| Error processing message: {0}".format(traceback.format_exc()))
					
	
@c.event
@asyncio.coroutine
def on_member_update(before, after):
	#console.display("DEBUG| {0} changed status from {1}  to -{2}-".format(after.name, before.status, after.status))
	if str(after.status) in ['idle', 'offline']:
		bot.update_member(after)

loop = asyncio.get_event_loop()

try:
	if config.cfg.DISCORD_TOKEN != "":
		console.display("SYSTEM| logging in with token...")
		loop.run_until_complete(c.login(config.cfg.DISCORD_TOKEN))
	else:
		console.display("SYSTEM| logging in with username and password...")
		loop.run_until_complete(c.login(config.cfg.USERNAME, config.cfg.PASSWORD))
	loop.run_until_complete(c.connect())
except Exception as e:
	console.display("ERROR| Disconnected from the server: "+str(e))
	loop.run_until_complete(c.close())
finally:
	loop.close()
	console.terminate()
	print("QUIT NOW.")
	os._exit(0)