def on_message(message): save() if message.content is "save" and message.author.id is client.user.id: level.save() commands.save() permission.save() logging.debug("Saving...") level.tick() level.process_message(message=message) if message.content.lower().startswith( '!block') and permission.has_permission(message.author.id) == 0: yield from commands.block(message=message, client=client) elif message.content.lower().startswith( '!unblock') and permission.has_permission(message.author.id) == 0: yield from commands.unblock(message=message, client=client) elif message.content.lower().startswith('!status'): yield from level.status(message=message, client=client) elif message.content.lower().startswith( '!givexp') and permission.has_permission(message.author.id) <= 1: yield from level.give_exp(message=message, client=client) elif message.content.lower().startswith( '!takexp') and permission.has_permission(message.author.id) <= 1: yield from level.take_exp(message=message, client=client) elif message.content.lower().startswith( '!setxp') and permission.has_permission(message.author.id) <= 1: yield from level.set_exp(message=message, client=client) elif message.content.lower().startswith( '!top') and permission.has_permission(message.author.id) <= 3: yield from level.top(message=message, client=client)
def save(): global timer if time.time() - timer > 3600: level.save() commands.save() timer = time.time() logging.debug("Saving...")
def test_check(reference): url = "http://my.test.com/download.html" filename = url_to_filename(url) downloaded = os.path.join(TEST_PATH, 'first_download.html') changed = os.path.join(TEST_PATH, 'second_download.html') with requests_mock.Mocker() as mocker, open(downloaded) as page: mocker.get(url, text=page.read()) # first save the file save(url, base_dir='') # then check identical one assert check_identical(url, base_dir='') # check modifications with requests_mock.Mocker() as mocker, open(changed) as page: mocker.get(url, text=page.read()) assert not check_identical(url, base_dir='') # clean up a bit os.remove(filename) os.remove(DEFAULT_DIFF_FILE)
def test_save(reference): url = "http://my.test.com/download.html" filename = url_to_filename(url) downloaded = os.path.join(TEST_PATH, 'first_download.html') with requests_mock.Mocker() as mocker, open(downloaded) as page: mocker.get(url, text=page.read()) assert save(url, base_dir='') == filename assert os.path.exists(filename) # clean up a bit os.remove(filename)
yield from level.top(message=message, client=client) def save(): global timer if time.time() - timer > 3600: level.save() commands.save() timer = time.time() logging.debug("Saving...") if __name__ == "__main__": logging.basicConfig(filename=config.LOG_PATH, filemode='w', level=logging.DEBUG) timer = time.time() commands.load() level.load() permission.load() loop = asyncio.get_event_loop() try: loop.run_until_complete(client.start(config.BOT_TOKEN)) except (KeyboardInterrupt, Exception): loop.close() client.logout() running = False finally: level.save() commands.save()
def main(): """ Main function to determine what command to enter """ segment_list = [] while True: command = raw_input("Enter a command (type 'help' or 'h' for help):\n") if command == 'exit': break # 'help' command # prints a list of possible commands elif command == 'help' or command == 'h': commands.help() # 'newarm (na)' command # creates newarms and their corresponding segment sequences in a # dictionary 'arms' elif command == 'newarms' or command == 'na': arms = commands.newarms() # 'show (s)' command # prints out the created arms elif command == 'show' or command == 's': try: commands.show(arms) except UnboundLocalError: print "Generate your arms first!" # 'link (l)' command elif command == 'link' or command == 'l': linker_list = commands.linker() # 'crunch (c)' command # produces random sequences of elif command == 'crunch' or command == 'c': try: strands except UnboundLocalError: print "Maybe you should generate your strands first ('strandgen')?" else: try: arms, strands, segment_list =\ commands.crunch(arms, strands, linker_list, segment_list) print segment_list except TypeError: print "Something's not right. Try 'crunch' again." # 'strandgen (sg)' command elif command == 'strandgen' or command == 'sg': try: strands = commands.strandgen(arms, linker_list) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'repeatcheck (rp) command elif command == 'repeatcheck' or command == 'rp': try: commands.repeatcheck(strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'dyadcheck (dc) command elif command == 'dyadcheck' or command == 'dc': try: commands.dyadcheck(strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'save (sv)' command elif command == 'save' or command == 'sv': try: commands.save(arms, strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" elif command == 'load' or command == 'ld': try: strands = commands.load() except (UnboundLocalError, TypeError): print "Try again?" else: print "What? Retype command!" return None
def on_message(bot, update): if hasattr(update.message, 'document'): bot.sendMessage(update.message.chat_id, text=save(update.message.from_user['username'], bot.getFile(update.message.document.file_id), update.message.document.file_name))