예제 #1
0
 async def get_channel(self, cid, cached=False, fetched=True):
     """
     Gets a channel from the core client
     or from the cache if one exists in the Cacher class.
     :type cid: int
     :type cached: bool
     :type fetched: bool
     :rtype: discord.TextChannel or discord.CategoryChannel or discord.VoiceChannel
     """
     cacheable = False
     cache_key = f'get_chn_{cid}'
     fh = get_fetch_helper(self)
     if cached and self.cfg.cache.type not in ['mixed', 'redis']:
         cacheable = True
         out = await self.cache.get_cache(cache_key)
         if not out:
             out = super().get_channel(cid)
     else:
         out = super().get_channel(cid)
     if not out and fetched:
         # noinspection PyBroadException
         try:
             out = await fh.fetch_channel(cid)
         except Exception:
             out = None
     if out:
         await fh.save_object_doc('channel', fh.make_channel_data(out))
     if out and cacheable:
         await self.cache.set_cache(cache_key, out)
     return out
예제 #2
0
 async def get_guild(self, gid, cached=False, fetched=True):
     """
     Gets a guild from the core client
     or form teh cache if one exists in the Cacher class.
     :type gid: int
     :type cached: bool
     :type fetched: bool
     :rtype: discord.Guild
     """
     cacheable = False
     cache_key = f'get_gld_{gid}'
     fh = get_fetch_helper(self)
     if cached and self.cfg.cache.type not in ['mixed', 'redis']:
         cacheable = True
         out = await self.cache.get_cache(cache_key)
         if not out:
             out = super().get_guild(gid)
     else:
         out = super().get_guild(gid)
     if not out and fetched:
         # noinspection PyBroadException
         try:
             out = await fh.fetch_guild(gid)
         except Exception:
             out = None
     if out:
         await fh.save_object_doc('guild', fh.make_guild_data(out))
     if out and cacheable:
         await self.cache.set_cache(cache_key, out)
     return out
예제 #3
0
 async def get_guild(self, gid, cached=False, fetched=True):
     """
     Gets a guild from the core client
     or form teh cache if one exists in the Cacher class.
     :param gid: The Guild ID of the requested guild.
     :type gid: int
     :param cached: Should the guild be cached/obtained from the cache.
     :type cached: bool
     :return:
     :param fetched: Should the guild fetched.
     :type fetched: bool
     :rtype:
     """
     cacheable = False
     cache_key = f'get_gld_{gid}'
     fh = get_fetch_helper(self)
     if cached and self.cfg.cache.type not in ['mixed', 'redis']:
         cacheable = True
         out = await self.cache.get_cache(cache_key)
         if not out:
             out = super().get_guild(gid)
     else:
         out = super().get_guild(gid)
     if not out and fetched:
         try:
             out = await fh.fetch_guild(gid)
         except Exception:
             out = None
     if out:
         await fh.save_object_doc('guild', fh.make_guild_data(out))
     if out and cacheable:
         await self.cache.set_cache(cache_key, out)
     return out
예제 #4
0
 async def get_channel(self, cid, cached=False, fetched=True):
     """
     Gets a channel from the core client
     or from the cache if one exists in the Cacher class.
     :type cid: int
     :type cached: bool
     :param cid: The Channel ID of the requested channel.
     :param cached: Should the channel be cached/obtained from the cache.
     :param fetched: Should the guild fetched.
     :type fetched: bool
     :return:
     """
     cacheable = False
     cache_key = f'get_chn_{cid}'
     fh = get_fetch_helper(self)
     if cached and self.cfg.cache.type not in ['mixed', 'redis']:
         cacheable = True
         out = await self.cache.get_cache(cache_key)
         if not out:
             out = super().get_channel(cid)
     else:
         out = super().get_channel(cid)
     if not out and fetched:
         try:
             out = await fh.fetch_channel(cid)
         except Exception:
             out = None
     if out:
         await fh.save_object_doc('channel', fh.make_channel_data(out))
     if out and cacheable:
         await self.cache.set_cache(cache_key, out)
     return out
예제 #5
0
async def guild_updater(ev, pld):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.GuildUpdatePayload
    """
    variant = 'guild'
    fh = get_fetch_helper(ev.bot)
    data = fh.make_guild_data(pld.after)
    await fh.save_object_doc(variant, data)
예제 #6
0
async def user_joiner(ev, pld):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.MemberPayload
    """
    variant = 'user'
    fh = get_fetch_helper(ev.bot)
    data = fh.make_user_data(pld.member)
    await fh.save_object_doc(variant, data)
예제 #7
0
async def guild_dumper(ev):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    """
    if ev.bot.cfg.dsc.shards is not None:
        variant = 'guild'
        responses = []
        fh = get_fetch_helper(ev.bot)
        for guild in ev.bot.guilds:
            data = fh.make_guild_data(guild)
            responses.append(await fh.save_object_doc(variant, data))
        ev.log.info(SaveResponse.describe(responses, variant))