Example #1
0
    async def handle_whitelist(self, message, option, username):
        """
        Usage: {command_prefix}whitelist [ + | - | add | remove ] @UserName
        Adds or removes the user to the whitelist. When the whitelist is enabled,
        whitelisted users are permitted to use bot commands.
        """
        if message.author.id != self.config.owner_id:
            return

        user_id = extract_user_id(username)
        if not user_id:
            raise CommandError('Invalid user specified')

        if option not in ['+', '-', 'add', 'remove']:
            raise CommandError('Invalid option "%s" specified, use +, -, add, or remove' % option)

        if option in ['+', 'add']:
            self.whitelist.add(user_id)
            write_file('./config/whitelist.txt', self.whitelist)

            return Response('user has been added to the whitelist', reply=True, delete_after=10)

        else:
            if user_id not in self.whitelist:
                return Response('user is not in the whitelist', reply=True, delete_after=10)

            else:
                self.whitelist.remove(user_id)
                write_file('./config/whitelist.txt', self.whitelist)

                return Response('user has been removed from the whitelist', reply=True, delete_after=10)
Example #2
0
    async def handle_blacklist(self, message, username):
        """
        Usage: {command_prefix}blacklist @UserName
        Adds the user to the blacklist, forbidding them from using bot commands.
        """
        user_id = extract_user_id(username)
        if not user_id:
            raise CommandError('Invalid user specified')

        self.blacklist.add(str(user_id))
        write_file('./config/blacklist.txt', self.blacklist)
Example #3
0
    async def handle_whitelist(self, message, username):
        """
        Usage: {command_prefix}whitelist @UserName
        Adds the user to the whitelist, permitting them to add songs.
        """
        user_id = extract_user_id(username)
        if not user_id:
            raise CommandError('Invalid user specified')

        self.whitelist.add(str(user_id))
        write_file('./config/whitelist.txt', self.whitelist)
Example #4
0
    async def cmd_blacklist(self, message, user_mentions, option, something):
        """
        Usage:
            {command_prefix}blacklist [ + | - | add | remove ] @UserName [@UserName2 ...]

        Add or remove users to the blacklist.
        Blacklisted users are forbidden from using bot commands.
        """

        if not user_mentions:
            raise exceptions.CommandError("No users listed.", expire_in=20)

        if option not in ['+', '-', 'add', 'remove']:
            raise exceptions.CommandError(
                'Invalid option "%s" specified, use +, -, add, or remove' %
                option,
                expire_in=20)

        for user in user_mentions.copy():
            if user.id == self.config.owner_id:
                print("[Commands:Blacklist] The owner cannot be blacklisted.")
                user_mentions.remove(user)

        old_len = len(self.blacklist)

        if option in ['+', 'add']:
            self.blacklist.update(user.id for user in user_mentions)

            write_file(self.config.blacklist_file, self.blacklist)

            return Response('%s users have been added to the blacklist' %
                            (len(self.blacklist) - old_len),
                            reply=True,
                            delete_after=10)

        else:
            if self.blacklist.isdisjoint(user.id for user in user_mentions):
                return Response('none of those users are in the blacklist.',
                                reply=True,
                                delete_after=10)

            else:
                self.blacklist.difference_update(user.id
                                                 for user in user_mentions)
                write_file(self.config.blacklist_file, self.blacklist)

                return Response(
                    '%s users have been removed from the blacklist' %
                    (old_len - len(self.blacklist)),
                    reply=True,
                    delete_after=10)
Example #5
0
    async def on_player_finished_playing(self, player, **_):
        if not player.playlist.entries and not player.current_entry and self.config.auto_playlist:
            while self.autoplaylist:
                song_url = choice(self.autoplaylist)
                info = await self.downloader.safe_extract_info(
                    player.playlist.loop,
                    song_url,
                    download=False,
                    process=False)

                if not info:
                    self.autoplaylist.remove(song_url)
                    self.safe_print(
                        "[Info] Removing unplayable song from autoplaylist: %s"
                        % song_url)
                    write_file(self.config.auto_playlist_file,
                               self.autoplaylist)
                    continue

                if info.get('entries',
                            None):  # or .get('_type', '') == 'playlist'
                    pass  # Wooo playlist
                    # Blarg how do I want to do this

                # TODO: better checks here
                try:
                    await player.playlist.add_entry(song_url,
                                                    channel=None,
                                                    author=None)
                except exceptions.ExtractionError as e:
                    print("Error adding song from autoplaylist:", e)
                    continue

                break

            if not self.autoplaylist:
                print(
                    "[Warning] No playable songs in the autoplaylist, disabling."
                )
                self.config.auto_playlist = False
Example #6
0
    async def handle_blacklist(self, message, option, username):
        """
        Usage: {command_prefix}blacklist [ + | - | add | remove ] @UserName
        Adds or removes the user to the blacklist. Blacklisted users are forbidden from
        using bot commands. Blacklisting a user also removes them from the whitelist.
        """
        if message.author.id != self.config.owner_id:
            return

        user_id = extract_user_id(username)
        if not user_id:
            raise CommandError('Invalid user specified')

        if str(user_id) == self.config.owner_id:
            return Response("The owner cannot be blacklisted.", delete_after=10)

        if option not in ['+', '-', 'add', 'remove']:
            raise CommandError('Invalid option "%s" specified, use +, -, add, or remove' % option)

        if option in ['+', 'add']:
            self.blacklist.add(user_id)
            write_file('./config/blacklist.txt', self.blacklist)

            if user_id in self.whitelist:
                self.whitelist.remove(user_id)
                write_file('./config/whitelist.txt', self.whitelist)
                return Response('user has been added to the blacklist and removed from the whitelist', reply=True, delete_after=10)

            else:
                return Response('user has been added to the blacklist', reply=True, delete_after=10)

        else:
            if user_id not in self.blacklist:
                return Response('user is not in the blacklist', reply=True, delete_after=10)

            else:
                self.blacklist.remove(user_id)
                write_file('./config/blacklist.txt', self.blacklist)

                return Response('user has been removed from the blacklist', reply=True, delete_after=10)