]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/menuitems.js
notifier now uses themes
[irc/quakenet/qwebirc.git] / js / ui / menuitems.js
index 2c7e8fc2eea7454a216d5c3e2ac9f359ab08a4de..82ecb5f2653e80e57c9b0263d8f1202db36bdde9 100644 (file)
@@ -1,11 +1,97 @@
-qwebirc.ui.MENU_ITEMS = [
-  ["whois", function(nick) {
-    this.client.exec("/WHOIS " + nick);
-  }],
-  ["query", function(nick) {
-    this.client.exec("/QUERY " + nick);
-  }],
-  ["slap", function(nick) {
-    this.client.exec("/ME slaps " + nick + " around a bit with a large fishbot");
-  }]
+qwebirc.ui.UI_COMMANDS = [
+  ["Options", "options"],
+  ["Add webchat to your site", "embedded"],
+  ["Privacy policy", "privacy"],
+  ["Feedback", "feedback"],
+  ["Help!", "help"],
+  ["About qwebirc", "about"]
 ];
+
+qwebirc.ui.MENU_ITEMS = function() {
+  var isOpped = function(nick) {
+    var channel = this.name; /* window name */
+    var myNick = this.client.nickname;
+
+    return this.client.nickOnChanHasAtLeastPrefix(myNick, channel, "@");
+  };
+
+  var isVoiced = function(nick) {
+    var channel = this.name;
+    var myNick = this.client.nickname;
+
+    return this.client.nickOnChanHasPrefix(myNick, channel, "+");
+  };
+
+  var targetOpped = function(nick) {
+    var channel = this.name;
+    return this.client.nickOnChanHasPrefix(nick, channel, "@");
+  };
+
+  var targetVoiced = function(nick) {
+    var channel = this.name;
+    return this.client.nickOnChanHasPrefix(nick, channel, "+");
+  };
+
+  var isIgnored = function(nick) {
+    return this.client.isIgnored(nick);
+  };
+
+  var invert = qwebirc.util.invertFn, compose = qwebirc.util.composeAnd;
+  
+  var command = function(cmd) {
+    return function(nick) { this.client.exec("/" + cmd + " " + nick); };
+  };
+  
+  return [
+    {
+      text: "whois", 
+      fn: command("whois"),
+      predicate: true
+    },
+    {
+      text: "query",
+      fn: command("query"),
+      predicate: true
+    },
+    {
+      text: "slap",
+      fn: function(nick) { this.client.exec("/ME slaps " + nick + " around a bit with a large fishbot"); },
+      predicate: true
+    },
+    {
+      text: "kick", /* TODO: disappear when we're deopped */
+      fn: function(nick) { this.client.exec("/KICK " + nick + " wibble"); },
+      predicate: isOpped
+    },
+    {
+      text: "op",
+      fn: command("op"),
+      predicate: compose(isOpped, invert(targetOpped))
+    },
+    {
+      text: "deop",
+      fn: command("deop"),
+      predicate: compose(isOpped, targetOpped)
+    },
+    {
+      text: "voice",
+      fn: command("voice"),
+      predicate: compose(isOpped, invert(targetVoiced))
+    },
+    {
+      text: "devoice",
+      fn: command("devoice"),
+      predicate: compose(isOpped, targetVoiced)
+    },
+    {
+      text: "ignore",
+      fn: command("ignore"),
+      predicate: invert(isIgnored)
+    },
+    {
+      text: "unignore",
+      fn: command("unignore"),
+      predicate: isIgnored
+    }
+  ];
+}();