#development

1 messages Β· Page 2040 of 1

sharp geyser
#

Send false numbers?

quartz kindle
#

the request uses FormData, not json

vivid fulcrum
#

topgg can't really confirm how many servers your bot is in so you can send whatever you want, that's not allowed though

solemn latch
#

oh yeah, totally possible. but we generally catch them quickly.

sharp geyser
#

So I can't publish a bot with 60m servers

quartz kindle
simple stump
quartz kindle
#

cant scrape them tho

#

not without logging in

solemn latch
#

no, just manually checking works fine though

quartz kindle
#

yeah but whos gonna do that for tens of thousands of bots

#

:^)

sharp geyser
#

They should include a way to get the bots guilds tho I bet that'd be very resource intensive or just annoying to do

quartz kindle
#

they should just expose the approximate count in the api

sharp geyser
#

Ye

simple stump
# quartz kindle

Got it to work! Tysm for your help:

let form = new URLSearchParams();
form.append('anime', query);

return axios.post(this.url + "/data/searchdata-test.php", form, { headers: { 'x-referer': this.url, 'user-agent': userAgent } }).then(res => {
  return res;
}).catch(err => {
  return err;
});
solemn latch
#

Even if they did that, I doubt we would use it, or only use it rarely.

quartz kindle
#

i would

#

and any bot thats planning on using webhook interactions only

solemn latch
#

that would be nice

quartz kindle
#

currently they have no way of getting the count without connecting to the websocket

#

well they have a way

#

but its slow asf

slender wagon
#

Or just include a report button to report fake server count

split hazel
#

@quartz kindle to make myself feel better about the email monopolies I will send all emails from gmail and outlook to spam

#

email spam is horrific though

#

the filters are so sensitive they block legitimate emails

#

google has a post on how to make your email not go to spam by doing some things such as setting up records which help to prove your domain is sending emails etc which does help

split hazel
#

there are also a shit ton of things Google tells you to do to "help" stop domain forgery

#

there is no set solution on stopping it

#

you can only try mitigate it

neat ingot
#

yall tried unreal engine 5? its dope!

#

discord needs to add a feature for embedding games in chat or something

#

like, they can already embed youtube videos, why not allow some specific game format to load as well 😒

boreal iron
dry imp
#

ue5 is indeed dope but my shitty mac wont be able to run it anyway

spark flint
#

coding

simple stump
#

HTTP requests to websites

sharp geyser
#

What all should I include in my websocket stuff?

#

I am already handling errors, I am already doing heartbeat & identify

viral plover
#

Can a Discord Bot create an invite link to a scheduled event?

sharp geyser
spark flint
#

they can create events too

viral plover
# spark flint yes

Great!
I was able to find how to create an event eventually, but nowhere on how to get the bot to make a link for said event.

spark flint
#

ah

#

it out rq

vivid fulcrum
#

even using something like webgl would definitely skyrocket the cpu usage beyond what would be considered acceptable

#

discord is more to blame than electron here tbh

#

the entirety of the client is heavily bloated and unoptimized

viral plover
spark flint
#

i mean i was gonna go check it out

viral plover
#

Oh, okay. Thanks.

lament rock
#

Discord uses a lot of high level and bloated libraries

#

my personal goal is to rid my bots' dependency tree of common bloat like lodash

split hazel
#

every time i see lodash in a package: πŸ’€

boreal stream
#

hey guys can someone help me with react i want to add js script for fetching json data in jsx component but i dont know how to do that

split hazel
#

i contacted my hosting provider to see if they can do something

vivid fulcrum
#

the question is too broad for you to get a concrete answer

boreal stream
lament rock
#

I have never felt so satisfied

boreal stream
#

im trying to put this script in my jsx

#

component

quartz kindle
vivid fulcrum
#

just use it like you would normally, considering you're using react you're going to want to put that inside of the useEffect hook and create a state that gets updated when the fetch finishes

lament rock
vivid fulcrum
#

pass an empty array as the second argument to useEffect though

lament rock
#

a few deps

vivid fulcrum
#

otherwise the effect will re-run on every rerender

quartz kindle
lament rock
#

I need to purge a few redundant deps

quartz kindle
#

xD

lament rock
#

Almost all of them, I import and use though

boreal stream
split hazel
#

i hate how complicated and annoying it is to setup api routes server-side and then implement handlers and requests client side

#

so unorganized

lament rock
#

I need to learn how to routify

vivid fulcrum
#

mvc in a nutshell

quartz kindle
lament rock
#

my website is static atm, so no need for routify yet, but will once I reimplement my bot's dashboard

boreal stream
#

like in html

quartz kindle
#

i dont see why not? doesnt jsx compile into html anyway?

boreal stream
#

yeah but jsx its js too

#

im going to try that

quartz kindle
#

the js in jsx is server side, used to help build the html

#

if you want browser side you need to put the code as a string in <script> tags

quartz kindle
#

i need to make one tho

lament rock
#

Github pages would be pretty easy

quartz kindle
#

my bot's donation process is all done manually

#

and its such a hassle

#

i need to build a dashboard to handle payments and user customization

lament rock
#

What's stopping me from doing that is simply; front end work sucks so badly

quartz kindle
#

yup

quartz kindle
#

also my entire work is stuck while i dont finish my api

#

because everything depends on it

quartz kindle
lament rock
quartz kindle
#

simple and straight to the point

#

oh and also

#

the domain i want for my bot

#

was taken

#

and expired on february

#

and its still not available for purchase

#

expired domains take like 3 months to return to the market

austere surge
#

put it all in one div or something

vivid fulcrum
#

that's a heavy antipattern

#

you don't use script tags inside of react

#

the whole thing is a script already

quartz kindle
#

oh comon

#

the domain i wanted was reregistered

#

and put on auction

#

-.-

austere surge
#

rip

lament rock
vivid fulcrum
#

domain snipers

boreal stream
vivid fulcrum
#

place it outside of the return

#

and inside of a useEffect hook

lament rock
#

I guess the best thing to do is get a different tld

#

.moe was pretty cheap. $15 usd a year

quartz kindle
#

the auction is curently at $3

#

im gonna bid

#

lmao

lament rock
#

cheap

#

Hope you win

boreal stream
# vivid fulcrum and inside of a useEffect hook
import { useEffect } from 'react';

const useScript = url => {
  useEffect(() => {
    const script = document.createElement('script');

    script.src = url;
    script.async = true;

    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    }
  }, [url]);
};

