async def checker(*args, **kwargs):
     channel = kwargs.get("channel", None)
     if not channel:
         raise customerrors.ServerLinkException()
     async with _bot.db.acquire() as con:
         channel_id = await con.fetchval(f"SELECT channel_id FROM serverlink WHERE channel_id={channel.id}")
     if not channel_id:
         raise customerrors.ServerLinkNotRegisteredChannel(channel)
     return await func(*args, **kwargs)
 async def checker(*args, **kwargs):
     ctx = kwargs.get("ctx", None)
     channel = kwargs.get("channel", None)
     if not ctx or not channel:
         raise customerrors.ServerLinkException()
     async with _bot.db.acquire() as con:
         amount_registered = await con.fetch(f"SELECT * FROM serverlink WHERE guild_id={ctx.guild.id}")
     if len(amount_registered) + 1 > 1 and not await premium.check_guild_premium(ctx.guild):
         raise customerrors.ServerLinkChannelLimitExceeded(ctx.guild)
     return await func(*args, **kwargs)
 async def checker(*args, **kwargs):
     initiator_id = kwargs.get("initiator_id", None)
     recipient_id = kwargs.get("recipient_id", None)
     if not initiator_id or not recipient_id:
         raise customerrors.ServerLinkException()
     async with _bot.db.acquire() as con:
         init_active = await con.fetchval(f"SELECT active FROM serverlink WHERE channel_id={initiator_id}")
         recip_active = await con.fetchval(f"SELECT active FROM serverlink WHERE channel_id={recipient_id}")
     if init_active or recip_active:
         raise customerrors.ServerLinkChannelUnavailable()
     return await func(*args, **kwargs)
 async def deny_request(self, ctx: commands.Context = None, other_channel_id: int = None):
     try:
         async with self.bot.db.acquire() as con:
             await con.execute(f"DELETE FROM serverlink_conn WHERE initiator_id={other_channel_id} AND "
                               f"recipient_id={ctx.channel.id} AND pending=TRUE")
     except Exception:
         raise customerrors.ServerLinkException()
     embed = discord.Embed(title="Request Denied",
                           description=f"{ctx.author.mention}, you denied the request",
                           color=discord.Color.blue())
     return await ctx.channel.send(embed=embed)
 async def checker(*args, **kwargs):
     ctx = kwargs.get("ctx", None)
     initiator_id = kwargs.get("other_channel_id", None)
     if not ctx or not initiator_id:
         raise customerrors.ServerLinkException()
     async with _bot.db.acquire() as con:
         request = await con.fetchval(f"SELECT request_time FROM serverlink_conn WHERE "
                                      f"(initiator_id={initiator_id} OR recipient_id={initiator_id}) AND "
                                      "pending=TRUE AND active=FALSE")
     if not request:
         raise customerrors.ServerLinkNoRequestFound(initiator_id)
     return await func(*args, **kwargs)
 async def make_unpublic(self, ctx, channel: discord.TextChannel = None):
     try:
         async with self.bot.db.acquire() as con:
             await con.execute("UPDATE serverlink SET public=FALSE WHERE "
                               f"channel_id={channel.id} AND public=TRUE")
     except Exception:
         raise customerrors.ServerLinkException()
     embed = discord.Embed(title="Channel Made Not Public",
                           description=f"{ctx.author.mention}, {channel.mention} is no longer "
                           "public and will not be shown on MarwynnBot's public ServerLink listings",
                           color=discord.Color.blue())
     return await ctx.channel.send(embed=embed)
 async def get_public_channels(self):
     try:
         async with self.bot.db.acquire() as con:
             entries = await con.fetch(f"SELECT channel_id, guild_id FROM serverlink "
                                       "WHERE active=FALSE AND public=TRUE")
     except Exception:
         raise customerrors.ServerLinkException()
     else:
         entry_list = []
         for entry in entries:
             try:
                 guild = self.bot.get_guild(int(entry['guild_id']))
                 entry_list.append(f"{guild.name} ⟶ <#{entry['channel_id']}>")
             except Exception:
                 continue
         return entry_list
 async def unregister_channel(self, ctx, channel: discord.TextChannel = None):
     try:
         async with self.bot.db.acquire() as con:
             check = await con.fetchval(f"DELETE FROM serverlink WHERE guild_id={ctx.guild.id} "
                                        f"AND channel_id={channel.id} RETURNING channel_id")
             await con.execute(f"DELETE FROM serverlink_conn WHERE recipient_id={channel.id}")
     except Exception:
         raise customerrors.ServerLinkException()
     if not check:
         raise customerrors.ServerLinkNotRegisteredChannel(channel)
     embed = discord.Embed(title="Channel Unregistered Successfully",
                           description=f"{ctx.author.mention}, the channel {channel.mention} "
                           "was successfully unregistered. All incoming requests to that channel "
                           "have been cancelled",
                           color=discord.Color.blue())
     return await ctx.channel.send(embed=embed)
 async def start_session(self, initiator_id: int = None, recipient_id: int = None):
     try:
         init_channel, recip_channel = await self.configure_session(initiator_id, recipient_id)
     except Exception:
         raise customerrors.ServerLinkException()
     title = "ServerLink Session Started"
     description = "Your ServerLink session with {} has started. Messages in {} will be relayed to {} automatically"
     to_initiator = discord.Embed(title=title,
                                  description=description.format(
                                      recip_channel.guild.name, init_channel.mention, recip_channel.mention
                                  ),
                                  color=discord.Color.blue())
     to_recip = discord.Embed(title=title,
                              description=description.format(
                                  init_channel.guild.name, recip_channel.mention, init_channel.mention
                              ),
                              color=discord.Color.blue())
     await init_channel.send(embed=to_initiator)
     await recip_channel.send(embed=to_recip)
     await self.session_handler(init_channel, recip_channel)
Esempio n. 10
0
 async def checker(*args, **kwargs):
     try:
         return await func(*args, **kwargs)
     except Exception:
         raise customerrors.ServerLinkException()
Esempio n. 11
0
 async def serverlink_deny(self, ctx, other_channel_id: int):
     channel = self.bot.get_channel(other_channel_id)
     if not channel.guild:
         raise customerrors.ServerLinkException()
     return await self.deny_request(ctx=ctx, other_channel_id=other_channel_id)