Esempio n. 1
0
 async def clear_subscriptions(self, channel: int) -> None:
     """
     Clear all subscriptions for the specified channel
     """
     Subscriptions.delete().where(
         Subscriptions.channel_id == channel).execute()
     self._reload()
Esempio n. 2
0
    async def unsubscribe(self, channel: int, world: str, subscription: str):
        """
        Unsubscribe a channel from hunt events
        """
        world = world.strip().lower().title()
        if world not in self.WORLDS:
            await self.bot.get_channel(channel).send(
                "No world by that name found on the Crystal DC - please check your spelling and try again"
            )
            return

        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

        Subscriptions.delete().where(
                (Subscriptions.channel_id == channel)
                & (Subscriptions.world == world)
                & (Subscriptions.category == sub)
        ).execute()

        await self.bot.get_channel(channel).send(f"""Unsubscribed channel from {str(sub).replace('_', ' ').title()}-Rank hunts on {world}""")
        self._reload()
Esempio n. 3
0
 async def _send_sub_message(self, message, embed: discord.Embed, sub: Subscriptions) -> typing.Optional[discord.Message]:
     """
     Attempt to send a subscription message
     """
     try:
         return await self.bot.get_channel(sub.channel_id).send(message, embed=embed)
     except AttributeError:
         self._log.warning(f"Subscription channel is no longer active; removing channel {sub.channel_id}")
         Subscriptions.delete().where(Subscriptions.channel_id == sub.channel_id).execute()
     except discord.errors.Forbidden:
         self._log.warning(f"No permission to send to channel {sub.channel_id}")
Esempio n. 4
0
    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()