export default useScript;```
#

you mean like this

vivid fulcrum
#

absolutely not

#

i mean

#

it's a way

#

however you should use the useEffect inside of your component

#

the actual one

#

and again

#

you don't use script tags

#

react is already a script

#

jsx compiles down to just javascript

#

everything in react is virtual

boreal stream
vivid fulcrum
#

what are you exactly fetching

#

an API or a file that's in the site

boreal stream
#

im creating div's with images inside like instagram posts

#

they are file in site now

vivid fulcrum
#

you can just require that then

#

there's absolutely no need to fetch something that exists locally already

#

require/import it and webpack will take care of it

boreal stream
#

but this fetch is creating div's by it self and creating posts with uniqe id and give links for every image

quartz kindle
#

LMAO

#

THIS SHIT IS RIGGED

#

THE MOMENT YOU PLACE A BID YOU GET AUTO 1 UPPED

vivid fulcrum
#

pick one

#

using react you will have to follow react patterns

solemn latch
#

many online bidding services you can set a max bid, and it will auto bid above the next person below.

vivid fulcrum
#

react has a virtual DOM, meaning you don't directly manipulate the contents of the website, react does beacause it programmatically stores what it needs to render

#

jsx is just an easier way to represent the virtual DOM

boreal stream
#

i understand but i still dont get it how i can fech json in react now

vivid fulcrum
#

<Component /> is actually just React.createElement() under the hood

#

if it's a json file that's local, you just import it

quartz kindle
solemn latch
#

πŸ‘€ someones cheating

boreal stream
#

can u give me a photo or part of code that can help me to understand more clearly that

vivid fulcrum
#

i will not spoonfeed you

#

id give you a quick example but im on my phone

#

writing code is annoying on a mobile keyboard

boreal stream
#

oh i know that sorry i didnt know that

vivid fulcrum
#

the beta docs are extremely good

#

will definitely help you clear confusion about what react actually is

boreal stream
#

mmm thanks for that im going to see that thanks to much for your help

vivid fulcrum
#

another tip i can give you is not to go hard on yourself with your first projects in react

#

you should start with something basic just to get the hang of it

#

doesn't matter if you'll use the thing you build or not

boreal stream
#

im more good in html css and js πŸ˜…πŸ˜‚

vivid fulcrum
#

i guessed so, you're shooting yourself in the foot by doing that though, react is definitely a feature rich framework that takes a bit of time to learn

#

you won't be able to port apps without knowing how react works first

#

also, here's a good video on how to avoid antipatterns once you familiarize yourself with state management and effects

#

🚨 IMPORTANT:

Learn React Today Course: https://courses.webdevsimplified.com/learn-react-today

Writing code is easy. Writing clean code, though, is much harder. In this video I take a look at three different React code examples from a beginner, intermediate, and advanced web developer. The goal of this is to show you how a senior developer will...

β–Ά Play video
solemn latch
#

oh wow, the beta docs are really nice

#

I just started rewriting a site from scratch, might be a good time for me to learn myself.

boreal stream
quartz kindle
#

lmao

solemn latch
#

πŸ‘€

boreal stream
solemn latch
#

note to self, dont mess with tim

spark flint
#

ah fuck wrong channel

quartz kindle
#

my last bid was 12 bucks, which got insta-topped to 13 bucks by the same account as before

quartz kindle
#

xD

vivid fulcrum
boreal stream
#

πŸ˜πŸ˜‚

wheat mesa
#

C:<

vivid fulcrum
#

do you happen to want to talk to a manager

#

it's an effective method!

boreal stream
vivid fulcrum
#

it's a paradox

#

oh no

boreal stream
#

i also have a restaurant and i can learn how to manage all work and peoples there so im still training for that

wheat mesa
sharp geyser
#

Other than handling events fully I think I have done all I need with the gateway for now

sharp geyser
#
  user: {
    verified: true,
    username: 'Teamer',
    mfa_enabled: true,
    id: '961018771261231104',
    flags: 0,
    email: null,
    discriminator: '1564',
    bot: true,
    avatar: null
  }

Is this everything a user could have or is this just what discord can return for this user?

#

Cause discord's docs says a user object is a lot more than that

#

Unless there is only a certain amount you can get with the bot's token versus a bearers token

peak fox
#

I am struggling what to add to my bot. I have a series of commands but feel like it needs more.

quartz kindle
#

the rest is pretty much on a need to have basis, as they are all nullable

sharp geyser
#

πŸ€”

quartz kindle
#

ie banner will only be there if the user actually has a custom banner

sharp geyser
#

Ah

#

I am wondering if I should set my author prop in the interface to be of type User (the class I made for users) or should i make an interface for the data it will have

quartz kindle
#

this is what i get when i fetch my own user (with the bot token)

sharp geyser
#

Why is bot marked as nullable in the discord docs?

#

I thought it was sent no matter what

sharp geyser
quartz kindle
#

well, its a boolean so, if its true its true, if anything else its implicitly false

#

in this case, if bot is false, its easier to simply not send it at all and save bandwidth

sharp geyser
#

Mmm makes sense

quartz kindle
#

but discord is known to be inconsistent

#

so you see things sometimes are null, other times are simply not sent

#

also avatar_decoration doesnt even exist in their docs

sharp geyser
#

Yea

#

tf

#
export class Message extends BaseStructure {
    public id: Snowflake;
    public channelId: Snowflake;
    public guildId?: Snowflake;
    public author: User;
    constructor(client: BaseClient, data: MessageDataOptions) {
        super(client);
        this.id = data.id;
        this.channelId = data.channel_id;
        this.guildId = data.guild_id;
        this.author = new User(this.client, data.author);
    }
}

export interface MessageDataOptions {
    id: Snowflake;
    channel_id: Snowflake;
    guild_id?: Snowflake;
    author: UserData;
    content: string;
    timestamp: string;
    edited_timestamp: null | string;
    tts: boolean;
    mention_everyone: boolean;
    embeds: [];
    pinned: boolean;
    type: MessageTypes;
}

Does this make sense to you tim? (Mainly talking about the user part)

#

My idea is, author would be of type UserData, and then i'd parse it into an actual user class instance when attaching it to the Message

quartz kindle
#

yes thats that djs does

sharp geyser
#

Mmm, I see

#
Message {
  client: <ref *1> BaseClient {
    _events: [Object: null prototype] {
      ready: [Function: log],
      debug: [Function: log],
      messageCreate: [Function (anonymous)]
    },
    _eventsCount: 3,
    _maxListeners: undefined,
    token: 'asdasd',
    properties: undefined,
    presence: undefined,
    compress: undefined,
    large_threshold: undefined,
    shard: undefined,
    intents: [ 512 ],
    rest: RestManager { _client: [Circular *1] },
    ws: WebsocketManager { totalShards: [Array], _client: [Circular *1] },
    [Symbol(kCapture)]: false
  },
  id: '976682394633510976',
  channelId: '972342210685206569',
  guildId: '957867801119449109',
  author: User {
    client: <ref *1> BaseClient {
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      token: 'asdasd',
      properties: undefined,
      presence: undefined,
      compress: undefined,
      large_threshold: undefined,
      shard: undefined,
      intents: [Array],
      rest: [RestManager],
      ws: [WebsocketManager],
      [Symbol(kCapture)]: false
    },
    id: '957347862314905610',
    username: 'Misty',
    discriminator: '6666',
    avatar: 'f0dbe90216d64cacf4c5fb14ae076d7a',
    bot: undefined,
    system: undefined,
    mfaEnabled: undefined,
    banner: undefined,
    accent_color: undefined,
    locale: undefined,
    verified: undefined,
    flags: undefined,
    premiumType: undefined,
    publicFlags: 0,
    avatarDecoration: null
  },
  content: 'asdasd',
  timestamp: '2022-05-19T03:07:08.762000+00:00',
  editedTimestamp: null,
  tts: false,
  mentionEveryone: false,
  embeds: [],
  pinned: false,
  type: 0
}

Do you think it is fine setting things like that?

#

I was thinking if discord didn't send it, then it shouldn't be displayed

#

so instead of it being undefined it should just not be there right?

quartz kindle
#

whatever you prefer

#

from a performance standpoint, v8 likes fixed objects better so it can keep reusing the same structure

sharp geyser
#

I kind of feel like if it wasn't provided why show it

quartz kindle
#

from a memory efficiency perspective, not having the props when not needed is better

sharp geyser
#

How do you suggest I remove them if they aren't provided

#

I could do something like a loop and del the undefined values from the object but

#

that is likely not wise

quartz kindle
#

just dont add thm in the first place?

sharp geyser
#

Mmm you make a fair point indeed

split hazel
pine nova
#

πŸ’€

tribal pine
#

extremely stupid question: but what to do if you lost your api token?

solemn latch
#

I dont know of any services which dont allow you to regenerate your token.

pine nova
#

πŸ’€

upper moss
tribal pine
#

solved it already thanks!

upper moss
ancient nova
#

const mentionedChannel = !args[0] ? message.channel.id : args[0].replace(/\D/g,'');
so I'm trying to get the current channel ID if there aren't any args, and get a channel if there is args, how do I check whether the channe mentioned in args is actually valid?

spark flint
#

what about it

#

It’s helpful giving context

ancient nova
spark flint
#

Ah

pale vessel
ancient nova
#

is there a way to check it using a one liner?

pale vessel
#

yeah

#

nah

#

that only gets the current channel name

wheat mesa
#

djs documentation is very easy to read btw

pale vessel
#

also, can't you use message.mentions.channels.first() ?? message.channel?

#

assuming channel is the only argument for that command

ancient nova
#

wait so that works for channels too?

pale vessel
#

yeah

ancient nova
#

well I still want it to work when I give a bare ID though

pale vessel
#

ah true

pale vessel
#
await message.guild.channels.fetch(mentionedChannel);```
ancient nova
#

