def invite(self, the_input): """Completion for /invite""" n = the_input.get_argument_position(quoted=True) if n == 1: comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) comp = sorted(comp) bares = sorted(roster[contact].bare_jid for contact in roster.jids() if len(roster[contact])) off = sorted(jid for jid in roster.jids() if jid not in bares) comp = comp + bares + off return Completion(the_input.new_completion, comp, n, quotify=True) elif n == 2: rooms = [] for tab in self.core.get_tabs(tabs.MucTab): if tab.joined: rooms.append(tab.jid.bare) rooms.sort() return Completion(the_input.new_completion, rooms, n, '', quotify=True)
def message(self, the_input): """Completion for /message""" n = the_input.get_argument_position(quoted=True) if n >= 2: return False l = [] for jid in roster.jids(): if len(roster[jid]): l.append(jid) for resource in roster[jid].resources: l.append(resource.jid) for jid in roster.jids(): if not len(roster[jid]): l.append(jid) return Completion(the_input.new_completion, l, 1, '', quotify=True)
def completion_groupmove(self, the_input): args = shell_split(the_input.text) n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion(the_input.new_completion, jids, n, '', quotify=True) elif n == 2: contact = roster[args[1]] if not contact: return False groups = list(contact.groups) if 'none' in groups: groups.remove('none') return Completion(the_input.new_completion, groups, n, '', quotify=True) elif n == 3: groups = sorted(group for group in roster.groups) return Completion(the_input.new_completion, groups, n, '', quotify=True) return False
def completion_groupremove(self, the_input): args = shell_split(the_input.text) n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion(the_input.new_completion, jids, n, '', quotify=True) elif n == 2: contact = roster[args[1]] if contact is None: return False groups = sorted(contact.groups) try: groups.remove('none') except ValueError: pass return Completion(the_input.new_completion, groups, n, '', quotify=True) return False
def completion_block(self, the_input): """ Completion for /block """ if the_input.get_argument_position() == 1: jids = roster.jids() return Completion(the_input.new_completion, jids, 1, '', quotify=False)
def completion_name(self, the_input): """Completion for /name""" n = the_input.get_argument_position() if n == 1: jids = [jid for jid in roster.jids()] return Completion(the_input.new_completion, jids, n, quotify=True) return False
def version(self, the_input): """Completion for /version""" comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) return Completion( the_input.new_completion, sorted(comp), 1, quotify=False)
def completion_name(self, the_input): """Completion for /name""" n = the_input.get_argument_position() if n == 1: jids = [jid for jid in roster.jids()] return Completion(the_input.new_completion, jids, n, quotify=True) return False
def invite(self, the_input): """Completion for /invite""" n = the_input.get_argument_position(quoted=True) if n == 1: comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) comp = sorted(comp) bares = sorted(roster[contact].bare_jid for contact in roster.jids() if len(roster[contact])) off = sorted(jid for jid in roster.jids() if jid not in bares) comp = comp + bares + off return the_input.new_completion(comp, n, quotify=True) elif n == 2: rooms = [] for tab in self.core.get_tabs(tabs.MucTab): if tab.joined: rooms.append(tab.name) rooms.sort() return the_input.new_completion(rooms, n, '', quotify=True)
def completion_block(self, the_input): """ Completion for /block """ if the_input.get_argument_position() == 1: jids = roster.jids() return Completion( the_input.new_completion, jids, 1, '', quotify=False)
def presence(self, the_input): """ Completion of /presence """ arg = the_input.get_argument_position() if arg == 1: return the_input.auto_completion([jid for jid in roster.jids()], '', quotify=True) elif arg == 2: return the_input.auto_completion([status for status in POSSIBLE_SHOW], '', quotify=True)
def completion_groupadd(self, the_input): n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion(the_input.new_completion, jids, n, '', quotify=True) elif n == 2: groups = sorted(group for group in roster.groups if group != 'none') return Completion(the_input.new_completion, groups, n, '', quotify=True) return False
def version(self, the_input): """Completion for /version""" comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) return Completion(the_input.new_completion, sorted(comp), 1, quotify=False)
def presence(self, the_input): """ Completion of /presence """ arg = the_input.get_argument_position() if arg == 1: return Completion(the_input.auto_completion, [jid for jid in roster.jids()], '', quotify=True) elif arg == 2: return Completion(the_input.auto_completion, [status for status in POSSIBLE_SHOW], '', quotify=True)
def message(self, the_input): """Completion for /message""" n = the_input.get_argument_position(quoted=True) if n >= 2: return False l = [] for jid in roster.jids(): if len(roster[jid]): l.append(jid) for resource in roster[jid].resources: l.append(resource.jid) return the_input.new_completion(l, 1, '', quotify=True)
def completion_groupadd(self, the_input): n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion( the_input.new_completion, jids, n, '', quotify=True) elif n == 2: groups = sorted( group for group in roster.groups if group != 'none') return Completion( the_input.new_completion, groups, n, '', quotify=True) return False
def impromptu(self, the_input): """Completion for /impromptu""" n = the_input.get_argument_position(quoted=True) onlines = [] offlines = [] for barejid in roster.jids(): if len(roster[barejid]): onlines.append(barejid) else: offlines.append(barejid) comp = sorted(onlines) + sorted(offlines) return Completion(the_input.new_completion, comp, n, quotify=True)
def impromptu(self, the_input): """Completion for /impromptu""" n = the_input.get_argument_position(quoted=True) onlines = [] offlines = [] for barejid in roster.jids(): if len(roster[barejid]): onlines.append(barejid) else: offlines.append(barejid) comp = sorted(onlines) + sorted(offlines) return Completion(the_input.new_completion, comp, n, quotify=True)
def last_activity(self, the_input): """ Completion for /last_activity <jid> """ n = the_input.get_argument_position(quoted=False) if n >= 2: return False comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) return Completion( the_input.new_completion, sorted(comp), 1, '', quotify=False)
def message(self, the_input): """Completion for /message""" n = the_input.get_argument_position(quoted=True) if n >= 2: return False online = [] offline = [] for jid in sorted(roster.jids()): if len(roster[jid]) > 0: online.append(jid) else: offline.append(jid) return Completion( the_input.new_completion, online + offline, 1, '', quotify=True)
def last_activity(self, the_input): """ Completion for /last_activity <jid> """ n = the_input.get_argument_position(quoted=False) if n >= 2: return False comp = reduce(lambda x, y: x + [i.jid for i in y], (roster[jid].resources for jid in roster.jids() if len(roster[jid])), []) return Completion(the_input.new_completion, sorted(comp), 1, '', quotify=False)
def message(self, the_input): """Completion for /message""" n = the_input.get_argument_position(quoted=True) if n >= 2: return False online = [] offline = [] for jid in sorted(roster.jids()): if len(roster[jid]) > 0: online.append(jid) else: offline.append(jid) return Completion(the_input.new_completion, online + offline, 1, '', quotify=True)
def completion_groupremove(self, the_input): args = shell_split(the_input.text) n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion( the_input.new_completion, jids, n, '', quotify=True) elif n == 2: contact = roster[args[1]] if contact is None: return False groups = sorted(contact.groups) try: groups.remove('none') except ValueError: pass return Completion( the_input.new_completion, groups, n, '', quotify=True) return False
def presence(self, the_input): """ Completion of /presence """ arg = the_input.get_argument_position() if arg == 1: to_suggest = [] for bookmark in self.core.bookmarks: tab = self.core.get_tab_by_name(bookmark.jid, tabs.MucTab) if tab is not None and tab.joined: to_suggest.append(bookmark.jid) return Completion(the_input.auto_completion, roster.jids() + to_suggest, '', quotify=True) elif arg == 2: return Completion(the_input.auto_completion, [status for status in POSSIBLE_SHOW], '', quotify=True)
def completion_groupmove(self, the_input): args = shell_split(the_input.text) n = the_input.get_argument_position() if n == 1: jids = sorted(jid for jid in roster.jids()) return Completion( the_input.new_completion, jids, n, '', quotify=True) elif n == 2: contact = roster[args[1]] if not contact: return False groups = list(contact.groups) if 'none' in groups: groups.remove('none') return Completion( the_input.new_completion, groups, n, '', quotify=True) elif n == 3: groups = sorted(group for group in roster.groups) return Completion( the_input.new_completion, groups, n, '', quotify=True) return False
def presence(self, the_input): """ Completion of /presence """ arg = the_input.get_argument_position() if arg == 1: to_suggest = [] for bookmark in self.core.bookmarks: tab = self.core.tabs.by_name_and_class(bookmark.jid, tabs.MucTab) if tab is not None and tab.joined: to_suggest.append(bookmark.jid) return Completion( the_input.auto_completion, roster.jids() + to_suggest, '', quotify=True) elif arg == 2: return Completion( the_input.auto_completion, [status for status in POSSIBLE_SHOW], '', quotify=True)
def command_deny(self, args): """ /deny [jid] Denies a JID from our roster """ if not args: item = self.roster_win.selected_row if isinstance(item, Contact): jid = item.bare_jid else: self.core.information('No subscription to deny') return else: jid = safeJID(args[0]).bare if not jid in [jid for jid in roster.jids()]: self.core.information('No subscription to deny') return contact = roster[jid] if contact: contact.unauthorize() self.core.information('Subscription to %s was revoked' % jid, 'Roster')
def command_deny(self, args): """ /deny [jid] Denies a JID from our roster """ if not args: item = self.roster_win.selected_row if isinstance(item, Contact): jid = item.bare_jid else: self.core.information('No subscription to deny', 'Warning') return else: jid = safeJID(args[0]).bare if jid not in [jid for jid in roster.jids()]: self.core.information('No subscription to deny', 'Warning') return contact = roster[jid] if contact: contact.unauthorize() self.core.information('Subscription to %s was revoked' % jid, 'Roster')
def block(self, the_input) -> Optional[Completion]: """ Completion for /block """ if the_input.get_argument_position() == 1: current_tab = self.core.tabs.current_tab chattabs = ( tabs.ConversationTab, tabs.StaticConversationTab, tabs.DynamicConversationTab, ) tabjid = [] # type: List[JID] if isinstance(current_tab, chattabs): tabjid = [current_tab.jid.bare] jids = roster.jids() jids += tabjid return Completion(the_input.new_completion, jids, 1, '', quotify=False) return None
def completion_remove(self, the_input): """ Completion for /remove """ jids = [jid for jid in roster.jids()] return Completion(the_input.auto_completion, jids, '', quotify=False)
def completion_remove(self, the_input): """ Completion for /remove """ jids = [jid for jid in roster.jids()] return Completion(the_input.auto_completion, jids, '', quotify=False)