From 9d68b4e57393f1bbe6ac3a5e2480ffade93dd388 Mon Sep 17 00:00:00 2001 From: lilyissillyyy Date: Sun, 20 Jul 2025 01:09:41 -0400 Subject: [PATCH] User Agent Command --- README.md | 3 ++- commands/random-res/user-agent.js | 17 +++++++++++++++++ commands/search/neopet.js | 3 ++- package.json | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 commands/random-res/user-agent.js diff --git a/README.md b/README.md index b3e43684..3e9a5392 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ things, I'm not taking any chances. 19. Start Xiao up! ## Commands -Total: 514 +Total: 515 ### Utility: @@ -187,6 +187,7 @@ Total: 514 * **smw-level:** Responds with a random Super Mario World level name. * **suggest-command:** Suggests a random command for you to try. * **superpower:** Responds with a random superpower. +* **user-agent:** Responds with a random User Agent. * **word:** Responds with a random word. * **xiao-fact:** Responds with a random fact about Xiao. * **yes-no:** Answers a yes/no question randomly. diff --git a/commands/random-res/user-agent.js b/commands/random-res/user-agent.js new file mode 100644 index 00000000..e9faf5d9 --- /dev/null +++ b/commands/random-res/user-agent.js @@ -0,0 +1,17 @@ +const Command = require('../../framework/Command'); +const { UserAgent } = require('user-agents'); + +module.exports = class UserAgentCommand extends Command { + constructor(client) { + super(client, { + name: 'user-agent', + group: 'random-res', + description: 'Responds with a random User Agent.' + }); + } + + run(msg) { + const agent = new UserAgent(); + return msg.say(agent.toString()); + } +}; diff --git a/commands/search/neopet.js b/commands/search/neopet.js index 07b17dfc..e45838ea 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -1,5 +1,6 @@ const Command = require('../../framework/Command'); const request = require('node-superfetch'); +const { UserAgent } = require('user-agents'); const { list } = require('../../util/Util'); const moods = { happy: 1, @@ -45,7 +46,7 @@ module.exports = class NeopetCommand extends Command { try { const { body } = await request .get(`http://pets.neopets.com/cpn/${encodeURIComponent(pet)}/${mood}/5.png`) - .set({ 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0' }); + .set({ 'User-Agent': (new UserAgent()).toString() }); return msg.say({ files: [{ attachment: body, name: `${pet}-${mood}.png` }] }); } catch (err) { if (err.status === 404) return msg.say('Could not find any results.'); diff --git a/package.json b/package.json index 340163d0..fc16461d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "152.4.13", + "version": "152.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -78,6 +78,7 @@ "text-diff": "^1.0.1", "tictactoe-minimax-ai": "github:marianoheller/tic-tac-toe-minimax", "twitter-openapi-typescript": "^0.0.55", + "user-agents": "^1.1.605", "valid-url": "^1.0.9", "wavefile": "^11.0.0", "winston": "^3.17.0",