import { ChatUserstate } from 'tmi.js' ; import Mongo from '../mongo' ; import Twitch from '../twitch' ; const twitch = Twitch . getInstance ( ) ; const mongo = Mongo . getInstance ( ) ; export async function join ( channel , tags , commandName , ... args ) { const db = await mongo . db ; twitch . join ( tags . username as string ) . catch ( ( err ) => { } ) ; db . collection ( 'channels' ) . updateOne ( { id : Number ( tags [ 'user-id' ] ) } , { $set : { name : tags . username } } , { upsert : true } ) ; return `Joining ${ tags . username }` ; } export async function part ( channel , tags , commandName , ... args ) { const db = await mongo . db ; twitch . part ( tags . username as string ) . catch ( ( err ) => { } ) ; db . collection ( 'channels' ) . updateOne ( { id : Number ( tags [ 'user-id' ] ) } , { $unset : { name : '' } } , { upsert : true } ) ; return `Leaving ${ tags . username }` ; }