import { runInAction } from "mobx" ; import { Route } from "../api/routes" ; import { Client } from "../Client" ; export default class Bots { client : Client ; constructor ( client ) { this . client = client ; } param id returns async fetch ( id ) { const { bot , user } = await this . client . req ( "GET" , `/bots/${ id }` as "/bots/id" ) ; return { bot , user : await this . client . users . fetch ( user . _id , user ) , } ; } param id async delete ( id ) { await this . client . req ( "DELETE" , `/bots/${ id }` as "/bots/id" ) ; } param id returns async fetchPublic ( id ) { return await this . client . req ( "GET" , `/bots/${ id }/invite` as "/bots/id/invite" ) ; } param id param destination async invite ( id , destination ) { return await this . client . req ( "POST" , `/bots/${ id }/invite` as "/bots/id/invite" , destination ) ; } param id returns async fetchOwned ( ) { const { bots , users : userObjects } = await this . client . req ( "GET" , `/bots/@me` ) ; const users = [ ] ; for ( const obj of userObjects ) { users . push ( await this . client . users . fetch ( obj . _id , obj ) ) ; } return { bots , users } ; } param id param data async edit ( id , data ) { await this . client . req ( "PATCH" , `/bots/${ id }` as "/bots/id" , data ) ; if ( data . name ) { const user = this . client . users . get ( id ) ; if ( user ) { runInAction ( ( ) => { user ! . username = data . name ! ; } ) ; } } } param data async create ( data ) { const bot = await this . client . req ( "POST" , "/bots/create" , data ) ; const user = await this . client . users . fetch ( bot . _id , { _id : bot . _id , username : data . name , bot : { owner : this . client . user ! . _id , } , } ) ; return { bot , user , } ; } }