Skip to content

Commit

Permalink
bump. bug fixes. ignore stuff adapted to better suit the current setu…
Browse files Browse the repository at this point in the history
…p with chatterbox. #87.
  • Loading branch information
Henry Rapley committed Dec 3, 2013
1 parent 0a468ee commit c1e5860
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 621 deletions.
263 changes: 72 additions & 191 deletions dist/wsc.dAmn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @module wsc
*/
var wsc = {};
wsc.VERSION = '1.7.53';
wsc.VERSION = '1.7.54';
wsc.STATE = 'release candidate';
wsc.REVISION = '0.21.138';
wsc.REVISION = '0.21.139';
wsc.defaults = {};
wsc.defaults.theme = 'wsct_dark';
wsc.defaults.themes = [ 'wsct_dAmn', 'wsct_dark' ];
Expand Down Expand Up @@ -2451,7 +2451,7 @@ wsc.defaults.Extension = function( client ) {
*
* @method Ignore
*/
wsc.defaults.Extension.Ignore(client);
wsc.defaults.Extension.Ignore(client, ext);

/**
* Implements away messages.
Expand Down Expand Up @@ -2809,237 +2809,118 @@ wsc.defaults.Extension.Away = function( client, ext ) {
*
* Implements the ignore functionality.
*/
wsc.defaults.Extension.Ignore = function( client ) {
wsc.defaults.Extension.Ignore = function( client, ext ) {

var settings = {};
var storage = client.storage.folder('ignore');
var istore = storage.folder('ignored');
ext.ignore = {
fignore: '/me is ignoring {user} now',
funignore: '/me is not ignoring {user} anymore',
ignored: []
};

var init = function( ) {

load();
save(); // Just in case we don't have the stuff stored in the first place.
ext.ignore.load();
ext.ignore.save(); // Just in case we don't have the stuff stored in the first place.

// Commands
client.bind('cmd.ignore', cmd_ignore);
client.bind('cmd.unignore', cmd_unignore);

// Settings window
//client.ui.on('settings.open', settings.page);

};
/*
settings.page = function( event, ui ) {

var page = event.settings.page('Ignores');
var orig = {};
orig.im = settings.ignore;
orig.uim = settings.unignore;
orig.usr = client.ui.umuted;
page.item('Text', {
'ref': 'intro',
'title': 'Ignores',
'text': 'Use <code>ignore</code> to ignore people.\n\n\
You can "ignore" other users of the chat server using the\n\
<code>/ignore</code> command. Ignoring a user hides their\
messages from you in the channel log.',
});
ext.ignore.load = function( ) {

page.item('Form', {
'ref': 'msgs',
'title': 'Messages',
'text': 'Here you can set the messages displayed when you ignore or\
unignore a user.\n\nThe text <code>{user}</code> is replaced\
with the name of the user your are ignoring or unignoring.',
'fields': [
['Textfield', {
'ref': 'ignore',
'label': 'Ignore',
'default': orig.im
}],
['Textfield', {
'ref': 'unignore',
'label': 'Unignore',
'default': orig.uim
}]
],
'event': {
'save': function( event ) {
settings.ignore = event.data.ignore;
settings.unignore = event.data.unignore;
save();
}
}
});
ext.ignore.fignore = storage.get('ignore', ext.ignore.fignore);
ext.ignore.funignore = storage.get('unignore', ext.ignore.funignore);
ext.ignore.ignored = JSON.parse( storage.get('ignored', JSON.stringify(ext.ignore.ignored)) );

var imgr = page.item('Items', {
'ref': 'ignoreds',
'title': 'Users',
'text': 'This is the list of users that you have silenced.\n\nUse the\
commands <code>/ignore</code> and <code>/unignore</code>\
to edit the list.',
'items': orig.usr,
'prompt': {
'title': 'Add User',
'label': 'User:',
},
'event': {
'up': function( event ) {
var swap = event.args.swap;
client.ui.umuted[swap['this'].index] = swap.that.item;
client.ui.umuted[swap.that.index] = swap['this'].item;
imgr.options.items = client.ui.umuted;
},
'down': function( event ) {
var swap = event.args.swap;
client.ui.umuted[swap['this'].index] = swap.that.item;
client.ui.umuted[swap.that.index] = swap['this'].item;
imgr.options.items = client.ui.umuted;
},
'add': function( event ) {
client.mute_user( event.args.item );
imgr.options.items = client.ui.umuted;
},
'remove': function( event ) {
client.unmute_user( event.args.item );
imgr.options.items = client.ui.umuted;
},
'save': function( event ) {
orig.usr = client.ui.umuted;
save();
},
'close': function( event ) {
load();
}
}
});
client.trigger( 'ignore.loaded', {
name: 'ignore.loaded',
ignored: ext.ignore.ignored
} );

};

ext.ignore.save = function( ) {

storage.set('ignore', ext.ignore.fignore);
storage.set('unignore', ext.ignore.funignore);
storage.set('ignored', JSON.stringify(ext.ignore.ignored));

};
*/

var cmd_ignore = function( cmd ) {
ext.ignore.add = function( user, suppress ) {

var users = cmd.args.split(' ');
var user = '';
var msg = '';
var mod = false;
var user = user.split(' ');
var u = '';
suppress = suppress || false;

for( var i = 0; i < user.length; i++ ) {

for( var i in users ) {
if( !users.hasOwnProperty( i ) )
if( !user.hasOwnProperty( i ) )
continue;

user = users[i];
tmod = client.mute_user( user );
if( !tmod )
u = user[i].toLowerCase();

if( ext.ignore.ignored.indexOf( u ) != -1 )
continue;

mod = tmod;
msg = replaceAll( settings.ignore, '{user}', user );
if( msg.indexOf('/me ') == 0 ) {
msg = msg.substr(4);
client.action( cmd.target, msg );
} else {
client.say( cmd.target, msg );
}
ext.ignore.ignored.push( u );
client.trigger( 'ignore.add', {
name: 'ignore.add',
user: user[i],
suppress: suppress
} );

}

if( mod )
save();
ext.ignore.save();

};

var cmd_unignore = function( cmd ) {
ext.ignore.remove = function( user, suppress ) {

var users = cmd.args.split(' ');
var user = '';
var msg = '';
var mi = -1;
var mod = false;
var tmod = false;
var user = user.split(' ');
var u = '';
var iidex = -1;
suppress = suppress || false;

for( var i in users ) {
if( !users.hasOwnProperty( i ) )
for( var i = 0; i < user.length; i++ ) {

if( !user.hasOwnProperty( i ) )
continue;

user = users[i];
tmod = client.unmute_user( user );
if( !tmod )
u = user[i].toLowerCase();
iidex = ext.ignore.ignored.indexOf( u );

if( iidex == -1 )
continue;

mod = tmod;
msg = replaceAll( settings.unignore, '{user}', user );
if( msg.indexOf('/me ') == 0 ) {
msg = msg.substr(4);
client.action( cmd.target, msg );
} else {
client.say( cmd.target, msg );
}
ext.ignore.ignored.splice( iidex, 1 );

client.trigger( 'ignore.remove', {
name: 'ignore.remove',
user: user[i],
suppress: suppress
} );

}

if( mod )
save();
ext.ignore.save();

};

var load = function( ) {

settings.ignore = storage.get('ignore', '/me is ignoring {user} now');
settings.unignore = storage.get('unignore', '/me is not ignoring {user} anymore');
settings.count = parseInt( storage.get( 'count', 0 ) );

var tu = null;
/*
for( var i in client.ui.umuted ) {
if( !client.ui.umuted.hasOwnProperty(i) ) {
continue;
}
client.unmute_user( client.ui.umuted[i] );
}
*/

//client.ui.umuted = [];

if( settings.count > 0 ) {
tu = null;
for( var i = 0; i < settings.count; i++ ) {
//client.mute_user( istore.get(i, null) );
//client.ui.mute_user( tu );
}
}

var cmd_ignore = function( cmd ) {

ext.ignore.add( cmd.args );

};

var save = function( ) {
var cmd_unignore = function( cmd ) {

storage.set('ignore', settings.ignore);
storage.set('unignore', settings.unignore);

for( var i = 0; i < settings.count; i++ ) {
istore.remove(i)
}
/*
if( client.ui.umuted.length == 0 ) {
storage.set('count', 0);
} else {
var c = -1;
for( var i in client.ui.umuted ) {
if( !client.ui.umuted.hasOwnProperty(i) )
continue;
c++;
istore.set( c.toString(), client.ui.umuted[i] );
}
c++;
settings.count = c;
storage.set('count', c);
}
*/
ext.ignore.remove( cmd.args );

};

Expand Down
Loading

0 comments on commit c1e5860

Please sign in to comment.