Writing an IRC Bot with Guile Scheme - System Crafters Live!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] oh what's up everybody Welcome to system cters live I'm David Wilson and we're back again with another late Friday stream when I say late I don't mean late in the day I mean late starting as usual uh where we get together as a community and talk about whatever topic I've come up with uh for the week and this week is no exception um let me see if I can make this chat just a little bit bigger there we go okay yeah once again I'm having to deal with the the tyranny of the broken USBC port on my uh other laptop that I normally use to drive the stream so I'm having to like set up things at the last minute on a second computer to head set up everything the right way to get stream chat and everything else but uh it seems to be working okay can everybody hear me I'm guessing they can hear me because otherwise people would be saying something by now so um a little bit under the weather today my daughter had it virus from school for I don't know a week now and I finally you know got the privilege of of catching that so if I sound a little bit weird that's why but uh I'm happy to be here I always enjoy uh being able ble to uh hang out with the folks in the chat and uh let me just say hello to the folks who are here so far uh let me get to the YouTube screen uh let's see we've got DJ cthulu Wade um uh Yash rorg Jake uh let's see Christopher fer uh fear for us uh yes and then on the IRC side I see C and fade ashra uh Jeff Glenn Peter uh I guess that's seven Majesty maybe and Dave and redacted thank you so much for being here folks and alalia as well on YouTube side and Richard uh let's see excuse me it's what's a common question which has never been revealed I don't know redact says how did you get a virus on an air gap system I don't I don't have an air gap system I'm I'm just like connected to the world here and uh seven Majesty says it's pronounced we okay good good to know we Majesty all right cool so um let me just go over some news really quickly uh thank you left pad says alternate Ved thanks alternate V for the reminder on that uh ashas points out an important thing in the uh YouTube chat that you can join the IRC side of the live stream chat on uh Libra chat ic. libra. chat in the system Clive Channel and also the system. netlive link um if you want to get in on the IRC chat the IRC chat is the one that's showing up on the screen right now so this is an example of a of a bot like we're going to talk about today uh but we're going to be working on a different bot today but if you want to get on the screen in here you can definitely go to the IRC chat to uh to join up on that uh Big Ed says has the HTML injection virus been ironed out I think you have your answer now thank you to binois for fixing that yeah we can't be running around with uh HTML injection attacks on the live chat it just shows how sloppy I can be whenever it comes to uh my little crafting projects that's that's basically the way it has a go right you work on something really quickly to get it working and you're like yeah cool it works and then you forget about the possible ways it can go wrong until it does go wrong and then uh you have a big uh pie in the face that was an elegant solution at that yeah it was it was pretty simple I should have I should have known to do it uh beforehand uh anyway I wanted to point out that the system crappers Forum was launched last week if you haven't checked that out yet definitely go check it out we've been having a lot of fun there over the last week just chatting about various system crafting topics um um and I I want to do a lot more stuff on the Forum uh going forward I haven't really like started organizing things correctly yet because I've been busy with other things this week uh but we will get a better form organization going soon um where it's clear how to post things related to various different topics and also instructions about like where you should post things I I really want people to come here to chat about the topics we talk about on the channel and in the community but also to share things you've been working on um and even things that aren't necessarily system crafting related because you know people have different interests so there might be like a certain section of the Forum that is um for a little bit more off topic sharing of of projects and whatnot so um definitely check out the Forum um I'm pretty happy with how it's been going so far it's it's a nice uh nice place to hang out it's a good combination to the um I guess good pairing for the IRC and Matrix chats because you can um have more longer form conversations and ask uh ask and answer questions Etc oh thanks ASAS for for pasting that if people want to leave a comment on that you sure can thank you I should I should be doing that actually I should be leaving uh links to the live streams every week but this week I was out of time didn't do it I was spending a lot of my time working on uh the second week of the guile scheme course that I'm putting on right now and that's going to be a lot of fun if those of you who are in the uh gu scheme Hands-On gu scheme for beginners course right now I've got the ex the exercises pretty much finished for the second week I decided to go with the exercises first and then fill in all the rest of the content just to make sure that everything's covered effectively and uh I think that was probably a uh probably a good idea because some of these things you need to have like a clear result that you're looking to get people to and then you need to know exactly what you need to explain to get them there um so that's going to be on Sunday for those of you who are involved that you probably already knew that also wanted to say that there's a bunch of cool announcements coming over the next few weeks um not really time to talk about them yet but um I've been working on a lot of things behind the scenes for the past month or two and uh I feel like uh it's going to be a a good year for system Crafters it's going to be pretty cool that I'm not getting sponsored by anyone that's that's not what it is so sponsorship for this channel is kind of a weird thing like what what company or product would be appropriate to sponsor this channel I mean we had you know mastering emac um uh Mickey Peterson setting up the like the affiliate link which is cool and definitely you know fits in with the the topics and the culture of the channel but you know other things like that is not likely to happen or other things that you normally see people uh getting sponsored by on channels let's see [Music] um uh Jeff says how do we use the Forum from email Max though there isn't a way right now uh Beno says eww you can read the form from eww but you can't uh post anything because all the posting infrastructure and logging in requires JavaScript so um pavle AKA square root minus one is that right square root minus one anyway Pavo has been looking into possibly writing an emx package for Discord someone um had been working on something like that a long time ago but I don't think it went anywhere yeah exactly ly we're not getting uh Squarespace or rage Shadow Legends or anything like that sponsorship wise because I mean the only way oh square root minus one right okay yeah yeah did I say that I think I said that right anyway it would be funny to take such a sponsorship just as a joke but I don't think they would appreciate that because I could have some fun doing a raid Shadow Legends promo uh and just completely be sarcastic about it but I don't think I don't think they let you do these things okay so um today what I wanted to do stream is sponsored by Oracle that sounds completely ominous it's like saying my stream is sponsored by the Death Star so today uh what I want to try to do is write an IRC bot with guile scheme um I've already sort of done something like this I mean the the chat that you see on the screen right now is actually guile scheme code that's connected to IRC and is powering like a web page that I have plugged into the stream overlay but what I really want is an ircbot a separate ircbot that can sort of serve the community in the system cers IRC Channel and um you know Pro provide certain functionality that uh would be fairly interesting to have like uh let's say maybe leaving a message for for another user who is offline which you is pretty common for IRC Bots um what else uh making it possible to call back chat history potentially like if you are trying to refer to something uh or like uh reply to old messages I don't know that there's probably some interesting things we can do to make it uh a little bit more friendly cuz IRC is pretty bare boned and it doesn't have a lot of the functionality of things like Matrix where you have conversation threads or um uh like persistent messages for other users things of that nature so we're going to try a few things like that uh also what I would like to do is uh attempt to come on now to make a uh a matrix Bridge okay let's say a simple Matrix Bridge because it's not going to be very very uh effective really it's going to be one of these Bridges where uh there's going to be one account in IRC or Matrix that is relaying the messages from all the other people and they're going to be speaking on their behalf so it's it's not uh not perfect but it's better than nothing because right now we have nothing because the uh Matrix Bridge was shut down oh so long ago which is terrible uh Beno says cool first time I saw my fix in action yes you fixed it thank you very much for fixing it Beno it does work ashra says next up broken utf8 maybe I think I think it does do utf8 yes if ashz uh wants to fix something he could fix the utf8 support if it's broken but so far all the Emojis are showing up just just fine so I think it's okay uh let's see what else oh one last thing I wanted to try to do we we probably won't get to all these things today but we'll just you know see what we can do because it's it's a laid-back stream it's all good uh What I would like to do is uh provide a way for community members to um register their IRC account or let's say connect their IRC account excuse me um and what I mean by that is that uh there's things I want to do in the chat I've been mention this a few times where I want um certain people like let's say you know uh people who are sponsoring the channel Etc like individuals who are sponsoring the channel for their names to show up in a in a different way and the only way to do that is to make sure that the person who's sponsoring the channel lets me know about their IRC account and I can trust that it comes from them so um the idea is that the uh IRC I guess the Community member um puts their name in a web page or IRC Nick let's say the ircbot uh contacts them via private message um and asks them to uh paste a token they got from the web page something like that just a simple little thing then while says k side I don't know you can leak an email to a gpg key to an IRC account we could do something like that too but I mean that's kind of like not everybody can do these things uh let's see so yeah that's sort of what I'm trying to go for today and also like fun things let's say add some fun commands of some sort another idea that someone had in the Forum I believe is uh make it possible to gather funny quotes from IRC and uh relay them to the Forum somehow that could be abused a little bit but I mean maybe we could think it a nice way to uh set that up just to have a little bit of fun Cal says I really should get on the board then yeah you should get on the board because it's fun we have a good time there let me see so I don't let me do I have all my alert stuff set up here think I do have it set up or I did have it set up whoops yeah now you're seeing me change all my screens in OBS sorry for the uh the funny stuff here all right let me paste this in paste reference boom okay I think that's why I didn't see the alerts last time when people were joining the channel it's because it was on a different uh different scene in OBS and it uh wasn't showing on the screen at all okay so how we're going to do this um I'm going to jump into projects code uh crafter bot let's say I know that Beno had made a project called crafter bot at some point in the past I'm just going to you know steal the name yes okay wait a second craft robot main.m we'll say save that so that creates the directory did it create the directory yes okay um the other thing we're going to need is a dot files uh emac elpa live crafter we need the Geeks manifest for sure we also need I'm just going to steal some stuff from my existing code to make this easier to start with because you don't want to see sit around watching me just poke around the whole time anything else we don't need the the HTML parts we just need that Ben says yeah I think the bot the Elis bot is kind of dead haven't touched it in a long time I think gu might be a much better language uh for for than Elis for a bot uh yeah it should be it should be all right so this is the main a SC file cool so what we'll do is uh dear local let's see add dear local variable can do that and I can set uh what is it scheme [Music] mode and then compilation command no it compile command there it is compile command uh geek shell M manifest. SCM uh gu main.m also um trailing garbage following expression thank you very much makes me feel really good about myself was I supposed to make that a uh string hey Trev we'll try that one more time yeah I need to to enter a value here not just a plain string Geeks shell M manifest SCM G uh main.m okay that's all good now if I go back to main say uh normal mode just to sort of refresh the variables and I should be able to say compile and then the command is there that's good so let's uh just change a few things up here I'm going to say crafter bot I'll tell you a little bit about this uh I don't know why this co-pilot thing keeps starting I I swear I turn it off off in my config we're not going to deal with uh passwords and stuff right now or twitch just deal with uh Libra chat I'll explain some of these things in just a moment I I also should say we're using a library called uh guile IRC which is kind of an old library but it does work um it might need some work here and there to make it do things we needed to do but you know so far it's been okay this is a library that's part of Geeks or it's in the Geeks package repository so you can easily pull it into a project um let me just uh get rid of some extra junk in here oh I forgot that I have lispy on here and lisby is going to love me deleting lines all right so so some of these things I might need the Json thing if I do the Matrix integration so um what I'm doing is defining some um basic configuration stuff uh for instance the um the Nick oh sorry the there's a variable for the IRC session which is false for now because we we're going to set it after we connect um also the uh Nick for the bot which I'll set later right about here and then the channel I wanted to connect to I just put those there to make it a little bit more or yeah oh easily configurable is the camera Frozen sometimes it does and then it fixes itself seems like it's fine now uh benw says you should use durm for Geek shell and emac de okay shouldn't all that config State be in a separate file uh yeah later once this is better code but for now it's just uh getting it working all right so we're we're going to connect to Libra chat over SSL Port 6697 real name is uh let's just say craftbot um all right and we're setting the value of Libra IRC to whatever comes from make IRC which comes from the guile IRC Library so that that will start establishing the connection but we need to install some handlers to make it possible to uh improve message uh yeah I'll I'll take that out thanks Sosh Ros just do that for now I don't know if it'll let me last too long without the authorization but we'll see um so we install a couple handlers you need the Ping Handler because um an IRC server is going to occasionally send you pings send the client pings which the client needs to respond to otherwise it would kill the connection uh also the printer is for logging purposes and that's kind of useful just to oh this is the twitch here let's just delete that um the print hand the print printer Handler it prints out sort of a log of all of the stuff that comes through which is useful for just sort of seeing what is happening so we call do connect and do register register I'm not exactly sure what that's doing let's actually take check the code really quick in fact you know I should probably just clone this repo so that uhuh I just go into the GitHub UI the whole time right all right get some eell in here just clone it in this folder so we can look at it really easily Kyle IRC IRC uh what was it uh do register glena says I'm looking at your code and actually understand some of it that's that's good that's good it's working it's working all right do register send Nick and user commands all right so this is basically where it's uh identifying the bot user to the the server yeah week two is going to get uh cranked up a notch which is good a lot of this will make a lot more sense so um try Nick do command so it's I think this do command is basically sending um commands over IRC I was using D priv message but there's also do commands somewhere else in here I think maybe not but we do need that register call otherwise I think the connection can't uh complete also I'll take well let's see in fact let's do it this way yeah you did not indent the region did you okay connect chats that's fine uh message CU that might be useful later we don't need the HTTP server so I'll just get that out of here and then uh threads we would need a thread if we had the Matrix polling going on at the same time so we'll keep that around for now and just see how it goes um also we can get rid of the HP thread or let's comment that out for now I know I'm just sort of glossing over some things here but I'll I'll explain it a little bit uh in a second uh response we'll leave those for a second so the other thing I wanted to do is make sure I could do all this in the reppel uh let's do a little bit of reppel deren development here uh to do that because I'm using a uh a threaded design I need to use this Co-op repple server which basically is a way to pull for reppel input uh at the time whenever the app is ready for it otherwise you're bound by the uh redeveloped print Loop of the normal guile repple uh Willam says maybe zoom in a bit yes I'd be happy to uh let's see default text scale increase is that a bit better hey gun all right so what was I saying yes Dave says the good old Co-op rep reppel server yeah uh people want to to see its demise but it works it certainly works all right so I'm this is the IRC thread uh 160 for the you sleep ah it's the first thing Dave ever worked on for the Upstream gu yes it's definitely necessary for writing games you need the co-op reppel server cuz you've got a a tight game Loop and you need to uh pull the repple while you're doing that so can't really do that uh oh for the font size thank you 136 uh is that good enough probably I I need to to calibrate all the fonts on this on this uh setup again what editor there is this Zed yeah of course is Zed also it's vs code it's both of them at the same time right okay so we did the connection set up we we wait for the registration to complete then we join a given channel so this going to join the channel that everybody's in um for the stream so that we can all Pummel it with messages which is going to be pretty funny running in zal J of course zel zel I don't know how it's supposed to be pronounced I've already forgotten um all right and then this add message Hook is a thing that comes from uh guile IRC where um it's saying for a given IRC connection we're going to have this Lambda function that takes a message and then you just do whatever you want with the message um in my case uh for the the IRC overlay in the Stream I push a message to the que which goes to the polling for the client but I'm not going to need that here um what I'll probably need is some kind of uh set of handlers but I gu I guess there's already a Handler Logic for guile IRC but eh why should I use what they did when I could just do my own I don't know cuis okay so I need some of this stuff because like things like uh getting the prefix type and the prefix is good for analyzing messages but maybe I don't need all this cuz some of this is related to uh passing on messages to Twitch IRC uh this push message part right here message I can't speak uh when Nick is private message string okay so the channel is Libra and it's not the nick of the twitch user which we don't really need I don't think then we do something with it and here's where we would call some kind of Handler um handlers let's say and uh whoops handle message gun says eventually logged into the correct chat yes this is uh the most correct chat so uh for now we can just display the message maybe it's going to be a little redundant message fact let's use format for that format uh T message I think that's the right syntax um message trailing message so this is some IRC terminology here ah two uh two blog posts on making a matrix bot in G scheme that's cool I didn't see that um there there's no library for Matrix in guile or at least there's not one in Geeks maybe there is one somewhere this is probably a pretty common thing people need can I do that okay good at least lisby still works for that purpose so can we just run this thing and see if it does anything did I break it already uh compile we're not compiling we're just running I also need to tell it to listen I think uh let's see what have I do done wrong uh address already in use uh oh the reppel server okay am I configuring that I must need to configure this uh run guile guile there we go oh really is that not the right command to use it anymore great so I'm not getting any uh help doc what I just do fantastic scheme mode all right so um guile reppel server nice job uh Cooperative repel servers I just saw Dave's blog post on the on the matter uh server socket so do I have to give it a socket and I have to [Music] listen for connections on server socket proper function The Reel server requires that be called periodically yeah of course um ah make TCP server socket so probably that's what I need make TCP server socket host uh address port and if you didn't know this 37146 that's actually guile or it looks like it says guile sort of backwards and upside down a little bit of trivia for you there okay um maybe I can do that here how did I make this read only excuse me I already have one running in the uh the chat overlay app so I have to to do a separate one now uh Define uh reppel server socket this is going to be fun uh Port 3001 I told you to get out of here okay trying to think of a better what is it the number let's just do seven okay that should be enough repple server socket I think this should work repple server socket and if we go back to compilation buffer run this again uh let's see Unbound variable I got to pull in system reppel server I think yep then we'll be able to do this interactively which will be much bettered says are we are we witnessing the start of the AI Uprising live on stream we're we're just witnessing my emac config not cooperating uh no I I did a stupid thing and I ran a mode that changed the major mode of the buffer and then when I changed it back it triggered co-pilot mode again let's see raise excep wrong number of arguments to connect chats well that makes sense we'll just make an empty list there for now because we don't really need to do anything for that and this should connect Famous Last Words twitch IRC fine all right so I also need to change this logic because I don't have multiple IRC servers to pull anymore so I can just drop that out and get rid of that message do listen server win message run message hook okay that's fine that's fine I don't need IRC servers anymore okay wrong type and argument position one server procedure uh line 90 oh yes it's uh what is it Libra IRC okay everyone's favorite kind of stream the one where I'm just making mistakes the whole time cool it seems to have connected oh this nickname is registered I don't know bino did we register that Nick in the past I think we did I'm trying to see if uh I have a Pastore entry I don't seem to have one but no so as you can see in the output here you you can see asra's message that says hello crafter bot so the structure of these messages is there's a few different sections of the message at the beginning you've got like the the colon that I think all of them start with on a new line and then uh the user details priv message which is interesting because it does it's not a private message it's a message in a chat room but I'm I guess they are distinguishing this message between like a global message that uh happens for everyone on the server um and then the channel that is associated with and then after the colon is the rest of the message uh that actually is shown to the users of the channel so pretty simple uh asra said maybe because I put in the name I don't know and this message part here is uh what I was writing out in my uh stuff so let's connect the reppel and see if I can break things that way um 37147 uh geyser connect local is that for a geyser socket connect no it's a socket file I don't want a socket file I want a port uh Local Host okay fine Local Host uh 37147 and here's a repple and that's in our existing process now the question is if I I need to I need to move some of this code around if I want it to actually um be changeable and the reason why I say that is uh for a reppel driven workflow you can't have a loop that has code that isn't calling functions that can be replaced at runtime so all this code that's in this Lambda that's running in a thread I can't really touch it because the thread's already running it's already off on it its little Loop here the wild Loop uh the only thing I can really change not even that I mean this stuff doesn't really need to change that much what I can change is this message Handler here so oh no I can't change that because it's a Lambda that's directly in the ad message hook so I think the first thing we would need to do is um make a uh see Libra message hook it's not a not a good name but whatever it's going to be a function with a message parameter and then I can just take this whole body and drop that in here da says trampoline yes so um there we go so we got that there I need to to to replace that with Libra message hook and just get rid of this Lambda syntax right there so in fact we could get rid of this Con chat's bit and just throw that down in the thread initialization I would say and I can even have a function well we don't need that uh let's do that right here instead get rid of connect chats so now we've added the message hook for Libra in fact that could even potentially go in the Libra IRC connect right after the doe weight let's say probably the right place to do that so we'll end up restarting this uh in just a second no more connect chats we got Libra message hook function I might need to Define that first but probably not uh no I don't need to Define it first all right so we got that now doesn't work Trev you're not going to get the fast one by me this time okay I can't add a command like that though just if people want to try try it I can add a new command and then you can call it and break the bot so we have the Libra message hook um this is a God awful mess okay as CU nothing is indented correctly of course okay so we got the message hook uh clean that up a little bit uh on the IRC thread we're just calling uh Libra IRC connect and then we run the loop we pull the reppel server connect the bot to GPT oh boy we could do that but I think that's going to be a nightmare I'll get my open AI account uh blacklisted when message run message hook and then that message hook will ultimately call this Libra message hook okay so if we were to go and uh kill this uh connection and you can see the the crafter bot dropped out of the channel as a result of that in theory if we restart we should be able to reconnect and things should be working again in in the ideal case Okay crafter bot is back in the channel now uh let's see test okay so it it is still uh printing out the uh m mesages now I should be able to to change this function and just reevaluate it oh I need to to reconnect to the reppel first though so uh control CZ and that's in the geyser I hope it did the right thing that's not going to work Geer repple let's see if it if it works to change the um let's see compilation uh main SCM can I just do control X is undefined uh geyser buffer wonder if I did that the wrong way let's just kill this reppel and and start it again yes okay so connect 3147 is it going to be connected to this buffer no that's annoying uh let's see there's a way to set the buffer at the repple geyser repple buffer clear buffer no to like attach a buffer to a repple ah I wonder why I didn't like it I wonder if my geyser version is out of date I wonder okay let's let's look at that that files uh emac Ela geyser okay good at least it's not installed by elpa it's installed by a uh eeks so at least it's a little more uh predictable all right so geyser R2 says are you using Geeks yes I'm using Geeks what I'm looking for is geyser connect buffer to reppel blinding is that a function and not an interactive function I wonder uh geyser repple [Music] buffer uh set this buffer reple so where is that set this buffer repple setup repple set oh there's another one here start reppel well geyser reppel set this buffer reppel current buffer uh yeah this is probably not going to do the right thing let's see nope that's very strange dude because it works fine for me in other cases uh Soto I guess is how you pronounce your name do you prefer reading documentation in browser instead of going to info mode uh it's a bad habit I try to use info mode as much as possible I know there's a way to do this is that what I can do can I set that n man this is annoying dude okay we're I'm trying to make sure I'm trying to get the uh current buffer to be registered to send uh Expressions over to the geyser reppel that I have running for some reason I can't remember the doesn't do it uh let's check the key binding actually uh control or contr x no commands Okay something's wrong with the the geyser set up maybe it's myig actually so uh dot files emac modules code Dev what is it geyser geyser connect no I I used geyser connect and it didn't do anything oh did Ari SN snarf the bindings is that what happened that must be what happened so you're telling me I'm going to have to uh oh geyser mode Auto that's what the problem is okay so maybe if I just restart that buffer okay let's go back to uh main.m we're going to kill that and then open it again and then check The Binding of control all X there we go that might work okay so just a bad config issue the reppel is still running I should be able to use control X here and I got unspecified so it must work so let's go go back to the compilation buffer and if anybody says something like me hello it did not work I wonder what which reppel did it try to send that to it it sent it somewhere clearly I changed the uh message Libra message hook ah you know what I do need a trampoline like Dave said cuz right here here I'm passing in the literal uh or I'm passing in the real function or procedure value of Libra message hook and I can't replace the function there so I would actually have to do this Lambda message uh Libra message hook and that's the only way that I'm going to be able to do that because add message Hook is just adding whatever I'm giving it here to a list somewhere and I can't change what's already stored there there's a value a procedure value that's being stored there so I need to wrap it with something so that I actually have access to it which is a little bit unfortunate but that's just the way it works with scheme I I find it to be fine you just have to remember how to to do it so because I had I had to make that change I'm going to restart the bot all right so now it's getting connected I'm going to change this message to Foo and then we'll see if it works in just a moment no guys are reppel for this buffer how did I do that no oh maybe it is oh it reconnected smart Okay uh possibly Unbound variable I don't think so a all right so I think it might have started a new reppel rather than reconnecting let me do this I'm going to kill this buffer and then I'm going to use geyser connect inside this buffer Local Host uh 31 37147 and uh I'll run this again and now in theory okay finally it works we see now at the message that I had here is now changed to Foo so we were able to re-evaluate this function and get different Behavior uh cool and also not so cool because I did something stupid here and well I think I took that out actually okay that's fine so we can do something different here how about this Define uh get out of here co-pilot I swear to God not in here where is it anyway uh message H we could just have some hardcoded stuff here for now we can make it a little bit more flexible later so what do we want to do Fighters what's that all right oh food Fighters yes well food Fighters pretty good so we have a message message trailing message uh we can say handle message message here very very nice right um I'm not going to run that yet I need to have some some kind of body here so uh we were looking at see the priv message and then the trailing message part so uh let message text is a message trailing come on the way this library is written does not work well with the uh indentation in in emx for scheme all right so we have message text here and then uh we can do a I think of the best way to approach this I just want to pull the like let's say we we'll do something like this um commands come on I hate you lisy uh let's see Hello we'll just say hello leap case and message test text yeah I don't want to have to write a a function for that unless I turn on co-pilot mode and let it write it for me we want to go down that route okay I mean I guess I could just you know replace all e with threes and that sort of thing but that's not waste our time I hate USB yes bot quote I hate USB uh let's see what else can we do some suggestions anybody got suggestions what commands we want to uh have here so uh slap uh Target let's say you slap someone around with a bit of trout what are the things count Trev says that Co pilot might take us down into the side of a mountain something thank left pad okay there we go left pad there's another bot in this chat uh let's see roll we could do a little dice rolling thing maybe I don't know is it is it roll die though it's not dice it's D nobody really knows that though command units can run arbitrary code which I mean I'm not using um what they're doing and their stuff I'm going to write my own little Handler for this for fun because I want to have things be broken all the time okay so I think I can just split the string um split string split there we go string split oh okay string split uh message text let's let's do a let Star here this is probably not the most efficient way to go about this but I'm not too bothered by it at the moment uh message text and uh we'll do a space on that uh links yes that's a good idea Forum okay so string split and um we can say the command let's see um o um man Parts I guess I could do it a little bit differently I could just you know search up to a certain excuse me a certain character but let's just do it this way for now Command parts and pair Command parts uh car man Parts just a little bit of tur logic here and that's good for that so now we can do a um case on command if it's uh hello now we need to a way to write something back and how was I doing that before chat. um do message message push message no uh do priv message okay there we go let me also do send message text simplify this a little bit uh Libra IRC Libra Channel there we go okay so we have the send message I'm going to eval that uh possibly Unbound variable message text yes thank you I did not actually say that did I the guile compiler can be helpful sometimes because it will catch you doing dumb things before you actually run the code uh all right so now inside this function we can say send message should I make an exclamation point on that okay send message uh hello now the other thing we might want is the um the sender of the command I think so message how was I getting that before um prefix if equivalent uh prefix type okay so I think it's this one right here take that little snippet okay so send message I'll use format on that as well t Okay and then sender that should be enough to start with I think so I've did that now I'm going to do this all right so do we have an error uh no interesting so let's do a little debugging little print line debugging here uh display uh command we'll do a format on that actually oh what am I doing I should be doing format uh F on these I think right because I don't want it to print on that so format t on this one and this would be command unspecified datm hello cannot be meaningful compared using oh okay what's the right way to do that then should I convert it to a symbol interesting I think I'm going to have to use cond for that but I really don't want to use cond uh scheme case uh compare comparing blah blah blah blah blah let's go to the guile reference manual and then the procedure index uh what am I looking for case syntax case conditionals case whoops I just do yeah there's a data driven way to do this but uh let's let's just do the do it this way for now yeah here we go symbol to string command um now it's we got a different problem here the problem is that the uh case macro syntax doesn't like having a string because it can't use the normal comparison eqv the equivalence operator on two strings because you need to use full equal I mean you can do it but it's not a good practice I think um all right so back to the repple or comp potion let's try this again so I I eval that I'll just eval that again one more time for good measure and then oh there we go so we at least have wait hold on did I this backwards wrong it needs to be string a symbol so it uh kicked us out of the program that's okay we'll just restart it all right the bot is back and we should be able to say something right all right it worked cool so now we have one command we could add some more commands like we were saying before yep see it works so we need to go outside of this and add one for let's say Forum oops on this one we can just say uh we can join the Forum at wrong H yeah that it didn't work did it I'm sure you'll find a bug at some point though no Geer re for this buffer let me go back and uh clean this up connect there it is now we can run this function again or eval that function and now there we go so we got some uh some basic commands starting here what else do we want uh let's see we'll do a little count thingy my jig oh wow whoa whoa whoaa what did I just do there we go and uh counter we also need to um what is the function for that is there there's no ink like ink F but there's like a one plus no okay anyway we're manipulating Global State here bad bad bad okay one times there you go now you can count my uh make the bot count a bunch of times count reset yeah we didn't add that yet and uh clearly it didn't trip on that did it I don't see an error that's good all right so we're doing okay so far all right so we got a few of these things uh let's do one that takes a parameter okay so what we need to do on this one it doesn't count for commands within text only at the start uh no it just counts for that count command I mean you just hit count and it just increments the counter all right so uh how do we do a parameter on this we have the command Parts technically I could just pull that I could say uh catter on Command parts let's see if it works um so I don't know where this old uh IRC thing comes from slapping someone around with a bit of trout but I mean I used to see it in uh MRC back in the day so I wonder what happens if you don't have that part is from MRC yeah okay and uh now someone can feel free to break the bot by not putting in a Target name there it is so easy that was the intention ashr you were supposed to do it I know you're waiting the whole time for an opportunity to break the butt okay so so uh let's see to make this a little bit more resilient yeah I got to I got to start the the bot back up now yes it's an interactive demo it's supposed to be broken uh let's see Target um you're behind the stream by 10 seconds that makes sense so Target I need to make sure I'm going to do this in a way that's not going to cause a crash also cuz I can't just say C or Command parts you need to make sure that there's a uh value there first so if I say uh pair cutter and catter uh I need to put this in here too Command parts bit of lack in real time yeah it could be my my Computing setup today okay so we got Target here if Target otherwise have a little bit of fun with you slaps thems thems himself kadat CAD kadat it's not a cadav if you use cadat what did I do wrong oh it's busted right got to restart and then start to slap themselves in their confusion that sounds better right slaps themselves for forgetting the second parameter all right so if I do uh well it should already be set up now but I need to just connect to reppel anyway that grammar doesn't sound right but that's the way we're going to do it okay so um that's cool we got one that has a parameter what else did we say we wanted to do left pad sure left pad come on Pull up The Prompt where is it is this really killing my computer to do this what is happening right now I'm just trying to copy an emoi for God's sake apparently it was enough to hang emac unless all right we got to figure this out procad what's going on here aside from OBS chewing up the whole system huh okay weird uh no it's not blocking it's not blocking okay so um I was trying to copy an emoji I'm just have to do it this way aren't I folded hands that's what it's called not praying hands I guess they wanted to try to keep the uh religious implication out of it there we go hey there we go okay it worked I think H who what is going on here there's some other Bots that's on left pad apparently unless ashas is just so fast yeah crafter bot said the right thing I don't know what this other bot's doing unless that there's someone pretending to be a bot in the chat it wouldn't be the first time anybody remember uh Sherry man that was a long time ago haven't seen Sherry in uh probably what a year and a half at least have we really been doing this that long okay okay so um we got left pad we got count we got slap we got hello we got Forum um oh yeah another another little meme just for fun those of you who've been in the system Crafters IRC the last two days know what I'm talking about not a bot yet we're going to have competing bots in here little omage okay uh what else roll dice that's easy I guess the question is how many sides do you want bot War like undiscovery oh boy yeah IRC bot War okay so we can start with just a normal uh six-sided die uh format uh F and I think there's just a plain old whoops what I delete here it's like a plain old random function that takes an integer yeah like the Max uh I think I need to do like a plus one on that probably we'll see Ash says I guess excuse me Mr the C 1999 versus left P discussion last weekend maybe so don't forget the seed ah I'm not that worried about seeding it uh wrong number of format arguments o you're right thank you compiler I'm spamming my own chat here it seems to be working okay so you can roll a dice wow so cool not really I'm just being vicious okay what else can we do here we said we wanted to try and do some kind of validation thing I don't know how easy that's going to be to implement right now what else what else how about change the number of faces on the die yeah we could do that late night IRC gambling okay so um we'll do a similar thing uh let sides uh and pair cter Command parts if I type it correctly I probably need to generalize the argument aspect of this so I don't have to keep doing the same logic over and over again but hey all right so we got that now um if sides oh let's not do that let's do it here uh let's see or yeah we need to see if it's actually a number though so maybe we should do a little bit more validation on that can we actually validate that is there any logic in gu to say that a string is a number without throwing an an error maybe there's like a try of some sort uh let's see it's it's not set up yet B all right let's go to top and then go to procedure index and then um let's see number to string oh okay if it's not valid it returns excuse me returns F that's that's perfect actually okay so then we can we could definitely depend on this where was it uh and sides string to number yeah that's good I like that let getting a little bit gnarly nessing it so so low uh sides in fact I mean I could just do this logic up here right so if that's there or uh yeah that's right string to number there we go and if it's if it's not that then I'm just going to default a six right so then I can just go back here and just put that back to what it was eval seems like it's okay all right so roll 20 uh-oh what happened did I break the logic somehow where is the reppel Why didn't it update oh roll dice maybe I should just call it roll huh okay it works should I just say roll I think roll is better isn't it now it's roll okay there you go that's better that's better no more complexity okay uh cool that's that okay so clearly it didn't work does scheme recognize that syntax is that what happened value out of range 999 is it because let me just pull up a repple real quick I I want to see this I roll like that that's right uh let's restart and go back to the repple there and then we'll start the Reel up again as soon as it gets rolling rolling okay so uh num yeah it does understand the exponent syntax that's one of the things about scheme is that it it could do um exponential numbers number oh wait wait a second wait a second wait a second wait a second tring number okay so even negative one even negative one that can't be right come on now um did it give us a stack Trace argument one out of range negative one so Random doesn't like negative numbers okay I guess we got to also check to make sure that uh we're not getting negative numbers roll nil yeah those won't have a problem you know I don't think scheme could do Roman numerals I also need to check all right or and greater than zero sides sides or default to six hey whoa yeah do it that way so uh it's either sides is not false or it's greater than zero and it's greater than zero or it's six take the ABS number eh I don't know I guess I could do that but it it's what's what's worse using the default number or uh using the absolute value which is not what was asked for maybe maybe ABS is better uh let me see is ABS just playing there in the global environment to start with let me rerun this first zo says I'm always surprised that Lis based language is never caught on in the infc world since the first instinct the most lispers to see how to break code yeah I don't know it takes someone actually writing Lis code first uh who said that that was weird dude let let me have the bot on for like 10 seconds Jesus Christ I can't fix it what happened this time value out of range again it's okay d dude it's okay I'm just joking around uh value out of range 999 so that's clearly a run geyser let's just take a look at that uh number no no string to number I'll just have it uh ignore all commands from ostras uh number e one to e999 value out of range okay so what is in what is in range that's fine so 999 is not cool all right so I got to remember how to catch uh errors in uh in guile so if I go to info whoa is is info buffer gone now okay I must have killed it oh here we go um concept and index catch no what is it condition uh raise guard what is the what is the the nomenclature for this I've forgotten what it was this is really unimportant I shouldn't even be bothering with this right now yeah there's no catch let's go to the procedure index catch okay so there is a catch what the hell why didn't it come up in the concept index is it is it under exceptions cuz I wouldn't think it would be called exceptions but maybe it is catching exceptions yeah as always ashz has the uh exact place in the info manual at hand okay so with exception Handler there we go so with exception Handler we don't need all this extra stuff I think cuz it's probably for continuations thanks Dave uh with exception Handler land the exception apply Handler just ignore it right maybe I just want to ignore it so anytime I'm doing some kind of conversion I need to ignore the the thing that happens now is there a way to to return a value of some sort I guess in this Lambda right I could probably just return a value from the Lambda and it will okay so the second thing is the expression I think uh with exception Handler where's the syntax okay so it's treating it as a thunk a a procedure to be invoked let's do that let's just see if we can prevent ashras from breaking the system zo says just make it behave as a D6 and tell people to can do other numbers and they are just rolling poorly yes I agree unwind tea you need that okay thanks Dave all right so we got this logic here uh right around the side the time I want to do the string the number I need to wrap that and this lovely syntax this thunk is going to become a Lambda with no parameters CU that's what a Thun is uh I'll take the unwind for type out hey Jose nice to see you all right so Lambda and the Lambda is uh this part so if the Lambda throws an exception then the Handler should be able to uh do something else which in this case I'm just going to return the default value of uh six let's say or I could I could return an error message of some sort to the the person who passed it in I don't know if this is going to work um Unbound value counter I think I'm not in the right place let me go back to the repo I haven't restarted the app yet okay uh ashra is saying it's the online manual at g.org out ofate I found that we were searching for guile Concepts on search engines somehow it finds an older version of the guile manual and it will just give th those links to you and you won't realize it's happening until you look at the URL and uh there are enough differences between the pre 2.0 versions of guile to 2.0 and beyond that um you can get yourself in some trouble with that okay geyser connect Local Host 3147 okay so now ashras do the honors see if this works it may still crash I don't know let's try it gota wait for the stream delay to kick in okay cool I think it caught the exception maybe it didn't though try try okay good good good roll a four I think it picked a six excellent oh the negative still come on now I can't be right wrong Oh wrong type argument in position one for what something else uh 141 okay who knows that's not a very helpful error message uh main 40 okay that's the add message hook that's that's pretty um unclear that's okay that's enough for now I mean it's enough of trying to catch the airs it needs to be more robust make this handle negative numbers I mean I think it should have handled it already discuss Easter eggs okay what kind of Easter eggs do you want what kind of Easter eggs I'm going to take roll out right now cuz it's a liability and I want to be able to uh to do this can we get the intern to write some unit tests we don't do unit testing here man don't you already know that I I just like Shi code to production without any testing roll the computer I need to roll my computer out the window that's right uh give me a second I get I'll get it back online okay we did that uh compilation buffer compilation where are you did I break that already Okay so let's run compile again all right there we go get back into the main SC buffer switch this one over as well we go yes we're doing the unit testing live yes uh Ash excuse me ashras is doing the QA testing here test module is called ashras that's correct now rooll is disabled uh what did Peter say roll Rick oh yeah that could work that could work if the B just start singing Never Going To Give You Up in the chat do a barrel roll Jose says throw a bad taste exception send a eurl of Rick on the web I think summer Rick Rolled somebody in the IRC the other day that was fun okay uh let's see I'm trying to think is there anything else useful we could do just as an example um I wonder how do private messages work so like if if someone were to send a query to me right now like a private message like slash MSG I could do it myself I guess what's it look like it doesn't have a room so what does that do in the code I wonder okay roll soccer ball yeah the roll command I disabled it because ASAS did such a good job of crashing the the bot every time I turned it on uh let's see so I think the channel part is the middle section if I were to check the middle section yeah I'm not actually checking SP on a thread to process commands I I am on a thread can we do eval no no no no we're not doing eval I would have to have a way to sandbox that and I can't figure that out right now uh let's do a handle private message maybe Define um handle private message Ash's laughs about the thought of eval yeah that's that's just asking for trouble we're gonna end up like somebody's going to figure out how to uh spawn a shell process to launch my browser to go to some terrible website all right so uh handle private messages it's just message right okay ah ask the bot how long they running yeah that's actually not a bad idea I haven't actually tried that yet that trying to do time operations basically on a priv message if the channel name is the name of a user it's a message oh is that how it works I don't think I saw it though let me see uh yeah I'm not oh the priv message has to be the nick of the uh the count okay okay okay yeah we do need like a command thing okay so you know it's the same right I just need to take this part out so if I if I change handle message um it's not Target what you call it room and if room starts with a hash it's a room it's a chat room otherwise it's a Nick okay but that would require let's do something different let's not do that let's do it this way so handle private message we're going to we're going to make sure so and Nick let's call that room instead uh say when it's a room and it's equal to private message then we go into this uh block here uh if I should do this wait yeah oh that's the that's the nick of the cinder I I shouldn't have changed that is that right I'm very confused now what did I do wrong so Nick is uh that and Nick okay that's fine so let's call it sender and it's a private message then we can jump in here if oh where is it my mouse or my cursor go if uh well maybe this needs to be like a cond so if it's a Libra Channel then handle message message otherwise if uh string equal message middle message what was it uh Libra Nick I'll get rid of this here is that good all right so handle private message let me just do a little quick job on this one need a similar deal here maybe we won't won't bother with uh fancy command handling right now cuz we're about to be out of time what I can do oh I forgot my uh extra PRS around uh that one right okay should I I shouldn't have to do that again the cinder bit I should have sender in there as part of it sender and this needs to have handle private message message [Music] sender all right so if we got the message text then what I can do is uh send message all right so send message maybe we should recipient let's do that excuse me now I got to go back through and change all these how about this send ah crap wrong okay that's better there needs to be a David will command is that what I'm seeing oh okay so uh we got the private message we can say send message uh to the sender and format that should be good enough as a response now I need to reeval all these things and also excuse me make sure that I'm not making a huge mistake uh I think we also need a command that says what my battery percentage is but that would require some extra work hey Judy USB [Music] yes all right so send message now we're we're definitely going to break here for sure uh let's see message text recipient possibly Unbound variable do priv oh okay am I in the wrong repple at this point I think so hold up Ripple yeah that's what happened guys are connect got that so send message okay handle message message handle private message message hook and uh go back to compilation buffer all right so message yeah that actually worked but I'm not printing it out on the screen so that you can see that someone sent a message so how about I do that okay now somebody send me a message did the stream die what the hell happened wow are we back wow that was weird there was like a momentary blip in the connection and I dropped a whole bunch of frames but then it came back yes I see on my screen right here that uh that Ash told me something so that's good never died okay good I don't know how that happened well alrighty I mean I think that we uh made some progress that's pretty cool right I mean it it's it's the beginning of something uh that's pretty useful this is more than I've ever done writing any chatbot before and it's all with the power of scheme I imagine that there's probably a lot of command handling stuff built into guile IRC that I didn't even bother looking at but I think it was a bit more fun just trying to to write this ourselves and uh see how far we can get with it there we go now we have some bot tobot interaction going on thanks to ashras and leftpad so I will uh drop this code in the show notes for the week in case anybody wants to just take it and play with it uh it's not the best code in the world but it will get you started if you want to write a IRC bot there you go if you want to ride an ircbot with um with scheme cuz I don't know know like if you want to learn scheme then you got to have some kind of project to work on and I think this is kind of a cool project to do because uh it has some utility but we don't need to have like you know 15 people with uh with Bots coming into the S Scrappers chat so let's try to keep it uh reasonable here if somebody wants to play with Bots we can create a special little room where everybody can put their bots in and have them fight each other uh but let's not do that in the main system cbers yet push the code to Source Hut yeah actually I think I got the text wrong on that what was it it wasn't emac in the profile what did did he say emac mention in the profile is that what it was what did I put in my profile today uh emac mention in the profile okay I think that's the literal phrase that was used okay uh that's it I think I got to go and eat some uh some pizza now for my birthday because today's my birthday um I yeah we'll back be back next week with something I'm not quite sure yet but uh we will have plenty of time to think about it between now and then um I might start doing some more uh programming streams and stuff soon not necessarily on Fridays but maybe other days of the week so um if there's things that people are interest interested in seeing sort of hacking system crafting wise let me know cuz uh I I would love to do some more um coding live coding I love live coding it's fun especially whenever you have you know 50 people watching you and heckling you and also trying to crash what you're writing at the same time much much uh much more fun that way in my opinion thank you very much for the birthday wishes I appreciate it Big Ed says bring you back Flex harmonic yeah that will happen it's not going to happen immediately but let's say two three months maybe I'll start doing some flux harmonic stuff regularly again um I would like to definitely do some game jams when is the next Lam Lam Dar uh there might be one in April or May uh April 12th I could probably do that and then October Glennon say says whing config on Geeks yeah we're definitely going to start uh doing some streams about that uh pretty soon maybe maybe whing config in general and then eventually rolling that into uh Geeks I think something must have happened on the twitch side uh Peter says Ass Bots is born yeah we're going to have to have some kind of you know Battle Royale channel for uh for IRC Bots written in different languages and see which one could crash the other that would be pretty funny actually actually I kind of like that idea kind of like a hackathon but the the whole point is to write Bots that IRC Bots that battle each other and see what happens it's probably been done before but H you never know maybe we could you know make that a new thing all right thank you very much leftpad for all the help uh today for making sure that the stream came online all hail left pad baton yes that sounds kind of weird though okay folks uh thank you all so much for being here today I appreciate your patience with me while I get everything set up on this other machine again but soon I'm going to have a new computer that's going to be super stable and we're not going to have this problem anymore and the stream is going to be incredible the quality is going to get much higher so we'll see when that happens hopefully it's soon um and uh like I said thank you all for being here and I hope you all have a great weekend and until next time happy hacking we'll see you
Info
Channel: System Crafters
Views: 1,172
Rating: undefined out of 5
Keywords:
Id: 0wKgTMdWyHc
Channel Id: undefined
Length: 108min 3sec (6483 seconds)
Published: Sat Feb 10 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.