IntriguingTiles / cleverbot-free

Simple package to interact with the same API that the Cleverbot website uses for free.
MIT License
37 stars 10 forks source link

Use random user agent #14

Closed Lukhajek closed 3 years ago

Lukhajek commented 3 years ago

I've noticed that sometimes it doesn't work and returns an error. I added random user agents. With this improvement, everything works as it should.

IntriguingTiles commented 3 years ago

It doesn't look like you're passing an actual user agent. Also, keep in mind that the user agent must remain consistent across requests otherwise the server will reject it.

Lukhajek commented 3 years ago

It works better for me with this.

Lukhajek commented 3 years ago

It is passing random user agent from the user-agents package.

IntriguingTiles commented 3 years ago

I just checked, you're setting the user agent to

function l(e){var t;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),v(a(t=p.call(this)),r,(()=>t.data.userAgent)),v(a(t),"toString",(()=>t.data.userAgent)),v(a(t),"random",(()=>{const e=new l;return M(e,t.cumulativeWeightIndexPairs),e.randomize(),e})),v(a(t),"randomize",(()=>{const e=Math.random(),[,i]=t.cumulativeWeightIndexPairs.find((([t])=>t>e)),r=n.default[i];t.data=(0,o.default)(r)})),M(a(t),(e=>{if(!e)return k;const t=f(e),i=[];return n.default.forEach(((e,o)=>{t(e)&&i.push([e.weight,o])})),w(i)})(e)),0===t.cumulativeWeightIndexPairs.length)throw new Error("No user agents matched your filters.");return t.randomize(),c(t,new Proxy(a(t),{apply:()=>t.random(),get:(e,t,i)=>{if(e.data&&"string"==typeof t&&Object.prototype.hasOwnProperty.call(e.data,t)&&Object.prototype.propertyIsEnumerable.call(e.data,t)){const i=e.data[t];if(void 0!==i)return i}return Reflect.get(e,t,i)}}))}