I feel like that would be slower than just adding one more regex to check if the arg is a discord IP

lament rock
#

I used to have a function to parse arbitrary user input that resolves to a Channel by searching by mention, name, or by ID

ancient nova
#

I would prolly just do something like args[0].match(/\d{17,18}/) maybe

lament rock
#

Do not specify ID lengths since they will overflow

ancient nova
#

how? isn't the base ID length between 17 and 18 chars

lament rock
#

and 1 is technically a valid ID

ancient nova
#

yeah that's why I'm checking the length

lament rock
#

What I just said flew over your head

ancient nova
#

if the match returns true then it's the correct length

wheat mesa
lament rock
#

The IDs will reach the max number available in that range and then overflow into a longer range

ancient nova
ancient nova
lament rock
#

Just trust me and do not specify ID ranges

#

it will save you the hassle

ancient nova
#

isn't max float range like 9999999999999999999999999

lament rock
#

IDs are ints

#

well. Strings

cinder patio
#

Just use the regex provided by discord.js ez

wheat mesa
#

IDs are bigints aren’t they?

ancient nova
#

then it won't overlow since integers don't have a max renge

lament rock
#

They specify the range

wheat mesa
#

Yeah they have a Snowflake util for checking if something is a valid snowflake

ancient nova
lament rock
#

They are can only fit into BigInt, yes

ancient nova
#

😭

#

what is it called

cinder patio
#

Overflow as in the integer will be longer than 18 characters

lament rock
#

any number is a valid Snowflake btw

#

even 0

cinder patio
#

so your regex will cut off the id

lament rock
#

The only way you can check invalid without fetching is if the timestamp is > the current date

ancient nova
#

then what should I do?

lament rock
#

0 would be at Discord's epoch

ancient nova
#

I need to keep that check all in one line

cinder patio
#

why

ancient nova
#

to make it neat

lament rock
#

Make a function for it

pale vessel
#

uhh i had this js export default function (text: string): boolean { try { const bigInt = BigInt(text); return bigInt >= 0n && bigInt <= 18446744073709551615n; } catch { return false; } }

lament rock
wheat mesa
#

It tries to convert the string to bigint, if it fails then returns false

#

If it doesn’t fail then it checks the value range

ancient nova
#

const checkValidID = function(text) {
try {
const bigInt = BigInt(text);
return bigInt >= 0n && bigInt <= 18446744073709551615n;
} catch {
return false;
}
}}

lament rock
#

literally just use what I provided

cinder patio
#

less or equal than?

lament rock
#

I meant the bigint after that

#

such an arbitrary number it seems

cinder patio
#

maybe it's when the world's gonna end

pale vessel
#

max unsigned 64 bit integer

lament rock
#

pretty sure BigInt can go over max unsigned 64bit int

pale vessel
#

but snowflakes can't

lament rock
#

Alternatively, just check if the timestamp in the snowflake is > Date.now()

#

your function can return false positives for Dates 1 week from now

#

The spec of SnowFlakes might change once 128bit or > computing becomes commercial

#

Hopefully not the end of the world by then

#

but creating work for yourself down the line is unwise

split hazel
#

anyone know how you can get the path in react SSR?

#

i tried window.location.pathname but its in a function and so it gets server rendered showing an error

#

and i cant throw it in useEffect

#

well i can it just wont look nice

#

i swear someone needs to come up with a framework which can actually detect client-side only code

#

all these frameworks but not one unique one

rocky hearth
#

what is equivalent of import X, { Y } from "xyz" in commonjs

split hazel
rocky hearth
#

X would be default import?

split hazel
#

yeah

rocky hearth
#

ohh ok thx

split hazel
#

though commonjs doesnt really have a concept such as default imports

rocky hearth
#

yeah that's what I asked, if X would be a object having default property

cinder patio
#
if (typeof window !== "undefined") {
  //...
}
#

Or even better, make it a function parameter so the function doesn't have to check that

#

and then pass whatever you want to it

split hazel
#

i figured out i fricked up on my end

#

i tried calling a function that was supposed to be called only on load in the render function without useeffect

#

fixed it now though and now it only renders when its supposed to

rocky hearth
#

y it is required to specify type of file in js imports?

#

I mean it'll always be .js, no?

quartz kindle
#

there is json cjs and mjs

#

also, are you talking about require or es6 import?

rocky hearth
#

es6

#

then y require doesnt need to specify types?

quartz kindle
#

according to a few stackoverflow answers, es6 doesnt need extensions either

#

it just needs to match the file name, extension included

rocky hearth
#

yes I'm talking about file extension. Y to specify them?

quartz kindle
#

meaning you can save your file as index.test and import "./index.test" and it will work

rocky hearth
#

but that is not the case for cjs imports. Or is it?

#

require doesnt need file extension right?

earnest phoenix
# rocky hearth then y require doesnt need to specify types?

CommonJS (CJS) is not part of the JavaScript standard and it's just a workaround as JavaScript didn't have modules back then, so it rather uses an algorithm to find files based on the file resolution, ECMAScript modules (ESM) is a part of the JavaScript standard and now officially supports modules and we require it because it doesn't really use an algorithm because we want to boost things up and force the developer to provide extensions instead of being lazy and not doing so, just as seen in many of the programming languages out there

#

Just to also avoid internal confusion

rocky hearth
#

oh wow, good to know that

quartz kindle
#

also there are other stuff besides cjs and esm

#

like RequireJS, SystemJS, AMD, UMD

rocky hearth
#

so that algorithms auto detects file extensions, I guess

quartz kindle
#

each has different rules

simple stump
#

Would it be possible to use JSDOM to execute external JavaScript? For example:

let stringToPrint = "hello";

Then a website having this function:

function printMessage(message) {
  console.log(message);
}

Then using JSDOM:

dom.something.printMessage(stringToPrint); // returns "hello" from the virtual console
quartz kindle
#

idk try attaching it to window

simple stump
#

like dom.window.printMessage

split hazel
#

what is this dollar store html dom rip off

#

the discounted dom

quartz kindle
simple stump
cinder patio
#

This sounds like a really bad idea

simple stump
#

It is unfortunately. But I'm trying to deobfuscate a URL through a function from the website. The function itself can only be used from the min file

cinder patio
#

Use puppeteer

simple stump
# cinder patio Use puppeteer

It takes forever to load though. I think this is possible via JSDOM since I could theoretically just inject a script:

let message = "hello";

let script = `
<script>
  printMessage(${message});
</script>
`;

And then just use runScripts: "dangerously" for JSDOM. But yeah, this generally isn't a good idea. I wouldn't do this unless I really have to.

spark flint
#

why is cloudflare refusing to update my dns records

#

added test.<domain>, doesn't work and dns checkers don't say its a valid record

boreal iron
#

It might has a large TTL value

spark flint
#

oh

boreal iron
#

And or the zone at all

spark flint
#

even tho i added a new record and it didn;t work?

#

ah

boreal iron
#

Means updates/pushes can take hours/days etc

spark flint
#

i've not modified any of that which is why i'm confused

boreal iron
#

Yeah by default TTLs are about an hour or more

#

Dunno about CF

split hazel
#

yoo nodejs crypto module has a reference to EDP445

spark flint
#

docker: Error response from daemon: driver failed programming external connectivity on endpoint minio1 (7644e2e5e28773f0123b9bd54ca926a4198e4bd27e21925d1d825ccefbea0e33): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 9001 -j DNAT --to-destination 172.17.0.2:9001 ! -i docker0: iptables: No chain/target/match by that name.

