#development
1 messages · Page 1963 of 1
No
c++ is a fat cunt compared to c
What matters is the coder, not the language
ive seen c++ and c code alike
Java is generally slower due to the large use of the heap rather than stack
not in this case
Everything is allocated on the heap except primitives iirc
im trying to do something that i cant do because c++ will not allow me
(Pretty much)
JVM deals with it natively, so the only difference is where the code is ran
You won't get better performance just because a language is lower level
Java is partially interpreted is it not?
Java is black magic
C++ will let you do anything
and i cant even use inline assembly because A that uses a flavour of assembly i greatly dislike and B C++ does not care about preserving your assembly
A shitty C code will be slower than a good python code
Have you possibly considered the fact that you might be the issue rather than the language?
Yes that’s true but anybody with half a brain writing C will outperform python 99 times out of 100
what are you even talking about
try perform a jump to another function in c++ without using a return
I mean, it has JIT, but it works differently from everything
it will result in the stack not being released and objects not being freed
Noone knows how jvm works, the ancient civilization who created it is long lost
Is that why it never seems to get better
that would have to make my code break if i change the optimisation level
On the otherhand, C just don't free anything and will just let everything be free 
Anything you can do in C you can do in C++, normally with the added bonus of having abstractions written by people smarter than you
I have an issue, I have made some custom bots for a server I am an admin in and it was hosted properly, it was running smoothly for 2 months now without any issues but all of a sudden, I am receiving rate-limited errors even tho the bot was working fine for the last 2 months, note, one of the 4 bots only has one function and that is creating member profiles and it is rarely used so that makes it even more weird
even my public bot that has been online for 5 months started receiving such errors, idk what's cause all of this
Jokes aside, it did improve a lot in the last years
kek
I dont even write C and C++ in my day job but I know enough and have worked with it enough to say there is a reason why OS' arent strictly all written in C and why most are now being written in higher level C++ and Rust...
Because people like not writing 10 billion lines of code
also because in that 10 Billion lines of code, you can quite easily make a mistake
I am just lurking during this conversation trying to see if I gain any knawlege
🤔 doing anything on a loop?
or in groups?
repeating actions? such as multiple api calls for one thing.
thing is
modern languages arent really written anymore to take into account the environment
ignorance of c is bliss
well yeah i do have loops but they have big time intervals
that's a wonderful thing
Ignorance of everything is my job
I don't care what os you're running or what version it's running: all I care about is if it supports websockets and the format I want
as an example c++ prefers to store things on the stack rather than registers which in my context slows things down
litterally anything that supports embedded / any systems programming language
and it was working fine for the past few months so i am not sure what's different
Have you heard of TempleOS 
AmogOS
You don't control that, writing it in C isn't going to make it better
just because it can run it does not mean it can produce code with the environment in mind
or more accurately, you shouldn't try to control it
There’s probably a good reason it doesn’t store things in registers
you think you know more than the 40 years worth of optimisations and development of your compiler?
C++ isn’t a new language
for example the register keyword in c++ used to hint to the c++ compiler to store something in registers as much as it can until it cannot
now it does nothing
Compiler (usually) knows best
you're like the over protected Mom at the doctors trying to tell the surgeon how best to fix your son's heart
Even some of the simple optimizations that modern C/C++ compilers make now are impressive
anyways lets start from scratch
what i was expressing first is that I would use assembly instead of c++ to write the scheduler code because the compiler does not take into account what I am trying to do - it does not know it has to preserve the contents of the registers, it does not know it has to release objects on the stack and heap which leads to a memory leak due to me throwing in inline assembly code which the compiler does not take into account
in other words it really is too high level for what i am trying to do
but if I were to sacrifice c++ i will struggle trying to implement classes I made such as maps and dynamic arrays in assembly
the compiler can do that in an instant
writing your own assembly for this application is not a good idea
you could say "use function calls" - i am actually trying to avoid them because they add unnecessary overhead
these days one of my coworkers said js/python are better than java/c# because, according to him, "you have to write less code to do things"
there's too much complexity in software today so he's right
java? never heard of it
yeah, he also said delphi has bigger support for multi-platform than react
Different uses for different languages
we were talking abt desktop applications
Lmfao what
problem is without assembly I cannot do what I need to do which is save/restore the registers as well as make calls to the IO bus
thats what I said
then I pointed that both js and python don't support multithreading
he said "but node can handle it nowadays"
Js and py are decent for desktop development but if you need anything to run fast (graphics beyond a rectangle) it’s 10000x better to use Java/c#/any other language
ANYTHING can render faster than those two
but..but.. that’s fundamentally wrong!
hell even scratch I don't doubt
iirc node runs a couple threads internally but you only have access to one
Workers are the way to go with “multi threading”
I mean. It literally is multithreading
just not very customizable considering they don't share the same memory space, so require cache go brrr
I’ve never really done multithreading in js since it’s not a language really... designed for such a thing
I remade LavaLink in js, so I had to use it
multithreading with node is like releasing a bunch of boats at the same time, then trying to put them together later on
Languages that arent written with concurrency in mind generally do suck to try and be concurrent / parallel with
well
I mean, js was made as a web language, and it excels at it
True
server sided js is still good
It would be cool to see a language similar to js but made with concurrency in mind
(Not sure if that exists)
groovy
maybe not ideal in all situations, but safety is their concern
trying to work out a better way of phrasing native concurrency vs internal concurrency managed by the language
A non jvm language thanks
java shares more with ts than it does js
I mean JS is concurrent, it's soul purpose in life was to be non-blocking scripting system that didn't block the render engine
( ̄_ ̄|||)
C was made to program apollo kekw
hence why it is litterally hell on earth to use with threading
Because of ts I found java to be easier 
cs
imo C# is the better package now
exactly
I thought abt trying ts cuz people said "it was closer to strict-typing langs"
hell wtf is that syntax
learning unity dev rn
Dot net 6 is just taking dumps on Oracle and the JVM
it's worse than c++
Personally I prefer C# over Java
I really like strongly typed languages
I dislike dynamic types
ik but, couldn't they put a few points in syntax?
doesn't guarantee your code will run, but
you mean strictly typed languages if you're talking about java?
Not java fuck no
it's like making a barbarian in d&d then trying to play as a diplomat
So you're refering to Python like typing
I like the feel of pure-OOP langs like C# and Java tbh
lmao idk I just somehow understand ts a bit more than js
Pure OOP and statically typed
hell yeah oop all the way
sounds painful
JS is dynamically typed
Python is strongly typed
C#, Rust, etc... are Strictly/Statically Typed
it's easier to understand when u can "touch" the data
There’s people that advocate for functional over OOP and vice versa, I find that a mix of the two is the way to go
Which is exactly what C# allows
I meant statically typed. My bad
PHP is "eh, whatever fits" typed
Yes but less so than Java imo
there's a guy here who furiously fight OOP and advocates for functional programming
don't remember his nick
Asp only just added support for running the main file without a program class
Personally i never bothered learning hte difference between Functional and OOP
I understand the appeal of functional but it’s just what I like
I just code and call it a day
Like even when I use ts all my shit is in classes and such lmao
I use classes as well
Ever since i discovered classes that is the only thing I really use
Js anf Ts has mostly moved to class based
functional: values will always be the same, no mutations, everything is passed to next step
OOP: MUTATIONS MUTATIONS MUTATIONS!!!!!
Ic
not always true
For example, C is a functional language for the most part (correct me if I’m wrong)
mm generally it's pretty true
functional programming is just about using functions for most things
but it's usually true
And Rust considers itself mostly functional
I need to find a place to either learn java in a way I understand or just give up on learning java 
also functional languages, programs can basically be mathematically proven to work or fail
rust isn't really functional
make a bot
multi-paradime
not really functional
it just throws itself in that pile since most languages support it
it has functional concepts
Yes but it’s not really OOP either
but err yeah no
That is assuming I know basic java
you'll get it along the way
C++ is whatever you want it to be
that's how I did
Mmmm
it's a diffrent kind of OOP
started with the bare concepts, improved along the way
that's true for most langs tbh
C++ is the ditto of paradigms
I learned go by making a bot
Fuck around with the internals of a language for your first project. You'll do fine
except if it is c++, fcking with c++ internals can lead to permanent damage to your disk 
shh don't tell them that
imagine fcking with bash then suddenly sudo chmod 777 / -R
I dont even wanna know what that does
rm -rf /
Why not it’s so fun 😭
Mmm I think not
its interesting to know that people prefer static typing which was a thing at first due to different types having different sizes which does not work well in a packed structure such as the stack
dynamic typing is supposed to be an advantage
So whats the diff between statically typed and the other one
javascript stores variables on the heap doesnt it
yeah but nowadays people like static typing for safety and convenience like autocompletion
not sure
but type systems tend to be terrible for information systems, like representing a user class
yeah it is safe
everything is on the Heap in JS
and better documentation
Everything has an underlying type either way
yes, but dynamic systems don't force that type constraint
statically = WAY easier debugging and stronger compile-time checking
Dynamic typing is just types checked at run time
you mean statically right?
You’re still fucked if you screw up a type, it just might not crash or be as strict on it
wdym
Holy fuck my brain
I had to edit that twice
Lmfao
I’m just a big fan of the safety that static types provide
I am a big fan of being lazy and having my editor do close to everything for me
i don't like to think
it is a disease
think smart not hard
Everyone is waiting for the day AI is coding for you
Make a code that is thread safe and prints amogus on all threads of the cpu
And you just need to make sure it doesn’t code anything related to destroying humans 
Make my game go brrr
If you run a program that keeps printing random letters and numbers then it’ll eventually print out a perfect program
Just might take you until the heat death of the universe
I mean it’s not a secret that a lot of things happened unexpectedly being a big step forward for humans
So who knows…
or backwards
covid moment
Not much of an issue for most of the people on earth tbh
you live in florida or something
Texas
oh even worse
Precisely
Well except a few kids this group of people actually isn’t affected at all
I’m waiting for our annual February winter storm that shuts the state down for a week
Personally I’m hoping I don’t get it because I’m high risk
I’m high risk of being hospitalized/dying of covid 😎
My immune system too busy fighting my own pancreas to fight anything else
You I remember and I’m sorry about that, but don’t get me wrong ,the global overreacting doesn’t justify fuck off the lives for so many unaffected people
If they would only thread people with an higher risk differently
I want to make a system that converts audio to text but it gives me the output like this;
typeof string
Protecting them from the masses instead of separating anyone from anyone else
is that wit.ai
I don't know how to get "text" from it
yes
I mean if covid wasn’t such a political battle then it wouldn’t be a very big problem
ah
Absolutely
i never used their speech to text function
:(
Alright gotta need to work now 
so whats wrong with it
the confidence 100% is a bit worrying
not a good thing in terms of machine learning
it may look normal now but its type is string
Anyways nice discussing with you all, gotta drive now so cya
what is a string?
when i push arraya it looks like this
dont be like fake and text and drive
can you show me how you get the data from wit.ai
its an easy solution from what it looks like but that shouldnt be happening
JSON.parse()
yeah but it shouldnt be like that in the first place
this function
nah, it's pretty simple and straightforward
just use jda
Mmm
i get json syntax error
But what should I make is the problem
Mmm okay
after that try to find a niche to get into
oh you're using their library
One thing I dislike about java is the documentation on a lot of stuff
i found that to be quite buggy
It seems so ugly and confusing
how are you trying to do it?
24-27
yes
.
output
remove console.log(json.parse(newarray))
thats probably whats stopping execution
then try again
Java can be annoying in terms of its interface like documentation and public static void main, but you should try it longer, as there are things to like and not like about it.
I am getting json syntax error again
Oh im not giving up on java
whats in the line you're getting the error at?
ohh you'll love javadocs when u press ctrl+Q
I just find a lot of java packages documentation are just ugly and confusing
Oh?
ctrl Q?
27
but every ide has that
I never knew this
JSON.parse(output)
:o
ik, but I only know intellij shortcut
javadocs are very well formatted when using quickdocs
example image pls
output gives me 2 objects, could this be the reason?
it seems like its already parsed
the output gives me 2 objects, could that be the reason?
no, its type is string
oh yeah that thing
are you using api?
maybe it is the promisify function thats breaking the code
intellij has a lot of nice support for java
was thinking outside of java because it's always been meh there
and gradle/maven/sbt/whatever
gradle is annoying
I don't want to learn groovy
and figure out the differences between declaring dependencies
oh
groovy is just java but with js strictness (or the lack of)
and wait 3 minutes to install anything
literally
i think i found it
KuuuHaKu are you sure its CTRL Q?
click on something then ctrl+Q
the lib does need to have docs tho
if u just added it as dependency u might need to download docs
Mmm I added jda as a dep
fetch docs
I do it through init args
oh?
hey i found it
what was the problem
idk how to start with maven, but concept is the same
if u use a init file all the envvars set there will be available within the runtime
just do System.getenv("name")
wdym by init file?
like the main file that gets ran?
yes, but it gives an error in the try part and goes to the catch part like that
What if I write the code inside the catch block directly into try ?
mvn dependency:resolve -Dclassifier=javadoc to load javadocs btw
press ctrl twice and put that in
or shift, I don't remember
ty
also what is the export NAME='value'
couldn't I just make a env file and use it?
export is how u do it in a bash file
you could do a env file too, it's up to u how u do it
just remember to gitignore it
yea
to get the file just do File f = new File("path");
or var f = new File("path"); if u want
although I dislike var
Does it not pickup on the env file being there?
only if u use a lib to auto load it
something like dotenv-java?
probably
okie thanks
I'd still use a bash/batch file for that
since they're already built-in and works just as fine
you can always press the green arrow next to main method
Dont I have to run it from the bash script ?
you can set envvars from intellij
oh?
and I can just do System.getenv("TOKEN")?
ye
sweet let me try that
The one thing throwing me off with java is the use of ;
so used to not really having to care
you get used to it
So do you not use try/catch when handling exceptions?
My IDE completely just deleted the try/catch
Oh?
Exception which is the father of all, NEEDS to be catched
and RuntimeException, which is an exception that might happen, doesn't need to be catched
So LoginException is what exactly?
java doesn't allow u to catch something impossible to happen
press ctrl+Q
see the hierarchy
but everything extends Exception
loginexception is if u put an invalid token probably
Ic so there really is no need to catch it?
you need to
u can also just throw it
public static void main(String[] args) throws LoginException {
btw, jsut write psvm and press ctrl + space
public static void main(String[] args) throws LoginException {
JDABuilder builder = JDABuilder.createDefault(System.getenv("TOKEN"));
builder.setCompression(Compression.ZLIB);
builder.enableCache(CacheFlag.MEMBER_OVERRIDES);
builder.setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES);
builder.build();
}
My IDE simply did throws LoginException just now
ye
u don't need that btw
public static void main(String[] args) throws LoginException {
JDA bot = JDABuilder.createDefault(System.getenv("TOKEN"))
.setCompression(Compression.ZLIB)
.enableCache(CacheFlag.MEMBER_OVERRIDES)
.setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES)
.build();
}
it's a builder, u can just chain
Ah
and afaik, u don't need to set compression
there are many ways to make one, for instance u can just make an interface and extend all commands from it
then store command instances in a map
Mmm, I think I get the idea
public interface Command {
public void execute(JDA bot, Message message);
}
public class Ping extends Command {
@Override
public void execute(JDA bot, Message message) {
message.getTextChannel().sendMessage("Ping!").queue()
]
}
public class Hi extends Command {
@Override
public void execute(JDA bot, Message message) {
message.getTextChannel().sendMessage("Hello!").queue()
]
}
like this
is it discords fault when i get a 404 when responding to a webhook? anyone else ever see 404 errors like this? it happen twice is a row, but hasn't happen for months before
Yea I get that part
both commands can be cast to Command due to common ancestors
and it's working fine again now
I am curious though where you would make this map?
And how would you add the commands to it
Unless you mean to add the commands to the command map in the command classes themselves
guessing you know its an existing webhook?
I put it in a class of its own
yeah, i have an interaction url endpoint that gets the webhook info so that should be existing
public class CommandHandler {
public static final Map<String, Command> commands = Map.of(
"ping", new Ping(),
"hi", new Hi()
)
}
something like that
obviously you can make it much more dynamic and allow aliases and shit
but that's an example
I don't think i have the knowledge currently to make an alias system
yeah, go slow
I could possibly make that automatic tho.
this I mean
Unless I can't loop through files and get the command names and then the command's class itself
Eh that is too much for now tbh I can't be bothered to figure out how to make it reccursive lookup
if doing with a list ```java
public class CommandHandler {
private static final List<Command> commands = List.of(
new Ping(),
new Hi()
);
public Command getCommand(String name) {
return commands.stream()
.filter(cmd -> cmd.getName().equalsIgnoreCase(name))
.findFirst()
.orElse(null);
}
}
for aliases it'd be the same, you just need to make a containsIgnoreCase
there are all 3 types of collections
cause in the message listener I can lookup commands by name and run their exec method no?
List, Map and Set
themselves have a shitton of specializations
like ConcurrentList
also, it's almost a must, INSTALL APACHE UTILS libs
at least collection and string utils
they are so useful
Also I assume getName would be a method in the command's class
ye
and overriden in each command
the advantage of interfaces is that u can have multiple files share a common signature
so u don't need to cast each command separately
So java classes don't work how i thought
How exactly would you provide a name for the command if Command interface specifies one needs to be set
public interface Command {
public void execute(JDA bot, Message message);
public String getName();
}
public class Ping implements Command {
@Override
public String getName() {
return "ping";
}
@Override
public void execute(JDA bot, Message message) {
message.getTextChannel().sendMessage("Ping!").queue()
]
}
public class Hi implements Command {
@Override
public String getName() {
return "hi";
}
@Override
public void execute(JDA bot, Message message) {
message.getTextChannel().sendMessage("Hello!").queue()
]
}
there are ways you can decrease that
the one I like most is annotations
@Info(name = "ping")
public class Ping extends Command {
@Override
public void execute(JDA bot, Message message) {
message.getTextChannel().sendMessage("Ping!").queue()
]
}
then just get the annotation of the class
but that's a more advanced concept, you'll get to it eventually
I see, also extending an interface isn't something you should do right? I thought you used implements
'onEvent(GenericEvent)' cannot override 'onEvent(GenericEvent)' in 'net.dv8tion.jda.api.hooks.ListenerAdapter'; overridden method is final What the heck does this mean?
Aren't you supposed to use @Override on methods in the class that extends ListenerAdapter
onEvent shouldn't be overriden
there are more specialized events like onGuildMessageReceived
Mmm, so the readme on jda's github is wrong
I am trying to use the ready event
aha
onReady
just type on and press ctrl space
all events will appear there
u can also press ctrl + O
package events;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
public class ReadyListener extends ListenerAdapter {
@Override
public void onReady(@NotNull ReadyEvent event) {
System.out.printf("");
}
}
I was using alpha kekw
lul
I love the handy
import commands.*
So I dont have to make a new import per command
So much about intellij I dont know
it only gets better over time
also, try to make that bot open source
after 3 months, if you're still actively contributing to it you can grab a free jetbrains license
you get to keep it for as long as you develop
Yea I was planning on making it open source
Hopefully people who know java better than me can fix stuff I did poorly at and I can learn from it

Don't worry abt it too much, you'll get better over time
Just keep ur tokens safe
so I noticed the orElse(null) doesn't actually let it return null if nothing is found so how can I check if getCommand returned nothing in the message event
That's a peculiarity of grabbing a single element from a stream
You COULD just use .get(), but it's not advisable to do so
Since it'll throw an exception
I see
I am just wondering how exactly to check if getCommand actually returned a result
cause if it didn't obv they can't execute a command
Check for null
orElse(null) makes it return null if not found
It returns whatever is inside the parens
String cmdName = event.getMessage().getContentRaw().substring(1).split(" ")[0];
String[] args = event.getMessage().getContentRaw().substring(1).split(" ");
Command command = CommandHandler.getCommand(cmdName);
if(command == null) return;
command.execute(event.getJDA(), event.getMessage(), args);
so something like this then?
Lets go!
Thanks for that
Should both of these work?
discord -> interaction url endpoint -> return `{type: 5}` -> post https://discord.com/api/v9/webhooks/${application_id}/${token}/messages/@original
vs
discord -> interaction url endpoint -> post https://discord.com/api/v9/webhooks/${application_id}/${token}/messages/@original -> return `{type: 5}`
So I can be under the assumption that you can't do the equivalent of
let member = message.member || message.guild.members.cache.get('someID')
in java (talking about ||)
what do you mean
{type:5} is a deferred response and the post to the webhook updates the message
so i was wondering if order matters
can i return a deferred after i respond with a post
Member member = message.getMentionedMembers().stream().findFirst()
|| message.getGuild().getMembers()
.stream()
.filter(mem -> mem.getId() == args[1])
.findFirst()
.orElse(message.getMember())
I was hoping this would work, but I am now learning java is more different then I thought.
I figured || worked similar
streams are very useful in java
Yeah, can't
Buuuut
ternary operator can work kinda
You can make a getOr method
Mmm
I always make one
public static <T> T getOr(T get, T or) {
return get == null ? get : or;
}
but who implements it
I always put it into a global helper class
ah
kotlin
uh no fuck kotlin
or scala
Yess pwiss uwu
I was using kotlin before but there was a shit ton of issues I had
kotlin is fun
or akka
but I'd rather use java
One of them being how annoying it was to compile donw into a usable jar file
I was considering making one in c# but I'd rather use java because it's easier with cross-platform compatibility in case I wanna throw it on to a vps
You could also use groovy
Both java and c# can run groovy
Groovy is technically java with dlc
Mmm but how would that working with multiple things? Cause what I want to do is get a member by mention, if that fails get by id, if that fails get by name, if that fails just get the user who initiated the command
Utils.getOr(something, fallback);
more complicated, also a language that I'm not very interested in using
java is what I have to learn in school atm
might as well use it in some projects
Ah fair then
yea I understand how the method works
maven is alright
I like gradle
probably a lot easier to use one of those than another with no documentation on how to use it
It's pretty simple once u understand
So far I like the simplicity of using maven
I'd rather use gradle than maven tbh
I still don't get how it can help solve the issue I am facing tho? Unless I chain the getOr somehow?
U could make it accept infinite args
Mmm
public static <T> T getOr(T... opts) {
for (T t : opts) {
if (t != null) return t;
}
return null;
}
There are many ways to approach that
I was using that I think
can orElse be chained?
Member member = message.getMentionedMembers()
.stream()
.findFirst()
.orElse(message.getGuild().getMembers()
.stream()
.filter(mem -> mem.getId() == args[1])
.findFirst()
.orElse(
message.getMember()
)
);
Idk if this is efficient at all but I found this works
Ye, 4 types
i think
Consumer, Function, Runnable and Callable
Consumer and Function have Bi and Tri versions
And as anything else, u can make ur own
Never tried with var tho
it should work
given they allow variables with multiple types when using var
with that lambda -> stuff
Member member = message.getMentionedMembers()
.stream()
.findFirst()
.orElse(message.getGuild().getMembers()
.stream()
.filter(mem -> mem.getId() == args[1])
.findFirst()
.orElse(
message.getGuild().getMembers()
.stream()
.filter(mem -> mem.getUser().getName() == args[0])
.findFirst()
.orElse(message.getMember())
)
);
Something about this just seems inefficient
But idk
it's just type inference made simple
You could do this:
nesting is a code smell
im new to java gib break :c
it's good that you noticed it looks inefficient
nesting like that should set off alarm bells
I know typically nesting is never good
List<Member> mbs;
if (members.isEmpty()) {
mbs = message.getGuild().getMembers().stream()
.filter(mb -> mb.getId().equals(args[0]))
.toList();
} else {
mbs = members;
}
Member member = mbs.get(0);
But I don't know any other way as of right now to make this more efficient
Members would be mentioned members
I see
But how does that help this situation wouldn't I still need to use streams?
I'd end up doing what I was doing before
Not at all, you get a member at the last line
Ah wait, yeah you'd need to filter it
Mmm, but I don't want to only get by mention
I want to get by ID or name as well
and if no mention, name or id is provided it would use the member who initiated the command
Yea thats cool, but again I don't only wanna check by id
I'd end up needing to nest again wouldn't i?
No prob, just add a OR conditional there
do you think java will ever allow if/else statements be assigned to a variable like scala does?
Like?
Elvis is in groovy
String x = if(true) {
"foo";
} else if {
"mmmkay"
} else {
"bar";
}```
The only language I've seen to really get it right are lisps
where everything is an expression
That's just a ternary
rust does this too
U can do that with switch btw
extremely convenient
yeah now imagine if you could do that with any construct
could build a lot of cool things
it can only do it with a few constructs
you can do it with anything because blocks can be assigned to variables
i need to learn rust
let foo = { return "bar" };
that's just a scope
String val = switch (type) {
case "a" -> "Hello";
case "b" -> "funny";
case "c" -> "big";
case "d" -> "world!";
};
you can do that with any language as well
not all languages allow you to return from a scope into a variable
does it?
that's invalid syntax
So i'd use a ternary operator?
that’s not assigning the return value of a block to a variable though
List<Member> mbs;
if (members.isEmpty()) {
mbs = message.getGuild().getMembers().stream()
.filter(mb -> mb.getId().equals(args[0]) || mb.getName().equals(args[0]))
.toList();
} else {
mbs = members;
}
Member member = mbs.get(0);
but basically the point is very expressive languages like those in the lisp family have little to no keywords
Although for that I'd make an utility method
so you can do things like { return 5; }
My Helper class has more than 10k lines cuz utility
It pays with parens tho
wait you mean you don't paste the same methods in all of your classes
Less words, more parens

