def set_prefix(guild_id: int, prefix: Optional[str], cur: MySQLCursor = None): cur.execute( ''' UPDATE config SET prefix = %s WHERE guild_id = %s ''', (prefix, guild_id)) cnx.commit()
def add_guild(guild_id: int, cur: MySQLCursor = None): cur.execute( ''' INSERT INTO config (guild_id) VALUES (%s) ON DUPLICATE KEY UPDATE guild_id=guild_id ''', (guild_id, )) cnx.commit()
def set_channel_download_blacklist(guild_id: int, blacklist: str, cur: MySQLCursor = None): cur.execute( ''' UPDATE config SET channel_download_blacklist = %s WHERE guild_id = %s ''', (blacklist, guild_id)) cnx.commit()
def set_pins_channel(guild_id: int, channel_id: Optional[int], cur: MySQLCursor = None): cur.execute( ''' UPDATE config SET pins_channel = %s WHERE guild_id = %s ''', (channel_id, guild_id)) cnx.commit()
def _insert_word(guild_id: int, user: int, channel: int, tag: str, word: str, cur: MySQLCursor = None): cur.execute( f''' INSERT INTO g{guild_id}_pos_tags (user, channel, tag, word) VALUES ( (SELECT key_id FROM users WHERE id=%s), (SELECT key_id FROM channels WHERE id=%s), %s,%s ) ON DUPLICATE KEY UPDATE use_count = use_count + 1 ''', (user, channel, tag, word)) cnx.commit()
def pin_message(guild_id: int, original_msg_id: int, pin_msg_id: int, cur: MySQLCursor = None): """ Add a mapping between an original message and Hawkbot's pin message sent in a guild's designated pins channel :param guild_id: guild id :param original_msg_id: the id of the original message that was pinned :param pin_msg_id: the id of the pin message Hawkbot sent linking to the original """ typecheck(guild_id, int, 'guild_id') cur.execute( f''' INSERT INTO g{guild_id}_pins (original, pin) VALUES (%s,%s) ''', (original_msg_id, pin_msg_id)) cnx.commit()
def _insert_message(msg: discord.Message, cur: MySQLCursor = None): guild_id = msg.guild.id typecheck(guild_id, int, 'guild_id') images = _get_images_urls(msg) if images: images = ';'.join(images) add_user(msg.author) add_channel(msg.channel) cur.execute(f''' INSERT INTO g{guild_id}_messages ( id, user, channel, timestamp, content, images ) VALUES ( %s, (SELECT key_id FROM users WHERE id=%s), (SELECT key_id FROM channels WHERE id=%s), %s,%s,%s ) ''', (msg.id, msg.author.id, msg.channel.id, msg.created_at, msg.content, images)) cnx.commit()
def unpin_message(guild_id: int, original_msg_id: int, cur: MySQLCursor = None) -> Optional[int]: """ Remove a mapping between an original message and Hawkbot's pin message sent in a guild's designated pins channel :param guild_id: guild id :param original_msg_id: the id of the original message that was pinned :return: the id of the pin message Hawkbot sent linking to the original, or None if the original message was not found """ typecheck(guild_id, int, 'guild_id') pin_msg_id = get_pin_msg_id(guild_id, original_msg_id) if pin_msg_id: cur.execute( f''' DELETE FROM g{guild_id}_pins WHERE original = %s ''', (original_msg_id, )) cnx.commit() return pin_msg_id return None