Beispiel #1
0
    def on_show_chat_feed(self, *args):

        if self.RoomFeed.get_active():
            self.frame.chatrooms.join_room(slskmessages.JoinRoom("Public "))
            self.frame.np.queue.append(slskmessages.JoinPublicRoom())
            return

        self.frame.np.queue.append(slskmessages.LeavePublicRoom())
        self.frame.chatrooms.leave_room(
            slskmessages.LeaveRoom("Public "))  # Faking protocol msg
Beispiel #2
0
    def on_leave(self, *args):

        if self.leaving:
            return

        self.leaving = True

        if self.room in config.sections["columns"]["chat_room"]:
            del config.sections["columns"]["chat_room"][self.room]

        if not self.meta:
            self.frame.np.queue.append(slskmessages.LeaveRoom(self.room))
        else:
            if self.room == 'Public ':
                self.frame.np.queue.append(slskmessages.LeavePublicRoom())
                self.chatrooms.leave_room(slskmessages.LeaveRoom(
                    self.room))  # Faking protocol msg
            else:
                log.add_warning(_("Unknown meta chatroom closed"))

        self.frame.np.pluginhandler.leave_chatroom_notification(self.room)
Beispiel #3
0
    def on_leave(self, *args):

        if self.leaving:
            return

        self.leaving = True

        if self.room in config.sections["columns"]["chat_room"]:
            del config.sections["columns"]["chat_room"][self.room]

        if not self.meta:
            self.frame.np.queue.append(slskmessages.LeaveRoom(self.room))

        elif self.room == 'Public ':
            self.chatrooms.roomlist.RoomFeed.set_active(False)

        self.frame.np.pluginhandler.leave_chatroom_notification(self.room)
Beispiel #4
0
 def on_popup_leave(self, *args):
     self.frame.np.queue.append(slskmessages.LeaveRoom(self.popup_room))
