file description module import type { Guild } from "eris" ; import type { RethinkProvider } from "../classes/RethinkDB" ; export async function itemExists ( guild , type , item , db , configItem ) { let check = true ; if ( type === "role" && Array . isArray ( item ) ) { const guildRoles = item . filter ( ( i ) => { const a = guild . roles . has ( i ) ; if ( ! a ) check = false ; return a ; } ) ; if ( ! check ) { const guildconfig = await db . getGuildConfig ( guild . id ) ; if ( ! guildconfig || ! guildconfig [ configItem ] ) return false ; guildconfig [ configItem as string ] = guildRoles ; await db . updateGuildConfig ( guild . id , guildconfig ) ; } return guildRoles ; } else if ( type === "channel" && Array . isArray ( item ) ) { const guildChannels = item . filter ( ( i ) => { const a = guild . channels . has ( i ) ; if ( ! a ) check = false ; return a ; } ) ; if ( ! check ) { const guildconfig = await db . getGuildConfig ( guild . id ) ; if ( ! guildconfig || ! guildconfig [ configItem ] ) return false ; guildconfig [ configItem as string ] = guildChannels ; await db . updateGuildConfig ( guild . id , guildconfig ) ; } return guildChannels ; } else if ( typeof item === "string" ) { if ( type === "role" ) check = guild . roles . has ( item ) ; else if ( type === "channel" ) check = guild . channels . has ( item ) ; if ( check ) return true ; else if ( ! check ) { const guildconfig = await db . getGuildConfig ( guild . id ) ; if ( ! guildconfig || ! guildconfig [ configItem ] ) return false ; if ( guildconfig [ item ] ) delete guildconfig [ configItem ] ; await db . replaceGuildConfig ( guild . id , guildconfig ) ; } return check ; } }