Пример #1
0
 def test_good_invul(self):
     """ GOOD test """
     medic = self.p1c
     now = Util.utc_to_chi(datetime.now())
     params = self.default_params
     Invul.handler(medic, params)
     self.assertEqual(len(self.invul_queue),1)
Пример #2
0
 def test_not_same_team(self):
     """ MEDIC can only INVUL same team """
     medic = self.p1c
     params = self.default_params
     with self.assertRaises(TeamError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, \
             "Invalid Team. You cannot do that action to someone on that team.")
     self.assertEqual(len(self.invul_queue), 0)
Пример #3
0
 def test_invul_not_medic(self):
     """ INVUL command must come from medic """
     medic = self.p1a
     params = self.default_params 
     params[0] = "p1c"
     with self.assertRaises(MeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You are not MEDIC")
     self.assertEqual(len(self.invul_queue), 0)
Пример #4
0
 def test_invul_medic_not_alive(self):
     """ MEDIC must be arrive when invoking command """
     medic = self.p1c
     medic.state = "DEAD"
     medic.put()
     params = self.default_params
     with self.assertRaises(MeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You are DEAD")
     self.assertEqual(len(self.invul_queue), 0)
Пример #5
0
 def test_invul_error_time_before_valid_time(self):
     """ MEDIC can only INVUL one person per 24 hour period """
     medic = self.p1c
     medic.can_set_after = Util.next_day()
     medic.put()
     params = self.default_params
     with self.assertRaises(TimeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You cannot set invul before time {}."\
             .format(Util.utc_to_chi(medic.can_set_after).strftime("%m-%d %I:%M%p")))
     self.assertEqual(len(self.invul_queue), 0)
Пример #6
0
 def test_invul_target_not_alive(self):
     """ Target must be alive """
     medic = self.p1c
     target = self.p1a
     target.state = "DEAD"
     target.put()
     params = self.default_params
     with self.assertRaises(TargetError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "Your target is DEAD")
     self.assertEqual(len(self.invul_queue), 0)
Пример #7
0
 def test_invul_error_time_before_now(self):
     """ MEDIC can only INVUL a time in the future """
     medic = self.p1c
     now = Util.utc_to_chi(datetime.now()) - timedelta(hours=1)
     params = ["p1a", str(now.month), str(now.day),\
             str(now.hour), str(now.minute)]
     with self.assertRaises(TimeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You cannot set {} before time {}."\
             .format(now.strftime("%m-%d %I:%M%p"),\
             Util.utc_to_chi(datetime.now()).strftime("%m-%d %I:%M%p")))
     self.assertEqual(len(self.invul_queue), 0)
Пример #8
0
    def inner_handler(cls, message):
        """ Return [(number, msg),...]"""
        action, params = CommandHandler.get_command(message.Body)
        attacker = Util.get_attacker(message.From)

        if action == "KILL":
            return Kill.handler(attacker, params)
        elif action[1:] == "REPLY":
            ref = params.pop(0)[:-1]
            return Reply.handler(ref, params, attacker)
        elif action == "BOMB":
            return Bomb.handler(attacker, params)
        elif action == "INVUL":
            return Invul.handler(attacker, params)
        elif action == "DISARM":
            return Disarm.handler(attacker, params)
        elif action == "SNIPE":
            if message.From != WEI_HAN:
                raise CommandError(action)
            sniper = Player.query(Player.codename == params[0]).get()
            if sniper == None:
                raise DbError(params[0])
            return Snipe.handler(sniper, params[1])
        elif action == "?":
            msg = "Guide for SAMSU Assassins:\n"
            msg += "KILL <target codename>\n"
            msg += "BOMB <mm> <dd> <hour> <min> <place>\n"
            msg += "INVUL <target codename> <mm> <dd> <hour> <min>\n"
            msg += "DISARM <target codename>\n"
            msg += "SNIPE - send message and picture to {}\n".format(WEI_HAN)
            msg += "REPLY - [REPLY <number>] Y or [REPLY <number>] N\n"
            msg += "If you receive an UNKNOWN ERROR or don't get a message that you expect, contact Wei Han at 312-731-0539."
            return [(attacker.key.id(), msg)]
        else:
            raise CommandError(action)
Пример #9
0
def invul_worker():
    ''' Get invul id'''
    req_key = request.form.get("id", "")
    inv = Invul.get_by_id(int(req_key))

    ''' No Inv found '''
    if not inv:
        logging.error("INV worker: no INV found")
        raise Exception()

    '''Inv deprecated'''
    if inv.deprecated:
        logging.info("INV Worker: Inv deprecated. No action.")
        return "INVUL Worker: Deprecated"

    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

    '''Target dead. Report back to medic'''
    logging.info(inv)
    target_num = inv.target
    logging.info(target_num)
    target = Player.get_by_id(target_num)
    medic = Player.get_by_id(inv.medic)
    logging.info(medic)
    if not target:
        logging.error("INV worker: cannot find target {}".format(target_num))
        return
    if target.state == "DEAD":
        logging.error("INV worker: Target {} has died. Cannot grant INVUL".format(target.codename))
        response = "Your INVUL target has died. Cannot grant dead people INVUL."
        msg = Message(From=SERVER_NUMBER,
                      To=inv.medic,
                      Body=response)
        msg.put()
        client.messages.create(
            to=inv.medic,
            from_=SERVER_NUMBER,
            body=response)
        return "INVUL Worker"

    '''Target alive. If INVUL not yet in effect, trigger'''
    if not inv.in_effect:
        logging.info("INVUL worker: Triggering 8 hour INVUL for target {} at {}".format(target.codename, datetime.now()))
        inv.in_effect = True
        inv_key = inv.put()
        task = taskqueue.Task(url="/invul", params={"id": inv_key.id()}, eta=inv.end_time)
        task.add(queue_name="invul")

        logging.info("Task queue okay")
        logging.info(target)
        target.invul = True
        target.put()

        logging.info("target set okay")
        logging.info(medic)
        medic.can_set_after = Util.next_day()
        medic.put()

        logging.info("medic set okay")
        response  = "You have been granted INVUL for 8 hour from {} to {}".\
                format(Util.utc_to_chi(inv.start_time).strftime("%m-%d %I:%M%p"),\
                Util.utc_to_chi(inv.end_time).strftime("%m-%d %I:%M%p"))
        msg = Message(From=SERVER_NUMBER,
                      To=inv.target,
                      Body=response)
        msg.put()
        client.messages.create(
            to=inv.target,
            from_=SERVER_NUMBER,
            body=response)
        logging.info("message set okay")
        return "INVUL Worker"
    else:
        logging.info("INVUL worker: END 8 hour INVUL for target {} at {}".format(target.codename, datetime.now()))
        inv.deprecated = True
        inv.put()
        target.invul = False
        target.put()

        response = "Your INVUL period has ended. You are no longer INVUL."
        msg = Message(From=SERVER_NUMBER,
                      To=inv.target,
                      Body=response)
        msg.put()
        client.messages.create(
            to=inv.target,
            from_=SERVER_NUMBER,
            body=response)
        return "INVUL Worker"