Esempio n. 1
0
    def getMatchDetails(self, *args, **kwargs):
        if "dm_output" in kwargs:
            match = kwargs.pop("dm_output")
        else:
            match = Match(client=self)

        params = self._prepare_dict(kwargs)
        url = self._getUrl("IDOTA2Match_570/GetMatchDetails/V001", params)
        f = urllib.urlopen(url)
        d = json.load(f)

        match.detailsFromJSON(d["result"])

        return match
Esempio n. 2
0
    def arg_body(self):

        user = self.user
        adversary_username = self.text

        if self.text == "/cancel":
            user.send_message("Game cancelled!",
                              reply_markup=telegram.ReplyKeyboardRemove(True))
        else:
            if adversary_username == user.username and not user.admin:
                user.send_message(
                    constants.ERROR_SAME_USER,
                    reply_markup=telegram.ReplyKeyboardRemove(True))
                return

            query = User.query(User.username == adversary_username)
            query_list = list(query.fetch())

            if len(query_list) != 1:
                # Adversary not found
                invite_button = [[
                    telegram.InlineKeyboardButton(
                        "Invite a friend",
                        switch_inline_query=constants.STRING_SHARED)
                ]]
                reply_markup = telegram.InlineKeyboardMarkup(invite_button)
                user.send_message(
                    adversary_username + " is not a Chess Duel Bot user.",
                    reply_markup=telegram.ReplyKeyboardRemove(True))
                user.send_message(constants.STRING_INVITE,
                                  reply_markup=reply_markup)
                return

            adversary = query_list[0]
            if adversary.status == UserStatus.IDLE:

                try:
                    timeout = int(user.pending_arg)
                except ValueError:
                    # TODO: Print error
                    return

                match = Match(white_id=adversary.key.id(),
                              black_id=user.key.id(),
                              timeout=timeout)
                match.put()

                # Adversary found
                user.setup_match(match, adversary, False)
                user.send_message(
                    constants.STRING_REQUEST_SENT,
                    reply_markup=telegram.ReplyKeyboardRemove(True))

                adversary.setup_match(match, user, True)
                accept_button = [[
                    telegram.InlineKeyboardButton("Accept",
                                                  callback_data='/accept'),
                    telegram.InlineKeyboardButton("Refuse",
                                                  callback_data='/refuse')
                ]]
                reply_markup = telegram.InlineKeyboardMarkup(accept_button)
                adversary.send_message(
                    constants.STRING_REQUEST_RECEIVED.format(
                        user.username,
                        humanfriendly.format_timespan(match.timeout)),
                    reply_markup=reply_markup)
            else:

                # Adversary busy
                user.send_message(
                    "Adversary is busy",
                    reply_markup=telegram.ReplyKeyboardRemove(True))