async def remove_asemoji( bot: commands.Bot, aschannel: discord.TextChannel, name: str ) -> None: check_aschannel = \ """SELECT * FROM aschannels WHERE id=$1""" check_asemoji = \ """SELECT * FROM asemojis WHERE name=$1 AND aschannel_id=$2""" del_asemojis = \ """DELETE FROM asemojis WHERE id=$1""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sasc = await conn.fetchrow( check_aschannel, aschannel.id ) if sasc is None: raise errors.DoesNotExist("That is not an AutoStar Channel!") se = await conn.fetchrow( check_asemoji, name, aschannel.id ) if se is None: raise errors.DoesNotExist( "That emoji is not on that AutoStar Channel!" ) await conn.execute( del_asemojis, se['id'] )
async def move_aschannel_lock(bot: commands.Bot, current_channel: discord.TextChannel, new_channel: discord.TextChannel) -> None: conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): is_curr_locked = await conn.fetchval( """SELECT locked FROM aschannels WHERE id=$1""", current_channel.id) is_new_unlocked = not await conn.fetchval( """SELECT locked FROM aschannels WHERE id=$1""", new_channel.id) if is_curr_locked in [False, None]: raise errors.DoesNotExist( f"Either {current_channel.mention} is not an AutoStar channel, " "or it is not locked.") if is_new_unlocked in [False, None]: raise errors.DoesNotExist( f"Either {new_channel.mention} is not an AutoStar channel, " "or it is already locked.") await set_asc_lock(bot, current_channel.id, False) await set_asc_lock(bot, new_channel.id, True) await current_channel.send( "This channel has been unlocked, and " f"{new_channel.mention} has been locked instead.") await new_channel.send(f"{current_channel.mention} was unlocked, and " "this one was locked instead.")
async def remove_role_blacklist( bot: commands.Bot, role_id: int, starboard_id: int, ) -> None: check_exists = \ """SELECT * FROM rolebl WHERE role_id=$1 AND starboard_id=$2""" delete_rolebl = \ """DELETE FROM rolebl WHERE role_id=$1 AND starboard_id=$2""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_rolebl = await conn.fetchrow( check_exists, role_id, starboard_id ) if sql_rolebl is None: raise errors.DoesNotExist( "That role is not blacklisted/whitelisted" ) await conn.execute( delete_rolebl, role_id, starboard_id )
async def add_role_blacklist( bot: commands.Bot, role_id: int, starboard_id: int, guild_id: int, is_whitelist: bool = False ) -> None: check_exists = \ """SELECT * FROM rolebl WHERE role_id=$1 AND starboard_id=$2""" check_starboard = \ """SELECT * FROM starboards WHERE id=$1 AND guild_id=$2""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_rolebl = await conn.fetchrow( check_exists, role_id, starboard_id ) if sql_rolebl is not None: raise errors.AlreadyExists( "That role is already whitelisted/blacklisted" ) sql_starboard = await conn.fetchrow( check_starboard, starboard_id, guild_id ) if sql_starboard is None: raise errors.DoesNotExist( "That is not a starboard!" ) await bot.db.q.create_rolebl.fetch( starboard_id, role_id, guild_id, is_whitelist )
async def add_starboard_emoji( bot: commands.Bot, starboard_id: int, guild: discord.Guild, emoji: Union[discord.Emoji, str] ) -> None: check_sbemoji = \ """SELECT * FROM sbemojis WHERE name=$1 AND starboard_id=$2""" get_all_sbemojis = \ """SELECT * FROM sbemojis WHERE starboard_id=$1""" check_starboard = \ """SELECT * FROM starboards WHERE id=$1""" if not isinstance(emoji, discord.Emoji): if not functions.is_emoji(emoji): raise errors.InvalidArgument( "I don't recognize that emoji. If it is a custom " "emoji, it has to be in this server." ) emoji_name = str(emoji.id) if isinstance( emoji, discord.Emoji) else str(emoji) emoji_id = emoji.id if isinstance( emoji, discord.Emoji) else None limit = await functions.get_limit(bot, 'emojis', guild.id) conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_starboard = await conn.fetchrow( check_starboard, starboard_id ) if sql_starboard is None: raise errors.DoesNotExist("That is not a starboard!") all_sbemojis = await conn.fetch( get_all_sbemojis, starboard_id ) if len(all_sbemojis) + 1 > limit: raise errors.NoPremiumError( "You have reached your limit for emojis " "on this starboard.\nSee the last page of " "`sb!tutorial` for more info." ) sbemoji = await conn.fetchrow( check_sbemoji, emoji_name, starboard_id ) if sbemoji is not None: raise errors.AlreadyExists( "That is already a starboard emoji!" ) await bot.db.q.create_sbemoji.fetch( emoji_id, starboard_id, emoji_name, False )
async def remove_starboard( bot: commands.Bot, channel_id: int, guild_id: int ) -> None: check_starboard = \ """SELECT * FROM starboards WHERE id=$1 AND guild_id=$2""" del_starboard = \ """DELETE FROM starboards WHERE id=$1""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_starboard = await conn.fetchrow( check_starboard, channel_id, guild_id ) if sql_starboard is None: raise errors.DoesNotExist( "That is not a starboard!" ) await conn.execute( del_starboard, channel_id ) await functions.refresh_guild_premium(bot, guild_id, send_alert=False)
async def add_asemoji( bot: commands.Bot, aschannel: discord.TextChannel, name: str ) -> None: check_aschannel = \ """SELECT * FROM aschannels WHERE id=$1""" check_asemoji = \ """SELECT * FROM asemojis WHERE name=$1 and aschannel_id=$2""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sasc = await conn.fetchrow( check_aschannel, aschannel.id ) if sasc is None: raise errors.DoesNotExist("That is not an AutoStar Channel!") se = await conn.fetchrow( check_asemoji, name, aschannel.id ) if se is not None: raise errors.AlreadyExists( "That emoji is already on this AutoStar Channel!" ) await bot.db.q.create_asemoji.fetch( aschannel.id, name )
async def remove_aschannel( bot: commands.Bot, channel_id: int, guild_id: int ) -> None: check_aschannel = \ """SELECT * FROM aschannels WHERE id=$1 AND guild_id=$2""" del_aschannel = \ """DELETE FROM aschannels WHERE id=$1""" conn = bot.db.conn # just in case we messed something up earlier and it's not in there if channel_id in bot.db.as_cache: bot.db.as_cache.remove(channel_id) async with bot.db.lock: async with conn.transaction(): sql_aschannel = await conn.fetchrow( check_aschannel, channel_id, guild_id ) if sql_aschannel is None: raise errors.DoesNotExist("That is not an AutoStar Channel!") await conn.execute(del_aschannel, channel_id) await functions.refresh_guild_premium(bot, guild_id, send_alert=False)
async def change_aschannel_settings(db, aschannel_id, min_chars=None, require_image=None, delete_invalid=None): get_aschannel = \ """SELECT * FROM aschannels WHERE id=$1""" update_aschannel = \ """UPDATE aschannels SET min_chars=$1, require_image=$2, delete_invalid=$3 WHERE id=$4""" conn = db.conn async with db.lock: async with conn.transaction(): sasc = await conn.fetchrow(get_aschannel, aschannel_id) if sasc is None: raise errors.DoesNotExist("That is not an AutoStar Channel!") s = {} s['mc'] = min_chars if min_chars is not None else sasc['min_chars'] s['ri'] = require_image if require_image is not None\ else sasc['require_image'] s['di'] = delete_invalid if delete_invalid is not None\ else sasc['delete_invalid'] if s['mc'] < 0: s['mc'] = 0 elif s['mc'] > 1024: s['mc'] = 1024 await conn.execute(update_aschannel, s['mc'], s['ri'], s['di'], aschannel_id)
async def remove_aschannel(bot: commands.Bot, channel_id: int, guild_id: int): check_aschannel = \ """SELECT * FROM aschannels WHERE id=$1 AND guild_id=$2""" del_aschannel = \ """DELETE FROM aschannels WHERE id=$1""" conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_aschannel = await conn.fetchrow(check_aschannel, channel_id, guild_id) if sql_aschannel is None: raise errors.DoesNotExist("That is not an AutoStar Channel!") await conn.execute(del_aschannel, channel_id)