From 116363f0f4ebb51127940c05c1456424e93932b5 Mon Sep 17 00:00:00 2001 From: HexaField Date: Thu, 26 Sep 2024 10:08:21 +1000 Subject: [PATCH] format --- src/bot/bot-class.ts | 14 ++++--- src/bot/bot-manager.ts | 20 ++++----- src/index.ts | 94 +++++++++++++++++++++--------------------- 3 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/bot/bot-class.ts b/src/bot/bot-class.ts index b36e86c..7a7eef2 100644 --- a/src/bot/bot-class.ts +++ b/src/bot/bot-class.ts @@ -193,12 +193,14 @@ export class IREngineBot { async clickEmoteButtonAndSelectEmote() { const emoteButton = await this.page.waitForSelector('[aria-label="Emote"]') if (emoteButton) { - await emoteButton.click().catch(err => { - console.error('Error clicking emoteButton:', err); + await emoteButton.click().catch((err) => { + console.error('Error clicking emoteButton:', err) }) await this.delay(6000) - const imgElement = await this.page.waitForSelector('button.MuiButtonBase-root-IIrwk.ispAN.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.MuiButton-root-gwFoGh.hLKZiD._menuItem_fba7b_146:nth-child(0)') + const imgElement = await this.page.waitForSelector( + 'button.MuiButtonBase-root-IIrwk.ispAN.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.MuiButton-root-gwFoGh.hLKZiD._menuItem_fba7b_146:nth-child(0)' + ) if (imgElement) { imgElement.click() console.log('Button clicked successfully.', imgElement) @@ -215,11 +217,11 @@ export class IREngineBot { const savebutton = await this.page.waitForSelector('li[tabindex="-1"][role="menuitem"]') if (savebutton) { await savebutton.click() - console.log("savebutton clicked") + console.log('savebutton clicked') await this.delay(4000) } const submitbutton = await this.page.waitForSelector('button[type="submit"]') - if (submitbutton){ + if (submitbutton) { await submitbutton.click() console.log('submitbutton clicked') await this.delay(10000) @@ -444,7 +446,7 @@ export class IREngineBot { '--use-fake-device-for-media-stream', '--disable-web-security=1', //'--no-first-run', - '--allow-file-access=1', + '--allow-file-access=1' //'--mute-audio', ].filter(Boolean), ...this.detectOsOption() diff --git a/src/bot/bot-manager.ts b/src/bot/bot-manager.ts index 6e7de4c..1870e76 100755 --- a/src/bot/bot-manager.ts +++ b/src/bot/bot-manager.ts @@ -20,11 +20,11 @@ export class BotManager { this.options = options } - findBotById(id:string) { + findBotById(id: string) { return this.bots[id] } - addBot(id:string,name:string ,options:any = this.options) { + addBot(id: string, name: string, options: any = this.options) { const foundBot = this.findBotById(id) if (foundBot) { return foundBot @@ -40,9 +40,9 @@ export class BotManager { return bot } - removeBot(id:string){ + removeBot(id: string) { const foundBot = this.findBotById(id) - if(!foundBot){ + if (!foundBot) { return null } foundBot.quit() @@ -50,19 +50,19 @@ export class BotManager { return foundBot } - getActions(){ + getActions() { return this.actions } - - addAction(botId:string, action:BotAction) { + + addAction(botId: string, action: BotAction) { this.actions.push({ botId, action }) } async run() { - console.log("bots : ",this.bots) + console.log('bots : ', this.bots) for (const botAction of this.actions) { - const { botId, action }:{botId:string,action} = botAction + const { botId, action }: { botId: string; action } = botAction const bot = this.findBotById(botId) if (!bot) { @@ -190,5 +190,3 @@ export class BotManager { this.bots = {} } } - - diff --git a/src/index.ts b/src/index.ts index aa461f9..a834e13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,71 +1,71 @@ -import Koa from 'koa'; -import Router from "koa-router" -import bodyParser from "koa-bodyparser" -import { BotAction } from './bot/bot-action'; -import { BotManager } from './bot/bot-manager'; +import Koa from 'koa' +import Router from 'koa-router' +import bodyParser from 'koa-bodyparser' +import { BotAction } from './bot/bot-action' +import { BotManager } from './bot/bot-manager' -const app = new Koa(); -const router = new Router(); -const botManager = new BotManager(); +const app = new Koa() +const router = new Router() +const botManager = new BotManager() -app.use(bodyParser()); +app.use(bodyParser()) router.get('/', (ctx) => { - ctx.body = { status: 'ir-bot api is working' }; -}); + ctx.body = { status: 'ir-bot api is working' } +}) router.get('/bots', (ctx) => { - ctx.body = botManager.bots; -}); + ctx.body = botManager.bots +}) router.get('/bots/:id', (ctx) => { - const id = ctx.params.id; - const bot = botManager.findBotById(id); - ctx.body = bot; -}); + const id = ctx.params.id + const bot = botManager.findBotById(id) + ctx.body = bot +}) router.get('/bots/actions', (ctx) => { - const actions = botManager.getActions(); - ctx.body = actions; -}); + const actions = botManager.getActions() + ctx.body = actions +}) router.put('/bots/:id/create', (ctx) => { - const id = ctx.params.id; - const body:any = ctx.request.body - const name = body.name; - const options = body.options; - const bot = botManager.addBot(id, name, options); - ctx.body = bot; -}); + const id = ctx.params.id + const body: any = ctx.request.body + const name = body.name + const options = body.options + const bot = botManager.addBot(id, name, options) + ctx.body = bot +}) router.post('/bots/:id/actions/add', (ctx) => { - const id = ctx.params.id; - const body:any = ctx.request.body - const action: BotAction = body.action; - botManager.addAction(id, action); - ctx.status = 200; -}); + const id = ctx.params.id + const body: any = ctx.request.body + const action: BotAction = body.action + botManager.addAction(id, action) + ctx.status = 200 +}) router.post('/bots/run', async (ctx) => { - await botManager.run(); - ctx.status = 200; -}); + await botManager.run() + ctx.status = 200 +}) router.delete('/bots/:id/delete', async (ctx) => { - const id = ctx.params.id; - const bot = botManager.removeBot(id); - ctx.status = 200; -}); + const id = ctx.params.id + const bot = botManager.removeBot(id) + ctx.status = 200 +}) router.delete('/bots/clear', async (ctx) => { - await botManager.clear(); - ctx.status = 200; -}); + await botManager.clear() + ctx.status = 200 +}) -app.use(router.routes()); -app.use(router.allowedMethods()); +app.use(router.routes()) +app.use(router.allowedMethods()) const PORT = process.env.PORT || 4000 app.listen(PORT, () => { - console.log(`Koa Server listening on port ${PORT}`); -}); + console.log(`Koa Server listening on port ${PORT}`) +})