Poke System
(Versions 1.6+)Here's how to use all the AWC customization options to end up with a poke system in your chatbox.
The poke system will work by adding a command to the chatbox using the custom commands option, the command will be 'poke', and you use it as so: [ic]/poke LGforum[/ic] to poke a user. The custom command will send a table to AWC so we can get it in the message hooks.
It then uses the Hook System in order to hook into the messages and look for the poke table. The hook checks if the user has been poked (and saves the time in order not to poke a user twice even though they've been poked once) and if they have it will change the tab title to 'User poked you!' and make a beep, regardless of whether they have sound turned on or off. The message in the chatbox will be changed to 'User poked you!' or 'You poked User' depending on whether your the poker or poked.
It also makes use of the event system in order to take care of a few pieces too.
I hope this helps demonstrate some of the power of AWC
[bspoiler=Versions 1.6 - 1.8]
- Code:
[panda=js](function(awc) {
('Avacweb chat Plug in Poke System');
//add out poke command :)
awc.commands.poke = {
description : '/poke username - Poke a user in the chatbox to get their attention.',
run : function(msg) {
var uid = avacweb_chat.get_user_data(msg).id;
if(!uid) {
avacweb_chat.popup(msg + ' ' + avacweb_chat.t('is not in the chat'));
return false;
}
//store the user id's and send in a table
return '[table class="achat_poke" rel="' + uid + '|' + avacweb_chat.user('id') + '][tr][td][/td][/tr][/table]';
}
};
awc.message_hook.push(function(row, username, user_id, user, msg) {
var poke = $('.achat_poke', row)[0]; // look for the poke table
if(!poke) return;
var users = poke.getAttribute('rel').split('|'), poker = parseInt(users[1]), poked = parseInt(users[0]), time = $('.date-and-time', row)[0].innerHTML;
if(!avacweb_chat.user('id') || !poker || !poked) return row.innerHTML = '';
if(poked == avacweb_chat.user('id')) {
if( !avacweb_chat.pokes[time] ) { //check if we've already alerted of this poke
avacweb_chat.pokes[time] = 1;
document.title = avacweb_chat.get_user_data(poker).name + ' ' + avacweb_chat.t('Poked You') + '!';
document.getElementById('achat_sound').innerHTML = '<embed src="' + avacweb_chat.sound_file + '" hidden="true" autostart="true" loop="false" />';
}
row.innerHTML = '<span class="poke">' + avacweb_chat.get_user_data(poker).name + ' ' + avacweb_chat.t('Poked You') + '!</span> ' + time;
}
else if(poker == avacweb_chat.user('id')) {
row.innerHTML = '<span class="poke">' + avacweb_chat.t('You poked') + ' ' + avacweb_chat.get_user_data(poked).name + '.</span>' + time;
}
else {
row.innerHTML = '';
row.style.display = 'none';
}
});
awc.add_event('onload', function() {
avacweb_chat.pokes = {}, cookie = avacweb_chat.cookie('pokes');
if(JSON && cookie) avacweb_chat.pokes = JSON.parse(cookie);
});
awc.add_event('onnew', function() {
if(JSON && avacweb_chat.pokes) {
avacweb_chat.cookie('pokes', JSON.stringify(avacweb_chat.pokes), 0);
}
});
})(avacweb_chat_config);
[bspoiler=Version 1.9+]
- Code:
[panda=js](function(awc) {
('Avacweb chat Plug in Poke System');
//add the poke command.
awc.commands.poke = {
description: '/poke username - Poke a user in the chatbox to get their attention.',
run : function(msg) {
var uid = avacweb_chat.get_user_data(msg).id;
if(!uid) {
avacweb_chat.popup(msg + ' ' + avacweb_chat.t('is not in the chat'));
return false;
}
return '[table class="achat_poke" rel="' + uid + '"][tr][td][/td][/tr][/table]';
}
};
awc.message_hook.push(function(row, username, user_id) {
var poke = $('.achat_poke', row)[0]
, ac = avacweb_chat;
if(poke) {
var poker = parseInt(user_id)
, poked = parseInt(poke.getAttribute('rel'))
, time = $('.date-and-time', row)[0].innerHTML;
if(!ac.user('id') || !poker || !poked) {
return row.innerHTML = '';
}
//if we are being poked...
if(poked === ac.user('id')) {
if( !ac.pokes[time] ) {
ac.pokes[time] = 1;
document.title = username + ' ' + ac.t('Poked You') + '!';
$('body').append('<embed src="http://www.freesfx.co.uk/rx2/mp3s/2/1305_1256857800.mp3" hidden="true" autostart="true" loop="false" />');
//save the pokes.
JSON && ac.cookie('pokes', JSON.stringify(ac.pokes), 0);
}
row.innerHTML = '<span class="poke">' + username + ' ' + ac.t('Poked You') + '!</span>' + time;
}
else if(poker === ac.user('id')) {
row.innerHTML = '<span class="poke">' + ac.t('You poked') + ' ' + ac.get_user_data(poked).name + '.</span>' + time;
}
else {
row.innerHTML = '';
row.style.display = 'none';
}
}
});
//load the pokes.
awc.add_event('onload', function() {
avacweb_chat.pokes = {};
avacweb_chat.original_title = document.title;
var cookie = avacweb_chat.cookie('pokes');
if(cookie && JSON) {
avacweb_chat.pokes = JSON.parse(cookie);
}
});
awc.add_event('onsend', function() {
document.title = this.original_title;
});
})(avacweb_chat_config);
If you want to change it into a "nudge" or "bump" system rather than poke, these are the only two bits you should change in the code:
- This bit, to change the command from /poke: [ic]commands.poke = [/ic]
- This bit to change the command description: [ic]'/poke username - Poke a user in the chatbox to get their attention.'[/ic]
Everything else should remain the same unless you could break the system.
You do not need to worry about translating anything in the script. Use the AWC translation tool to do so.
You should also do this if you change it to something other than a "poke" system.
You can add these to the AWC translation object if you need to translate/change these bits.
- Code:
"you poked" : "You Poked",
"poked you" : "Poked You",
"is not in the chat" : "is not in the chat"
If you need help understanding AWC Translation read here: http://chat.avacweb.net/translate
Additionally, you can style the pokes in the chatbox using [ic].poke { //styling }[/ic] in your CSS.