async def subscribe(self, channel: int, world: str, subscription: str, conditions: typing.Optional[str] = 'all'): """ Subscribe a channel to hunt events """ # Validate world world = world.strip().lower().title() if world not in Worlds.get_worlds(): await self.bot.get_channel(channel).send( "No world by that name found - please check your spelling and try again" ) return # Validate subscription channel try: sub = getattr(self, f"""SUB_{subscription.upper()}""") except AttributeError: await self.bot.get_channel(channel).send( "Invalid subscription provided, valid subscriptions are: shb_a, shb_s, sb_a, sb_s, hw_a, hw_s, arr_a, arr_s" ) return # Validate conditions if conditions == 'all': conditions = list(self.CONDITIONS) else: conditions = conditions.replace(' ', '').lower().split(',') _invalid_conditions = set(conditions) - set(self.CONDITIONS) if _invalid_conditions: await self.bot.get_channel(channel).send( "Invalid conditions supplied: " + str(_invalid_conditions)) return # Already subscribed? if Subscriptions.select().where( (Subscriptions.channel_id == channel) & (Subscriptions.world == world) & (Subscriptions.category == sub)).count(): await self.bot.get_channel(channel).send( "This channel is already subscribed to this feed. If you want unsubscribe, use the unsub command" ) return for condition in conditions: Subscriptions.insert({ 'channel_id': channel, 'world': world, 'category': sub, 'event': condition }).execute() await self.bot.get_channel(channel).send( f"""Subscribed channel to {str(sub).replace('_', ' ').title()}-Rank hunts on {world}""" ) self._reload()
async def subscribe_all(self, datacenter: str, channel: int, subscription: str, conditions: typing.Optional[str] = 'all'): """ Subscribe a channel to hunt events on all worlds """ # Validate subscription channel try: sub = getattr(self, f"""SUB_{subscription.upper()}""") except AttributeError: await self.bot.get_channel(channel).send( "Invalid subscription provided, valid subscriptions are: sb_a, sb_s, hw_a, hw_s, arr_a, arr_s" ) return # Validate conditions if conditions == 'all': conditions = list(self.CONDITIONS) else: conditions = conditions.replace(' ', '').lower().split(',') _invalid_conditions = set(conditions) - set(self.CONDITIONS) if _invalid_conditions: await self.bot.get_channel(channel).send( "Invalid conditions supplied: " + str(_invalid_conditions)) return # Validate datacenter datacenter = datacenter.strip().lower().title() if datacenter not in Worlds.get_datacenters(): await self.bot.get_channel(channel).send( f"Invalid datacenter provided, valid datacenters are: {', '.join(Worlds.get_datacenters())}" ) return for world in Worlds.get_datacenter_worlds(datacenter): # Already subscribed? Overwrite it Subscriptions.delete().where((Subscriptions.channel_id == channel) & (Subscriptions.world == world) & (Subscriptions.category == sub)) for condition in conditions: Subscriptions.insert({ 'channel_id': channel, 'world': world, 'category': sub, 'event': condition }).execute() await self.bot.get_channel(channel).send( f"""Subscribed channel to {str(sub).replace('_', ' ').title()}-Rank hunts on **all worlds**""" ) self._reload()