Skip to content

Commit

Permalink
refactor: give axios a try
Browse files Browse the repository at this point in the history
  • Loading branch information
Sham committed Jan 19, 2023
1 parent 17e7acc commit 856b87f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lib/bot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RawData, WebSocket } from 'ws'
import { EventEmitter } from 'events'
import { Message, MessageResponse } from './types/message.js'
import fetch from 'node-fetch'
import axios from 'axios'
import { EvangelineValueError } from './errors.js'

const DEFAULT_REST_URL = 'https://eludris.tooty.xyz/'
Expand Down Expand Up @@ -127,14 +127,11 @@ export class Bot extends EventEmitter {
* @private
*/
private async createMessage(message: Message): Promise<MessageResponse> {
const response = await fetch(`${this.rest}/messages`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(message)
})
return response.json() as Promise<MessageResponse>
const response = axios.post(`${this.rest}/messages`, {
author: this.author,
content: message.content
}).then((v) => v.data)
return await response as MessageResponse
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"typescript": "^4.9.3"
},
"dependencies": {
"node-fetch": "^3.3.0",
"axios": "^1.2.3",
"ws": "^8.11.0"
}
}

0 comments on commit 856b87f

Please sign in to comment.