/* Debug mode (extensions.nabaztag.script.debug): 0=no warnings + message sent to the nabz 1=only warnings 2=warnings + message sent to the nabz */ var noun_type_radio = { _name: "radio list", suggest : function suggest(text, html, callback) { var lst_array = Nabaztag.getKey("extensions.nabaztag.radiolist").split(";"); for (var i=0; i < lst_array.length; ++i) { if (jQuery.trim(text.toLowerCase()) == lst_array[i].substr(0, jQuery.trim(text).length)) { result = lst_array[i]; callback(CmdUtils.makeSugg(lst_array[i], lst_array[i], result)); } } return [CmdUtils.makeSugg("")]; } } var noun_type_bot = { _name: "bot list", suggest : function suggest(text, html, callback) { var lst_array = Nabaztag.getKey("extensions.nabaztag.botlist").split(";"); for (var i=0; i < lst_array.length; ++i) { if (jQuery.trim(text.toLowerCase()) == lst_array[i].substr(0, jQuery.trim(text).length)) { result = lst_array[i]; callback(CmdUtils.makeSugg(lst_array[i], lst_array[i], result)); } } return [CmdUtils.makeSugg("")]; } } Nabaztag = { getKey:function(key){ if (Application.prefs.has(key)) { return (Application.prefs.get(key).value); } else { displayMessage("Key " + key + ", doesn't exist."); return ""; } }, getKey2:function(key){ if (Application.prefs.has(key)) {return (Application.prefs.get(key).value);} else {return "";} }, setKey:function(key, val){ Application.prefs.setValue(key, val); return ""; }, } CmdUtils.CreateCommand({ name: ["nabz-ia","IA"], arguments:[ {role: 'object', nountype: noun_arb_text, label: 'input'}, {role: 'goal', nountype: noun_type_bot} ], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Ubiquity, Nabaztag and Pandorabots linked together.", preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.current.bot")) { pblock.innerHTML = "Current Bot is <b>" + Nabaztag.getKey("extensions.nabaztag.current.bot")+ "</b>."; } else { pblock.innerHTML = "There is no current bot assigned."; } }, execute: function(input, mods) { DEBUGMODE = Nabaztag.getKey("extensions.nabaztag.script.debug"); TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); NABZNAME = Nabaztag.getKey("extensions.nabaztag.nabzname"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); VOICE = Nabaztag.getKey("extensions.nabaztag.voice"); if (mods.to.text == "") { BOTNAME = Nabaztag.getKey("extensions.nabaztag.current.bot"); } else { BOTNAME = mods.to.text; } if (DEBUGMODE != 0) {CmdUtils.log("Bot Name................. : " + BOTNAME);} BOTID = Nabaztag.getKey("extensions.nabaztag.bot." + BOTNAME); // RNAME = Nabaztag.getKey("extensions.nabaztag.replace.botname"); // RURL = Nabaztag.getKey("extensions.nabaztag.replace.url"); if ((DEBUGMODE=="")||(TIMEOUT=="")||(NABZNAME=="")||(TOKEN=="")|| (SN=="")||(VOICE=="")||(BOTID=="")||(BOTNAME=="")) { return; } if (DEBUGMODE != 0) {CmdUtils.log("Input.................... : " + input.text);} input.text = input.text.replace("à ", "a"); input.text = input.text.replace("á", "a"); input.text = input.text.replace("â", "a"); input.text = input.text.replace("ä", "a"); input.text = input.text.replace("ç", "c"); input.text = input.text.replace("è", "e"); input.text = input.text.replace("é", "e"); input.text = input.text.replace("ë", "e"); input.text = input.text.replace("ê", "e"); input.text = input.text.replace("ì", "i"); input.text = input.text.replace("Ã", "i"); input.text = input.text.replace("î", "i"); input.text = input.text.replace("ï", "i"); input.text = input.text.replace("ò", "o"); input.text = input.text.replace("ó", "o"); input.text = input.text.replace("ô", "o"); input.text = input.text.replace("ö", "o"); input.text = input.text.replace("ù", "u"); input.text = input.text.replace("ú", "u"); input.text = input.text.replace("û", "u"); input.text = input.text.replace("ü", "u"); input.text = input.text.replace("ý", "y"); input.text = input.text.replace("ÿ", "y"); if (DEBUGMODE != 0) {CmdUtils.log("Input formatted.......... : " + input.text);} jQuery.ajax({ type: "GET", timeout: TIMEOUT, datatype: "xml", timeout: TIMEOUT, url: "http://www.pandorabots.com/pandora/talk-xml", data: {botid: BOTID, input: input.text, custid: SN}, error: function() {displayMessage("Pandorabot error.");}, success: function(xml) { jQuery(xml).find('result').each(function(){ tts = jQuery(this).find('that').text(); if (Nabaztag.getKey("extensions.nabaztag.replace.botname") == "true") { // Replace the name of the bot by the name of your nabaztag tts = tts.replace(BOTNAME, NABZNAME); tts = tts.replace(BOTNAME.toLowerCase(), NABZNAME); tts = tts.replace(BOTNAME.toUpperCase(), NABZNAME); } if (Nabaztag.getKey("extensions.nabaztag.replace.url") == "true") { // Replace <url>*</url> with the content of this url. var reg = /<url[^>]*>.*?<\/url>/g; var lst_occ = reg.exec(tts); if (lst_occ) { for (var i=0; i < lst_occ.length; ++i) { url = jQuery.trim(lst_occ[i].replace(/<\S[^><]*>/g, "")); myreturn = jQuery.ajax({ type: "GET", timeout: TIMEOUT, async: false, url: url, }).responseText; tts = tts.replace(lst_occ[i], myreturn); if (DEBUGMODE != 0) { CmdUtils.log("Url " + i + ".................... : " + url); CmdUtils.log("Return " + i + "................. : " + myreturn); } } } } tts = tts.replace(/<script[^>]*>.*?<\/script>/g, ""); // remove <script>*</script> tts = tts.replace(/<\S[^><]*>/g, ""); // remove html tags tts = tts.replace(/\s+/g, " "); // remove double spaces tts = tts.replace("!"," !"); tts = tts.replace("?"," ?"); tts = tts.replace("Ã ", "à "); tts = tts.replace("á", "á"); tts = tts.replace("â", "â"); tts = tts.replace("ä", "ä"); tts = tts.replace("ç", "ç"); tts = tts.replace("è", "è"); tts = tts.replace("é", "é"); tts = tts.replace("ê", "ë"); tts = tts.replace("ë", "ê"); tts = tts.replace("ì", "ì"); tts = tts.replace("ÃÂ", "Ã"); tts = tts.replace("î", "î"); tts = tts.replace("ï", "ï"); tts = tts.replace("ò", "ò"); tts = tts.replace("ó", "ó"); tts = tts.replace("ô", "ô"); tts = tts.replace("ö", "ö"); tts = tts.replace("ù", "ù"); tts = tts.replace("ú", "ú"); tts = tts.replace("û", "û"); tts = tts.replace("ü", "ü"); tts = tts.replace("ý", "ý"); tts = tts.replace("ÿ", "ÿ"); tts = tts.replace("À", "À"); tts = tts.replace("", " "); tts = tts.replace("", " "); tts = tts.replace("", " "); tts = tts.replace("", " "); tts = tts.replace("!", "!"); tts = tts.replace(""", " "); tts = tts.replace("#", "#"); tts = tts.replace("$", "$"); tts = tts.replace("%", "%"); tts = tts.replace("&", "et"); tts = tts.replace("'", "'"); tts = tts.replace("(", "("); tts = tts.replace(")", ")"); tts = tts.replace("*", "*"); tts = tts.replace("+", "+"); tts = tts.replace(",", ","); tts = tts.replace("-", "-"); tts = tts.replace(".", "."); tts = tts.replace("/", " "); tts = tts.replace("(-)", " "); // tts = tts.replcate(" l ", " l'"); // tts = tts.replcate(" j ", " j\\\'"); // tts = tts.replcate(" qu ", " qu\\\'"); tts = jQuery.trim(tts); lastdigit = String(tts).substring(String(tts).length - 1, String(tts).length); if ((lastdigit != ".")&&(lastdigit != "!")&&(lastdigit != "?")) {tts = tts + ".";} if (DEBUGMODE != 0) { CmdUtils.log("Last digit............... : " + lastdigit); CmdUtils.log("Output................... : " + jQuery(this).find('that').text()); CmdUtils.log("Output Formatted......... : " + tts); } if (DEBUGMODE != 1) { jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api.jsp", data: {sn: SN, token: TOKEN, voice: VOICE, tts: tts}, error: function() {displayMessage("Nabaztag error : message not sent.");}, success: function() {displayMessage("Message sent to your Nabaztag.");} }); } }); }, }); } }); CmdUtils.CreateCommand({ name: ["nabz-repeat","REPEAT"], arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'}], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Your Nabaztag will repeat the text entered.", preview: "<b>Your Nabaztag will repeat this text !!</b>", execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); VOICE = Nabaztag.getKey("extensions.nabaztag.voice"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")||(VOICE=="")) { return; } jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api.jsp", data: {sn: SN, token: TOKEN, voice: VOICE, tts: input.text}, error: function() {displayMessage("Nabaztag error : message not sent.");}, success: function() {displayMessage("Message sent to your Nabaztag.");} }); } }); CmdUtils.CreateCommand({ name: ["nabz-radio","RADIO"], arguments: [ {role: 'object', nountype: noun_arb_text, label: 'noun_type_radio'}], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Listen your favorite radio using your Nabaztag.", preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.radiolist")) { lstrad = "Radios available : " + "<b>" + Nabaztag.getKey("extensions.nabaztag.radiolist").replace(/;/g, ", ") + ".</b>"; pblock.innerHTML = lstrad.replace(", .","") + "."; } else { pblock.innerHTML = "No radios available."; } }, execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")) { return; } mrad = Nabaztag.getKey2("extensions.nabaztag.radio." + input.text.toLowerCase()); if (mrad == "") { displayMessage("This radio is not configured."); return; } jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api_stream.jsp", data: {sn: SN, token: TOKEN, urlList: mrad}, error: function() {displayMessage("Radio not sent to your Nabaztag.");}, success: function() {displayMessage("Radio sent to your Nabaztag.");} }); } }); CmdUtils.CreateCommand({ name: ["nabz-quote","NQUOTE"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Send a quotation to your Nabaztag.", arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'}], preview: "<b>Send a quotation to your Nabaztag.</b>", execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); VOICE = Nabaztag.getKey("extensions.nabaztag.voice"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")||(VOICE=="")) { return; } Utils.parseRemoteDocument( "http://finance.google.com/finance?client=ob&q=NYSE:" + input.text, null, function(doc) { // success callback var mtts = "le cours de l'action " + input.text + " est de " + jQuery("*[@id='ref_13010797_l']", doc).text() + " dollars."; jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api.jsp", data: {sn: SN, token: TOKEN, voice: VOICE, tts: mtts}, error: function() {displayMessage("Nabaztag error : message not sent.");}, success: function() {displayMessage("Message sent to your Nabaztag.");} }); }, function() { // error callback displayMessage("Error!"); } ); } }); CmdUtils.CreateCommand({ name: ["nabz-switch-bot"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Switch bot.", arguments: [{role: 'object', nountype: noun_arb_text, label: 'input'}], preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.current.bot")) { shtml = "Current Bot is <b>" + Nabaztag.getKey("extensions.nabaztag.current.bot") + "</b>."; } if (Application.prefs.has("extensions.nabaztag.botlist")) { lstbot = Nabaztag.getKey("extensions.nabaztag.botlist").replace(/;/g, ", "); lstbot = "<br><br>Bots available : " + "<b>" + lstbot + ".</b>"; lstbot = lstbot.replace(", .","") + "."; shtml = shtml + lstbot; } pblock.innerHTML = shtml; }, execute: function(input) { if (Application.prefs.has("extensions.nabaztag.current.bot")) { if (Application.prefs.has("extensions.nabaztag.bot." + input.text.toLowerCase())) { Application.prefs.setValue("extensions.nabaztag.current.bot", input.text.toLowerCase()); displayMessage("New bot is " + input.text.toLowerCase()); } else { displayMessage("This bot doesn't exist."); } } else { displayMessage("Key extensions.nabaztag.current.bot, doesn't exist."); } } }); CmdUtils.CreateCommand({ name: ["nabz-wakeup"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Wake up your Nabaztag.", preview: "Wake up your Nabaztag.", execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")) { return; } jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api.jsp", data: {sn: SN, token: TOKEN, action: "14"}, error: function() {displayMessage("Nabaztag error : action not sent.");}, success: function() {displayMessage("Action sent to your Nabaztag.");} }); } }); CmdUtils.CreateCommand({ name: ["nabz-sleep"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "It's time to go to bed for your Nabaztag.", preview: "It's time to go to bed for your Nabaztag.", execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")) { return; } jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api.jsp", data: {sn: SN, token: TOKEN, action: "13"}, error: function() {displayMessage("Nabaztag error : action not sent.");}, success: function() {displayMessage("Action sent to your Nabaztag.");} }); } }); CmdUtils.CreateCommand({ name: ["nabz-setup"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "By following this wizard, you will (re)configure the commands created for Ubiquity in order to interact with your Nabaztag.", preview: "By following this wizard, you will (re)configure the commands created for Ubiquity in order to interact with your Nabaztag.", execute: function(input) { var window = Utils.currentChromeWindow;
window.alert("Welcome.\n\nBy following this wizard, you will configure the commands created for Ubiquity in order to interact with your Nabaztag."); //displayMessage("Welcome.\n\nBy following this wizard, you will configure the commands created for Ubiquity in order to interact with your Nabaztag."); SN = window.prompt( "Please, fill the serial number of your nabaztag:", Nabaztag.getKey2("extensions.nabaztag.serial")); Nabaztag.setKey("extensions.nabaztag.serial", SN.toLowerCase()); TOKEN = window.prompt( "Please, fill the token number of your nabaztag:", Nabaztag.getKey2("extensions.nabaztag.token")); Nabaztag.setKey("extensions.nabaztag.token", TOKEN.toLowerCase()); VOICE = window.prompt( "Please, indicate the voice of your nabaztag:", Nabaztag.getKey2("extensions.nabaztag.voice")); Nabaztag.setKey("extensions.nabaztag.voice", VOICE.toLowerCase()); NABZNAME = window.prompt( "Please, indicate the name of your nabaztag:", Nabaztag.getKey2("extensions.nabaztag.nabzname")); Nabaztag.setKey("extensions.nabaztag.nabzname", NABZNAME.toLowerCase()); if (window.confirm( "Do you want that automatically, the name of the bot is replaced by the name of your nabaztag ?")) { Nabaztag.setKey("extensions.nabaztag.replace.botname", "true"); } else { Nabaztag.setKey("extensions.nabaztag.replace.botname", "false"); } Nabaztag.setKey("extensions.nabaztag.bot.lola","8ce5b2747e366417"); Nabaztag.setKey("extensions.nabaztag.bot.mathilde","eff729829e36e89c"); Nabaztag.setKey("extensions.nabaztag.bot.mctarek","bb9d8db85e36d4b9"); Nabaztag.setKey("extensions.nabaztag.bot.émilie","94d255a09e366de1"); Nabaztag.setKey("extensions.nabaztag.botlist","lola;mathilde;mctarek;émilie;"); Nabaztag.setKey("extensions.nabaztag.current.bot","émilie"); window.alert("The following bots have been added automatically : lola, mathilde, mctarek and émilie (bot by default)."); Nabaztag.setKey("extensions.nabaztag.radio.europe 1","http://213.205.96.91:9200"); Nabaztag.setKey("extensions.nabaztag.radio.le mouv","http://213.205.96.91:9923"); Nabaztag.setKey("extensions.nabaztag.radio.oui fm","http://217.71.214.35:8080"); Nabaztag.setKey("extensions.nabaztag.radio.tsf jazz","http://broadcast.infomaniak.net:80/tsfjazz-high.mp3"); Nabaztag.setKey("extensions.nabaztag.radiolist","europe 1;le mouv;oui fm;tsf jazz"); window.alert("The following radios have been added automatically : europe 1, Le mouv, oui fm and tsf jazz."); Nabaztag.setKey("extensions.nabaztag.script.debug",2); Nabaztag.setKey("extensions.nabaztag.api.timeout",20000); Nabaztag.setKey("extensions.nabaztag.replace.url","true"); window.alert("Congratulation. Everything is now properly configured.\n\nAt any time, you can reconfigure everything either by restarting this wizard or by changing manually the settings into the 'about.config' using the filter 'nabaztag'.\n\nNow,...Enjoy !!"); } }); CmdUtils.CreateCommand({ name: ["nabz-setup-add-radio"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Setup a new radio.", arguments: [ {role: 'object', nountype: noun_arb_text, label: 'radio'} //, {role: 'source', nountype: noun_arb_text, label: 'stream'} ],
preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.radiolist")) { lstrad = "Radios already available : " + "<b>" + Nabaztag.getKey("extensions.nabaztag.radiolist").replace(/;/g, ", ") + ".</b>"; pblock.innerHTML = lstrad.replace(", .","") + "."; } else { pblock.innerHTML = "No radios available."; } }, execute: function(radio, mods) { RADIONAME = radio.text.toLowerCase(); if (Application.prefs.has("extensions.nabaztag.radio." + RADIONAME)) { displayMessage("This radio already exist."); return; } // RADIOURL = mods.stream.text.toLowerCase(); RADIOURL = window.prompt("Please, fill url for this radio:", "http://"); Nabaztag.setKey("extensions.nabaztag.radio." + RADIONAME, RADIOURL); nKey = (Nabaztag.getKey("extensions.nabaztag.radiolist") + ";" + RADIONAME + ";").replace(/;;/g, ";"); Nabaztag.setKey("extensions.nabaztag.radiolist", nKey); if (Application.prefs.has("extensions.nabaztag.radio." + RADIONAME)) { displayMessage("New Radio correctly added."); } else { displayMessage("New Radio NOT correctly added."); } } }); CmdUtils.CreateCommand({ name: ["nabz-setup-remove-radio"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'} ], description: "Remove an existing radio.", preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.radiolist")) { lstrad = "Radios available : " + "<b>" + Nabaztag.getKey("extensions.nabaztag.radiolist").replace(/;/g, ", ") + ".</b>"; pblock.innerHTML = lstrad.replace(", .","") + "."; } else { pblock.innerHTML = "No radios available."; } }, execute: function(input) { RADIONAME = input.text.toLowerCase(); if (Application.prefs.has("extensions.nabaztag.radio." + RADIONAME)) { try { Application.prefs.get("extensions.nabaztag.radio." + RADIONAME).reset(); Nabaztag.setKey("extensions.nabaztag.radiolist", Nabaztag.getKey("extensions.nabaztag.radiolist").replace(RADIONAME + ";", "")); displayMessage("Radio " + RADIONAME + " is now removed"); } catch(e) { displayMessage(e) } } else { displayMessage("This radio doesn't exist."); } } }); CmdUtils.CreateCommand({ name: ["nabz-setup-add-bot"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Add a new bot.", arguments: [ {role: 'object', nountype: noun_arb_text, label: 'bot'} //,{role: 'alias', nountype: noun_arb_text, label: 'botid'} ],
preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.botlist")) { lstbot = Nabaztag.getKey("extensions.nabaztag.botlist").replace(/;/g, ", "); lstbot = "<br><br>Bots already available : " + "<b>" + lstbot + ".</b>"; lstbot = lstbot.replace(", .","") + "."; shtml = lstbot } pblock.innerHTML = shtml; }, execute: function(bot, mods) { BOTNAME = bot.text.toLowerCase(); if (Application.prefs.has("extensions.nabaztag.bot." + BOTNAME)) { displayMessage("This bot already exist."); return; } // BOTID= mods.botid.text.toLowerCase(); BOTID = window.prompt("Please, fill the botid for this bot:", ""); Nabaztag.setKey("extensions.nabaztag.bot." + BOTNAME, BOTID); nKey = (Nabaztag.getKey("extensions.nabaztag.botlist") + ";" + BOTNAME + ";").replace(/;;/g, ";"); Nabaztag.setKey("extensions.nabaztag.botlist", nKey); if (Application.prefs.has("extensions.nabaztag.bot." + BOTNAME)) { displayMessage("New Bot correctly added."); } else { displayMessage("New Bot NOT correctly added."); } } }); CmdUtils.CreateCommand({ name: ["nabz-setup-remove-bot"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'}], description: "Remove an existing bot.", preview: function( pblock, input ) { if (Application.prefs.has("extensions.nabaztag.botlist")) { lstbot = Nabaztag.getKey("extensions.nabaztag.botlist").replace(/;/g, ", "); lstbot = "<br><br>Bots available : " + "<b>" + lstbot + ".</b>"; lstbot = lstbot.replace(", .","") + "."; shtml = lstbot } pblock.innerHTML = shtml; }, execute: function(input) { BOTNAME = input.text.toLowerCase(); if (Nabaztag.getKey("extensions.nabaztag.current.bot") == BOTNAME) { displayMessage("You cannot remove this bot because this is the bot used by default."); return; } if (Application.prefs.has("extensions.nabaztag.bot." + BOTNAME)) { try { Application.prefs.get("extensions.nabaztag.bot." + BOTNAME).reset(); Nabaztag.setKey("extensions.nabaztag.botlist", Nabaztag.getKey("extensions.nabaztag.botlist").replace(BOTNAME + ";", "")); displayMessage("Bot " + BOTNAME + " is now removed"); } catch(e) { displayMessage(e); } } else { displayMessage("This bot doesn't exist."); } } }); CmdUtils.CreateCommand({ name: ["nabz-radio-stop","STOP RADIO"], homepage: "http://twitter.com/jbx028", author: {name: "Johnny Baillargeaux", email: "jbx028@hotmail.com"}, license: "MPL", description: "Stop the radio.", execute: function(input) { TIMEOUT = Nabaztag.getKey("extensions.nabaztag.api.timeout"); TOKEN = Nabaztag.getKey("extensions.nabaztag.token"); SN = Nabaztag.getKey("extensions.nabaztag.serial"); if ((TIMEOUT=="")||(TOKEN=="")||(SN=="")) { return; } jQuery.ajax({ type: "GET", timeout: TIMEOUT, url: "http://api.nabaztag.com/vl/FR/api_stream.jsp", data: {sn: SN, token: TOKEN, urlList: mrad}, error: function() {displayMessage("Error.");}, success: function() {displayMessage("Radio will be stopped.");} }); } });
|