def subtitle(self, msg, **config): action = None agent = None line = None if 'meetbot.meeting.start' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{owner} started meeting "{name}" in {channel}') else: tmpl = self._('{owner} started a meeting in {channel}') elif 'meetbot.meeting.complete' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{owner}\'s meeting titled "{name}" ' 'ended in {channel}') else: tmpl = self._('{owner}\'s meeting ended in {channel}') elif 'meetbot.meeting.topic.update' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('The topic of {owner}\'s "{name}" meeting ' 'changed to "{topic}" in {channel}') else: tmpl = self._('The topic of {owner}\'s meeting ' 'changed to "{topic}" in {channel}') elif 'meetbot.meeting.item.' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{agent} {action} in the "{name}" meeting ' 'in {channel}: "{line}"') else: tmpl = self._('{agent} {action} in a meeting ' 'in {channel}: "{line}"') key = msg['topic'].rsplit('.')[-1] action_lookup = { 'agreed': 'noted agreement', 'accepted': 'accepted an item', 'rejected': 'rejected an item', 'action': 'noted an action', 'info': 'raised a point of information', 'idea': 'proposed an idea', 'help': 'called for help', 'link': 'linked to more information', } action = action_lookup[key] line = msg['msg']['details']['line'] else: raise NotImplementedError("%r" % msg) if 'details' in msg['msg']: agent = nick2fas(msg['msg']['details']['nick'], **config) owner = nick2fas(msg['msg']['owner'], **config) name = msg['msg']['meeting_topic'] channel = msg['msg']['channel'] topic = msg['msg'].get('topic', 'no topic') return tmpl.format(owner=owner, agent=agent, name=name, channel=channel, topic=topic, action=action, line=line)
def subtitle(self, msg, **config): if "meetbot.meeting.start" in msg["topic"]: if msg["msg"]["meeting_topic"]: tmpl = self._('{user} started meeting "{name}" in {channel}') else: tmpl = self._("{user} started a meeting in {channel}") elif "meetbot.meeting.complete" in msg["topic"]: if msg["msg"]["meeting_topic"]: tmpl = self._('{user} ended meeting "{name}" in {channel}') else: tmpl = self._("{user} ended a meeting in {channel}") elif "meetbot.meeting.topic.update" in msg["topic"]: if msg["msg"]["meeting_topic"]: tmpl = self._("{user} changed the topic of " '"{name}" to "{topic}" in {channel}') else: tmpl = self._("{user} changed the topic " 'to "{topic}" in {channel}') else: raise NotImplementedError("%r" % msg) user = nick2fas(msg["msg"]["owner"], **config) name = msg["msg"]["meeting_topic"] channel = msg["msg"]["channel"] topic = msg["msg"].get("topic", "no topic") return tmpl.format(user=user, name=name, channel=channel, topic=topic)
def subtitle(self, msg, **config): if 'meetbot.meeting.start' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{user} started meeting "{name}" in {channel}') else: tmpl = self._('{user} started a meeting in {channel}') elif 'meetbot.meeting.complete' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{user}\'s meeting titled "{name}" ' 'ended in {channel}') else: tmpl = self._('{user}\'s meeting ended in {channel}') elif 'meetbot.meeting.topic.update' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('The topic of {user}\'s "{name}" meeting ' 'changed to "{topic}" in {channel}') else: tmpl = self._('The topic of {user}\'s meeting ' 'changed to "{topic}" in {channel}') else: raise NotImplementedError("%r" % msg) user = nick2fas(msg['msg']['owner'], **config) name = msg['msg']['meeting_topic'] channel = msg['msg']['channel'] topic = msg['msg'].get('topic', 'no topic') return tmpl.format(user=user, name=name, channel=channel, topic=topic)
def subtitle(self, msg, **config): if 'meetbot.meeting.start' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{user} started meeting "{name}" in {channel}') else: tmpl = self._('{user} started a meeting in {channel}') elif 'meetbot.meeting.complete' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{user} ended meeting "{name}" in {channel}') else: tmpl = self._('{user} ended a meeting in {channel}') elif 'meetbot.meeting.topic.update' in msg['topic']: if msg['msg']['meeting_topic']: tmpl = self._('{user} changed the topic of ' '"{name}" to "{topic}" in {channel}') else: tmpl = self._('{user} changed the topic ' 'to "{topic}" in {channel}') else: raise NotImplementedError("%r" % msg) user = nick2fas(msg['msg']['owner'], **config) name = msg['msg']['meeting_topic'] channel = msg['msg']['channel'] topic = msg['msg'].get('topic', 'no topic') return tmpl.format(user=user, name=name, channel=channel, topic=topic)
def objects(self, msg, **config): objs = set([ 'attendees/' + nick2fas(person, **config) for person in msg['msg']['attendees'] if person not in blacklisted_people ] + ['channels/' + msg['msg']['channel']]) if msg['msg']['meeting_topic']: objs.add('titles/' + msg['msg']['meeting_topic']) if msg['msg'].get('topic', None): objs.add('topics/' + msg['msg']['topic']) return objs
def objects(self, msg, **config): objs = set([ 'attendees/' + nick2fas(person, **config) for person in msg['msg']['attendees'] if person not in blacklisted_people ] + [ 'channels/' + msg['msg']['channel'] ]) if msg['msg']['meeting_topic']: objs.add('titles/' + msg['msg']['meeting_topic']) if msg['msg'].get('topic', None): objs.add('topics/' + msg['msg']['topic']) return objs
def objects(self, msg, **config): objs = set( [ "attendees/" + nick2fas(person, **config) for person in msg["msg"]["attendees"] if person not in blacklisted_people ] + ["channels/" + msg["msg"]["channel"]] ) if msg["msg"]["meeting_topic"]: objs.add("titles/" + msg["msg"]["meeting_topic"]) if msg["msg"].get("topic", None): objs.add("topics/" + msg["msg"]["topic"]) return objs
def usernames(self, msg, **config): return set([nick2fas(nick, **config) for nick in msg["msg"]["attendees"] if nick not in blacklisted_people])
def secondary_icon(self, msg, **config): if 'details' in msg['msg']: user = nick2fas(msg['msg']['details']['nick'], **config) else: user = nick2fas(msg['msg']['owner'], **config) return avatar_url(user)
def secondary_icon(self, msg, **config): user = nick2fas(msg["msg"]["owner"], **config) return gravatar_url(user)
def usernames(self, msg, **config): return set([ nick2fas(nick, **config) for nick in msg['msg']['attendees'] if nick not in blacklisted_people ])
def secondary_icon(self, msg, **config): user = nick2fas(msg['msg']['owner'], **config) return gravatar_url(user)
def matches(self, msg): # First, do a lightweight check to see if the msg matches a pattern. if not self.trigger.matches(msg): return set() # Before proceeding further, let's see who would get this badge if # our more heavyweight checks matched up. If the user specifies a # recipient_key, we can use that to extract the potential awardee. If # that is not specified, we just use `msg2usernames`. if self.recipient_key: subs = construct_substitutions(msg) obj = format_args(self.recipient_key, subs) if isinstance(obj, (basestring, int, float)): obj = [obj] # On the way, it is possible for the fedmsg message to contain None # for "agent". A problem here though is that None is not iterable, # so let's replace it with an equivalently empty iterable so code # further down doesn't freak out. An instance of this is when a # user without a fas account comments on a bodhi update. if obj is None: obj = [] awardees = frozenset(obj) if self.recipient_nick2fas: awardees = frozenset( [nick2fas(nick, **fedmsg_config) for nick in awardees]) if self.recipient_email2fas: awardees = frozenset( [email2fas(email, **fedmsg_config) for email in awardees]) else: usernames = fedmsg.meta.msg2usernames(msg) awardees = usernames.difference(self.banned_usernames) # Strip anyone who is an IP address awardees = frozenset([ user for user in awardees if not (user.startswith('192.168.') or user.startswith('10.')) ]) # If no-one would get the badge by default, then no reason to waste # time doing any further checks. No need to query the Tahrir DB. if not awardees: return awardees # Limit awardees to only those who do not already have this badge. # Do this only if we have an active connection to the Tahrir DB. if self.tahrir: awardees = frozenset([ user for user in awardees if not self.tahrir.assertion_exists( self.badge_id, "*****@*****.**" % user) ]) # Also, exclude any potential awardees who have opted out. awardees = frozenset([ user for user in awardees if not self.tahrir.person_opted_out("*****@*****.**" % user) ]) # If no-one would get the badge at this point, then no reason to waste # time doing any further checks. No need to query datanommer. if not awardees: return awardees # Check our backend criteria -- likely, perform datanommer queries. try: if not self.criteria.matches(msg): return set() except IOError as e: log.exception(e) return set() # Lastly, and this is probably most expensive. Make sure the person # actually has a FAS account before we award anything. # https://github.com/fedora-infra/tahrir/issues/225 awardees = set( [u for u in awardees if user_exists_in_fas(fedmsg_config, u)]) return awardees
def matches(self, msg): # First, do a lightweight check to see if the msg matches a pattern. if not self.trigger.matches(msg): return set() # Before proceeding further, let's see who would get this badge if # our more heavyweight checks matched up. If the user specifies a # recipient_key, we can use that to extract the potential awardee. If # that is not specified, we just use `msg2usernames`. if self.recipient_key: subs = construct_substitutions(msg) obj = format_args(self.recipient_key, subs) if isinstance(obj, (basestring, int, float)): obj = [obj] # On the way, it is possible for the fedmsg message to contain None # for "agent". A problem here though is that None is not iterable, # so let's replace it with an equivalently empty iterable so code # further down doesn't freak out. An instance of this is when a # user without a fas account comments on a bodhi update. if obj is None: obj = [] awardees = frozenset(obj) if self.recipient_nick2fas: awardees = frozenset([ nick2fas(nick, **fedmsg_config) for nick in awardees ]) else: usernames = fedmsg.meta.msg2usernames(msg) awardees = usernames.difference(self.banned_usernames) # Strip anyone who is an IP address awardees = frozenset([ user for user in awardees if not ( user.startswith('192.168.') or user.startswith('10.') ) ]) # If no-one would get the badge by default, then no reason to waste # time doing any further checks. No need to query the Tahrir DB. if not awardees: return awardees # Limit awardees to only those who do not already have this badge. # Do this only if we have an active connection to the Tahrir DB. if self.tahrir: awardees = frozenset([ user for user in awardees if not self.tahrir.assertion_exists( self.badge_id, "*****@*****.**" % user )]) # Also, exclude any potential awardees who have opted out. awardees = frozenset([ user for user in awardees if not self.tahrir.person_opted_out( "*****@*****.**" % user )]) # If no-one would get the badge at this point, then no reason to waste # time doing any further checks. No need to query datanommer. if not awardees: return awardees # Check our backend criteria -- likely, perform datanommer queries. if not self.criteria.matches(msg): return set() return awardees
def matches(self, msg): # First, do a lightweight check to see if the msg matches a pattern. if not self.trigger.matches(msg): return set() # Before proceeding further, let's see who would get this badge if # our more heavyweight checks matched up. If the user specifies a # recipient_key, we can use that to extract the potential awardee. If # that is not specified, we just use `msg2usernames`. if self.recipient_key: subs = construct_substitutions(msg) obj = format_args(self.recipient_key, subs) if isinstance(obj, (basestring, int, float)): obj = [obj] awardees = set(obj) if self.recipient_nick2fas: awardees = set([ nick2fas(nick, **fedmsg_config) for nick in awardees ]) else: usernames = fedmsg.meta.msg2usernames(msg) awardees = usernames.difference(self.banned_usernames) # Strip anyone who is an IP address awardees = set([ user for user in awardees if not ( user.startswith('192.168.') or user.startswith('10.') ) ]) # If no-one would get the badge by default, then no reason to waste # time doing any further checks. No need to query the Tahrir DB. if not awardees: return awardees # Limit awardees to only those who do not already have this badge. # Do this only if we have an active connection to the Tahrir DB. if self.tahrir: awardees = set([user for user in awardees if not self.tahrir.assertion_exists( self.badge_id, "*****@*****.**" % user )]) # Also, exclude any potential awardees who have opted out. awardees = set([user for user in awardees if not self.tahrir.person_opted_out( "*****@*****.**" % user )]) # If no-one would get the badge at this point, then no reason to waste # time doing any further checks. No need to query datanommer. if not awardees: return awardees # Check our backend criteria -- likely, perform datanommer queries. if not self.criteria.matches(msg): return set() return awardees