#

tf do i do lmao

spark flint
#

yeah fixed that

#

now minio is pissing me off

#

redirects to localhost when i nginx proxy

spark flint
#

ok it all works no

#

now

#

lets goooo

quartz kindle
#

yes

#

ff
n i nginx proxy

spark flint
#

lmao

#

i like minio now

#

it is no longer pissing me off

#

and its speedy af

quartz kindle
#

i dont even know what that is, but i dont really wanna know

#

:^)

spark flint
#

self hosted s3

carmine summit
#

is there a way to attach a string in a message (id) so it cannot be visible to clients but will be visible on fetched message? without using any database? or do I need to make some kind of discord powered database? or just a normal database using quickdb? kinda dumb question when I think about it...

quartz kindle
#

well you can put it inside a button

#

other than that, no

lyric mountain
#

Like a map or database

carmine summit
#

discord powered database it is then!

#

cant see what can go wrong

lyric mountain
#

Does it need to stay valid after restarts?

carmine summit
#

yep

lyric mountain
#

U can setup a sqlite db in minutes

#

Simple single-table structure

#

Programs do that all the time

sharp geyser
#

tho if you wanna use arrays it will be a bitch in sqlite (unless they changed it)

carmine summit
#

yeah but dependencies, id rather use discord databse

lyric mountain
#

Also he said string, so it'll be fine

lyric mountain
#

Which is like, kbs at most

sharp geyser
#

This guy just said...discord database?

carmine summit
#

discord is like database.send() or data.edit() and database.fetch()

#

it works ive tried it

sharp geyser
#

πŸ‘€

#

but...why

carmine summit
#

why not?

sharp geyser
#

It is just not smart way to save data, at any point that could get deleted and poof gone

carmine summit
#

its not like its for a public bot that hundreds of servers gonna use

lyric mountain
#

Jokes aside, if discord ever allows bots to edit user notes I bet people will use it as db

sharp geyser
#

Time to edit ur user note

#

:)

#

Why use ur own database when you could use discord's?

lyric mountain
#

Serialize an entire sqlite file and save inside notes mmulu

sharp geyser
#

Sounds like a plan

#

Ima serialize ur address into your usernote

lyric mountain
sharp geyser
#

Should I even worry about making a 'super' class for channels?

#

I myself don't see the benefit of having such a thing but i've been told it is probably a good idea. I just still somewhat doubt it (as they never really said why it'd be a good idea)

loud tree
#
#include<stdlib.h>
#include<string.h>
#define str_size 2999
#define chr_no 255
int main()
{
    char b[str_size], m;
    int d[chr_no];
    int i, max = 0, x;
    
    printf("Input the string\n> ");
    scanf("%[^\n]%*c", b);

    for(i = 0; i < chr_no; i++)
    {
        d[i] = 0;
    }
    
    int c = strlen(b);
    int l;

    for(i = 0; i <c; i++)
    {
        l = (int)b[i];
        d[l]++;
    }

    for(i = 0; i < chr_no; i++)
    {
        if(d[i] >= max)
            max = i;
            m = (char) i;
    }

    printf("The maximum occurring character is %c occurring %d times\n", l, max );
 
    return 0;
}```
#

I don't know where I am doing wrong

#
    {
        l = (int)b[i];
        d[l]++;
    }

    for(i = 0; i < chr_no; i++)
    {
        if(d[i] >= max)
            max = i;
            m = (char) i;
    }```

probabaly here
split hazel
#

it will make it quicker to add changes to the channels apis

#

as a lot of the channel apis are the same across multiple channels

#

so instead of duplicating code you can extend them

rocky hearth
#

which is better approach to duplicate an array?
[...arr] or arr.slice()

boreal iron
#

Just to duplicate it?

#

new_array = old_array;

#

But I assume you wanna do it inline instead

cinder patio
#

That doesn't clone the array

earnest phoenix
#

The reason it's faster is because it's a fixed method to only one type of object which are arrays, while the spread operator (...) is not a fixed operator and works for multiple types of primitives, which can slow it down, and it also depends on what wraps it

split hazel
#

you know bro spends too much time with javascript when he calls array slice array.prototype.slice

split hazel
#

aight so since the stack verse won't help because the question i wrote isn't "perfect" and has been closed (god I hate the stack community)
relating to SMTP what kind of measures should I employ to kind of perform a soft check on incoming emails? Emails can be easily spoofed so this needs to be done

What I do right now is check if the incoming email is valid and if it has a valid MX record but not sure if I should do more than that

vivid fulcrum
#

correct

#

what measures have you taken to protect your source code (if closed source), to protect your token etc.

#

and obviously the server your bot is hosted at

split hazel
#

does anyone know a regex that will extract subdomains from an email?

spark flint
#

(\w+@[\w.]+\w)

spark flint
#

πŸ˜”

split hazel
spark flint
#

wait

#

for regex

#

isn;t it <regex>.match("test@test.gmail.com")

#

wait thats probs not js

spark flint
#

@split hazel

#

"test@test.gmail.com".match(/([^.@]+)/)

#

ah wait that doesn't work

#

fml

#

the webite i used to test worked tho

split hazel
#

rip

earnest phoenix
earnest phoenix
#

Here's the regex: /[a-z1-9_.-]+@((?:[a-z1-9-]+\.)*)[a-z1-9-]+\.[a-z1-9-]+/i

#

The i flag included for case-insensitivity

ancient nova
#
  let welcomeChannel = settings.welcomeChannel;
  // here's some regex to remove both "<#" and ">" elements from it
  member.guild.channels.cache.find(c => {
      if (c.name === welcomeChannel) {
          //return channe by name.
      } else if (c.id === welcomeChannel.replace(/\D/g,'')) {
          //return channel by ID
      }
  }).send(welcomeMessage);
#

you guys seem to be better at regex than me. I'm trying to make it find either by channel name or by ID, ID will work both in case mentions or just pasting plain ID

#

but something is wrong I keep getting random errors

#

can't figure out where because it doesn't exactly tell me

earnest phoenix
#

...and the error is?

ancient nova
#

there is a couple, I cleared the console already but from what I remember it was something along "couldn't get" and "couldn't cache"

#

basically a discord API error

earnest phoenix
#

We can't really help without an exact error, and the way you're trying to find the channel can be pretty slow as you keep replacing rather than replacing once

ancient nova
#

it happens in the guildMemberAdd event, I'm trying to make it as accesible as I can if many servers use that at the same time

wheat mesa
#

I’m still baffled by this obsession about regex you have

ancient nova
#

basically you can make a library full of functions and it's only gonna be a couple of lines

cinder patio
#

why do u care about file size

earnest phoenix
# ancient nova it happens in the guildMemberAdd event, I'm trying to make it as accesible as I ...
// A regex to match IDs.
const channelIdReg = /^\d+$/;
// A regex to match channel mentions, and to also capture the ID if available.
const channelMentionReg = /^<#(\d+)>$/;

...

const { welcomeChannel } = settings;

// Declare variables with no value, we'll modify it later.
let channel, match;

if (channelIdReg.test(welcomeChannel))
  channel = member.guild.channels.cache.get(welcomeChannel);
else if (
  // Match against the channel regex.
  (match = welcomeChannel.match(channelMentionReg)) !== null
)
  // If it matched, get channel by ID.
  channel = member.guild.channels.cache.get(match[1]);
else
  // Otherwise find by channel name.
  channel = member.guild.channels.cache.find(
    (channel_) => channel_.name === welcomeChannel
  );

// If the channel is not found, return.
if (channel === undefined) return;

// Otherwise send the message.
await channel.send(...);
ancient nova
earnest phoenix
#

And your point?

ancient nova
#

settings by itself won't really work as you think it does

#

it will return a map of settings

earnest phoenix
#

I literally wrote that based off of the code you showed

ancient nova
#

whoops now I see how it works

#

I just woke up don't blame me

wheat mesa
ancient nova
#

shouldn't you await cache.get and cache.find?

wheat mesa
#

No

#

Cache is not a promise

ancient nova
#

😐

wheat mesa
#

Anything from cache is stored in memory already

ancient nova
#

okay understood

ancient nova
#

checking for <# and > without regex would be a pain

wheat mesa
#

Ever heard of .substring() πŸ˜›

ancient nova
#

😐

cinder patio
#

regex is good yes

#

but not always

ancient nova
#

@earnest phoenix it works with mentions but doesn't work with names

#

ERROR Uncaught Exception: TypeError: Cannot read properties of undefined (reading 'cache')

#

tried fixing it myself but nothing worked

earnest phoenix
#

Because I forgot to put the s after channel

#

I edited the code so try it

ancient nova
# earnest phoenix I edited the code so try it

I'll try ```js
if (channelIdReg.test(welcomeChannel)) {
channel = member.guild.channels.cache.get(welcomeChannel);
// Match against the channel regex.
} else if ((match = welcomeChannel.match(channelMentionReg)) !== null) else {
// If it matched, get channel by ID.
channel = member.guild.channels.cache.get(match[1]);
} else {
// Otherwise find by channel name.
channel = member.guild.channels.cache.find((channel_) => channel_.name === welcomeChannel);
}

earnest phoenix
#

Uh, you've got an extra else at almost the end of the second if statement

ancient nova
#

wut

#

oh

stiff lynx
#

showing the list of guilds where the bot is, is against discord tos?

stiff lynx
spark flint
#

topgg don't approve bots if anyone can run that command

#

only the developer should be able to run it

stiff lynx
# spark flint only the developer should be able to run it

I've asked this question bcs I'm doing a partnership command where a partner is send in other servers, I have a counter that update the message, for example 'message send in 3 servers' => 'message send in 4 server' and for make the command more real I would like to change it in 'message send in Server A' => 'message send in server B' and at the end say like 'message send in 10 servers'

#

I wanted to know if this was against discord tos

earnest phoenix
#

I dont think its against the tos if the server owners can set the message sending channel

#

or can turn it on/off

solemn latch
#

many anime api's don't properly label series and can send nsfw, or even illegal content(in some countries) when filtering.

#

also, it seems the reason they gave is much more broad than just the api's you use. it could be any feature of your bot.
when they say "APIs" they are referring to the discord APIs

lament rock
#

they never give specific details

#

They explicitly say 3rd party APIs btw

solemn latch
#

πŸ‘€ where?

lament rock
#

oh nvm I am so fucking tired

#

my bad

#

they implicitly mean 3rd party APIs

solemn latch
#

well, in the dev terms of service "APIs" always refers to the discord API's

lament rock
#

as if Discord offers multiple

solemn latch
#

they do

lament rock
#

Discord.js has examples you can comb through

lament rock
#

So, you're basically telling us you're too lazy to look and possibly find other information you might find helpful

#

What did you expect that to do

solemn latch
#

so your question is fetching a dm channel?

earnest phoenix
#

guys

#

is anyone here ?

pale vessel
#

nobody's here, try again next time

spark flint
#

we're all dead sorry

#

:)

