字幕表 動画を再生する 英語字幕をプリント (whistle tooting) - Hello, welcome to video number 7,629 about Mastadon bots. (Daniel laughing) I have been on a journey, a journey (imitates train clacking) on along the tracks of Mastadon. And I started from nowhere and I have arrived to the point where I have a bot. It's called codingtrainbot, and what this bot does, if you follow the bot, it says, welcome aboard. And if you toot at the bot and use a certain keyword, it will favorite or re-toot, boost, whatever it is, your particular post. And I want to add one more thing to it. So, I want to be able to respond to a question. So, let's just say, I'm going to look for any post at me that ends with a question mark. This is going to be tricky cause there's the html tags in it. I'm just going to look for a question mark, I'll let you make this fancier. So let's add one more check. I'm going to constant regex3. I'm just going to look for a question mark. Oh, question mark is a metacharacter, so I think I might have to do this, \? So I want to look for a question mark, if regex3 matches the content. And by the way, this is, by the way, this is like the very basics of making a chatbot, which is just doing basic pattern matching. Now chatbot systems use machine learning and try to categorize what people are saying into intense and do all sorts of text analysis, but at a core level, you could just use regular expressions to try to match what somebody's saying and respond accordingly. And if you, I do have a set of videos about Rivescript, which is a pattern matching utility that you can use in any programming, a number of programming languages, but you can use it in Javascript, to build your own chatbot. So this is interesting to think about, what do you want your bot to actually do, but in this case, I'm just going to use regular expressions. I'm going to look for a question mark. So let me just actually make sure this works. I'm going to say, I got a question. And let me look at the content. So I think I'm going to not always console.log the content anymore, I know that's working. Now I want to just look at it, console.log, data, what was it called that I put it in a variable? Content. So I'm just going to look at the content. So I am now going to run this. You know, by the way, if you're doing this on your own, you're going to want to have a second Mastadon account (laughing) where you can then test it. I am a weird, crazy person who does this sort of stuff on a live stream, apparently. I just assume that the people out in the world watching will interact and hopefully be kind. Okay, now, let us run it again. Let's see if we can get some mentions with a question mark in them and see if, oh there we go. So, I got a question. Okay, oo, that's interesting. Oh, I got a question, that's not what somebody said to me. Why, with a question mark. Okay, so that seems to be working, so I'm going to assume that that's good. Thank you for that. And now, what I want to do, is I want to say, I want to do, I want to create, sorry, a reply. So I'm going to say, reply equals the meaning of life is, and I'm going to use this, oh I have this from before by accident, luckily, is num and then I want to just send that reply, but here's the thing. A couple things. One is I want to mention that person. So I did that before when somebody followed me, so I can do at and then the account, which I should still have, hmmm. I didn't actually save the account, so if somebody mentions me, where do I get the account? Data account, accounts, the same thing. So I can actually go back, msg.data.account. Actually, I think I kind of like always want this, whether it is a follow or a mention. Whoops! So I'm going to put this out here so I have access to that account. Sorry that the font got smaller here, hopefully you can still read it. So, I want to first mention that account and then say, but here's the thing, you can mention, but it's not going to actually understand it as a threaded reply unless I include in reply to id. So I actually also need to get the id, which I have here, msg.data.status.id, so what I'm going to do is I'm going to overload this function with a second argument, id. And I'm going to say, in_reply_to, we got to look at the documentation, I don't remember what it is, but if I look here, oh, it's actually over here. in_reply_to or reply_to. Oh no, I'm in the wrong place, oh, I'm totally in the wrong, but I was in the right place before! in_reply, there we go. I'm looking for in_reply_to_id, so I want to grab this and I want to put this here, and then I want to put in the id. And I guess what I want to do is, the thing is, I'm going to do it this, this is a little goofy, I probably could use some fancy ternary operators or something, but I'm just going to say, if id exists, then I'm going to add it. params.in_reply_to_id equals id. So it's, based on whether or not, if I send into this function, I'm always going to send into this function some content that I want to toot, but if there's an id, I also want to add that in. So now, we should be good. If somebody asks a question, we are now replying with at that person, oh and this should have an at. At that person, did I do that up here? Yes, at account. So at account, the meaning of life is, and then the number. Okay, here we go. Let's actually run this. You can now ask me your questions. And I will wait. (peppy music) Alright, I'm back and a bunch of people, or at least two, I got two mentions, so if I go back now and look at my bot account, hopefully it's not too spammy. Are you for real? And then if we look at this, we can see the meaning of life is 40. And this one has a question like this, Yes? You can see the meaning of life is 65. And I'm just curious if somebody, I was looking for one that also has the (laughs). So this one, for example, some fake danshiffman, this one was both favorited and boosted and replied to. So this bot will actually do all of the things. It is now a bot, oh look at this. Oh, I'm just going to favorite this manually. By the way, everyone should look at Alca's pannable Lissajous table, it's wonderful. I will be releasing my lissajous coding challenge video very soon. And here you go. So this is it. We have now finished this up. We now have made a bot. We've seen how a bot can post periodically with set interval something, and you might come up with an idea of what you want to do. We have now seen how a bot can favorite, or boost things, and reply to things. So now it's time for you to be creative. What kinds of replies, what kinds of activity, maybe you have a bot that makes up a poem, I haven't shown you how to generate an image and post it, so I will show you that. I've got to make a video to show you how to do that. But there's all sorts of wonderful possibilities of how you can make your automated bot, use it on Mastadon at botsin.space. So choo choo everybody. (whistle tooting) See you in a future video. I hope you enjoyed this series about making a Mastadon bot, more to come in the future, I'm sure. Good-bye. (upbeat tech music) (bell dings)
A2 初級 4.7: Mastodon Bot - メンションへの返信 (4.7: Mastodon Bot - Replying to a Mention) 1 0 林宜悉 に公開 2021 年 01 月 14 日 シェア シェア 保存 報告 動画の中の単語