Beispiel #1
0
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Responds with current time in UTC.
     """
     now = datetime.utcnow().isoformat(sep=' ', timespec='seconds')
     respond.to_sender(f'The time is now {now} UTC')
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        If a previous !request returned more than one match, this command allows to pick an exact match.

        Picking an exact match is subject to the same rules as request.

        Position can be used as a shorthand, e.g. instead of "!pick 1", you can just use "!1".

        You can change your pick as long as it is still in the queue, unless you are ADMIN.
        Instead, ADMIN can !pick for the last !next result, even if it's not theirs.
        Pick for !next can be changed with a follow-up !pick.
        """
        choice = self.__choice(alias, args)
        if not choice:
            return respond.to_sender(f'Try !pick 1-{self.__max_pick}')

        picker = Picker(user)
        with self._queue:
            request = self._queue.find(picker.needs_picking)
            if not request:
                if user.is_admin:
                    return self.__pick_last(choice, respond)

                request = self._queue.find(picker.has_pick_for)
                if not request:
                    return True

            chosen = request.pick(choice)
            if not chosen:
                return respond.to_sender(
                    f'{choice} is not available; max: {len(request)}')

            position = self._queue.offer(chosen, picker.last_pick)
            return self._validate_position(position, chosen, respond)
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Prints all the requests in the request queue memory.
     """
     requests = ', '.join(match.short
                          for match in self.__queue.memory()) or 'none'
     respond.to_sender(f'Requests played: {requests}')
Beispiel #4
0
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Stops the bot from executing any further commands unless the user is ADMIN.
     """
     is_admin_only = self.__commander.flip_admin_switch()
     message = 'is now' if is_admin_only else 'no longer'
     respond.to_sender(f'Bot {message} in ADMIN only mode')
Beispiel #5
0
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Tries to index CDLCs from customsforge into elasticsearch.
     """
     has_loaded = self.__loaderer.load()
     message = '' if has_loaded else ' could not be'
     respond.to_sender(f'CDLCs{message} indexed')
     return not has_loaded
Beispiel #6
0
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Prints the list of hosts for the channel.
     """
     streamer = self.__users.admin().nick
     hosts = self.__twitch.hosts(streamer)
     message = ', '.join(hosts)
     respond.to_sender(f'Hosts: {message}')
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Prints the last song that was popped from the queue.
        """
        last = self.__queue.last()
        if not last:
            return respond.to_sender('No requests have been played yet')

        respond.to_sender(f'Last: {last} by {last.user}')
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     """
     Prints the request queue. If the queue is big, may choose to print only some top elements.
     """
     copy = self.__queue[:]
     total = len(copy)
     visible = min(self.__max_print, total)
     requests = ', '.join(match.short
                          for match in copy[:visible]) or 'empty'
     respond.to_sender(f'Playlist ({visible}/{total}): {requests}')
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Move the latest request by user with given nick to the top of the queue.
        """
        nick, space, ignore = args.partition(' ')
        request = self.__queue.bump(lambda m: m.is_from(nick))
        if not request:
            return respond.to_sender(f'No requests by <{nick}> in queue')

        respond.to_sender(
            f'Request {request} by {request.user} is now in position 1')
    def __pick_last(self, choice: int, respond: ResponseHook) -> bool:
        request = self._queue.last()
        if not request:
            return respond.to_sender('Nothing to pick')

        chosen = request.pick(choice)
        if not chosen:
            return respond.to_sender(
                f'{choice} is not available; max: {len(request)}')

        self._queue.mandela(chosen)
        respond.to_sender(f'Next: {chosen}')
        if self.__job and self.__job.supports(chosen.exact.link):
            self.__job.handle(chosen.exact.link)
Beispiel #11
0
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook):
        """
        Sets manual rank to the user.
        """
        rank, nick = self.__rank_and_nick(alias, args)
        if not rank or not nick:
            return respond.to_sender(f'Try !{self.the_alias()} RANK NICK')

        try:
            rank = UserRank[rank.upper()]
        except KeyError:
            return respond.to_sender(f'{rank.upper()} is not a valid rank')

        rank_set = self.__users.set_manual(nick, rank)
        message = f'{nick} is now {rank.name}' if rank_set else 'Rank could not be set'
        respond.to_sender(message)
        return not rank_set
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Pop the next song in request queue. After calling this, it is considered played.

        If the request was not exact, ADMIN rank can then call !pick to make it exact.

        Only the picked value will be considered played in that case.
        """
        request = self.__queue.next()
        if not request:
            return respond.to_sender('Request queue is empty')

        if request.is_exact:
            respond.to_sender(f'Next: {request} by {request.user}')
            if self.__job and self.__job.supports(request.exact.link):
                self.__job.handle(request.exact.link)
        else:
            respond.to_sender(
                f'Pick for {request} by {request.user}: {pick_format(request)}'
            )
Beispiel #13
0
 def __joke_time(self, respond: ResponseHook):
     respond.to_sender(
         'First, a joke. What do you get when you cross an owl with a bungee cord?'
     )
     time.sleep(12)
     respond.to_sender('My ass. Nyah, he he, he he, he ha')
     time.sleep(5)
     respond.to_sender('ENOUGH')
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Adds any matching songs to the request queue. Query is taken as a literal search string. Can be empty.

        If multiple matches are found, you will be able to use !pick to choose the most relevant ones.

        The following rules do NOT apply to ADMIN rank:
        * If you already had a song in the queue, replaces it instead.
        * If the song is already in the queue, does not add it.
        * If the song has been played already, does not add it.
        """
        matches = list(CustomDLC.search(query=args)[:self.__max_search])
        if not matches:
            return respond.to_sender(f'No matches for <{args}>')

        playable = list(filter(lambda match: match.is_playable, matches))
        if not playable:
            unplayable = '; '.join(match.short for match in matches)
            return respond.to_sender(
                f'Matches for <{args}> not playable: {unplayable}')

        request = Match(user, args, *playable[:self.__max_pick])
        return self._enqueue_request(user, request, respond)
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Same as !request, but automatically picks from ALL possible matches. This includes matches that cannot
        be picked with !pick due to lower relevance. Usually best used with artists, e.g. !random acdc
        """
        with self._queue:
            match = CustomDLC.random(args, *self.__exclusions())
            if not match:
                without_exclusions = CustomDLC.random_pool(query=args).count()
                message = f'Everything already played or enqueued' if without_exclusions else f'No matches'
                return respond.to_sender(f'{message} for <{args}>')

            request = Match(user, args, match)
            return self._enqueue_request(user, request, respond)
    def _validate_position(self, position: int, request: Match,
                           respond: ResponseHook) -> bool:
        if not position:
            return respond.to_sender(f'Already played {request}')

        if position < 0:
            return respond.to_sender(
                f'Request {request} already in queue position {-position}')

        respond.to_sender(
            f'Your request for {request} is now in position {position}')
        if request.is_exact:
            if request.exact.is_official:
                return respond.to_sender(
                    'WARNING! This song is official, so it may not be playable. Ask or try again!'
                )
        else:
            respond.to_sender(f'To pick exact: {pick_format(request)}')
Beispiel #17
0
 def execute(self, user: User, alias: str, args: str, respond: ResponseHook):
     """
     Prints all commands available to the user's rank.
     """
     commands = ', '.join(self.__commands_for_rank(user))
     respond.to_sender(f'Commands: {commands}')
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     respond.to_sender('Thanks for following!')
 def execute(self, user: User, alias: str, args: str,
             respond: ResponseHook):
     return respond.to_sender('I fail')