Beispiel #1
0
 def test_isGGTrackerMessageBodyValidLink(self):
   inValid = Struct(body = "blahblahblah")
   validSimple = Struct(body = "ggtracker.com/matches/1234")
   validSimpleWithD = Struct(body = "ggtracker.com/matches/1234/replay")
   validNested = Struct(body = " wee ggtracker.com/matches/1234 wee")
   validNestedWithD = Struct(body = " wee ggtracker.com/matches/1234/replay wee")
   self.assertEqual(funcs.isMessageBodyValidLink(inValid), False)
   self.assertEqual(funcs.isMessageBodyValidLink(validSimple), "http://ggtracker.com/matches/1234/replay")
   self.assertEqual(funcs.isMessageBodyValidLink(validSimpleWithD), "http://ggtracker.com/matches/1234/replay")
   self.assertEqual(funcs.isMessageBodyValidLink(validNested), "http://ggtracker.com/matches/1234/replay")
   self.assertEqual(funcs.isMessageBodyValidLink(validNestedWithD), "http://ggtracker.com/matches/1234/replay")
Beispiel #2
0
def handleMessage(message):
  print "handleMessage from " + message.author.name

  savedReplayName = "tmp/working.SC2Replay"

  replayLink = funcs.isMessageBodyValidLink(message)

  if not replayLink:
    funcs.messageReply(message, "replay link not found in message")
    return False

  urllib.urlretrieve(replayLink, savedReplayName)

  archive = mpyq.MPQArchive(savedReplayName)
  # Read the protocol header, this can be read with any protocol
  contents = archive.header['user_data_header']['content']
  header = protocol15405.decode_replay_header(contents)


  # The header's baseBuild determines which protocol to use
  baseBuild = header['m_version']['m_baseBuild']
  try:
    _temp = __import__('s2protocol', globals(), locals(), ['protocol%s' % (baseBuild,)])
    protocol = getattr(_temp, 'protocol%s' % (baseBuild,))
  except:
    print >> sys.stderr, 'Unsupported base build: %d' % baseBuild
    sys.exit(1)


  contents = archive.read_file('replay.details')
  details = protocol.decode_replay_details(contents)
  events = protocol.decode_replay_message_events(archive.read_file('replay.message.events'))
  return handleReplayDetails(details, message, events)
Beispiel #3
0
 def test_isDropScMessageBodyValidLink(self):
   inValid = Struct(body = "blahblahblah")
   validSimple = Struct(body = "drop.sc/replay/1234")
   validSimpleWithHttp = Struct(body = "http://drop.sc/replay/1234")
   validSimpleWithHttps = Struct(body = "https://drop.sc/replay/1234")
   validNested = Struct(body = " wee drop.sc/replay/1234 wee")
   validNestedWithHttp = Struct(body = " wee http://drop.sc/replay/1234 wee")
   self.assertEqual(funcs.isMessageBodyValidLink(inValid), False)
   self.assertEqual(funcs.isMessageBodyValidLink(validSimple), "http://sc2replaystats.com/download/1234")
   self.assertEqual(funcs.isMessageBodyValidLink(validSimpleWithHttp), "http://sc2replaystats.com/download/1234")
   self.assertEqual(funcs.isMessageBodyValidLink(validSimpleWithHttps), "http://sc2replaystats.com/download/1234")
   self.assertEqual(funcs.isMessageBodyValidLink(validNested), "http://sc2replaystats.com/download/1234")
   self.assertEqual(funcs.isMessageBodyValidLink(validNestedWithHttp), "http://sc2replaystats.com/download/1234")