Beispiel #5
0
    def on_enter(self, widget):

        text = widget.get_text()

        if not text:
            widget.set_text("")
            return

        if is_alias(text):
            alias_text = expand_alias(text)

            if not alias_text:
                log.add(_('Alias "%s" returned nothing'), text)
                return

            text = alias_text

        s = text.split(" ", 1)
        cmd = s[0]

        # Remove empty items created by split, if command ended with a space, e.g. '/ctcpversion '
        if len([i for i in s if i]) == 2:
            arg_self = args = s[1]
        else:
            if not self.is_chatroom:
                arg_self = self.entity
            else:
                arg_self = ""

            args = ""

        if cmd[:1] == "/" and cmd[:2] != "//" and cmd + " " not in self.command_list:
            log.add(_("Command %s is not recognized"), text)
            return

        if cmd in ("/alias", "/al"):
            append_line(self.textview, add_alias(args), None, "")

            if config.sections["words"]["aliases"]:
                self.frame.update_completions()

        elif cmd in ("/unalias", "/un"):
            append_line(self.textview, unalias(args), None, "")

            if config.sections["words"]["aliases"]:
                self.frame.update_completions()

        elif cmd in ("/w", "/whois", "/info"):
            if arg_self:
                self.frame.np.userinfo.request_user_info(arg_self)
                self.frame.change_main_page("userinfo")

        elif cmd in ("/b", "/browse"):
            if arg_self:
                self.frame.np.userbrowse.browse_user(arg_self)
                self.frame.change_main_page("userbrowse")

        elif cmd == "/ip":
            if arg_self:
                self.frame.np.request_ip_address(arg_self)

        elif cmd == "/pm":
            if args:
                self.frame.np.privatechats.show_user(args)
                self.frame.change_main_page("private")

        elif cmd in ("/m", "/msg"):
            if args:
                s = args.split(" ", 1)
                user = s[0]
                if len(s) == 2:
                    msg = s[1]
                else:
                    msg = None
                self.frame.np.privatechats.show_user(args)
                self.frame.np.privatechats.send_message(user, msg)
                self.frame.change_main_page("private")

        elif cmd in ("/s", "/search"):
            if args:
                self.frame.SearchMethod.set_active(0)
                self.frame.SearchEntry.set_text(args)
                self.frame.on_search(self.frame.SearchEntry)
                self.frame.change_main_page("search")

        elif cmd in ("/us", "/usearch"):
            s = args.split(" ", 1)
            if len(s) == 2:
                self.frame.SearchMethod.set_active(3)
                self.frame.SearchEntry.set_text(s[1])
                self.frame.UserSearchEntry.set_text(s[0])
                self.frame.on_search(self.frame.SearchEntry)
                self.frame.change_main_page("search")

        elif cmd in ("/rs", "/rsearch"):
            if args:
                self.frame.SearchMethod.set_active(2)
                self.frame.SearchEntry.set_text(args)
                self.frame.on_search(self.frame.SearchEntry)
                self.frame.change_main_page("search")

        elif cmd in ("/bs", "/bsearch"):
            if args:
                self.frame.SearchMethod.set_active(1)
                self.frame.SearchEntry.set_text(args)
                self.frame.on_search(self.frame.SearchEntry)
                self.frame.change_main_page("search")

        elif cmd in ("/j", "/join"):
            if args:
                self.frame.np.queue.append(slskmessages.JoinRoom(args))

        elif cmd in ("/l", "/leave", "/p", "/part"):
            if args:
                self.frame.np.queue.append(slskmessages.LeaveRoom(args))
            else:
                self.frame.np.queue.append(slskmessages.LeaveRoom(self.entity))

        elif cmd in ("/ad", "/add", "/buddy"):
            if args:
                self.frame.np.userlist.add_user(args)

        elif cmd in ("/rem", "/unbuddy"):
            if args:
                self.frame.np.userlist.remove_user(args)

        elif cmd == "/ban":
            if args:
                self.frame.np.network_filter.ban_user(args)

        elif cmd == "/ignore":
            if args:
                self.frame.np.network_filter.ignore_user(args)

        elif cmd == "/ignoreip":
            if args:
                self.frame.np.network_filter.ignore_ip(args)

        elif cmd == "/unban":
            if args:
                self.frame.np.network_filter.unban_user(args)

        elif cmd == "/unignore":
            if args:
                self.frame.np.network_filter.unignore_user(args)

        elif cmd == "/ctcpversion":
            if arg_self:
                self.frame.np.privatechats.show_user(arg_self)
                self.frame.np.privatechats.send_message(
                    arg_self, self.frame.privatechats.CTCP_VERSION, bytestring=True)

        elif cmd in ("/clear", "/cl"):
            self.textview.get_buffer().set_text("")

        elif cmd in ("/a", "/away"):
            self.frame.on_away()

        elif cmd in ("/q", "/quit", "/exit"):
            self.frame.on_quit()
            return  # Avoid gsignal warning

        elif cmd in ("/c", "/close"):
            self.frame.privatechats.users[self.entity].on_close()

        elif cmd == "/now":
            self.frame.np.now_playing.display_now_playing(
                callback=lambda np_message: self.send_message(self.entity, np_message))

        elif cmd == "/rescan":
            # Rescan public shares if needed
            if not config.sections["transfers"]["friendsonly"] and config.sections["transfers"]["shared"]:
                self.frame.on_rescan()

            # Rescan buddy shares if needed
            if config.sections["transfers"]["enablebuddyshares"]:
                self.frame.on_buddy_rescan()

        elif cmd in ("/tick", "/t"):
            self.frame.np.queue.append(slskmessages.RoomTickerSet(self.entity, args))

        elif cmd == "/tickers":
            self.frame.chatrooms.joinedrooms[self.entity].show_tickers()

        elif cmd == "/toggle":
            if args:
                self.frame.np.pluginhandler.toggle_plugin(args)

        elif cmd == "/me":
            self.send_message(self.entity, text)

        elif text[:2] == "//":
            text = text[1:]
            self.send_message(self.entity, text)

        elif cmd[:1] == "/" and self.is_chatroom:
            self.frame.np.pluginhandler.trigger_public_command_event(self.entity, cmd[1:], args)

        elif cmd[:1] == "/" and not self.is_chatroom:
            self.frame.np.pluginhandler.trigger_private_command_event(self.entity, cmd[1:], args)

        else:
            self.send_message(self.entity, text)

        self.entry.set_text("")
