import { Store } from "mx-puppet-bridge" ; const CURRENT_SCHEMA = 4 ; export class IDbEmoji { public emojiId : string ; public name : string ; public animated : boolean ; public mxcUrl : string ; } export class DiscordStore { constructor ( private store ) { } public async init ( ) { await this . store . init ( CURRENT_SCHEMA , "discord_schema" , ( version ) => { return require ( `./db/schema/v${ version }.js` ) . Schema ; } , false ) ; } public async getBridgedGuilds ( puppetId ) { const rows = await this . store . db . All ( "SELECT guild_id FROM discord_bridged_guilds WHERE puppet_id=$puppetId" , { puppetId , } ) ; const result = [ ] ; for ( const row of rows ) { result . push ( row . guild_id as string ) ; } return result ; } public async isGuildBridged ( puppetId , guildId ) { const exists = await this . store . db . Get ( "SELECT 1 FROM discord_bridged_guilds WHERE puppet_id=$p AND guild_id=$g" , { p : puppetId , g : guildId , } ) ; return exists ? true : false ; } public async setBridgedGuild ( puppetId , guildId ) { if ( await this . isGuildBridged ( puppetId , guildId ) ) { return ; } await this . store . db . Run ( "INSERT INTO discord_bridged_guilds (puppet_id, guild_id) VALUES ($p, $g)" , { p : puppetId , g : guildId , } ) ; } public async removeBridgedGuild ( puppetId , guildId ) { await this . store . db . Run ( "DELETE FROM discord_bridged_guilds WHERE puppet_id=$p AND guild_id=$g" , { p : puppetId , g : guildId , } ) ; } public async getBridgedChannels ( puppetId ) { const rows = await this . store . db . All ( "SELECT channel_id FROM discord_bridged_channels WHERE puppet_id=$puppetId" , { puppetId , } ) ; const result = [ ] ; for ( const row of rows ) { result . push ( row . channel_id as string ) ; } return result ; } public async isChannelBridged ( puppetId , channelId ) { const exists = await this . store . db . Get ( "SELECT 1 FROM discord_bridged_channels" + " WHERE puppet_id=$p AND channel_id=$c" , { p : puppetId , c : channelId , } ) ; return exists ? true : false ; } public async setBridgedChannel ( puppetId , channelId ) { if ( await this . isChannelBridged ( puppetId , channelId ) ) { return ; } await this . store . db . Run ( "INSERT INTO discord_bridged_channels (puppet_id, channel_id) VALUES ($p, $c)" , { p : puppetId , c : channelId , } ) ; } public async removeBridgedChannel ( puppetId , channelId ) { await this . store . db . Run ( "DELETE FROM discord_bridged_channels WHERE puppet_id=$p AND channel_id=$c" , { p : puppetId , c : channelId , } ) ; } }