コード例 #1
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
 def send_game_not_found(self, when, user):
     if random.randint(0, 1) == 0:
         self.send_message(":warning: {0}, there isnae game at {1}".format(
             format_user(user), when_str(when)))
     else:
         self.send_message(
             ":warning: scrubadubdub, there's no game at {}".format(
                 when_str(when)))
コード例 #2
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
    def handle_imminent_games(self):
        scheduled_games = filter(lambda g: g.state == GameStates.scheduled,
                                 self.games)
        active_games = filter(lambda g: g.state == GameStates.active,
                              self.games)

        self.update_game_states()

        # keep games until end-of-day (to allow late entrants, etc)
        self.games = filter(lambda g: g.state != GameStates.dead, self.games)

        imminent_games = filter(lambda g: g.state == GameStates.active,
                                scheduled_games)
        just_finished_games = filter(lambda g: g.state == GameStates.finished,
                                     active_games)

        for g in imminent_games:
            if len(g.players) == 0:
                banter = "big game ({0}) about to kick off at {1}, no one wants to play?".format(
                    g.description, when_str(g.when))
            else:
                banter = self.load_banter(
                    "kickoff", {
                        "s": g.pretty_players(),
                        "t": when_str(g.when),
                        "d": g.description,
                    })

            suggested_teams = suggest_teams(g)
            if suggested_teams:
                banter += "\n{}".format(suggested_teams)

            nextgame = self.game_straight_after(g,
                                                threshold=GAME_FOLLOWON_TIME)
            if nextgame:
                nextgame_banter = self.load_banter(
                    "follow-on", {
                        "s": format_user(nextgame.creator),
                        "d": nextgame.description,
                        "c": nextgame.channel,
                    })
                banter += "\n({})".format(nextgame_banter)

            self.send_message(banter, to_channel=g.channel)

        for g in just_finished_games:
            msg = vote_message(g)
            if msg:
                self.update_game_message(g, msg)
コード例 #3
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
    def maybe_cancel_game(self, message, rest):
        user = message.user

        if len(rest) == 0:
            user_games = self.games_created_by(message.user)
            if len(user_games) == 1:
                game = user_games[0]
            else:
                self.send_too_many_owned_games_message(user_games, "cancel")
                return
        else:
            try:
                when = parse_time(rest)
            except ValueError:
                self.send_message(
                    ":warning: scrubadubdub, when's this game you want to cancel?"
                    .format(rest))
                return

            game = self.game_occuring_at(when)
            if not game:
                self.send_game_not_found(when, user)
                return

        if game.creator != user:
            self.send_message(
                ":warning: scrubadubdub, only {} can cancel the {} {}".format(
                    format_user(game.creator), when_str(game.when),
                    game.description))
            return

        self.games = filter(lambda g: g != game, self.games)

        rip_players = game.pretty_players(with_creator=False)
        rip_players_message = " (just burn some time on kimble instead {})".format(rip_players) \
            if len(rip_players) else ""

        self.send_message(
            ":candle: {}'s {} ({}) has been flown out by {}{}".format(
                game.channel, game.description, when_str(game.when),
                format_user(user), rip_players_message))

        newtext = game.message.text + "\n:warning: Cancelled :warning: :candle::candle:"
        self.update_message(newtext, original_message=game.message)

        self.history.cancel_game(game)

        self.save()
コード例 #4
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
    def save(self):
        try:
            with open(SAVE_FILE, "w") as f:
                for g in self.games:
                    print >> f, "{} {} {} {} {} {} {} {} {}".format(
                        when_str(g.when), g.channel, g.creator, g.state,
                        ",".join(g.players), g.max_player_count, g.play_time,
                        g.mode or "None", g.description)

                    msg = g.message
                    print >> f, "{}\n{}\n{}".format(msg.timestamp, msg.channel,
                                                    msg.text)
                    print >> f, ""

                for channel, latest in self.latest_stats_table.iteritems():
                    print >> f, "stats {} {} {}".format(
                        channel, latest.timestamp,
                        latest.year.year if latest.year else "")

                for user, options in self.user_options.iteritems():
                    if len(options):
                        print >> f, "user {} {}".format(
                            user, " ".join(options))

        except IOError as e:
            print >> sys.stderr, "exception saving state: {}".format(e)

        self.history.save()
コード例 #5
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
    def remove_user_from_game(self, user, game, subtle_message=False):
        if game.remove_player(user):
            banter = ":candle: {}".format(format_user(user))
        else:
            if subtle_message:
                # don't say anything - they're silently removing their failed join-attmept-emoji
                return

            banter = ":warning: you're not in the {} game {} (\"{}\")".format(
                when_str(game.when), format_user(user), game.description)

        self.history_sync()

        if not subtle_message:
            self.send_message(banter)
        self.update_game_message(game, banter if subtle_message else None)
        self.save()
コード例 #6
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
    def maybe_scuttle_game(self, message, rest):
        tokens = rest.split(" ")

        if len(tokens) >= 3 and tokens[-2] == "to":
            str_to = tokens[-1]
            str_from = " ".join(tokens[:-2])
        elif len(tokens) == 1:
            str_from = None
            str_to = tokens[0]
        else:
            self.send_scuttle_usage()
            return

        try:
            when_desc = None
            when_to = parse_time(str_to)
        except ValueError:
            self.send_scuttle_usage()
            return

        try:
            when_from = parse_time(str_from) if str_from else None
        except ValueError:
            when_desc = str_from

        if when_desc:
            game_to_move = None
            for g in self.games:
                if g.description == when_desc:
                    if game_to_move:
                        self.send_message(
                            ":warning: scrubadubdub - there's multiple games called \"{}\""
                            .format(when_desc))
                        return
                    game_to_move = g

        elif when_from:
            # we've been given an explicit game to move
            game_to_move = self.game_occuring_at(when_from)
            if not game_to_move:
                self.send_game_not_found(when_from, message.user)
                return
        else:
            # no explicit game to move, if the user has just one, move it
            created_games = self.games_created_by(message.user)
            if len(created_games) != 1:
                self.send_too_many_owned_games_message(created_games,
                                                       "scuttle")
                return
            game_to_move = created_games[0]

        if game_to_move.creator != message.user:
            self.send_message(
                ":warning: scrubadubdub, only {} can scuttle the {} {}".format(
                    format_user(game_to_move.creator),
                    when_str(game_to_move.when), game_to_move.description))
            return

        game_in_slot = self.game_overlapping(when_to,
                                             game_to_move.play_time,
                                             ignoring=game_to_move)
        if game_in_slot:
            self.send_duplicate_game_message(game_in_slot)
            return

        old_when = game_to_move.when

        banter = self.load_banter("created", {"s": format_user(message.user)},
                                  for_user=message.user,
                                  in_channel=game_to_move.channel)

        game_to_move.update_when(when_to, banter)
        self.update_game_message(
            game_to_move, "moved by {} to {}".format(format_user(message.user),
                                                     when_str(when_to)))

        pretty_players = game_to_move.pretty_players(with_creator=False)
        self.send_message(
            ":alarm_clock: {}{} moved from {} to {} by {}".format(
                pretty_players + " - " if len(pretty_players) else "",
                game_to_move.description, when_str(old_when),
                when_str(when_to), format_user(message.user)))

        self.save()
コード例 #7
0
ファイル: PS4Bot.py プロジェクト: stevenjob/lunchbot
 def send_duplicate_game_message(self, game):
     self.send_message(
         ":warning: there's already a {} game at {}: {}. rip :candle:".
         format(game.channel, when_str(game.when), game.description))