{"id":491,"date":"2012-07-19T10:13:01","date_gmt":"2012-07-19T14:13:01","guid":{"rendered":"http:\/\/www.deadcodersociety.org\/?p=491"},"modified":"2012-07-18T22:22:21","modified_gmt":"2012-07-19T02:22:21","slug":"mixing-the-command-line-and-irc-bots","status":"publish","type":"post","link":"http:\/\/www.deadcodersociety.org\/blog\/mixing-the-command-line-and-irc-bots\/","title":{"rendered":"Mixing the Command-Line and IRC bots"},"content":{"rendered":"<figure id=\"attachment_494\" aria-describedby=\"caption-attachment-494\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/10375090-kitchenaid-mixer.jpeg\"><img loading=\"lazy\" class=\"size-medium wp-image-494\" title=\"mixer\" src=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/10375090-kitchenaid-mixer-300x300.jpeg\" alt=\"mixer\" width=\"300\" height=\"300\" srcset=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/10375090-kitchenaid-mixer-300x300.jpeg 300w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/10375090-kitchenaid-mixer-150x150.jpeg 150w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/10375090-kitchenaid-mixer.jpeg 500w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-494\" class=\"wp-caption-text\">Making cookies with IRC and the command-line<\/figcaption><\/figure>\n<p>My IRC bot checks a directory every minute for files and reads the contents into a channel. This simple feature\u00a0is also one of my favorites.<\/p>\n<p><strong>The loop:<\/strong><\/p>\n<ol>\n<li>Checks for the presence of files under \/say.<\/li>\n<li>Reads the contents of the file into a string.<\/li>\n<li>Prints the contents into a channel (pulled from filename).<\/li>\n<li>Removes the file.<\/li>\n<\/ol>\n<p>Mix crontab into this and you can use any of your favorite commandline tools. Here&#8217;s a few examples from my own usage:<\/p>\n<p><strong>Finance tip at 8AM every day:<\/strong><\/p>\n<pre>00 08 * * * curl -sLk http:\/\/bit.ly\/OowzSt -o ~\/say\/#finance@tip<\/pre>\n<p>This just hits a PHP script that returns a random money tip.\u00a0<span style=\"text-decoration: underline;\">Note:<\/span>\u00a0The @ sign is being used to separate the name of the channel and a unique identifier for the file. Multiple files can land in the directory without one overwriting the other.<\/p>\n<p><strong>Top HackerNews link at 1PM:<\/strong><\/p>\n<pre lang=\"bash\" escaped=\"true\">00 13 * * * ~\/cronjobs\/hackernews.pl &gt; ~\/say\/#dcs@hn<\/pre>\n<p><span style=\"text-decoration: underline;\">Note:<\/span> The original job was a one liner using <a title=\"Mojolicious\" href=\"http:\/\/mojolicio.us\/\" target=\"_blank\">Mojolicious<\/a>:<\/p>\n<pre language=\"perl\" escaped=\"true\">perl -Mojo -E 'say g(\"http:\/\/hackerne.ws\")-&gt;dom-&gt;at(\"tr &gt; td.title &gt; a\")-&gt;tree-&gt;[2]-&gt;{href}'<\/pre>\n<p>It&#8217;s been expanded since to include the title and keep the crontab clean.<\/p>\n<p><strong>One-off website update checker:<\/strong><\/p>\n<pre lang=\"bash\" escaped=\"true\">* * * * * curl -s http:\/\/stantheman.biz | diff file1 -\r\n|| echo 'The page changed!' &gt; ~\/say\/msg@stan_theman@update<\/pre>\n<p>This is a quick cheap way of being automatically alerted to changes on a website.<\/p>\n<p><span style=\"text-decoration: underline;\">Note:<\/span> You could easily toss this into a shell script and do some more work to update the file being diffed. This would let you know about continued changes. The current script will ping you until you remove the cronjob in this state. You also need to curl the page into <em>file1<\/em> before installing the script &#8212; I said it was cheap!<\/p>\n<p>You can use this for any short piece of information (RSS feed updates, system mail, CPU\/disk usage). I&#8217;ll continue with my other favorite use for this in the next blog post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My IRC bot checks a directory every minute for files and reads the contents into a channel. This simple feature is also one of my favorites.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_links_to":"","_links_to_target":""},"categories":[4],"tags":[31,28,36,17,30],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/491"}],"collection":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":32,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":523,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/491\/revisions\/523"}],"wp:attachment":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}