示例#1
0
 def check_events(self):
     logger.info("Checking for event updates")
     self.storg.update_upcoming_events()
     for event in self.storg.upcoming_events:
         self._handle_event(event)
         self._handle_rsvps(event)
     logger.info("Done checking")
示例#2
0
 def _handle_event(self, event: Event):
     cet = timezone(timedelta(0, 3600), "CET")
     # Check for new event
     event_names = [b.name for b in self.trello.boards]
     if event.name not in event_names:
         logger.info("New event found: {}".format(event.name))
         self.chat.message(
             "Woohoo! We've got a new event coming up! :party_parrot:\n{}".
             format(event.event_url),
             channel="#announcements")
         self.trello.create_board(event.name, team_name=self.team_name)
示例#3
0
    def _handle_event(self, event):
        cet = timezone(timedelta(0, 3600), "CET")
        # Check for new event
        event_id = event["id"]
        if event_id not in self.stored_events.keys():
            logger.info("New event found: {}".format(event["name"]))
            event_date = int(event["time"]) / 1000
            event_date = datetime.fromtimestamp(
                event_date, tz=cet).strftime('%A %B %d %H:%M')

            # self.chat.new_event(event["name"], event_date, event["venue"]["name"], event["event_url"])
            self.trello.create_board(event["name"], team_name=self.team_name)
            self.stored_events[event_id] = event
            self.stored_events[event_id]["participants"] = []
示例#4
0
    def rtm(self, queue, read_delay=1):
        """Creates a Real Time Messaging connection to Slack and listens for events
        https://api.slack.com/rtm

        :param queue: (queue) A Multiprocess Queue where it'll put the incoming events
        :param read_delay: (int) How often to check for events. Default: 1s
        :return: None
        """
        if self.sc.rtm_connect():
            logger.info("Slack RTM connected")
            while True:
                command, channel, user_id = self._parse_slack_output(self.sc.rtm_read())
                if command and channel and user_id:
                    logger.debug("command found text: {}, channel: {}, user_id: {}".format(command, channel, user_id))
                    queue.put((command, channel, user_id))
                sleep(read_delay)
示例#5
0
    def _handle_rsvps(self, event):
        event_id = event["id"]
        event_name = event["name"]
        venue = event["venue"]["name"]
        channel_for_venue = {
            "STORG Clubhouse": "#storg-south",
            "STORG Northern Clubhouse": "#storg-north"
        }
        channel = channel_for_venue.get(venue)
        newcomers = []
        cancels = []

        for rsvp in self.storg.rsvps(event_id):
            member_name = rsvp["member"]["name"]
            member_id = rsvp["member"]["member_id"]
            try:
                known_participants = self.stored_events[event_id][
                    "participants"]
            except KeyError:
                logger.error("No key {}".format(event_id))
                logger.error("Known events: {}".format(self.stored_events))

            if member_name not in known_participants and rsvp[
                    "response"] == "yes":
                self.trello.add_rsvp(name=member_name,
                                     member_id=member_id,
                                     board_name=event_name)
                # self.trello.add_contact(member_name=member_name, member_id=member_id)
                newcomers.append(member_name)
                sleep(0.2)
            elif member_name in known_participants and rsvp["response"] == "no":
                self.trello.cancel_rsvp(member_id, board_name=event_name)
                cancels.append(member_name)

        if newcomers or cancels:
            spots_left = int(event["rsvp_limit"]) - int(
                event["yes_rsvp_count"]) if event["rsvp_limit"] else 'Unknown'

            if newcomers:
                logger.info("Newcomers found: {}".format(newcomers))
                self.chat.new_rsvp(', '.join(newcomers), "yes", event_name,
                                   spots_left, channel)
                self.stored_events[event_id]["participants"] += newcomers
                logger.debug("Participant list: {}".format(
                    self.stored_events[event_id]["participants"]))

            if cancels:
                logger.info("Cancellations found: {}".format(cancels))
                self.chat.new_rsvp(', '.join(cancels), "no", event_name,
                                   spots_left, channel)
                self.stored_events[event_id]["participants"] = [
                    p for p in self.stored_events[event_id]["participants"]
                    if p not in cancels
                ]
                logger.debug("Participant list: {}".format(
                    self.stored_events[event_id]["participants"]))
        else:
            logger.info("No changes for {}".format(event_name))
示例#6
0
    def _handle_rsvps(self, event: Event):
        event_name = event.name
        venue = event.venue["name"]
        channel_for_venue = {
            "STORG Clubhouse": "#storg-south",
            "STORG Northern Clubhouse": "#storg-north"
        }
        channel = channel_for_venue.get(venue)
        newcomers = []
        cancels = []
        waitlist_names = []
        newcomer_names = []
        cancel_names = []

        for rsvp in self.storg.rsvps(event.event_id):
            member_name = rsvp.member["name"]
            member_id = rsvp.member["member_id"]
            known_participants = self.trello.participants(event.name)

            if member_id not in known_participants and rsvp.response == "yes":
                self.trello.add_rsvp(name=member_name,
                                     member_id=member_id,
                                     board_name=event_name)
                newcomers.append(member_id)
                newcomer_names.append(member_name)
                sleep(0.2)
            elif member_id in known_participants and rsvp.response == "no":
                self.trello.cancel_rsvp(member_id, board_name=event_name)
                cancels.append(member_id)
                cancel_names.append(member_name)
            elif rsvp.response == "waitlist":
                waitlist_names.append(member_name)

        spots_left = int(event.rsvp_limit) - int(
            event.yes_rsvp_count) if event.rsvp_limit else 'Unknown'

        if cancels:
            logger.info("Cancellations found: {}".format(cancels))
            self.chat.new_rsvp(', '.join(cancel_names), "no", event_name,
                               spots_left, event.waitlist_count, channel)
            # logger.debug("Participant list: {}".format(known_participants))
            return

        if newcomers:
            logger.info("Newcomers found: {}".format(newcomers))
            self.chat.new_rsvp(', '.join(newcomer_names), "yes", event_name,
                               spots_left, event.waitlist_count, channel)
            # logger.debug("Participant list: {}".format(known_participants))
            return

        logger.info("No changes for {}".format(event_name))