Skip to content

Instantly share code, notes, and snippets.

@aweary
Created October 27, 2014 03:31
Show Gist options
  • Save aweary/85ee4c94cc56fd6700bb to your computer and use it in GitHub Desktop.
Save aweary/85ee4c94cc56fd6700bb to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//move to commands.js
var commands = {
"!article": function(_article) {
console.log("This is article " + _article);
}
};
// move to context.js
var admins = ["sjobs", "tcook", "jives"];
// move to stanzaHandler.js
var stanzaHandler = function(stanza) {
var command = stanza.getChildText('body').split(' ')[0],
message;
//insert code to associate JID and alias
var message_options = {
stanza : stanza,
from : userID,
content : stanza.getChildText('body'),
content_array : message.content.split(' ')
};
//make sure the command is within either the private or group set
if (command in group || command in priv) {
if (command in group) {
message = group[command](stanza);
} else if ((command in priv) && (userID in admins)) {
message = priv[command](stanza);
}
var options = {
to: stanza.attr.from,
from: "bot_address",
type: stanza.attr.type
};
var reply = new ltx.Element('message', options);
reply.c('body').t(message);
}
};
var botCommands = (function() {
//internal configuration
var _config = {
_userCallable: true,
_testMode: false,
_responsive: true
};
// exported methods
return {
//allows configuration of internal option variables
group_commands: {
"!_config": function(option, value) {
_config[option] = value;
},
//allows testing of internal option variables
"!_test": function(option) {
console.log(option + " is " + _config[option]);
},
"!article": function(user, article) {
if(admins.indexOf(user) !== -1){
console.log('This is article ' + article);
}
else {
console.log("You are not allowed to do that");
}
}
}, // end group_commands
private_commands: {
"!config": function(option, value) {
_config[option] = value;
},
"!admin_test": function(admin) {
if (admins.indexOf(admin) !== -1) {
console.log('admin user');
return true;
} else {
console.log('not an admin');
return false;
}
}
}
};
})();
var group = botCommands.group_commands;
var priv = botCommands.private_commands;
</script>
<script id="jsbin-source-javascript" type="text/javascript">//move to commands.js
var commands = {
"!article": function(_article) {
console.log("This is article " + _article);
}
};
// move to context.js
var admins = ["sjobs", "tcook", "jives"];
// move to stanzaHandler.js
var stanzaHandler = function(stanza) {
var command = stanza.getChildText('body').split(' ')[0],
message;
//insert code to associate JID and alias
var message_options = {
stanza : stanza,
from : userID,
content : stanza.getChildText('body'),
content_array : message.content.split(' ')
};
//make sure the command is within either the private or group set
if (command in group || command in priv) {
if (command in group) {
message = group[command](stanza);
} else if ((command in priv) && (userID in admins)) {
message = priv[command](stanza);
}
var options = {
to: stanza.attr.from,
from: "bot_address",
type: stanza.attr.type
};
var reply = new ltx.Element('message', options);
reply.c('body').t(message);
}
};
var botCommands = (function() {
//internal configuration
var _config = {
_userCallable: true,
_testMode: false,
_responsive: true
};
// exported methods
return {
//allows configuration of internal option variables
group_commands: {
"!_config": function(option, value) {
_config[option] = value;
},
//allows testing of internal option variables
"!_test": function(option) {
console.log(option + " is " + _config[option]);
},
"!article": function(user, article) {
if(admins.indexOf(user) !== -1){
console.log('This is article ' + article);
}
else {
console.log("You are not allowed to do that");
}
}
}, // end group_commands
private_commands: {
"!config": function(option, value) {
_config[option] = value;
},
"!admin_test": function(admin) {
if (admins.indexOf(admin) !== -1) {
console.log('admin user');
return true;
} else {
console.log('not an admin');
return false;
}
}
}
};
})();
var group = botCommands.group_commands;
var priv = botCommands.private_commands;
</script></body>
</html>
//move to commands.js
var commands = {
"!article": function(_article) {
console.log("This is article " + _article);
}
};
// move to context.js
var admins = ["sjobs", "tcook", "jives"];
// move to stanzaHandler.js
var stanzaHandler = function(stanza) {
var command = stanza.getChildText('body').split(' ')[0],
message;
//insert code to associate JID and alias
var message_options = {
stanza : stanza,
from : userID,
content : stanza.getChildText('body'),
content_array : message.content.split(' ')
};
//make sure the command is within either the private or group set
if (command in group || command in priv) {
if (command in group) {
message = group[command](stanza);
} else if ((command in priv) && (userID in admins)) {
message = priv[command](stanza);
}
var options = {
to: stanza.attr.from,
from: "bot_address",
type: stanza.attr.type
};
var reply = new ltx.Element('message', options);
reply.c('body').t(message);
}
};
var botCommands = (function() {
//internal configuration
var _config = {
_userCallable: true,
_testMode: false,
_responsive: true
};
// exported methods
return {
//allows configuration of internal option variables
group_commands: {
"!_config": function(option, value) {
_config[option] = value;
},
//allows testing of internal option variables
"!_test": function(option) {
console.log(option + " is " + _config[option]);
},
"!article": function(user, article) {
if(admins.indexOf(user) !== -1){
console.log('This is article ' + article);
}
else {
console.log("You are not allowed to do that");
}
}
}, // end group_commands
private_commands: {
"!config": function(option, value) {
_config[option] = value;
},
"!admin_test": function(admin) {
if (admins.indexOf(admin) !== -1) {
console.log('admin user');
return true;
} else {
console.log('not an admin');
return false;
}
}
}
};
})();
var group = botCommands.group_commands;
var priv = botCommands.private_commands;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment