예제 #1
0
def init(config, _db, _ch):
    global bot, db, ch, message_queue, allow_documents
    if config["bot_token"] == "":
        logging.error("No telegram token specified.")
        exit(1)

    logging.getLogger("urllib3").setLevel(
        logging.WARNING)  # very noisy with debug otherwise
    bot = telebot.TeleBot(config["bot_token"], threaded=False)
    db = _db
    ch = _ch
    message_queue = MutablePriorityQueue()

    allow_contacts = config["allow_contacts"]
    allow_documents = config["allow_documents"]

    types = ["text", "location", "venue"]
    if allow_contacts:
        types += ["contact"]
    types += [
        "audio", "document", "photo", "sticker", "video", "video_note", "voice"
    ]

    cmds = [
        "start", "stop", "users", "info", "motd", "toggledebug", "togglekarma",
        "version", "source", "modhelp", "adminhelp", "modsay", "adminsay",
        "mod", "admin", "warn", "delete", "uncooldown", "blacklist", "s",
        "sign", "settripcode", "t", "tsign"
    ]
    for c in cmds:  # maps /<c> to the function cmd_<c>
        c = c.lower()
        registered_commands[c] = globals()["cmd_" + c]
    handler(relay, content_types=types)
예제 #2
0
파일: server.py 프로젝트: darrenkuo/SP
                f = open(session_file, 'r')
                text = f.read().split('\n')
                username = text[0]
                t = int(text[1])

                print "trying to make session with username: "******" time: ", t

                print "current time: ", int(time() * 1000)

                if abs(time() * 1000 - t + (60 * 1000)) < 600000:
                    session.user = username

        raise web.seeother('/magic?page=/summary')

    def POST(self):
        return self.GET()
        
app = web.application(urls, globals(), True)

if web.config.get('_session') is None:
    session = web.session.Session(app, web.session.DiskStore('sessions'),
                                  initializer={'user': '******'})
    web.config._session = session
else:
    session = web.config._session

if __name__ == "__main__":
    regenerateNext()
    setup_dbs()
    app.run()
예제 #3
0
    def propagateRoom(self, room, tier):
        children = self.corp.struct[tier]['CHILDREN']
        sizes = self.corp.struct[tier]['SIZES']
        shapes = self.corp.struct[tier]['SHAPES']

        directions = [UP, DOWN, LEFT, RIGHT]

        # number of child rooms
        for i in range(rd.randint(*children)):
            shape = rd.choice(shapes)

            # number of tries to find a valid child
            for i in range(50):
                direction = rd.choice(directions)
                alignment = rd.choice([MIN, MAX])

                w = rd.randint(*sizes)
                h = rd.randint(*sizes)

                if shape is 'Corridor':
                    if direction in [UP, DOWN]:
                        w = 5
                        h = int(1.5 * rd.randint(*sizes))
                    else:
                        w = int(1.5 * rd.randint(*sizes))
                        h = 5

                if shape is 'Dome':
                    w = rd.randint(*sizes)
                    h = w

                offset = np.array(
                    self.getOffset(room, direction, alignment, w, h))
                rect = Rectangle(room.pos + offset, w, h)

                for other in list(self.getRooms()) + room.children:
                    if rect is not None and rect.intersects(
                            other) or not self.contains(rect):
                        rect = None
                        break

                if rect is not None:
                    break

            if rect is not None:
                if shape is 'Corridor':
                    directions.remove(direction)

                roomClass = globals()[shape]
                nextRoom = roomClass(rect.pos, rect.size[X], rect.size[Y],
                                     room.tier + 1, room)
                nextRoom.color = self.palette[room.tier + 1]
                room.children.append(nextRoom)
                self.tier[room.tier + 1].append(nextRoom)
                nextRoom.carve(self)

                # carve a connection
                if direction in (UP, DOWN):
                    self.carveDoorway(nextRoom, room, room.tier,
                                      not rect.size[X] < room.size[X])
                elif direction in (LEFT, RIGHT):
                    self.carveDoorway(nextRoom, room, room.tier,
                                      rect.size[Y] < room.size[Y])
        return room.children