Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def _prefix_setter(self, item):
if inspect.iscoroutinefunction(item):
item = await item()
elif callable(item):
item = item()
if isinstance(item, (list, tuple)):
self.prefixes = item
elif isinstance(item, str):
self.prefixes = [item]
else:
raise ClientError('Invalid prefix provided. A list, tuple, str or callable returning either should be used.')
async def _get_prefixes(self, message):
prefix = ret = self.prefixes
if callable(prefix):
ret = prefix(self, message.content)
if inspect.isawaitable(ret):
ret = await ret
if isinstance(ret, (list, tuple)):
ret = [p for p in ret if p]
if isinstance(ret, str):
ret = [ret]
if not ret:
raise ClientError('Invalid prefix provided.')
return ret
async def _prefix_setter(self, item):
if inspect.iscoroutinefunction(item):
item = await item()
elif callable(item):
item = item()
if isinstance(item, (list, tuple)):
self.prefixes = item
elif isinstance(item, str):
self.prefixes = [item]
else:
raise ClientError('Invalid prefix provided. A list, tuple, str or callable returning either should be used.')
for x in self.connections.values():
if len(x._topics) == 50:
continue
elif len(x._topics) + len(topics) > 50:
continue
if x._websocket:
return x
await x.connect()
if x._websocket.open:
return x
raise WSConnectionFailure('Unable to delegate WebSocket. Please try again.')
raise ClientError('Maximum PubSub connections established.')
async def _get_prefixes(self, message):
prefix = ret = self.prefixes
if callable(prefix):
ret = prefix(self, message.content)
if inspect.isawaitable(ret):
ret = await ret
if isinstance(ret, (list, tuple)):
ret = [p for p in ret if p]
if isinstance(ret, str):
ret = [ret]
if not ret:
raise ClientError('Invalid prefix provided.')
return ret