or
(if true
(let [x 5]
(+ x 5))
(or false true))
Which basically reads, if true, return x (5) plus 5 (10), else check if false || true. In a lot of languages, if, let, +, and or are keywords
Ah, it's actually 3k lines
Less than I thought
how did you get it to 3000
lisp might be expressive but it’s horrible to read
for a helper class
lol
Utility
lisp is actually quite beautiful once you get used to it
yeah, you need to use function scope to do that
Hey haku do you know how to format a date so its like
Joined Server: 1 month ago
Search my helper class for durationToString
Or u could use discord unix timestamp
<t:seconds:R> iirc
It's been 52 years...
Nice
Say I wanted to get all roles that make them stand out from everyone else i would use a filter right?
evening gamers 🙂
Mmm so I filtered out to only get the roles that hoist but how would I get the names to display them?
Map
.map(Role::getName)
Or Role::getAsMention
To get as discord formatted mentions
what language is this? the :: notation reminds me of ruby.
At the end, .collect(Collectors.joining(" "))
Java
That's a method reference
Like, the method is Role.getName()
ahh ok, not played too much with java other than basic android apps
In a map, you can reduce .map(r -> r.getName()) to .map(Role::getName)
yea basically directly passing the function, makes sense 🙂
It's a nice language, people say otherwise but it's worth to give it a go
After jdk 8 it improved a lot
that :: syntax is nice
hmm, i never really had issues with it. plenty of resources online to help guide you when lost 😄
.addField("**Roles:**", member.getRoles().stream()
.filter(Role::isHoisted)
.map(Role::getAsMention)
.collect(Collectors.joining(", ")),
false
)
Looks cleaner
but again, i only made simple apps
Haku has been a big help for me with java so far
Eventually I will have to stop asking him tho