Beispiel #6
0
    def on_enter(self, *_args):

        if not self.frame.np.logged_in:
            return

        text = self.entry.get_text()

        if not text:
            return

        if is_alias(text):
            alias_text = get_alias(text)

            if not alias_text:
                log.add(_('Alias "%s" returned nothing'), text)
                return

            text = alias_text

        is_double_slash_cmd = text.startswith("//")
        is_single_slash_cmd = (text.startswith("/")
                               and not is_double_slash_cmd)

        if not is_single_slash_cmd or text.startswith("/me"):
            # Regular chat message (/me is sent as plain text)

            self.entry.set_text("")

            if is_double_slash_cmd:
                # Remove first slash and send the rest of the command as plain text
                text = text[1:]

            self.send_message(self.entity, text)
            return

        cmd_split = text.split(maxsplit=1)
        cmd = cmd_split[0]

        if cmd + " " not in self.command_list:
            log.add(_("Command %s is not recognized"), cmd)
            return

        # Clear chat entry
        self.entry.set_text("")

        if len(cmd_split) == 2:
            args = arg_self = cmd_split[1]
        else:
            args = ""
            arg_self = "" if self.is_chatroom else self.entity

        if cmd in ("/alias", "/al"):
            parent = self.frame.np.chatrooms if self.is_chatroom else self.frame.np.privatechats
            parent.echo_message(self.entity, add_alias(args))

            if config.sections["words"]["aliases"]:
                self.frame.update_completions()

        elif cmd in ("/unalias", "/un"):
            parent = self.frame.np.chatrooms if self.is_chatroom else self.frame.np.privatechats
            parent.echo_message(self.entity, unalias(args))

            if config.sections["words"]["aliases"]:
                self.frame.update_completions()

        elif cmd in ("/w", "/whois", "/info"):
            if arg_self:
                self.frame.np.userinfo.request_user_info(arg_self)
                self.frame.change_main_page("userinfo")

        elif cmd in ("/b", "/browse"):
            if arg_self:
                self.frame.np.userbrowse.browse_user(arg_self)
                self.frame.change_main_page("userbrowse")

        elif cmd == "/ip":
            if arg_self:
                self.frame.np.request_ip_address(arg_self)

        elif cmd == "/pm":
            if args:
                self.frame.np.privatechats.show_user(args)
                self.frame.change_main_page("private")

        elif cmd in ("/m", "/msg"):
            if args:
                args_split = args.split(" ", maxsplit=1)
                user = args_split[0]
                msg = None

                if len(args_split) == 2:
                    msg = args_split[1]

                if msg:
                    self.frame.np.privatechats.show_user(user)
                    self.frame.np.privatechats.send_message(user, msg)
                    self.frame.change_main_page("private")

        elif cmd in ("/s", "/search"):
            if args:
                self.frame.np.search.do_search(args, "global")
                self.frame.change_main_page("search")

        elif cmd in ("/us", "/usearch"):
            args_split = args.split(" ", maxsplit=1)

            if len(args_split) == 2:
                self.frame.np.search.do_search(args_split[1],
                                               "user",
                                               user=args_split[0])
                self.frame.change_main_page("search")

        elif cmd in ("/rs", "/rsearch"):
            if args:
                self.frame.np.search.do_search(args, "rooms")
                self.frame.change_main_page("search")

        elif cmd in ("/bs", "/bsearch"):
            if args:
                self.frame.np.search.do_search(args, "buddies")
                self.frame.change_main_page("search")

        elif cmd in ("/j", "/join"):
            if args:
                self.frame.np.queue.append(slskmessages.JoinRoom(args))

        elif cmd in ("/l", "/leave", "/p", "/part"):
            if args:
                self.frame.np.queue.append(slskmessages.LeaveRoom(args))
            else:
                self.frame.np.queue.append(slskmessages.LeaveRoom(self.entity))

        elif cmd in ("/ad", "/add", "/buddy"):
            if args:
                self.frame.np.userlist.add_user(args)

        elif cmd in ("/rem", "/unbuddy"):
            if args:
                self.frame.np.userlist.remove_user(args)

        elif cmd == "/ban":
            if args:
                self.frame.np.network_filter.ban_user(args)

        elif cmd == "/ignore":
            if args:
                self.frame.np.network_filter.ignore_user(args)

        elif cmd == "/ignoreip":
            if args:
                self.frame.np.network_filter.ignore_ip(args)

        elif cmd == "/unban":
            if args:
                self.frame.np.network_filter.unban_user(args)

        elif cmd == "/unignore":
            if args:
                self.frame.np.network_filter.unignore_user(args)

        elif cmd == "/ctcpversion":
            if arg_self:
                self.frame.np.privatechats.show_user(arg_self)
                self.frame.np.privatechats.send_message(
                    arg_self, self.frame.np.privatechats.CTCP_VERSION)

        elif cmd in ("/clear", "/cl"):
            if self.is_chatroom:
                parent = self.frame.chatrooms.pages[self.entity]
            else:
                parent = self.frame.privatechat.pages[self.entity]

            parent.chat_textview.clear()

        elif cmd in ("/a", "/away"):
            self.frame.on_away()

        elif cmd in ("/q", "/quit", "/exit"):
            self.frame.on_quit()

        elif cmd in ("/c", "/close"):
            self.frame.privatechat.pages[self.entity].on_close()

        elif cmd == "/now":
            self.frame.np.now_playing.display_now_playing(
                callback=lambda np_message: self.send_message(
                    self.entity, np_message))

        elif cmd == "/rescan":
            self.frame.np.shares.rescan_shares()

        elif cmd == "/toggle":
            if args:
                self.frame.np.pluginhandler.toggle_plugin(args)

        elif self.is_chatroom:
            self.frame.np.pluginhandler.trigger_public_command_event(
                self.entity, cmd[1:], args)

        elif not self.is_chatroom:
            self.frame.np.pluginhandler.trigger_private_command_event(
                self.entity, cmd[1:], args)
Beispiel #7
0
 def on_popup_leave(self, widget):
     self.frame.np.queue.put(slskmessages.LeaveRoom(self.popup_room))
Beispiel #8
0
 def request_leave_public_room(self):
     self.queue.append(slskmessages.LeavePublicRoom())
     self.leave_room(slskmessages.LeaveRoom("Public "))
Beispiel #9
0
 def request_leave_room(self, room):
     self.queue.append(slskmessages.LeaveRoom(room))