<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def name(self, ch, firstwordonly=False):
 """Return channel name for ch. ch is the channel name or the index number for the channel name, 0-based. ch: str or int. The channel name or indexed number. firstwordonly: bool or "pattern". If True, return only the first non-spaced word in the name. If a string, use as a re-pattern to re.findall and return the first element found. There will be error if no match. r'\w+' is good pattern for excluding leading and trailing obscure characters. Returned channel name is the fallback string if "custom" names are not available. """


        names = self.chnames or self.chnames_0
        i = self._key(ch)

        if not firstwordonly:
            return names[i]
        elif firstwordonly is True or firstwordonly == 1:
            return names[i].split()[0].strip()

        # According to user pattern
        return re.findall(firstwordonly, names[i])[0]