changeset 0:eb059bcb6081

Init
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 07 May 2018 22:06:36 -0400
parents
children ee3320bc1f6b
files chocobot.d
diffstat 1 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/chocobot.d
@@ -0,0 +1,54 @@
+// chocobot.d --- Post regular kwehs to Mastodon
+
+// Copyright  © 2018 Jordi Gutiérrez Hermoso <jordigh@octave.org>
+
+// Author: Jordi Gutiérrez Hermoso
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 3
+// of the License, or (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import std.stdio;
+import std.net.curl;
+import std.random: dice, uniform;
+import core.thread : Thread;
+import std.datetime: dur;
+import std.string: chomp;
+
+auto kweh() {
+  static squawks = ["Kweh", "Kweh!?", "Kwehhh!?",  "K-KWEHHH!!!", "Whark!"];
+  return squawks[dice(5, 4, 3, 2, 1)];
+}
+
+void sleep() {
+  Thread.sleep(dur!"minutes"(uniform(40,80)));
+}
+
+void send(string squawk) {
+  auto token = File("chocotoken").readln.chomp;
+  auto http = HTTP();
+  http.addRequestHeader("Authorization", "Bearer " ~ token);
+  try {
+    writeln(post("https://botsin.space/api/v1/statuses", ["status": squawk], http));
+  }
+  catch (CurlException e) {
+    writeln(e.msg);
+  }
+}
+
+void main(string[] args) {
+  while(true) {
+    kweh.send;
+    sleep();
+  }
+}