earnest phoenix
#

does the Button and SELECT_MENU Collectors work on discord.jsv12

spark flint
#

just move to 13 lmao

earnest phoenix
earnest phoenix
#

in the version 3

spark flint
#

version 3 what???

earnest phoenix
spark flint
#

oh

#

just move to v13 when you can

earnest phoenix
spark flint
#

not that i know of

earnest phoenix
#

const collector = msg.createMessageButtonCollector()

#

it say createMessageButtonCollector() is not a function

spark flint
#

then you've answered your question

#

not available

#

in v12

earnest phoenix
#

alright ty

simple stump
#

I'm trying to run a script within JSDOM, however I get the error that imgReverser isn't defined. I'm attempting to access a function in read.min.js, but what's strange is that when running await imgReverser("a") in dev tools the code runs. It's just within NodeJS that I encounter the error that imgReverser isn't defined.
Code: https://sourceb.in/ZZ3bHp63fe

This is what I send into dev tools:

imgReverser("link_to_image").then(canvas => {
  console.log(canvas.toDataURL('image/jpeg', 0.9));
});

The output is as expected which is data:image/jpeg;base64,/9j/.....

ancient nova
#

I have a couple messages that I return within the script but somehow multiple returns activate???

#

how is that even possible

split hazel
#

only one return can activate unless you're doing something wrong

proven lantern
#

is there a website that lists all the utf characters/emojis and lets you know which OSs they are available on?

split hazel
#

tho you generally shouldnt worry about that

#

if you really need an emoji to be shown everywhere you need to use your own emote pack

proven lantern
#

i'm thinking about replacing -> and <- with something like this β‡  β‡’

split hazel
#

oh thats a character

proven lantern
#

oh nice

split hazel
#

it should be supported pretty much everywhere

#

unicode characters are very widely supported

proven lantern
#

i guess i could look at the value of it. the higher it is the less it's supported probably

split hazel
#

yeah

ancient nova
#

does anyone have any idea how to use the .replace function on a json?

split hazel
#

what are you trying to do?

ancient nova
#

get a json, and format it

#

obviously what I've done doesn't work

solemn latch
#

what is response?
.json() can be a promise depending on what response is

ancient nova
#

I've awaited the function

#

not sure if that is enough?

solemn latch
#

you need to await the json() function too

ancient nova
#

how do I await a .then() func then?

solemn latch
#

you cant afaik

ancient nova
#

then(async (response) => {}) is what I've been trying to do

ancient nova
solemn latch
ancient nova
#

😐

stiff lynx
#

People that doesnt pay attension triggers me ngl

ancient nova
#

I've been trying to avoid doing just that

#

isn't .then supposed to magically resolve the json anyway

solemn latch
#

I dont see you use .then either

stiff lynx
#

me 2

ancient nova
#

a double then will solve everything

ancient nova
stiff lynx
#

u r replacing value

ancient nova
# stiff lynx what

then(response => response.json).then(result => result);; result being a json which I can work with

solemn latch
#

thats kind of hard to read isnt it?

stiff lynx
#

I find It useles, u r using replace()

ancient nova
stiff lynx
#

and replacing the same values

ancient nova
stiff lynx
#

and avoiding this

#

for True and False u can put toLowerCase () and replace only the undefined

ancient nova
#

forEach doesn't even work

#

how come, it is a json, right

solemn latch
#

its an object at that point

#

objects are not iterable,

stiff lynx
#

imo working directly at the data input is easier than doing this

ancient nova
#

how do I format this then?

#

I'm so confused

stiff lynx
#

me too about this

ancient nova
#

the ${}? I just wanted to make sure it's a string

solemn latch
#

wont that just turn it into [Object object]

ancient nova
#

it shouldn't

solemn latch
ancient nova
#

it does appear to work as a json normally and I can use it like response_.result

solemn latch
#

its not a json, its an object

ancient nova
#

then what is the point of .json()

solemn latch
#

response.json() returns a promise of an object

#

to turn a string into an object

stiff lynx
ancient nova
#

that is why I used a double .then()...

ancient nova
solemn latch
stiff lynx
ancient nova
#

is it even possible to keep it all inside the .then() func...

#

I need it to be like this otherwise the code will look bloated

stiff lynx
#

Obj are not iterable

#

Woo already told u

ancient nova
#

is there no other way to do this?

solemn latch
#

sure, it just seems like you're trying to do random stuff until it works.

That will take days to get something kind of working

stiff lynx
#

days if u are optimistic

ancient nova
#

so I'm gonna have to do response_.something.replace(...).replace(...) for every single string then?

stiff lynx
#

WHAT IS THIS REPLACE MAN

#

replace concatenation

ancient nova
#

