[Music]
hello good afternoon good evening good
night good morning there are so many
time zones all over this world that we
live in I am touched part of today was
my mic muted which is rare I guess I'll
start my mic muted and it takes me about
five minutes to realize that and then
the first five minutes of silence but
you know today I'm actually speaking to
you it's Friday I am looking forward to
this weekend yeah okay about happen
about what you're here for
it's been a long week a little bit tired
there was already a live stream today
with a guest and feel the same which I
will maybe mention I'm gonna mentioning
it now but I'm back to continue the
threads of last week earlier this Monday
let's see sorry let me get the chat
chicken going here
alright so hi really ready yet so let me
open up a web browser I'm completely
unprepared for this in as I always am
like I can't even get my web browser to
open this is how unprepared I am so if I
Lim lo later I don't want to try Safari
thank you if I go to this YouTube
channel called the coding train there's
an upcoming live stream and one right
now that's interesting but this is what
I wanted to refer to so this morning
this live stream happened this morning
which was a live stream sponsored by
spell which is a cloud computing service
and guest Nabil Husein trained a LS TM
neural network which is a kind of neural
network that's well-suited for sequences
trained model on a text so text from an
author this in this case a rapper was
used song lyrics were used the model was
trained and then after that was
completed that model was brought into
javascript into the browser and can be
interacted with generating new lyric so
if you're interested in that you can
check out the live stream from this
morning we did have some technical
difficulty a few times here and there so
at some point I'll
hopefully be producing an edited version
of that it was it was actually only it
was only 58 minutes my guess is the
edited version will be like 35 or 40
minutes or something like that and Rui
in the chat are we read gamer who was
watching me my other channel that I will
not mention the secret laptop it's not
so secret right here it is it's not that
I want this laptop to be secret it's
that it's just too many things blocking
the way but alright but I'm on a mission
here
none of the last on Monday earlier this
week here it is
Mastodon trying again I spent two and a
half hours creating a mastodon pot
talking about what Mastodon is which is
an open-source decentralized social
networking platform I created my own
instance called choo-choo dot space it's
still there
Kouji member of choo-choo dot space has
posted this wonderful picture of a koala
but okay we are totally using this
fixture how do I get this image copy
image address maybe yes okay thank you
koji for somehow knowing that I could
use an image of a koala koala let's put
it on the desktop okay I don't know if
we really gonna use this but I'm saving
it for later and a Magikarp over here is
talking about nice to see Schiffman talk
about mastodon okay thank you all right
so this is Mastodon and the instance
that I'm using with my coding trained
bot is Mastodon dot space bots and
sometimes my the words keep coming out
of my mouth but my brain completely shut
off I bring a blue Lee shut off and
words just kept coming because
livestreaming and I feel like if I'd
stop talking I'll be silenced but what
would be the worst thing about silence
all right that was good a little moan
silence there I feel refreshed how do
you feel I'm trying to decide if this
makes sense to be a coding challenge
like mastodons image bot processing
image bot one things I love about this
example that I'm going to do today is it
brings so many things together brings
together api's and node and javascript
in asynchronous I'm gonna use a sink and
a weight which is like es 8 JavaScript
syntax and processing and creating
images and shell scripting oh so many
pieces together into one project the
project that I'm going to build is a
project that starts with a processing
sketch let's see our recent this version
of processing I have is three point four
that's perfect starts with a processing
sketch from node execute the processing
sketch the processing sketch saves an
image node grabs the image uploads it to
mastodons media server then posts a tute
to Macedon referencing the image so if
we look at bots in space one of my
favorite let's look at the local time
line this is nice posting gifts but I
really like the tree how do I find let's
see if I search for tree bot I think I
can actually just go to bots in space
like if I want a cube storm oh it would
be cubes oh interesting the URL for an
account is its number so I can't simply
just know the name of it but let me say
tree bought at BOTS in that space will
this find it for me here is the yeah
there we go no I don't want to email it
don't know how this here we go random
trees oh no I can just do this so I can
do this tree buck there we go no no
Rann oh it is random trees it's random
trees random trees I'm like a lunatic
how long oh this is a different pot this
is totally a different pot you're the
one I was looking forward to fractal
tree one nobody will tell me all right
yes Mastodon again because it's not
master that again it's so what do you
what should this be a doesn't really
matter I'm making the video I think that
I like the idea of trying this as a
coding challenge to Reba there's a
different tree bot hold on how many BOTS
could there be on BOTS in space just
just humor me for a minute here like it
posts free often the one that I'm
thinking of all right I'm gonna give up
in a second I like this one emoji DNA
that's pretty awesome
mutant emoji bot so it's kind of fun
alright so here we go do I want to
create a new bot just I think I'm gonna
use the Prius so I think I'm gonna do
this as a coding challenge but I am
going to get myself who set up a little
bit so what I need is to close these
things then I need I turn open let's
install the update
okay I've got I term open we are going
to go to the desktop
mastodons and open this oops
yeah we're going to get Mastodon bot to
look at all this stuff in here Mastodon
bot - and this is going to be Jo tree
underscore bot thanks tree underscore
bot thank you - Alka for finding that
for me Mastodon bot 3 box in space at
tree underscore bot yeah this is what I
was looking for I want to make exactly
this who created this are they going to
mind a bot gendering tree is made by
Alex Novi Soni okay by this person
all right I'm gonna recreate this this
is gonna be my coding challenge then
close this I'm gonna be here I'm gonna
close this I don't need this and then I
need processing and I need this is gonna
be long
hmm I don't I don't I don't care I'm
gonna do this the way that's gonna be
right and then I need code Visual Studio
code open and close these my son bought
three oh boy oh boy I don't need any of
these files that are extra stuff and
everything else is fine and then
I'm gonna start
with this much code I'm gonna start with
this much code so what I'm trying to
decide is should I do this I mean this
really doesn't matter because I want to
just make this project here's what I'm
gonna do I got an idea I'm going to act
as if this is a coding challenge but I'm
not going to say the words coding
challenge I'm going to just do it as if
it's a tutorial and then at the end if
it feels like it could actually be one
video coding challenge and it doesn't
end up being multi-part tutorial then I
will record a brief intro calling it a
coding challenge how about that
everybody wins
you know I win I mean I'm I don't know
all right we're gonna I check out this
whiteboard thing over here don't think
that I need note though ooh whoa Oh
wrong oh there it is they do want to
erase the whiteboard actually which I'm
going to do very quickly with my fancy
eraser mechanism if I could find it I
can't find where it did it get thrown
away my erasers I know you can't see me
right now I don't want to be seen want
to be seen looking for the eraser am I
going to have to go in the hallway and
get a paper towel the earth will be very
sad I have a nice reusable eraser
doohickey is completely Oh though here
it is found it
this is actually okay
okay there we go now got a marker I am
going to okay here we go
everybody stretch stand up stretch with
me I don't know if this is maybe some
correct stretching thing all right so
other things that I need open here are I
need I need the mastodon API Docs and
mastodons API Docs okay so these I will
definitely probably need to reference
I've got the tree bot I've got the
coding train bot and I've got some code
and let's just make sure like that
that's something okay
all right oh I got a notification I
probably should turn those off all these
people are following me look at
everybody it's all of a sudden so much
activity here okay okay let's I just
want to do something here that's good
I'm trying to figure out like if there's
I just want to uh can I just get rid of
this for a little bit play sound let's
get rid of this please sounds I sound I
actually can I clear notifications yes
oh no but I turn them all off there's no
way to just like turn them all off or
have a done pin yes there we go I just
don't want
I'm afraid of random stuff appearing
that other people are posting all right
Oh Adam in the chat apologies so if you
want to join Chuchu dot space I have I
created an invite for members of YouTube
channel and patrons but I'll have to get
off to generate I didn't realize that it
expired I'll generate a new one after
this is over okay
hello I'm going to make something in
this video and what I'm going to make is
a tree bot I love this bot it is a
bought on Mastodon it is called tree
underscore bot it is made by Alex novo C
was made for nom nom omamo which just
must be some like national BOTS making
month national about making but when
does that happen is it now cuz it we
should all make BOTS for national BOTS
making month so I am going to I love
this bot it makes a tree
this is my one start over if I pour
guests I could get who come here to do a
guest video I don't let them like they
don't start over like 15 times like me
as if I was doing this live hello in
this video I'm going to make a bot and
I'm going to make an image bot I'm very
excited about this project because it
pulls together a whole lot of different
things I am going to use processing to
generate an image I'm going to use node
2x2 call processing to generate the
image I'm gonna use no to talk to an API
and the API is mastodons so one thing
you might want to do is I'll refer you
to all of my tutorial series about the
basics of making a mastadon bot I will
start largely from scratch here but I am
going I've already gotten my API keys
and I already have imported and
installed this node package called
mastodons api and this dot env package
that that loads my API keys for me so
that is stuff that I've done in another
video if you want to see that I'll link
to that in the video description but I'm
just gonna get started so what is the
first thing that I want to do okay
actually let's go to so this is my
inspiration tree bot made by Alex
Novosti for national bot making month
and I am going to try to recreate this
my trees won't be nearly as nice so the
first thing I want to do is I want to
use processing now I don't have to I
could find some node package that does
drawing or generates an image SVG
whatever but I I love processing it's my
happy place and I'm pretty sure I could
get processing to generate a treat in
fact I don't even have to like write the
code for this because I have before so
I'm just gonna go to examples right here
somewhere topics simulate no no no okay
I'll be back in a second oh yeah
I'm back I found it under fractals in
l-systems tree look recursive tree by
daniel keith lon
this is my this is a recursive tree and
as i move the mouse it changes the angle
so let's alter this code a little bit
let's say that
we don't care about a framerate and
let's not let's have the angle be random
between zero and 2pi oh and it's
converting it to radians so okay between
0 and 360 oh and it's doing it over and
over again and draw that's exciting
I'm gonna say no loop so it's done each
time I run this I get a random tree
there's so much more that I could do to
the design of the tree and I'm so
tempted to recode the tree but I'm gonna
just leave it as is you know maybe I
want to like not have so many large
angles and there we go beautiful tree
okay so now now that I've done that what
do I want
I want my processing sketch to also save
and I'm just call it tree dot PNG so
when it's done drawing it's gonna save
an image okay this is exciting now I
need to save this somewhere well where
I've got my Mastodon code right here to
talk to the bot and so what I want to do
actually is I prefer to talk to the bot
I've got my math lab cook brain is
turned off today stretch break water
over here need to slow down yeah I made
the tree in p5 also in a coding
challenge I've got my code here this is
the code that will talk to the mastodons
service and what I want is for this code
to actually run a processing sketch but
this is node this is JavaScript
processing is Java and it's like a
desktop environment where I hit the play
button how can I possibly do this well
the first thing I'm gonna do is actually
go and save this processing sketch in
where my bot is and I'm actually working
in this folder mastodons bot 3 you can
see the no modules bot touch is so I'm
gonna save it there and I'm gonna call
it tree at regen so I'm gonna save it
tree Jen I'm gonna make sure it still
runs it still runs and now what I'm
gonna do I'm gonna show you a little
trick now wouldn't it be nice if in
the in terminal I could do things like
just say hey run processing but says
processing is not found what if I were
to say processing - Java permission
denied it's different
how interesting right I was gonna do
that wouldn't it be nice if I could just
execute a command like processing run of
course in terminal and the shells are
gonna know what that is but a little
known fact about processing which I have
done this in other videos before but
just to start anew again processing
command line there is actually a way to
run a processing sketch command line by
saying processing - Java the path of the
sketch and then - - run but the only way
you can do that is by installing first
processing java to your system so this
is installing a command line command to
run a processing sketch so I'm gonna do
this install processing Java I'm gonna
say yes for all users it's going to want
to use my password I'm gonna enter my
password because it needs it needs to be
able to put that where it needs to go
and now I can actually say processing -
Java and you can see I get all sorts of
stuff it doesn't know what I want to do
but watch this I can say let me just
look in here there is the tree Jen
processing sketch so I can say
processing - Java sketch equals is that
what it was let's go look at the sketch
equals now I need the full path so the
full path and I'm gonna show you a way
around this in a second is this tree Jen
right this is the full path of that
processing sketch then I could say - -
run here we go magic it ran it look
there's the processing sketch this is
really cool now watch what's exciting
about this and it's bothering me that
the the background isn't 51 which is
very important I can actually quit
processing completely I don't need that
processing open and still do this
there's my tree beautiful ah but I catch
- one half process ago because I've got
a little bit of a problem here and we
can see here look that image is there
it's now saved what I want to do is go
back and open this again open open open
open open and I want to add one thing
like I want it to be I want it to go
away
so I actually want to say after I save
it exit and I'm also this is going to be
helpful for me later I want to say print
line tree generated you'll see where
this comes up later okay now quit
processing and now I'm gonna run this Oh
finished regenerated finished one more
time finished okay this is really
exciting because there's so much stuff
you could do now here's the thing I am
executing this command via the shell but
I want node to execute it how can I
execute it in node and it turns out
there is a way to execute any generic
shell command from node and it is with
the child process package so if I go to
child process you'll see here that there
is a method called exec child process
exact spawns a shell and runs a command
within that shell truth of the matter is
I might be useful to use this exact sink
because I'm gonna want to sink me in
synchronous meeting wait until it's done
to go onto the next thing I've got a
crazy plan here I want to do
asynchronous stuff with es8 this wait
and async function you may or may not
have heard about so I'm gonna use this
one exec so what I need to do is in my
node code I need to say Const exec
equals require and where was this it is
in child process exec child underscore
process no there's no yeah that's right
huh Oh dot exec yes I'm confused so this
is me requiring the child process
package and I don't have to npm install
this you'll know you'll notice that I'm
on the nodejs documentation page I'm not
in some separate third-party NPM package
this is built into node but just like
filesystem is but I've got to say
to use it so require child process and
all I want is that exact function so now
there's no reason why I can't just say
exec and then pass in what exactly this
oh let me make this is so unwieldy so a
nice little trick that I can do is I can
actually always get the current path
right if I want to get the current path
I just type PWD print working directory
well guess what I can actually have PWD
executed within this command by using
these back ticks I'm pretty sure this is
how I do it
so now I'd say run and I think I don't
actually even need this first slash
write run sketch equals print working
directory vent regen run let's see if
this works this is done okay so now so
great so I can grab this this is my
command we're gonna get to that the
mastodons stuff in a second uh constant
command equals let's just put this in a
variable like this then I can say exec
command and then that's gonna have a
call back oh I don't want the let me
just run this let's just run this let's
see what happens no bot Jas Hey look
what happened it made it happen now
here's the thing I was the next thing I
was gonna do is that a call back but I'm
a new I'm not turning over a new leaf
I'm turning a new page in the book of
JavaScript and I I'm a kind of person
who uses promises and not only a kind of
uses a person uses promises I even use
the async and await keyword to really
make my life full of just ease it's not
full of ease but I'm doing my best
so what does that mean the thing is this
particular node package to child process
exec and I have a feeling if I bother to
look at the chat which I'm gonna open up
for a second someone's gonna tell me I
could just use something else now that
natively supports promises the e key
does not work on this computer which is
invisible to you oh it's the run I've
been typing in the wrong password okay
there it is
Oh being told that nodejs has underscore
directoryname so there are other ways
people tell me otherwise I could get the
directory name but what I'm going to do
is I'm I'm going to promise a Phi which
is a word apparently promise if I I'm
going to probably look at this I must
have googled this another time Felicity
is very common by using Java not Java
sorry the node package util so a node
package util if I go look at util and I
actually just want to be here there is a
promise if I util dot promise if I so
what I can actually do is I can say
Const util equals require util and then
I can say util dot promise if I with a
weird word I don't know what happens if
I promise if I myself this so now this
require child process exact function no
longer uses a callback now uses a
promise and what does that mean that
means I can say dot then and whatever
the result the response is I can
console.log that response and then I can
also catch any error and I can console
dot error that error now this might be
and this this there's no semicolon there
there's a semicolon there this might
look completely insane to you if you
haven't seen promises used before in
JavaScript it's very similar to a
callback but instead of saying a
callback I basically have this callback
that happens in dot then I'm also using
the arrow syntax the arrow syntax is a
nice way of sort of short handing this
I'm getting the response as the argument
to the callback and I'm console logging
it so if you want to know more about
those things I have a whole playlist
about promises and a and a video about
the arrow function that you could go and
look at but this is the basic idea this
is a little bit of an advanced video
here with or not advanced but just I'm
using
kind of modern JavaScript stuff if you
consider like three years ago modern
okay so now I've got this exact function
so let's actually run this one more time
and see it should do exactly the same
thing but look at this that response has
standard out standard error so in other
words standard out is what that's the
thing that in prop I closed my
processing sketch I guess I should have
left it open the processing sketch has a
print line in it so I can read whatever
that print line is so I can actually get
more information from processing if I
want for example I could get the angle
actually this this is great let's add a
little feature to this this will be fun
cuz why not make this video longer than
it already is where my desktop desktop
Mastodon Mastodon bought three tree Jen
so what I'm gonna do here look at this
this is great let's leave this open
because maybe I'm gonna want to do more
stuff with it I am going to let's just
make the angle between 0 and 90 that's
what those in the comments and then I'm
also gonna say print line and I'm just
gonna say angle or is it was it angle
theta whatever a I'll just keep the a a
and I'm gonna say floor a so just get
the just get the or int am just to
convert it to an integer so watch so now
when I do this in in node I'm gonna say
console dot log response dot standard
out so I don't need to see that whole
object I just want to see the stuff that
came out of processing let's run it one
more time because it that was the angle
42 spooky spooky 42 beating of life okay
so great so here's the thing I want to
once I have that image I want to post
that image to Macedon isn't this all
about Mastodon I've loaded up and can
connect it to Mastodon through this like
bot if you don't know what Mastodon is
did I say this already I've got a whole
set of videos describing that I'm gonna
could go back and look but I want to
somehow post it to this particular bot
the coding train but ok so now in order
to do that I
- I need to look up the functions in the
mastodons API so I'm using this
mastodons API node package and if I go
here I can look and see that it has a
mastadon get mastodons post so this is
what I want mass on a post here's the
thing I didn't realize this when I made
my other videos about Mastodon because
it says path parameters and callback but
guess what this supports promises so I
actually got to do this without a
callback with promises I'm going to
break this out and didn't I say I was
gonna use a sink in a wait it's gonna
write it with just that but I think I
have to start a little bit I have to go
a little bit further with the full
promise of syntax then I'm gonna clean
it up with a sink and a wait in a second
so now there's no semicolon there so now
what I want to do is I want to basically
say this I want to post the image and I
want to return this as if this returns a
promise guess what I get to do I get to
say dot then response and have another
function right so this is the idea of
chaining promises and this is what in
theory I mean basically if the whole
theory of this is to avoid callback hell
and really we just did promises well
it's all hell but eventually we will
float into the clouds and feel like
we're like butterflies on wings or
something I don't know okay so if I
returned the post that I want to do when
that's done so I'm executing this
command when that's done then do this
that and then when the next promises
done then do this we're all right so
what do I need here the path so the
first thing I need to know what's weird
about and actually it might be worth
just taking a minute to like write the
steps out because it'll make it more
clear I want to exact processing that's
one then two I want to upload image and
then three I want to toot alright so
what this is the same thing for to the
Twitter API it doesn't work that you
just if you want to tweet an image you
don't just simply send your tweet
with the image you have to first upload
the media get that path to the media and
then you can tweet with that media
reference so this will actually return
an ID for the media and then as long as
I attach the ID to this so this creates
output dot PNG this creates an ID and
then use that ID here and then I'm done
then we're just like done this is the
three-step process each one of these
returns a promise so when do this then
this then that alright that's the
process I'm working with here alright so
now so okay so the path so let's go to
the mastodons API Docs and I'm actually
looking for a media so we can click here
and this is what I this is what I wanna
do I don't media upload I think media
uploads just this I post to here and
then these are the things I need to send
okay so file description focus let's
look at that okay so I need to I'm gonna
create some parameters oh no I'm up here
I'm just gonna I'm gonna create some
parameters and I need the file which is
presumably output PNG and this is not
exactly right yet I can't just put the
file name there but I'll get to that in
a second then I want the description now
the description is really important this
is not the text that is going along with
the actual post what this is is alt text
alternative text this is for
accessibility so somebody who is blind
or with low vision was using a screen
reader instead of seeing this image
would actually hear this description so
I would say a randomly generated fractal
tree oh and I want to get this is I'm
gonna say Const angle equals response
dot standard out with and then oh and I
need to use my the new thing that I
always use now which is template
literals for Strings with angle so this
would be the description and then
there's one other
so the file is required the description
it says is optional but it really
shouldn't be optional you should be
using alt tax for accessibility and then
a focus this really is optional I am
assume you actually have not tried this
yet but I'm assuming this has to do with
where the crop is if it's showing a
preview image something like that okay
so then I can say so this is done and
then we're path and then those
parameters because this could be an
array o path no but okay path oh yeah
the path is media sorry I'm posting to
this path the media path of the API with
these parameters but this isn't right
this I mean let's run this we'll get an
error so I make the image finished
params is not defined so that's a
different error per an params whatever
one more time run the bot weirdly it's
like didn't complain at me oh but oh you
I didn't mean to complain because I
didn't console.log this response I know
why I'm going crazy to show you this
error when I could just fix the error in
the first place all right so all this
stuff came in and I looks like maybe
this worked because I'm getting all this
stuff but somewhere up here I'm gonna
see like an error code oh so much stuff
false high watermark I don't know this
seems to have worked no this is nonsense
this is saying this page is not correct
let me go back
but this doesn't this doesn't need I get
it edit this out cuz it's not that you
just go back to here
so this is almost done but there's a
problem
I can't just pass it the file name this
actually needs to be a readable stream
and so I need to use the files file
system package if I go and look for an
ode file system package and in here
somewhere I think there's like a create
stream function and actually probably a
better place for me to look is just
right here in hold on I don't have to do
this again
hmm there's some stuff going on oh I
didn't I didn't look into that no sorry
sorry I forgot what it is create read
stream yeah if that's what I want to
think okay I'm pretty sure that's what I
want okay sorry let me go back and do
this one more time Thank You mats yeah
all right
so almost there but this actually isn't
correct it doesn't work the API is not
gonna just accept a string of the
filename and figure out how to like read
that file and post all the date of that
file to the server what I actually need
to do is give it a readable stream and
if I and so the code for doing that it's
part of the file system package so I
need to I need to actually also require
that and we could look up the
documentation for it
but I happen to know it I think so I
need to say I'm gonna say constant
stream equals file system create there
it is read stream autocomplete thank you
output PNG oh and this actually isn't
even right because guess what remember
output that PNG was saved in the
processing sketch which is the folder
tree gen slash output dot PNG so now
this is the stream and this is the
description that goes with it
okay and then I want to make sure this
worked so I want to actually console.log
the response so now in theory I have the
code all the way for executing
processing uploading the image I need to
want to get the response I need to get
the ID and then I go and actually just
post the status okay here we go let's
try this unhandled stream error in pipe
no such foul path no such foul no such
file oh it's not called output dot PNG I
called a tree dot PNG okay let's try
that again
finished and great so look this is all
the stuff that I got back now it's kind
of too much stuff for me to like look
through oh what a pain did this actually
work my goodness
craziest but this is all I care about
there's more important stuff there's
more stuff lots of tons of metadata
about the image you just uploaded but
all I really need is data ID so let me
just go here and say console.log
response data ID and I've apologized
apologies to the bots and dot space for
overloading your server and you can see
there's the ID okay now guess what oh
can I should I start using I'm gonna
just keep going why not go with this
promise chain this is how I would do it
probably then Oh No and then all I need
to do is return a one more promise
so I'm also gonna say constant
parameters now I want to do I need to
look at the API for for what post but
just statuses so this is where as I'm
looking looking looking looking looking
actually I need to look for API v1
statuses sorry oh I failed do what maybe
I want to maybe I should like actually
now rewrite this using async and await
I'm gonna do that I'm gonna do that I'm
gonna do that I'm gonna do that I'm
gonna go from where I printed this out
now the next step would be for to use
this ID and then actually in the in the
in this response right I exec the I
execute the command I upload the image
and then I should be saying return MDOT
post again and I'm going to statuses
I should say returned MDOT post again
and I'm going to the path I'm going to
his statuses so this is what I should be
doing but I can't resist do you see how
this is I mean it's great
I kinda it's kind of nice start the
promise chain then do this return a new
promise then do this return a new
promise and if any error happens
anywhere any here catch so why not but
this is the thing this is now there is a
way there is a new way for me to write
all of this in what feels more
sequential more synchronous in fact and
with less kind of indentation and
brackets and stuff and that is using
this async and await syntax so what I'm
actually going to do is I'm going to
write a function I'm going to call it
tutor or just toot and I'm going to
modify this function with the keyword
async this means this is an asynchronous
function this is indicating to
JavaScript this is a feature of es 8 a
new feature of JavaScript that's
indicating that this function will be
handled asynchronously and always always
always return a promise and it will auto
magically it'll basically automatically
return that promise so we'll look at
that later how does that so in other
words but this I want to do the same
thing like what I want to do here is I
want to say exact execute the command
alright these are the steps and then I
want to say post a media post the media
the nice thing about using this syntax
is I don't have to separate it out with
these chaining these dot vens I can
actually just use the await keyword what
the await keyword means is don't go to
the next line of code oh wait the end of
this function so if I have a bunch of
asynchronous things if I package them
all together in an asynchronous function
I can write them sequentially as line
after line after line and essentially
and you know I'm gonna have some other
params here
so this is basically I get to write it
like this now I need to do stuff in
between that's the thing like for
example this returns a response and then
what I want to do is get the angle and
create the stream so this goes here so
this is my step one this is my step one
write execute processing look at it just
exactly like this now I have my step two
where I need to create these parameters
that are getting passed in and by the
way I don't have to make a separate
variable it could be embedded right in
here but it's just sort of like a little
bit for legibility I'm making it
something separate and so I'm now gonna
say basically step two is upload upload
upload media and that's gonna have a
response and then what do I need I need
to get the ID out of that and then I am
now going to say step three and by the
way I suppose if I'm being accurate
about this this is all I suppose this is
part of step two I don't know it doesn't
this is a little bit silly what I'm
getting myself worked up about but which
line of code is part of which step I
don't know but up but step three and
maybe I'll name this params one just to
be just four I don't know why why not
have them have different variable names
then step three which is params - I want
the status to be and this is you know
I'd have to I think I know it's supposed
to be but behold my beautiful tree with
angle and then I should use the string
litter the template literals again
degrees
and then I need ah so now so this room
okay what let me look this up in the in
the mastodons API Doc's give me a second
to find this let's edit out me looking
for it
API v1 v1 statuses statuses jeez Louise
there's got to be a better way to search
on this oh it was all the way at the end
here it is okay I found it this is the
API this is the path statuses for
posting a status and I'm this is the
text of the status there are other
things you could do here that I've
talked about in previous videos but this
is what I want media IDs now notice this
is an array it's an array of media IDs
because a particular status could have
and it says here maximum for more than
one image associated with it so you can
upload more than one image so that might
be an exercise that you try to do after
this video but basically now I can say
comma media underscore IDs and I just
have that one ID so I just put make I
can make an array in it there and then
this has to be statuses params and then
what I can do is I can and this is the
response and I can just now say return
response so if we could look at this all
together I think you have to make this
like a tiny bit smaller for you to see
it can I fit it all in one nice place
look at this look how beautiful this is
it's almost like I've written this code
in a language like Java or C that's like
perfectly synchronous and linear and
procedural because what I'm saying is a
weight executing this command then do
some stuff then await uploading the
media and do some other stuff then a
weight posting the actual status and
when you're done return and guess what
if I now say we may
it's bigger again whoops if I say toot
guess what this tooth function that I've
written async remember I said it
natively returns a promise well by the
way I said return right down here so
this thing right there is the promise
it's returning and I actually might I
could configure my own object which
could be kind of interesting like what
if I said return I I could just say
something like success true and status
[Music]
stat status behold my beautiful tree
whatever and I could just say angle
whatever I could put like angle and then
that angle there so I could actually
configure an object and I could pull
stuff out of the response there I could
return that and then I would say then
[Music]
then response I can't spell today I mean
I can never spell console dot log that
response catch any error console dot
error error and this needs a period here
and I hit save and something's wrong too
many not enough too many dots mmm two
dot then response why can I can't see
this oh there's too many dots too many
dots votes are too many dots still too
many dots toot then toot then response
console.log response is it just not Auto
formatting it
no it's Auto for attitude and response
console.log response dot catch Oh may I
need a semicolon no then catch put a
look at the chat yeah I know I should
wrap things in a
I can't get the password it's computer
to work the dot goes on the next line
oh that's what it is oops yes okay
it's not too many was too many dots but
I fixed that the issue is the dot goes
on the next line that's the convention
that's what it's looking for there now
it's four rather than what that wanted
to be so I still have to engage oh boy
with this idea of a promise but I can I
can basically wrap that all into this
one asynchronous function and I just be
able to chatter telling me I can
actually I don't need to do the then and
catch in this way because I could
actually put a try and catch inside of
here one step at a time I think I might
be done all right let's see let's see
what happens okay no response away oh so
I have also reused so I should call this
response one response to maybe there's a
more thoughtful way of doing this
response three and I didn't actually use
the response but whatever
there we go start the bot make the image
the angle 72 finished params is not
defined it was so close uh params one
params two params to here and I think
Graham's one there all right
[Music]
I'm feeling pretty confident a success
angle is 56 flash finished that's a
little weird
but let's see here let's go to the bot
look behold my beautiful tree with angle
56 finished degrees okay so there's a
little bit of awkwardness there in that
the standard out is just always giving
me the word finished so because I would
like this to work work without that I
think I'm guess what I'm gonna have to
do is that is that just something that
happens like with processing Java
because I didn't write finished anywhere
in here right that's not a print line I
put in here so I think what I could do
is when that comes the standard outcomes
I could say response I mean I could just
do a substring I could do a regular
expression so many things so many things
I could do
why don't I split it out equals response
response standard out split and I could
just split it by the line break right
cuz finish comes after the line break
and then what's and then I could just
take the first one
so this split is a function that takes a
string and splits it up into chunks
based on a delimiter and you can get
really fancy with that but I think and
then this should just be out without the
caps lock I mean I should really test
this so what is that visible on the
street a little bit of spittle just
projected out of my mouth I got
overexcited well edit that part out
perhaps I mean I really should probably
test this but I'm gonna have to just
rely on the fact that I think I wrote
that code correctly that's my way of
testing it let's run this one more time
[Music]
undefined true angle 55 what's that
undefined there I liked seeing that oh
there we go
behold my beautiful tree with angle 55
degrees what was undefined
what did i console.log in an undefined
way console.log response standard out is
that it no no that's ten finished wait
if it was ten why did this become fifty
five I'm so confused
let's be a little more methodical here
oh because huh Oh what am I looking at
oh I kid ah it does it twice
I didn't happening twice let's take that
out apologies everybody this thing is
happening twice because I had the old
code in there I mean I'm just gonna
delete that throw caution to the wind
but a little mess here okay that's weird
that I did that twice I'm so confused
okay
angle 74 just did it once there we go
okay one more thing that I need to do
just so this becomes a true bot is what
I want to do is I want to say set
interval and have it do this thing that
it just did there every well let's have
it do it every five sec ten seconds
right now I don't want it to do it every
ten seconds but just to boy I guess
there's another another parenthesis
there there we go no this is so hard
maybe I should just write a separate
function okay set interval then I put
the function which is this which calls
to which is this which does this every
10,000 seconds this is not right
okay well look at this what a mess I
mean if I was doing it without the arrow
syntax it would look like this right and
then this would go here no no that goes
first
ah right that's close what's wrong here
this is opening the function that's
closing it no there's no parenthesis
there that's the end of the function
then this then this we're good we're
good this is it oh but look how we I
hate I don't like this at all
this is making me crazy I'm gonna do I'm
gonna do this
I mean it's so silly function tutor and
then I'm gonna put this is like I'm a
ridiculous person I'm gonna put this in
Oh No Oh help me help help I'm gonna get
this and I put this and then I'm just
gonna name my function forget about this
anonymous stuff this is what I want
right I have a separate function which
calls my asynchronous function does the
vent in the catch and then I'm gonna
have that happen every 10 seconds okay
by the way someone in the chat a k1 and
G Julian is asking would it be possible
to ask the bot to create a tree with
this
that's right angle yes and that is where
I'm gonna do any follow-up tutorials
you'll see that in the next one okay
here we go
and we have a tree oh right it's gonna
wait so one thing about set interval
want long which is that I mean it works
okay I'll just keep going now set
interval will not execute that function
immediately it will wait 10 it'll wait
the amount of time before doing it the
first time but now we did it twice every
10 seconds first one was angle 44 and
the second was angle 28 let's let's wick
away 10 so you can watch this video for
10 more seconds we can also speed this
up now let it happen like 4 or 5 times
but I think that's good so let's just go
and check here and we can see 83 degrees
28:44 there we go and 44 28 83 44 28 83
wonderful ok so this is working you know
now of course I don't want to leave it
like this right having a bot post every
10 seconds no one wants to follow a bot
that post every 10 seconds maybe I
wanted to just once a day it's gonna do
maybe once an hour might be the maximum
the most I would do but let's just let's
if I want to do it once a day it would
be 24 hours times 60 set 60 minutes
there's 60 seconds in a minute and a
thousand milliseconds in a second so
this would now be but I wouldn't want it
to wait a whole day so I probably want
to call it once so I'll call it once
then set the interval and I'm sure
there's a more elegant way to do that
that all of you will someday will write
in the comments and here we go and node
bah bah bah yes here we go it's just the
first one and then now we're going to
wait here room 24 we're gonna wait 24
hours oh wait yes we'll wait and then in
24 hours I'll still be standing here ok
I could take the go home have dinner go
to sleep come back this laptop would
still be here and it would do the next
one we're just gonna have to believe
that that's gonna happen again there is
a question of like well where would I
actually want to deploy this I've got to
talk about that
video but just the quick answer is
you're gonna want to find a server maybe
you have one through a hosting company
maybe you happen to have like a computer
that's always on in your home or
Raspberry Pi that can act as a server
but you need somewhere where you can
just let it run over and over again
forever okay so thanks for watching this
video
making a mastadon image bot and what I'm
going to do I want to do one more
tutorial because what how would you do
it so that if someone at mentions the
bot let's say with an angle then the bot
replies back with a tree with that angle
let's see if we can make that work
that's gonna be fun
okay see you in the next video okay okay
so Nathan asks a really good question
about deploying wooden processing
starting as a desktop app prevent the
bots from working so I've actually
covered this in prequel in my previous
Twitter bot series yes but no so it
needs a windowing environment for
processing to run so that's gonna work
on this laptop on a Raspberry Pi if you
have a headless server like you know I'm
running this instance off digitalocean
so I could deploy the bot there I would
have to run a bunch of commands to not
to trick it I was gonna say but to you
and I have this documented with for
Twitter BOTS and I want to rewrite all
anyone's to help me rewrite all these
pages or basically do I intend to make
an entire new version of this page with
mastodons but I just I don't have the
time to write this up but I think in
here deploy bought to Amazon ec2 which
is actually admittedly probably the
hardest ways to deploy hits so but here
somewhere in here I have the
instructions for yeah so this you need
to make sure that the server has Java
and you can install Java that way then
you need to do this weird stuff that
creates a fake display for processing to
render on and then you need to also like
always run that to
in the background and once you've done
this it works so I have tested this not
in a year but it does work yes I mean
the stream is not over it is 510 hmm but
I definitely want to fit this is going
to be the end of the Mastodon bought
stuff I'm just coming over here to look
I have a bunch of messages okay oh and
apparently I got a new a new member
thank you - I've sort of gone from the
Chad happened in the middle of me thank
you - I think Joel Joel who joined as a
member preciate it
Joel with you Oh Joely can see joel has
tha this dot icon this dot icon is for
if you've been a member for left the
first icon you get and then I think if
you're a member later you get so that
question is so now the question is sorry
I should finish my sentences I have a
problem not finishing my sentences if
you're a member for more than a month
you get a different one and two months I
don't remember what those are let's do
what those are at whatever okay cuz
that's so the question is now should
that be well should that be a coding
challenge and or should just probably
just be in the mastodons tutorials I
don't know I never know these things I
don't know alright so okay
all right but I'm gonna do part two and
then I'll think about it I'm exporting
the sketch as a Java app would it make a
difference it did it's still need
processing the app still needs that that
you can also do that but you still need
a windowing environment we I don't
believe that would remove the need for
x11
1/8 Nathan asks in the chat but I could
be wrong about that but I'm pretty sure
like it it's not actually the processing
IDE never opens its processing is just
like it's just running they're just
compiling the processing code and
executing it as an app it's basically
doing that for you so I'm pretty sure
you need a windowing environment maybe
there's some other way you could do it
and by the way you don't have to use
processing you know this is just I think
really useful because you know it's sort
of it's very I love the fact that it
sort of gluing these different things
together ok
and just drink a little water out of
sight water hasn't paid their
sponsorship recently so I'm not going to
drink water in in how you and visually
in a apparent way sometimes the words
don't deform in my brain and exit out of
my mouth in a way that makes sense
all right
hello so previously I made a bot that
picked a random number between 0 and 90
generated this fractal tree using that
angle using processing made the image
and then posted that image to mastodons
using this coding trained bot at BOTS
and space dot BOTS in Doc's pick
whatever Hudson's face the instance so
you can see a bunch of these here and so
now what I want to do is instead of and
the bot if we look at the code is just
executing all of this stuff to generate
the image and post it once a day so what
I would like to do now in this video is
change it no I'm not going to set
interval in fact I'm not ever going to
post an image I am only going to post an
image as a reply to somebody else and
I'm gonna look in their reply find the
angle that they've specified and send
them back a tree with that angle and you
can just imagine the possibilities of
things you can do I mean one of my
favorite this is a Twitter bot but one
of my favorite BOTS is low-poly bot and
what low-poly bot does is it still
running it's the question because most
of these bots you can't reason why I'm
using Mastodon one of the reasons why
I'm using Mastodon is that these don't I
don't think you can't really run these
anymore on Twitter they've changed the
API specifications too much so the idea
is that you send in an image and an
image process for you and sends it back
okay so now let's do this so the thing
that I need to do is I need to connect
to a stream I've you I've talked about
this in previous videos where I made a
bot that just replied I need to connect
to the streaming API and so the way that
I do that is here MDOT stream so I'm
gonna say MDOT stream and then I want to
connect to the user stream and doing
that I should get a promise then
response console dot log response can
you see what I'm typing here and then
auto fill it's gone crazy catch any
error console dot err err err err err
and I put too many dots too many dots
too many dots the dots go there where
did the dots go I've lost the dot I
really have a problem with dots
apparently okay now so the idea is now
anytime there is a user event anytime
there's a user event I'm gonna look at
that event now I've done this before
isn't it okay for me to since I just did
this in a previous tutorial I think it's
okay for me to look up what I did in
that instead of like figuring out again
so a mastadon bot underscore two right
now is where I had some code from a
previous video and I can look at the bot
code and I can see what I actually did
is if I said if the event was a
notification whoa oh look at this oh
look at this ah you know what I've
written this code incorrectly you have
to configure when you're using the
streaming API it doesn't work like the
get or the post API you actually have to
call this on function to specify an
event so apologies for that good thing I
looked the way this should actually be
written is a Const listener like I want
to create a listener that's connected to
that user stream right whoops where's
the other code alright a streaming slash
user yeah I knew that
streaming slash user and then I want to
say listener dot on notification so if I
get a notification and now I'm going to
guess that this returns a promise but it
will I'm so sad my doesn't give up I
give up I quit I can't do this kind of
syntax I did it with a call back before
stream returns a stream listener
instance see examples on how to use it
give me a second here
I can't over here
event emitters do not return promises
let's let's start over let's go back so
that doesn't that that won't give me a
promise that's fine that's fine I'm okay
with that
fine where was I so I want to connect to
the streaming API and I want to connect
to the user stream meaning anytime I get
any sort of notification somebody
favorite something mentions me reblogged
me if I post something I think I get an
event so the way that I do that is by
saying m dot stream right if I have to
go look it up here in this API m dot
stream path and parameters returns a
stream listener instance see examples on
how to use it okay why not I've done
this already in a previous video but so
I could look at my previous code but
let's actually sorry let's just go to
examples streaming yes and what we can
see that here so this is what I want to
do I want to connect to the stream
create a stream instance by connecting
to streaming slash user and then on a
particular event like a notification was
that what it was
oh no just a message so I it's the event
here is called message and then on a
message and this by the way I just been
told from the chat thank you to Alka and
the chat that the streaming API doesn't
support promises so in this case I do
have to use a callback and I can say
response I like to use the word response
like this so now here anytime I get a
response and you start anytime there is
a message what do I want to do
you need a callback not a promise
also please stop separating dots with
keywords I don't know what that means
why fact you keep separating the dots
from the keywords oh yeah that's why I
put the duck because I'm not used to
this
I broke I've been like for like 15 years
with all this JavaScript promises
nonsense I'm learning I'm learning give
me give me a break here I could be going
home there's a there's a baseball game
starting in two hours I got that I
intend to watch okay all right so in now
I do want to look up my previous code
because I need to figure out what I need
to determine what I'm looking for in
that response so I have that open here
and you can see that what I'm doing here
is if them if the event is a
notification and if it's a mention
that's what I'm looking for I'm looking
for a mention so I'm going to say if
response dot event equals a notification
I'm just only going to do mentions and
response dot data type I think equals
mention is that right
this is B just looking at my previous
code response message data dot type
message dot event so where is the
mention in this one that I did mention
ah message that data's right there
message data dot type so I'm using
different variable names which is fine
but if the event is a notification and
the type of the event is a mention then
now I'm ready to basically do this right
the idea if I mentioned go ahead and do
this but and I don't need a separate
function for this uh what up so I'm just
gonna take this here but what I want to
do is I need to add some stuff to this
so for exam
Paul I probably want to mention a user
account and I want to have a reply ID
and also that angle so I need to if I'm
going to reply i all i want to add
mention them so i need their account to
reference i also if i want it to be
threaded i need the ID of that post so i
can include that and then the angle i
want so now the angle shouldn't come oh
I've got to send the angle into
processing all right that's gonna be
something we have to figure out okay I'm
gonna get to that in a second so let's
try to get the whole flow of this
working that this is an interesting
problem that I completely forgot that I
had to figure out so they so first let
me get the ID is and I did this before
so I'm just going to we can see the ID
is this
this is pulling the ID out of them and I
you I said response instead of message
which is fine and then the account name
is right here
so I want to also get the account which
is also a response so I can then pass in
the account passed in the ID eight now
the angle is a tricky one so what am I
expecting the person to say I guess I'm
expecting somewhere in there post that
there's a number and they could put
multiple numbers I'm just gonna pick the
first number so what I'm going to do
what this is by the way my inspiration
the tree bot but where where am i I'm
looking my code I need to get the
content of what they've sent me this is
their message content so what I want to
do is use a regular expression so my
regular expression is going to be I need
to find a number the number that I want
is between two and three digits so I get
then going to allow I mean do I allow at
angle greater than 90 I mean sure I
could actually it could be any number
right I could really just say any number
doesn't matter how big so I want to
match this and so if I say regular code
so if I say content dot match regular
expression is this now I've forgotten Oh
regular expressions work so let's just
go to the browser for a second and let's
noodle around here so let's say if I
make a ret
their expression and I make it equal to
this and then I have a string like hello
42 goodbye if I say s dot match that
regular expression what do I get
ah perfect I get what it matched the
index and some more information all it
cares about is what it matched and I
don't need it to be global I don't need
to get all the numbers like I could get
all the numbers and average them or
something but I'm just going to get the
first one so this is fine so then I'm
going to and do have to deal with the
fact what if it doesn't match anything
so let's see what it gives me if it
doesn't match so let's say s equals this
and I'm gonna say S match regular
pressure no so that's fine so now I'm
going to say results equals content
match regular expression and the angle
so I'm gonna say if results all right
could I if results I could probably use
that ternary thing then the angle equals
results index zero otherwise angle
equals o otherwise I'm gonna say there's
no angle I could reply and say you need
to you need to you need to mention me
with a number so I'll so I'm actually
going to just say yeah angle equals
negative one so I'm going to use
negative one as like a and I can
actually just do this and then do this
okay great so now in theory now I can
pass that angle here so all right now
one thing I can do let's just do this so
if the first thing I want to do is just
say if angle equals negative one right
if I've gotten a negative one angle I
want to actually just be done like I
want to say oh but I have to mention the
person okay
so I have to say if in a status post can
I find that here
right so the text of the status if this
texas-sized in reply to ID so this is
important so I'm gonna say please
specify an angle in degrees using digits
cuz it won't work you say the word 99
eed to say in reply what is it in reply
to ID in reply to ID is that reply ID
and then also I I want to use their the
account so I'm gonna I want to start
with the account account and do I'd say
at I think I have to say at the account
please specify an angle and digits then
in reply to ID okay so this is good and
I'll call this and then I'm going to say
response I'm gonna say prams in response
and it's a success angle negative one
okay so this now should if I run this
and you and then I'm gonna put an else
here this function has gotten quite long
but basically what I'm doing is first
I'm checking if there was a legitimate
angle and if there wasn't I'm replying
back to say please specify an angle in
degrees and then let's see how that goes
so right now if I run this bot oh I
forgot to make a new one that's fine
laughter if I run this bot somebody
should feel free to add mention me
without a digit could somebody do that
please
I'm looking at the chat I'm taking a
break for a second this will get edited
out okay I got an error okay all right
somebody at messaged me thank you for
helping me debug this and I got an error
in box yes line 25 about touch is line
25 ah response response response sorry
response response all right let's try
this again be prepared
all right at mentioned me with no number
please you can put a number in it but it
won't work if you put a number in it all
right
ooh interesting please there we go okay
so let's take a look
so someone mentioned B with a number
that's great that we had both of those
tested and we can see this one said
please specify an angle in degrees using
digits that's right and then this one
just said behold my beautiful tree so I
haven't done the thing where I actually
get the angle so let's let's first let's
just first if I really do get an angle
let's do all the same steps but right
now I'm going to also add at account so
I'm going to mention that account with
angle and then I'm going to use the
angle that they asked for and then so
this and I need in reply ID in what was
it in repose same thing in reply to ID
where is that where is that where is
that here we go and reply to ID okay so
now if I run this one more time you can
now add mention me with an angle and
you'll get a tree back or you can at
mention me with no angle and you will
get a message back saying you need an
angle but I won't be using the angle you
asked for it just yet but let's just see
if this works
alright somebody somebody still
mentioned me please with no angle with
nono digits
that's weird once somebody know digits
please no digits okay okay great so we
can see that we got one two three four
five mentions one of which had a
negative one so let's see let's just
check our bots now and we could see 60
38:56 now here's the thing I'm not
actually using the angle it's still just
a random angle so what I need to do is
oh and I forgot that I was pulling it
out of here so it's actually not lit
hold on let's lose the alka asked for 56
and I made a tree with 52 so now let's
take this out right and actually try to
use that angle now here's the thing I
can't just how do I do this so what I'm
actually going to do this is interesting
is I need to go back to that exact
command where did I have that where is
that elk command so that's what's all
the way way up here so what I actually
need to do is I need to add another
argument to this and so what I'm going
to do and I think well I haven't done
this in a while
what's all right let's let's do it this
way sorry let me grab this command we're
going to figure this out together and we
go back to here and I'm gonna run that
command so this runs and I get the egg
that's fits out the angle now there
should be a way in processing for me to
get the arguments how do you get the
arguments in Java command line arguments
somebody must know this it's like system
dot args this is like the most this is
like the core string args is it just
there in a global variable somewhere in
processing I should know this I did this
like a year ago print line system dot
args what's the chance like that that's
like a thing No
timeout gonna look us up
why is his computer keep going to sleep
by the way Adam asked in the chat
doesn't only reply to local or any
account in the Federation it will apply
to any account the Federation I could
set it up to only reply to local but
that's not what it does by default so I
did this like a year ago with my Twitter
image reply err oh but uh oh this was
even crazier because I download an image
that somebody else posts I'm pretty sure
yeah Oh args it's just in args it's just
in args silly me
silly me okay I looked it up I can't
believe I forgot this but processing
actually just has built-in a variable
built-in variable called args which has
those command-line arguments so I'm
going to put print a lot print array
args and now I'm gonna do this we should
see whoa oh there it's no because there
were none that's weird
because where do those go they're not
here where how do I pass arguments if I
just add something else like here well
yeah there we go okay so if I just add
the arms come at the end
I thought make some of these might be
argument of course there's none so we
can see here if I just execute it with
an argument like with the angle 40 then
40 because I have some iPad to be help
in there block 40 comes out okay perfect
this is much easier than I thought all I
need to do is now say command where do I
execute that command right here
execute command +
a space angle right I guess I could use
a template literal there so I just need
to add that angle there and you know I
probably want to double check to make
sure there are any args but all right if
args is not equal to know then and then
I'm gonna I'm gonna make this a global
variable a equals zero and then I'm
going to say a equal args index zero I
guess that's gonna be a string right so
I need to convert that to an integer or
a float maybe and then I don't need it
here and now here we go
so now if well let's take out the exit
just so we see let's do this
processing Java run with the angle 10
that looks like the angle 10 right now
let's run with an angle of 90 and that
looks like the angle 90 perfect I've
passed in the angle and so now I should
be able to I mean right is there
anything left to do I think this works
cuz I got the angle I've got the angle
I'm going to give it the angle yeah all
right what the hey ho let's run this
node bot jf macedon bot starting and now
I'll just wait for a little bit
try test anything you can imagine
Oh whoops sorry stop stop it's funny
like actually this is fine I forgot the
exit thing so amusingly I forgot the
exit thing so it's opening up processing
but it's never finishing so it's
actually that exit thing is very
important because I forgot that I had
that in there I've got to put that back
in there and let's try this one more
time and here we go all right thank you
everybody this looks like some good
testing I hope that knowing is like and
so let's take a look now all right thank
you everybody this looks like some good
amount of testing let's go now to box in
space and take a look here is a behold
my tree with an angle of ninety please
specify an angle so we can see here nope
right that worked here a right triangle
has an angle of 90 degrees I love right
triangles there we go perfect so 89 and
there we go 128 degrees 128 this is
working
this is done so I hope now you have
enjoyed you can imagine sort of I mean
there is another piece to this that I
could do which is what if the person
sends me an image and I do something
image and send it back I guess I'll have
to come back another day and do that one
but now you can see the full process
that you can have another user at
mention you with some data text data use
that text data to generate an image and
send it back up so hope you enjoyed this
tutorial I hope you make some wonderful
box at BOTS in space and I will see you
in future video
okay don't be snide asks is he okay
definitely not I think I've ever been
okay looking and I'm also going bald
hey Cody Gardner with CJ is here hello
hello hello hello alright I think I'm
done for today it is 5:40 I have got to
go
does anybody have any questions they
want to ask I can't believe this doesn't
it doesn't crash anymore I think I'm
done
oh the question is should this that
should that have been a coding challenge
maybe it should just be two more
tutorials I should have realized that
from the beginning though I don't know
anybody of any I guess I'm gonna like
I'll pretend I'm gonna do two intros
just in case I don't know
this is before people haven't wash
before this is the weird thing that I do
that this all gets edited later it's a
shorter standalone videos that go in
playlists so I often like after I finish
something we'll do an intro so Daniel
writes make it a tutorial joel asks are
there limitations to the shell commands
executable by node not really I mean the
limitations are what you can excuse the
shell command it's there's no difference
between calling the exec function and
node and just typing the thing into the
Shelf there is this limitation though
that if the shell command opens a window
or operates like you know some
application that's on a mac computer and
you happen to deploy this to a server
that's a linux server it's not gonna
work but as long as the system you're
using supports that shell command you
can execute it from node and it's sports
node okay hello welcome to a coding
challenge this was a little bit weird
because it's more like an extension of a
tutorial series that I'm doing but I did
it all in one video so I think maybe it
can be a coding challenge I completed it
I made a bot for Mastodon that picks a
random number generator little fractal
tree using that angle and then and then
post that image this is inspired by the
tree bot which I'm going to reference
again in a second because there did
before and so but so if you're about to
watch this enjoy the coding challenge I
will publish the code for this make your
own Mastodon bot if you want to know
more about what is Mastodon and how do
you sign up to get an API key and all
that stuff then I will refer you to the
tutorial series of which this video is
also in the playlist I don't know does
this make sense
whatever watch the video I do the whole
project and then I finish it
[Music]
what if I send a very big number wave at
more than 360 should work I'm you know
it's it's the rotation once you get if
you 365 it's gonna be the same as five
degrees so I think it would still work
I could constrain it if I wanted to
within the code okay
okay part two of this coding challenge
yeah in part two of this coding
challenge I actually change it from just
being a bot that automatically posts a
tree every so often to a bot that
receives a post a toot their call toots
I just got used to saying tweet and now
I gotta say to to this is very hard it
receives a toot mentioned from another
account Nathan thank you to Nathan growl
for helping me test this and it says
give me an 89 degree angle tree please
and then I decoding train bot replies
generates that tree image and replies
back with so I complete this aspect of
it is and it's kind of convoluted I
probably refactor that code a little bit
but and I hope you enjoy watching this
second part of the coding challenge yeah
a float would just get the integer part
because of the regular expression that
I'm using I could have made my rhyme
expression so sorry the question is from
Adam I wonder how would it handle a
float or a number greater than 360
floats would probably be okay
so I could definitely change my regular
expression to to account for that I
forgot where I have it so I could say
like optionally you know something like
optionally a dot but I'd have to do this
right because I want a literal dot
optionally and then some more digits
optionally whatever something like that
I could do but I'm not can I leave it
running for a while I want some trees um
I can why don't I play this I kind of
need to I kind of want to make a I
probably shouldn't make the bot that
does all the things in all the videos
that I've shown so far and then deploy
it anybody wants to help with that so
anybody wants to help with that let me
do this
[Music]
let's do this real quick before I go
[Music]
let's create a new repo coding train bot
no no stop
coding train bot stop bot bot code for
coding train a sure whatever yep
okay then I am going to let me create a
new file dot dot git ignore and I want
to ignore node modules sorry that you
can't see this and I want to ignore what
did I have in what am i ignoring in all
my things
I don't want dot vs code I think because
who knows what's in that and I don't
want dot env so whoops so this is get
ignore come on you can do it you can
commit this new file there we go let's
try cloning this
get clips get clone this open so what
I'm gonna do is where's that coding
training Mastodon bot Mastodon I'm gonna
put so here's what I would love
oh boy I would love you forever if you
can help me with this so I'll file the
issues so let me give me a second here I
so I would I want to get rid of I don't
need this kid ignore like this was only
that get ignore I don't need that get
ignore okay so now get status oops
[Music]
okay I'm gonna be very confident I did
get ignore correctly and I'm gonna get
add git commit and I'm gonna say upload
whoops PAH shoot ah how do I associate
editor with git I can't use VI I'm
incapable using VI so I'm gonna and I
could just do - M but I'm I'm trying to
be a good citizen and you guys are
really spamming this bot oh shoot all
those files thank you I forgot about
that
oh good but I haven't I haven't done
that yet can I remove those is it too
late
can I unstable
how do i unstaged files can I just do
remove get on stage on staging files
get reset oh great let's do that get
reset go get status perfect thank you
that was easy get reset so here I don't
want any of these and here so it's just
in that one in theory yes I think I
really have to shut off the bots making
me crazy
get status wait whoa whoops good status
now let me get my editor working here I
did that on the camera went off here we
go git config - - global core editor get
config - - global quartet etre code - -
wait I think that that right yeah so now
all right so now I'm going to add those
stage those files to wait for that to
draw that tree say get commenced okay I
have to shut it off I'm sorry everybody
I can't take it anymore I can't take it
anymore
okay git commit alright so now I am
adding code from all mastodons tutorials
this needs some work I'll open issues
but it's missing the image uploader
thought without replying and I also
intend to put all of this together in a
single bot and deploy it okay so this
will be poll requests and community feed
welcome yeah we did that and then get
push origin master okay so so what I
need now anybody wants to oh and I
forgot to put this he's a transfer of
this repo transfer repo transfer what is
the name of the repo coding train baat
mastodons and new owners should be
coding train transfer the repository to
my password sure now I want to go to a
coding train organization and coding
train baat mastodons and by the way now
because it's in the coding train there's
no reason I can just call it Mastodon
bot okay so now let's go to did it not
change that come on settings settings
masted Mastodon bot rename there we go
okay so okay so now I need to profile
some issues missing image uploader bot
when I went on to code the example bot
that when I went on to code the example
bought that replies with an image I
wrote over the bot jeaious file that was
the that that posted posted a tree every
24 hours
I would like to revive that if anyone
was I like to revive revive that
so and so what do I have here there's
Mastodon bought one which is just the
one that does a random number that's
fine
Mastodon bought two is the one that
[Music]
replies favorites so that's fine so then
also issues a new issue one box to rule
them all
I would like altum Utley the examples
that will live in but here I'd like to
combine them all I'd like to combine
them all as one bot that I can deploy
deploy and leave running for testing and
fun times and this labels Help Wanted
and issues labels help want it okay also
probably redo with promises should i
redo the earlier bot examples with
promises i don't know question it's
tricky because i I'd like that to be
available but but I used callbacks in
the videos so would make it hard to
follow along maybe I should
both available all right so now
everybody has their work cut out for
them this weekend I'm accepting pull
requests from here and if I could
somehow revive this laptop I can look at
the chat
all right so ohok tober fest I don't
know I don't know about this hack Tober
fest I don't know how to make that
happen
what there's no pull requests yes still
in two minutes I have to go it's six
o'clock
American League East Division Series
Yankees vs. Red Sox you can all try to
guess who I'll be rooting for go Orioles
next year's gonna be the heir Orioles go
Orioles I don't buy sure brought my
Orioles baseball hat and but I don't
have that with me all right so I am
happy to take a couple questions while I
kind of figure out if there's anything
else that I need to do I will put on my
[Music]
oh you don't have to do anything to
allow users to participate in the hack
tobor necessarily just for visibility on
their site oh so wait is there a way oh
[Music]
there's a good question here Joel in the
chat rightz also do you need to auto
delete the images to prevent buildup dan
or are they not stored by processing
okay so this is a great question so to
be clear the if I run if the bot runs
where let's find I don't know I go I
guess I deleted the image let me run it
again I don't know so I'm running this
bot to be clear if this makes an image
of a tree it's going to save it as tree
dot PNG on the computer so there is a
PNG on this computer then it's going to
upload that as a media file to mastodons
where it will be stored permanently on
you know on the bots in space server and
then and then it's and that's those are
the two places where it is now if it
does it again it's going to overwrite
the image on this laptop because my
processing code which I've now closed
just says save tree dot PNG so I'm not
numbering them I'm not saving it's
always overwriting it but then when that
gets posted that's a new media file so
what I'm doing is I am building up a lot
on the box in dot space server
presumably but at the moment hope you
know the server
I guess can sustain a bunch of image
bots I don't you know I want to
cautiously not go crazy with this I'm
going to turn this off but you'll see
here even though it made three images in
this folder only the last one is there
the zero angle tree good question
Oh maintaining a repo create issues
labeled or label existing ones hacked
Ober Fest on your github projects to
help contributors know what to work on
tag any spam or a relevant pull request
with the invalid label to disqualify
them so okay let's I guess this is a
Oktoberfest I guess is a digitalocean
sponsored thing and if you do a certain
amount of pull requests you get like a
t-shirt okay oh boy I got a lot of so
let's just do that right now real quick
for these issues so labels I probably
have to make one new label hack tober
fest October fest this should be like
orange I'm just gonna keep instead of
trying to figure out orange oh it's
pretty orange yeah good enough okay
create label issues labels Oktoberfest
oh boy anybody wants to help me here's a
prawn I have so many open-source
projects that I should go through I'll
do this on some other things too
other coding trained repos maybe but
that's a place to get started okay
that's great thank you for letting me
know that
[Music]
I also wanted to I should have done this
at the beginning I forgot but I wanted
to mention processing India
I think it's processing community today
in India there are actually 4 processing
community days in India in these 4
different cities the one in Bangalore is
being organized by to an alumni and to
alumni of the ITP program where I teach
so I encourage you to if you're
interested in getting involved with any
of these to check them out matura had
emailed me and said to mention it on a
live stream so I'm doing that now I'll
try to remember maybe at the beginning
of the next one to mention it goes who
knows I'm still watching this now ok Oh
Alka asked which folder would you want
the combine Bhatt called mastodons Bhatt
combined so I'm open to any way of
reorganizing the repo maybe actually
just have a folder called Bhatt and
that's the combined one and then the
other ones are like maybe a folder
called Bhatt folder called examples so
Bhat is the one or it could just be in
the the root directory could be the
actual Bhatt and there's some examples
but that's probably confusing so but
something like that I'm open to
suggestion
[Music]
ah this is such a great question
oh well V asks open-source is daunting
for beginners how should I start this is
such a good question and a really free
foam just keeps ringing hold on just
hold on a second
hello yes
okay sorry that was important I had to
just answer that let me just send a
message here and that's fine okay okay
what was I saying oh yeah I'll
contribute to open source this is a
really tough problem I actually am
teaching a course this semester open
source to do at ITP let's see if I
google that if it comes up and so if
your this is a course that I'm teaching
and you know in here under resources I
would this is some nice guides and open
source projects for beginners there's a
lot bunch of readings that I would
suggest that are here on the syllabus
for this course I mean you can read a
lot of the students post and respond so
this this course is about contributing
to open source projects so there might
be some places here that'll help you get
started but my my recommendation is and
this I realize that not everybody can do
this but if you can find a local meetup
where an open source project is hosting
an event to encourage people to
contribute it's really great to be with
a group of people who are learning and
figuring it out that's a really
wonderful way to do it I'm p5.js we try
to have these and processing foundation
we try to have things like that when
possible I know that I'm dev - in New
York is having like a hack Tober fest
event so this is is you can sign up and
some stuff here there I think they're
having like a meet-up for this so this
is just about Oktoberfest but there is
also I think on October 10th they're
having a hack Tober fest Meetup so
that's just one example so that will be
my advice is really hard and but you
want to try to find what's really nice
about here's I really recommend looking
at these great for new contributors
awesome for beginners and first-timers
only links because you want to find an
open-source project that's going to have
a welcoming atmosphere
and that's that's that are looking to
help bring beginners into the community
and I would hide I hope then that's
certainly our goal with processing and
p5.js in the processing foundation
[Music]
ciao shebar Aurora Chevron
good night I say good night in Italian
[Music]
yeah I need to learn about like modules
and imports and exports that's like an
es6 or NES 8 thing right that's a thing
that I'm not using yet that I need to
learn about right instead of using
require or instead of just like
importing a library and like the
index.html maybe that's the thing that I
need to learn about and do some stuff
with somebody in the slack Channel
please let me know so Joel says I should
post that answer as a video I mean maybe
that's I would like to do some specific
videos about contributing to open source
certainly I do have a github for poets
if you google that you'll find mine this
is these these are doing quite a while
ago I think they're still mostly
up-to-date think some things have
changed these are 2016 so almost three
years ago two and a half years ago but
this will certainly help you at least
with some of the technical aspects of
using git and github
[Music]
according p5 just es6 interesting
suggestion I think there's a roadmap of
related to that you can find alright
everybody thank you so much for watching
this episode of the coding train I will
be back next Friday
not before next Friday next Friday stay
tuned all of the edited versions of the
mastodons bot videos are coming out an
edited version of nabeel's live stream
this morning if you're use the spell dot
run platform you can sign up at spell
dot run slash coding train if you use it
please send me a tweet i mastodons toot
a comment on youtube something like that
I'd love to hear about it and hear what
your experience was like okay what am I
gonna do next time bonne nuit what am I
gonna do next time I don't know but word
Tyvek is coming up so actually the
things that I need to do if I look at my
other course that I'm teaching this
semester 8 is the f18 this will really
tell us tell me what I need to do think
I would like to do Bayesian
classification that's something I would
like to do I have I did videos on this
last year word Tyvek the LS TM thing I
think I can probably just leave I don't
need to I'm not gonna I mean I would
like to make videos on that but I have
nabeel's guest 1 now so I think that's
gonna be fine and then work to vex so
that's what's coming up next work Tyvek
alright bye everybody have a great
weekend