Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Sep 26, 2024
1 parent d2e8982 commit 116363f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 64 deletions.
14 changes: 8 additions & 6 deletions src/bot/bot-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 9 additions & 11 deletions src/bot/bot-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,29 +40,29 @@ export class BotManager {
return bot
}

removeBot(id:string){
removeBot(id: string) {
const foundBot = this.findBotById(id)
if(!foundBot){
if (!foundBot) {
return null
}
foundBot.quit()
delete this.bots[id]
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) {
Expand Down Expand Up @@ -190,5 +190,3 @@ export class BotManager {
this.bots = {}
}
}


94 changes: 47 additions & 47 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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}`)
})

0 comments on commit 116363f

Please sign in to comment.