okay it's not causing any issues I'll fix it later

#

focus on the error

solemn latch
#

whats the error?

stiff lynx
#

send a beatufull code block with the err

ancient nova
#

forEach is not a function.. like I said I need to make it iterate somehow to format it

stiff lynx
#

πŸ’€

solemn latch
#

if you want to iterate over an object youll need to turn it into an array, then back into an object

stiff lynx
#

so u want to loop all over the JSON and change the values?

solemn latch
#
simple stump
#

What is a good way to execute code on a website and return the data using NodeJS? I'm trying to run a script with JSDOM, however I get the error that imgReverser isn't defined. I'm attempting to access a function in read.min.js, but what's strange is that when running await imgReverser("a") in dev tools the code runs. It's just within NodeJS that I encounter the error that imgReverser isn't defined.
Code: https://sourceb.in/ZZ3bHp63fe

However, despite these issues, I don’t want to use a headless browser like Puppeteer or Selenium. Using those tools are extremely resource intensive and take a while to load. I’m hosting my web server on a 2 GB VPS, so unfortunately headless browsers aren’t a good option at the moment :/

solemn latch
simple stump
solemn latch
#

require the script containing the function in the head of the html, then run

simple stump
#

I used window.document.createElement(β€˜script’); with the source being the min file, then did window.document.body.appendChild(), but for some reason when using console.log(imgReverser(β€˜some_url’); nothing got logged.

#

I think I’m misunderstanding JSDOM a bit though lol. If it helps I can send the code I used when I get back on my laptop.

simple stump
simple stump
#

Nothing is logged or appended unfortunately.

#

I do get an error thrown from runScripts: "dangerously" so I'm trying to use outside-only instead of dangerously, but its the same result regardless.

solemn latch
bleak sigil
#

Need some help with making a bot on MacOS
Been trying to get everything to work but as soon as that happens, another issue comes along.
I am using Python to make a custom bot for my server and I can't seem to download the Discord library. I use the command pip install discord but it responds with pip: command not found
Any help would be appreciated.

solemn latch
quartz kindle
#

check their example for how to use async loading again, everything that is async needs to be done like that

#

because jsdom is synchronous, it doesnt wait for any async code execution, hence why you only get empty data

quartz kindle
velvet jolt
#

some js pro in here?

solemn latch
#

tim is

velvet jolt
#

@quartz kindle u here?

boreal iron
#

Just ask your question

velvet jolt
#

ok so im comming from python learned some js not advanced tho basically im trying to

a = 5
b = "."
print(b*a)``` in js
#

im getting js NaN

cinder patio
#

That's not a thing in JS

velvet jolt
#
let a = 5
let b = "."
console.log(b*a)```
#

yeah noticed

cinder patio
#

b.repeat(a)

quartz kindle
#

what is the logic of multiplying a dot by 5?

#

ah you want to do string repetition?

velvet jolt
velvet jolt
boreal iron
#

lol

quartz kindle
#

yeah do what google said

velvet jolt
#

ty lol

simple stump
quartz kindle
#

the example shows node.js creating a custom function and attaching it to window

#

onModulesLoaded would be this custom function

#

then the the script from inside jsdom will access this function to signal the node side

#
const dom = new JSDOM(...) // create the dom
dom.window.MYCUSTOMFUNCTION = (data) => { // attach a custom function to the window object
  console.log(data) // this will be executed when this function is called
}
#
<script>
// do some async function or long running process
  window.MYCUSTOMFUNCTION(result) // when done call the custom function with the result, to send the result back to node
</script>
simple stump
#

Oh I see. I misinterpreted the documentation. Thank you! That's super helpful.

subtle fiber
#

bomba

simple stump
#

Alright I think I'm not doing this correctly haha. The documentation is a bit confusing to me unfortunately. This is what I have so far:

let d = "some_url";
script.textContent = `
// Added this, didn't work either unfortunately.
a().then(res => {
  window.a(res);
});
async function a() {
  let canvas = await imgReverser('${d}');
  const uri = canvas.toDataURL('image/jpeg', 0.9);
  let newP = document.createElement('img');
  newP.src = uri;
  newP.classList.add('asdfasdf');
  document.body.appendChild(newP);
  return newP;
}
`;
newDOM.window.document.body.appendChild(script);
let dataa = await newDOM.window.a;
stuff.push(dataa);
cinder patio
#

Does JSDOM have a virtual canvas as well?? I doubt it does

hexed hound
#

Hey programmers! πŸ™‚

#

Thought I might try here

#

I am coding a Connect 4 game. I need to display a board image which updates after user input based on where they place the circle.

Now the problem is I have been trying to think of a way to pass in a two dimensional array representing the board state and this function returns an image of the board (basically visualizing the array).

Does anyone have an idea in mind on how to implement this function? Is it possible?

Here are some ideas that I have thought initially but are not efficient:

  1. Have an images folder with every possible combination of board state and fetch the image based on the array. Can't do that since it will take a ton of time to create images of all possible states.

  2. Call an API endpoint where I generate the image in HTML/CSS (DOM), then respond with an image of that. Scratched that too since I am not experienced with React/Angular/Vue or anything similar, will have to host that somehow too and lastly I am not certain if you can generate an image from HTML/CSS and respond with that.

quartz kindle
hexed hound
quartz kindle
#

you can always use canvas

hexed hound
#

is this a js feature/package?

quartz kindle
#

or any image compositing library if you have the board components as images, like jimp, sharp, gm, etc

hexed hound
#

hmm

#

board components?

quartz kindle
#

lets say you have an image of the empty board, and two images of the pieces, one for each player color. you can do basic image compositing, ie merge the background image with copies of the pieces images in specific x-y positions

hexed hound
#

oh wow

quartz kindle
#

you can do that with sharp for example, a pretty popular image manipulation library

hexed hound
#

thats sounds exactly what I wanted

#

i will def check that out

quartz kindle
#

alternatively, you can fully draw the board and the pieces from scratch using geometric shapes and lines without needing any image, you can do that with canvas

hexed hound
#

appreciate it, did not know there were such libraries around

quartz kindle
#

both of them require native code tho, so you will need to have your build tools in order

#

ie windows-build-tools on windows, or build-essential on linux

hexed hound
#

what is native code?

quartz kindle
#

code written in C/C++

#

linked to node.js

hexed hound
#

welp that wont do it then :/

#

dont know any c++

quartz kindle
#

you dont need to

#

the libraries sharp and canvas are written in C/C++

#

you just need to have the tools to compile them before you can use them in node

#

npm does all of that for you, as long as you have the tools installed

hexed hound
#

i see, how will that affect the hosting part?

#

files and bot is run on a server

quartz kindle
#

if you have a vps running linux, just install the build tools there

#

if you're using something like heroku, you might need to search for specific build-packs

#

if you're using a cheap hosting that uses one of those pterodactyl control panels, you might need to ask support to help you if you get errors

hexed hound
#

i see, will ask the provider for info on this if they support it

#

im using sparkedhost

quartz kindle
#

first try installing the library and see if you get any error

#

ie: npm install sharp

simple stump
hexed hound
#

tomorrow hopefully! πŸ™‚ bed time now

quartz kindle
#

also you didnt do it right

simple stump
simple stump
quartz kindle
#
let d = "some_url";
script.textContent = `
window.a = async function {
  let canvas = await imgReverser('${d}');
  const uri = canvas.toDataURL('image/jpeg', 0.9);
  let newP = document.createElement('img');
  newP.src = uri;
  newP.classList.add('asdfasdf');
  document.body.appendChild(newP);
  return newP;
}
`;
newDOM.window.document.body.appendChild(script);
let dataa = await newDOM.window.a();
stuff.push(dataa);
``` does that work?
simple stump
#

lemme try

#

Says it isn't a function. Hm.

const newDOM = await JSDOM.fromURL(requestChapter.url.href, { runScripts: "outside-only", resources: "usable", virtualConsole });
const script = newDOM.window.document.createElement('script');

script.textContent = `
window.a = async function {
  let canvas = await imgReverser('${d}');
  const uri = canvas.toDataURL('image/jpeg', 0.9);
  let newP = document.createElement('img');
  newP.src = uri;
  newP.classList.add('asdfasdf');
  document.body.appendChild(newP);
  return newP;
}
`;
newDOM.window.document.body.appendChild(script);
let dataa = await newDOM.window.a();
stuff.push(dataa);
#

I'll also try in the dev tools console

quartz kindle
#

forgot () sorry

#

window.a = async function() {

simple stump
#

Yea just noticed haha.

#

Still says it isn't a function :/

#

trying in dev tools rn

#

Works fine in dev tools.

quartz kindle
#

what about this? ```js
let d = "some_url";
script.textContent = async function a() { let canvas = await imgReverser('${d}'); const uri = canvas.toDataURL('image/jpeg', 0.9); let newP = document.createElement('img'); newP.src = uri; newP.classList.add('asdfasdf'); document.body.appendChild(newP); window.b(newP); } a();
newDOM.window.document.body.appendChild(script);
newDOM.window.b = (data) => {
console.log(data);
}

simple stump
#

lemme try πŸ‘

#

my function is setup weirdly lol so i cant log it for some reason. could i do let dataa = await newDOM.window.b();?

#
async getImages(requestChapter, id) {
  const newDOM = await JSDOM.fromURL(requestChapter.url.href, { runScripts: "outside-only", resources: "usable", virtualConsole });
  const script = newDOM.window.document.createElement('script');

  script.textContent = `
        async function a() {
            let canvas = await imgReverser('${d}');
            const uri = canvas.toDataURL('image/jpeg', 0.9);
            let newP = document.createElement('img');
            newP.src = uri;
            newP.classList.add('asdfasdf');
            document.body.appendChild(newP);
            window.b(newP);
        }
        a()
  `;
  let dataa = await newDOM.window.b;
  newDOM.window.document.body.appendChild(script);
  stuff.push(dataa);
  return stuff[0];
}
quartz kindle
#

no, let dataa = await newDOM.window.b makes no logical sense

simple stump
#

okay thats what a thought rip. aight nvm lemme try smth else rq

#

Yeah idk whats going on with my functions it just isnt logging anything and res returns null

quartz kindle
#

did you try my code example?

simple stump
#

yea im trying rq.

#

it returns undefined

#

i think

#
function doSomething() {
  return this.getImages(request, readingID).then(res => {
    if (!res) {
      return null;
    } else {
      return res.call();
    }
  });
}

async getImages(requestChapter, id) {
  const newDOM = await JSDOM.fromURL(requestChapter.url.href, { runScripts: "outside-only", resources: "usable", virtualConsole });
  const script = newDOM.window.document.createElement('script');
  script.textContent = `
        async function a() {
            let canvas = await imgReverser('${d}');
            const uri = canvas.toDataURL('image/jpeg', 0.9);
            let newP = document.createElement('img');
            newP.src = uri;
            newP.classList.add('asdfasdf');
            document.body.appendChild(newP);
            window.b(newP);
        }
        a()
  `;
  newDOM.window.document.body.appendChild(script);
  return newDOM.window.b = (data) => {
    console.log(data);
            
    stuff.push(data);
            //return stuff[0];
    return data;
  };
}
quartz kindle
#

that will always return undefined, but does it log anything on the nodejs side?

simple stump
#

nah

#

it doesnt log anythjing or at least i cant get it to

quartz kindle
#

what if you do window.b("abc");

simple stump
#

i feel like im doin smth wrong tho

simple stump
quartz kindle
#

just to see if any data can come accross

#

ah

#

also

#

newDOM.window.b = (data) => {

#

needs to be before appendchild

#

well actually it doesnt really matter, but its safer that way

simple stump
#

aight ill try that. tysm for your help

#

it says it isnt a function

#

newDOM.window.b("something"); i mean

quartz kindle
#

thats not what i meant

#

i meant replace this

#

window.b(newP);

#

for example ```js
let d = "some_url";
script.textContent = async function a() { window.b("abc"); } a();
newDOM.window.document.body.appendChild(script);
newDOM.window.b = (data) => {
console.log(data);
}

simple stump
#

oh wait ic. mb.

#

it prints undefined

#
        script.textContent = `
        async function a() {
            let canvas = await imgReverser('${d}');
            const uri = canvas.toDataURL('image/jpeg', 0.9);
            let newP = document.createElement('img');
            newP.src = uri;
            newP.classList.add('asdfasdf');
            document.body.appendChild(newP);
            window.b("abc");
        }
        a()
        `;
quartz kindle
#

can you put together a very basic test to see if this even works?

simple stump
#

will do πŸ‘

quartz kindle
#

just these two tests ```js
// test 1
const newDOM = await JSDOM.fromURL(requestChapter.url.href, { runScripts: "outside-only", resources: "usable" });
const script = newDOM.window.document.createElement('script');
script.textContent = window.a("test");
newDOM.window.a = (data) => console.log(data);
newDOM.window.document.body.appendChild(script);

// test 2
const newDOM = await JSDOM.fromURL(requestChapter.url.href, { runScripts: "outside-only", resources: "usable" });
const script = newDOM.window.document.createElement('script');
script.textContent = window.a = () => "test";
newDOM.window.document.body.appendChild(script);
console.log(newDOM.window.a());

#

if these dont work, try them again with runScripts: "dangerous"

simple stump
#

So just window.a("test")? I don't need the await imgReverser?

quartz kindle
#

no, remove everything else, just do the test

simple stump
#

okay

#

Test 1 doesn't log anything.

#

Test 2 returns newDOM.window.a isn't a function.

#

Lemme try the runScripts thing

#

Same thing for test 2. Test 1 works actually and test is logged

#

Just taht I get a ton of errors saying, "MessageChannel isn't defined" and issues with grecaptcha lol

#

but ty this is super helpful

quartz kindle
#

but the question is whether the returned value will be what you expect

#

what exactly is the return value you want?

simple stump
simple stump
#

Never mind. Just realized that the URL I inputted was wrong haha. When I use window.b though, I get the error saying it isn't a function.

async function a() {
  let canvas = await imgReverser('imgurl');
  const uri = canvas.toDataURL('image/jpeg', 0.9);
  let newP = document.createElement('img');
  newP.src = uri;
  newP.classList.add('asdfasdf');
  document.body.appendChild(newP);
  window.b(uri);
}
a()
quartz kindle
#

did you add the newDOM.window.b = (data) => console.log(data);?

sharp geyser
#

Should I make it so the super class 'Channel' can accept any kind of channel data to make a basic channel?

#

or should i not bother with having any actual data with the Channel class and just have useful methods other classes that extend it should need so I dont gotta duplicate code yknow

lyric mountain
#

Superclass should be just commonly shared methods and stuff like id

#

The child classes can then inherit it and have their specific methods and properties

#

Don't nest channels within channels, that'll just result in mess

sharp geyser
#

I am trying to make any understanding of how djs does it but it is hard to even comprehend those mega brain people

#

One thing I did notice is that it seems like they have a static create method on the super class that converts the data given to their respective channel types

#

why they made it static tho I have no idea as it seems like they never actually use it like how you'd use a static method

quartz kindle
simple stump
quartz kindle
#

that doesnt explain where that idea came from, window.b = (uri); makes no logical sense

simple stump
#

Yeah I'm not sure what I'm doing tbh. I'm quite unfamiliar with DOM

quartz kindle
#

try putting the ```js
newDOM.window.b = (data) => {
console.log(data);
}

simple stump
#

ive been trying to do some reesearch and slowly learning how dom works

simple stump
#

Yeah nothing is logged.

sharp geyser
#

This is why I love ts cause you can just overwrite types and tell it to fuck off

quartz kindle
#

um wat

simple stump
#

I tried replacing window.b = uri with window.b(uri) and I still get the error that window.b isn't a function (in the DOM not NodeJS)

simple stump
#

The image works

#

and loads

sharp geyser
simple stump
#

its just that getting the data doesnt work

sharp geyser
#

Tho it probably isn't a good idea to really do that as it has no actual value

simple stump
quartz kindle
#

lmao

simple stump
# simple stump using `newDOM.window.b = ...`

Using Cheerio to fetch the HTML elements doesn't work etiher cause the image loads AFTER the page itself. one solution is to just use jsdom again for the actual html and then get the source but i feel thats inefficient

#

anyways i sorta got it to work so ty for your help. ill see if i can find smth more efficient rq

sharp geyser
simple stump
sharp geyser
#

Ima be honest I haven't really read the documentation other then about decorators and generics

simple stump
#

thats my approach to any language to πŸ™ makes coding 10x harder sadly

#

tbh i didnt learn abt module.exports until 6 months ago

sharp geyser
#

Indeed

#

I have a small attention span

simple stump
#

even tho ive been doing js for a while now

simple stump
quartz kindle
simple stump
#

So my solution at the moment is to create an HTML file, require the min file using <script>, then using JSDOM add a script that has the image I'm trying to decode that I fetch on the node side and run it.

quartz kindle
#

and what images are these?

#

can you link an example?

simple stump
daring apex
#
const ytdl = require("ytdl-core");
const { MessageEmbed } = require("discord.js");
const { QUEUE_LIMIT, COLOR } = require("../config.json");

module.exports = {
  async play(song, message) {
    const queue = message.client.queue.get(message.guild.id);
    let embed = new MessageEmbed().setColor(COLOR);

    if (!song) {
      message.client.queue.delete(message.guild.id);
      embed.setAuthor("Dispatcher queue ended | Opus Returned a Queue End");
      embed.setDescription(
        `Ended without playing a song? DM 0_0#6666 for assistance!\n\n **Don't worry I won't leave ${queue.channel} Waiting There For More Music To Be Played!**`
      );
      return queue.textChannel.send(embed).catch(console.error);
    }

    try {
      var stream = await ytdl(song.url, {
        highWaterMark: 1 << 25
      });
    } catch (error) {
      if (queue) {
        queue.songs.shift();
        module.exports.play(queue.songs[0], message);
      }

      if (error.message.includes === "copyright") {
        return message.channel.send(
          "Β© | Contents of this video are copyright protected."
        );
      } else {
        console.error(error);
      }
    }

    const dispatcher = queue.connection
      .play(stream)
      .on("finish", () => {
        if (queue.loop) {
          let lastsong = queue.songs.shift();
          queue.songs.push(lastsong);
          module.exports.play(queue.songs[0], message);
        } else {
          queue.songs.shift();
          module.exports.play(queue.songs[0], message);
        }
      })
      .on("error", console.error);

    dispatcher.setVolumeLogarithmic(queue.volume / 100); //VOLUME
    embed
      .setAuthor(
        "πŸ’Ώ | Started Playing Your Song",```
#

It's not working πŸ˜‘

simple stump
#

and yea im making a web scraper πŸ™

quartz kindle
#

wheres the part that needs decoding?

simple stump
simple stump
daring apex
simple stump
#

ill try to find the link to the website if it helps

simple stump
daring apex
#

Don't know

#

And even the bots online too

simple stump
quartz kindle
#

and you have to scrap this exact website? cant do it on any of the other dozens of manga websites out there?

simple stump
#

but i see what u mean. it might be best to try a diff site. regardless, tysm for your help. i really appreciate it

#

i dont think i would even get the image displaying to work if it wasnt for your help so thank you

daring apex
simple stump
sharp geyser
#

mmm using dots in variable names what could go wrong

simple stump
#

i diidnt see that whooops

sharp geyser
#

Ah ur fine I am sure nothing could go wrong mmLol

wheat mesa
rocky hearth
#

does vsc "organize imports" works for commonjs imports?

quartz kindle
#

even though the script errors, the errors do not affect the parts needed for the reverser function

#

meaning if you work on deobfuscating and cleaning the script, you will eventually be able to isolate and extract the functions needed

sharp geyser
#

tim has anyone told you how cute you are?

quartz kindle
#

😳

#

but i dont wanna be cute

#

i wanna be rich

#

:^)

sharp geyser
#

Man you and me both buddy

#

πŸ˜”

simple stump
quartz kindle
#

also what the fuck is this

#
function toFinite(_0xf384) {
    return _0xf384 ? (_0xf384 = toNumber(_0xf384)) !== 0x1 / 0x0 && _0xf384 !== -0x1 / 0x0 ? _0xf384 == _0xf384 ? _0xf384 : 0x0 : 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 * (_0xf384 < 0x0 ? -0x1 : 0x1) : 0x0 === _0xf384 ? _0xf384 : 0x0;
}
#

lmfao

simple stump
#

min file moment

quartz kindle
#

its literally a hex representation of Number.MAX_VALUE

#

probably made by a transpiler set to lower versions of js where MAX_VALUE might not exist

simple stump
#

lmao yea that would prob make sense

#

idk what sane person would actually type out that many 0's

#

I removed some unnecessary parts of the script but now am encountering some weird issues with functions

quartz kindle
#

this worked for me on dev tools

#
try {
  entire read.min.js code here
} catch(e) {}

imgReverser(...)
simple stump
#

Thanks lemme try that out rq. I'm attempting to isolate the imgReverser function but deobfuscating min files is painful

quartz kindle
#

best case scenario would include making it work on pure nodejs using the canvas library

simple stump
#

Yeah probably. I'll see if I can deobfuscate the function from some online tool or smth and see if that works

quartz kindle
#

well good luck, im gonna go sleep

sharp geyser
#

gn tim

simple stump
#

okay. ty i rlly appreciate all your help!

wheat mesa
#
sharp geyser
#

very useful

wheat mesa
#

3.9 billion downloads

sharp geyser
#

I thought that was a G

wheat mesa
#

giga

#

billion

sharp geyser
#

oop

wheat mesa
#

potato potato

sharp geyser
#

Infinity isn't a number?

wheat mesa
sharp geyser
#

one of u is wrong

wheat mesa
#

all depends on your intended behavior I'm sure

sharp geyser
#

ye

#

imagine having an actual bot

#

πŸ˜”

stable eagle
#
message.usage = cmd.usage

AttributeError: 'Message' object has no attribute 'usage'

Why does python think im trying to use message.usage? I am setting it?

copper cradle
#

cmd is probably where the error is originating

slender thistle
wide rock
#

You have mutual top-level imports, which is almost always a bad idea.

If you really must have mutual imports in Python, the way to do it is to import them within a function:

In b.py:

def cause_a_to_do_something():
import a
a.do_something()
Now a.py can safely do import b without causing problems.

(At first glance it might appear that cause_a_to_do_something() would be hugely inefficient because it does an import every time you call it, but in fact the import work only gets done the first time. The second and subsequent times you import a module, it's a quick operation.)

#

Found a fix for you bud

slender thistle
#

What imports lol

#

Plus I feel like it's pointless to do local imports unless you know what you're doing

split hazel
#

So in react I have a select form input inside of a component but the problem is when that component re-renders fully, the select form loses its state going back to the default select, what is the best way to solve this?

#

I can make it stateful by adding a useState but dont know how I would preverse the state with a select

#

nevermind it was easier than i thought just add a value={state} to the select

split hazel
#

very helpful thank you very much /s

rigid maple
#

How can I download a sent voice message using the WhatsApp API?

#

I have to download audio message and convert it to ogg format

split hazel
#

that is a very broad question

rigid maple
#

I take data in the form of downloadMedia().data in whatsapp-web.js and convert it to base64 format

#

and i print it to another ogg file

#

but this gives no result in my speech to text function, although it gives a result when opened normally