def test_mez_returns_background_task(self): line = "a mob has been mesmerized" unit = MessageGenerator('/path/to/eq', IRRELEVANT_CHARACTER, ACTIONS_MAP) task = unit.action_for(line) self.assertEqual(19, task.timeout) self.assertEqual('Mesmerize Warning', task.message) self.assertEqual('Mez', task.title) expected_command = 'urxvt -iconic -geometry 15x1 -bg red -fg white -title Mez -e python stop_watch.py 19 "Mesmerize Warning" 1' self.assertEqual(expected_command, task.command)
def test_basic_tell(self): unit = MessageGenerator('/path/to/eq', IRRELEVANT_CHARACTER, ACTIONS_MAP) line = "anothertoon tells you, 'hello there'" expected_message = 'Incoming Tell' self.assertEqual(expected_message, unit.action_for(line).message)
def test_tell_that_we_ignore(self): unit = MessageGenerator('/path/to/eq', 'tabashir', ACTIONS_MAP) line = "a vendor tells you, That'll be 10 plat" self.assertIsNone(unit.action_for(line))
def test_line_depending_on_character_name_when_character_not_matched(self): unit = MessageGenerator('/path/to/eq', 'tabashir', ACTIONS_MAP) line = "shadows will consume you, anothertoon" self.assertIsNone(unit.action_for(line))
def test_line_depending_on_character_name_when_character_matches(self): unit = MessageGenerator('/path/to/eq', 'tabashir', ACTIONS_MAP) line = "shadows will consume you, tabashir" expected_message = 'Run away from the raid' self.assertEqual(expected_message, unit.action_for(line).message)
def test_basic_full_line_match_returns_message(self): unit = MessageGenerator('/path/to/eq', IRRELEVANT_CHARACTER, ACTIONS_MAP) line = "Marnek enters the realm of the dead" expected_message = "Marnek is in skeleton form, shrouded players DPS now" self.assertEqual(expected_message, unit.action_for(line).message)
def test_unrecognised_line_should_return_nothing(self): unit = MessageGenerator('/path/to/eq', IRRELEVANT_CHARACTER, ACTIONS_MAP) line = 'this will not be parsed' action = unit.action_for(line) self.assertIsNone(action)
# move to the end of the file f.seek(0, 2) generator = MessageGenerator(eq_home, character, actions_map) # loop over each new line of the file # act on keywords from chat messages parsed from logfile # if no new line, wait for short while before re-checking # NOTE: this is to prevent excessive CPU when there are no # incoming lines, it should not delay between pending lines while True: line = f.readline() if not line: time.sleep(0.1) continue # print("DEBUG: "+ line) action = generator.action_for(line) if action: print("ACTION: %s" % (action.message)) action.run() # handle ctrl+c for clean exit except KeyboardInterrupt: print("") print("Closing The EverQuest Alerter") raise except Exception: traceback.print_exc() finally: f.close()