Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 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)
Beispiel #6
0
 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
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
 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)
Beispiel #12
0
 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
Beispiel #13
0
 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)
Beispiel #14
0
 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)
Beispiel #15
0
 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)
Beispiel #16
0
 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
Beispiel #17
0
 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)
Beispiel #18
0
 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)
Beispiel #19
0
 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)
Beispiel #20
0
 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)
Beispiel #21
0
 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)
Beispiel #22
0
 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)
Beispiel #23
0
 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
Beispiel #24
0
 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)
Beispiel #25
0
 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
Beispiel #26
0
 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)
Beispiel #27
0
    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')
Beispiel #28
0
    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')
Beispiel #29
0
    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
Beispiel #30
0
 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)
Beispiel #31
0
 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)