Always here to help a fellow coffee drinker
kek
The more I use java the more interesting it becomes
My end goal with java is to use https://lwjgl.org
Ah, nice
Are u using jdk 15+?
JDK 17
I didn't have a choice really linux auto installed that for me when I went to install it
You have a ton of qol features then
Like multiline strings
And switch expressions
yikes one of my mouse traps just went off
Or type check-cast
if (smth instanceof Command c) {
c.doSomething();
}
I was using that in the ReadyEvent before
i swear thats js 😄
After you get used to java I really recommend peeking into groovy
It has ALL the vanilla features of java
decorators are poggy
Such that converting a file to groovy is just changing extensions
\
could I change this
if(command == null) return;
// to
if(command instanceof Command c) {
c.execute(/* put the args */)
}
have you tried kotlin before kuu
What is ui supposed to be?
think it's buttons
buttons UI
or components
Heard abt it, but didn't see much
yuh
Yeah, instanceof checks for null
No problem
Instanceof works for both types
Extends and implements are brothers of the same mom
String[] contents = event.getMessage().getContentRaw().substring(1).split(" ");
Command command = CommandHandler.getCommand(contents[0]);
if(command instanceof Command) {
command.execute(event.getJDA(), event.getMessage(), contents);
}
``` so I assume this then?
If so then that is sick
It negates me having to check for null myself
In that case u could just do command != null
Since it's guaranteed to return something that extends Command
do you have to manually manage memory in java?
Nope
Makes sense
U can hint the gc to run tho
And use jvm args to customize how it works
ZGC is one hell of collector
why the string[] notation for a string then? seems obsolete
Zero latency when running
Those are args passed by cmdline
java -Dname=blabla -jar myProject.jar
most people use higher abstractions, like array lists
oooooohhhhh ok yea im dumb 😄
String[] args will have {blabla}
Weird why is it returning me, the ID belongs to a bot in the guild

List<Member> mbs;
List<Member> members = message.getMentionedMembers();
if(members.isEmpty()){
mbs = message.getGuild().getMembers().stream()
.filter(mb -> mb.getId().equals(args[1]) || mb.getUser().getName().equals(args[1]))
.toList();
} else {
mbs = members;
}
Member member = mbs.stream().findFirst().orElse(message.getMember());
Trim the arg then
Actually, how did u split it?
Orrr, maybe it didn't cache members
String[] contents = event.getMessage().getContentRaw().substring(1).split(" ");
that removes the prefix from the command and returns the cmdName with the arguments
I was thinking that just now
I enabled the intents and the cache flag
.enableCache(CacheFlag.MEMBER_OVERRIDES)
.setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_PRESENCES)
does setting intents with createDefault not work?
EnumSet<GatewayIntent> intents = EnumSet.allOf(GatewayIntent.class);
shiroShards = DefaultShardManagerBuilder.create(ShiroInfo.getBotToken(), intents)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)
.setMemberCachePolicy(m -> !m.getUser().isBot())
.setBulkDeleteSplittingEnabled(false)
.setEventPool(Executors.newFixedThreadPool(20), true)
.build();
Damn
Github
This is how I did it
Shard manager, but should be the same for single JDA instance
I was going to ask how sharding works in jda but no point in me knowing rn
That's how it works, everything else is the same mostly
No need for broadcastEval or any weird thing
Just use ShardManager instead of JDA
Nope, just grab it from shard manager
JDA is rather nice
I miiiiight be doing some shameless ads, but if u want a pagination lib, there's Pagination-Utils
Or putils for short
Jda has jda-utilities, but for god's sake I can't understand why it's so complicated
That's why I made one
Cosmo#2064 has logged in.17:36:29.470 JDA MainWS-ReadThread JDA ERROR One of the EventListeners had an uncaught exception java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
yikes
I forgot if you supply whois command nothing that happens
Yea issue is if members.isEmpty() then it will try and use args[1] but if I supply nothing as well then there is no args[1]
I might have to check if args length is 0 before hand or smth
Oh?
That returns null if index doesn't exist
public class <T> LenientList<T> extends ArrayList<T> {
@Override
public T get(int index) {
try {
return super.get(index);
} catch (Exception e) {
return null;
}
}
}
Same for all other access methods
And to convert an array into list: LenientList<String> list = (LenientList<String>) List.of(args)
you forget to check for negatives
java.lang.ClassCastException: class java.util.ImmutableCollections$List12 cannot be cast to class structure.LeniantList (java.util.ImmutableCollections$List12 is in module java.base of loader 'bootstrap'; structure.LeniantList is in unnamed module of loader 'app')
Mmm it has an issue with
LeniantList<String> list = (LeniantList<String>) List.of(contents);
If you have the time, could you explain what that error means exactly?
Or just make a custom constructor for LenientList
List.of() returns an immutable list, it's basically final and can never be changed
The error comes cuz we didn't implement it
So it can't be cast
Well this wouldn't work anyway there would be a type issue
That was a quick example I did, there is a lot of improvement to be done to reduce verbosity
ArrayList can be cast
Cuz we extended it
Ah right
I already tried that aha
It told me it expected 0 but got 1
LeniantList<String> list = (LeniantList<String>) new ArrayList<String>(List.of(contents)); even when doin this same error
public class <T> LenientList<T> extends ArrayList<T> {
public LenientList(List<T> values) {
super.addAll(values);
}
public LenientList(T... values) {
this(List.of(values));
}
@Override
public T get(int index) {
try {
return super.get(index);
} catch (Exception e) {
return null;
}
}
}
Then just new LenientList<>(args)
You do need to override the other methods present in ArrayList btw, to guarantee you treated all data accesses
Also, List<String> list = new LenientList<>(args) is valid
It'll keep the exception handling but allow to be passed as a generic list
No need to keep repeating LenientList
Ayo that works lets go
public LenientList(List<T> values) {
super.addAll(values);
}
public LenientList(T... values) {
this(List.of(values));
}
Can you explain how these two work?
Does the first one just allow you to give it your own list
The top one is the actual constructor, since we extended ArrayList it contains all method of it
and the second let you give it stuf to make a list?
addAll adds all the content from a list into it
Ah
So when creating a new LenientList, we add all the passed values as initial content
The bottom constructor is an alternate constructor that calls the other one
This allows both a List and an array to be passed
Ye
and if that isn't it will throw a type error?
And since we declared a varargs there, zero arguments is also valid
Which will result in an empty array
LenientList is very useful not only for just the arguments but for other things as well
I wish it was an actual built in java list
It won't even compile, T is the list type
Ah
so LenientList<T> becomes LenientList<String> in this case
which only accepts String as values
this is the magic of generics
to have a "whatever" list, u could use LenientList<Object>
I see java heavily uses Generics unlike ts where you didn't really need to
which allow all types of data
generics are also fun cuz u can have less-generic generics
like public <T extends Command> void addCommand(T command)
it'll only allow classes which extend Command
or implements, same thing
Ic
Also
public class <T> LenientList<T> extends ArrayList<T> {
what is the point of <T> after class cause my IDE doesn't like it being there
I had to remove it
I forgot how to define generics in classes kekw
<T> defines generic extension
