def guess(self, dest): """Guess the recipient of the message First, it will check if it is a Telegram ID (string with #), then if it is a Zoe user and finally Telegram nicknames for each user. """ if '#' in dest: # Already a unique ID return int(dest.rsplit('#')[1]) subjects = zoe.Users().subjects() if dest in subjects and 'tg' in subjects[dest]: subject_ids = [s.strip() for s in subjects[dest]['tg'].split(',')] # Find unique ID for sid in subject_ids: if '#' in sid: return int(sid.rsplit('#')[1]) # Try to find the username for subj in subjects: subject_ids = [s.strip() for s in subjects[subj]['tg'].split(',')] if dest in subject_ids: for sid in subject_ids: if '#' in sid: return int(sid.rsplit('#')[1])
def guess(self, dest): if "#" in dest: return dest subjects = zoe.Users().subjects() if dest in subjects: address = subjects[dest]["tg"] return address
def __init__(self, interval=1, db=None): if not db: conf = zoe.Config() db = conf.conf("zoe-users.conf") self._listener = zoe.Listener(self, name="users") self._model = zoe.Users(db) self._interval = interval self.update()
def finduser(self, user): model = zoe.Users() subjects = model.subjects() for s in subjects: if "tg" in subjects[s] and str(user) in subjects[s]["tg"].split( ","): uid = subjects[s]["uniqueid"] return subjects[uid]
def guess(self, dest): if "@" in dest: return dest subjects = zoe.Users().subjects() if dest in subjects: address = subjects[dest]["jabber"] if "," in address: address = address.split(",")[0] return address
def finduser(self, jid): user = jid.user + "@" + jid.domain model = zoe.Users() subjects = model.subjects() for s in subjects: if "jabber" in subjects[s] and user in subjects[s]["jabber"].split( ","): uid = subjects[s]["uniqueid"] return subjects[uid]
def fillsender(self, parser, builder): sender = parser.get("sender") if not sender: return builder user = zoe.Users().subject(sender) if not user: return builder for key in user: builder = builder.put("sender-" + key, user[key]) return builder
def finduser(self, address): """ Finds the Zoe user with a given email address """ name, addr = email.utils.parseaddr(address) model = zoe.Users() subjects = model.subjects() for s in subjects: if "mail" in subjects[s] and subjects[s]["mail"] == addr: return subjects[s]
def send(self, to, msg): if to: if to[0] == "@": msg = to + " " + msg else: try: guessed = zoe.Users().subject(to)["twitter"] msg = guessed + " " + msg except Exception as e: msg = "@" + to + " " + msg self._twitter.statuses.update(status=msg)
def extract_users(self, cmd): users = zoe.Users().subjects() foundusers = [] remaining = [] for word in cmd.split(): cleanword = self.removespurious(word).strip() if cleanword in users.keys() and not word in foundusers: foundusers.append(users[cleanword]) remaining.append("<user>") else: remaining.append(word) return (foundusers, " ".join(remaining))
def sendto(self, recipient): if recipient.find("@") == -1: # recipient is a user, not an email address user = zoe.Users().subject(recipient) if not recipient: print("Can't find user", user) return recipient = user["mail"] self._msg['To'] = recipient server = smtplib.SMTP(self._smtp, self._port) server.ehlo() server.starttls() server.ehlo() server.login(self._user, self._password) server.sendmail(self._user, recipient, self._msg.as_string().encode('UTF-8')) server.close() return self
def finduser(self, user_ids): """Find a given user or group. First checks the group ID to see if anyone in the given group can communicate with Zoe. If no occurence is found, the user ID is checked, and then the username (if present). """ subjects = zoe.Users().subjects() # Store a relation so users are not accessed all the time id_rels = {} for subj in subjects: if 'tg' not in subjects[subj]: continue for s in subjects[subj]['tg'].split(','): id_rels[s.strip()] = subjects[subj]['uniqueid'] for usr in user_ids: if usr in id_rels.keys(): return usr, subjects[id_rels[usr]] return None, None
def _feedback(self, message, user, dst=None, subject=None): """Send a message or mail to the given user. Args: message (str): Message to send. user (str): Unique ID of the user. dst (str): Destination of the message. subject (str): If using email, subject for the mail. """ to_send = {'dst': 'relay', 'to': user} # Check destination if not dst: # If no preferred is found, default to mail users = zoe.Users() if user not in users.subjects(): self.loger.info('Cannot send message, user %s not found' % user) return relayto = users.subject(user).get('preferred', 'mail') else: relayto = dst to_send['relayto'] = relayto if relayto == 'mail': to_send['subject'] = subject or 'Zoe ICE' to_send['txt'] = message else: to_send['msg'] = message return zoe.MessageBuilder(to_send)
def __init__(self): self._users = zoe.Users().subjects() # Remember that the constructor must not be blocking, # that is, the channel event loop must run in its own thread. pass
def __init__(self): self._users = zoe.Users() self._cmdmap = {}
def guess(self, rcpt): if "@" in rcpt: return rcpt return zoe.Users().subject(rcpt)["mail"]
def send(self, msg, to, group="broadcast", by=None): users = zoe.Users() if to: return self.sendto(msg, to, users, by) else: return self.sendgrp(msg, group, users, by)