From cb88ac9cac612b671cfcbd1de73247a179482ebf Mon Sep 17 00:00:00 2001 From: walle303 Date: Fri, 9 Dec 2016 05:33:38 +0000 Subject: [PATCH 1/3] Add command to rename group chats --- src/commands.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/commands.js b/src/commands.js index c0b2092e..e5acfcf3 100644 --- a/src/commands.js +++ b/src/commands.js @@ -444,6 +444,41 @@ FFZ.prototype.get_banned_users = function() { } + + // --------------------- + // Group Chat Renaming + // --------------------- +FFZ.chat_commands.renamegroup = function(room, args) { + // Get the current room. + var controller = utils.ember_lookup('controller:chat'), + room_id = controller.get('currentRoom.id'), + room = this.rooms[room_id], + has_product = false, + f = this; + + //Join the arguments and check to see if something was entered + newname = args.join(' '); + if ( encodeURI(newname).split(/%..|./).length-1 == 0 ) { + return "Usage: /renamegroup \nThis command must be used inside a group chat that you are owner of." + } + + //Are we in a group chat and are we the owner? + if ( ! f.rooms[room_id].room.get('isGroupRoom') ) { + return "You must be in a group chat to use renamegroup." + } + if ( ! f.rooms[room_id].room.get('isOwner') ) { + return "You must be the owner of the current group chat to use renamegroup." + } + + //Check that the length of the arguments is less than 120 bytes + if ( encodeURI(newname).split(/%..|./).length-1 > 120 ) { + return "You entered a room name that was too long." + } + + //Set the group name + f.rooms[room_id].room.tmiRoom.session._depotApi.put("/rooms/"+[room_id],{display_name:newname}) +} + /*FFZ.ffz_commands.massunban = function(room, args) { var user = this.get_user(); if ( ! user || (user.login !== room.id && ! user.is_admin && ! user.is_staff) ) @@ -458,4 +493,4 @@ FFZ.prototype.get_banned_users = function() { -}*/ \ No newline at end of file +}*/ From 065d5b552f49837f37514f8c76dc25acbe2e3fc0 Mon Sep 17 00:00:00 2001 From: walle303 Date: Fri, 9 Dec 2016 06:14:54 +0000 Subject: [PATCH 2/3] Clean up the group chat rename code --- src/commands.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/commands.js b/src/commands.js index e5acfcf3..39d75387 100644 --- a/src/commands.js +++ b/src/commands.js @@ -449,34 +449,33 @@ FFZ.prototype.get_banned_users = function() { // Group Chat Renaming // --------------------- FFZ.chat_commands.renamegroup = function(room, args) { - // Get the current room. - var controller = utils.ember_lookup('controller:chat'), - room_id = controller.get('currentRoom.id'), - room = this.rooms[room_id], - has_product = false, - f = this; + // Shorten the FFZ instance + var f = this; - //Join the arguments and check to see if something was entered - newname = args.join(' '); - if ( encodeURI(newname).split(/%..|./).length-1 == 0 ) { + // Join the arguments and check to see if something was entered + var newname = args.join(' '); + if ( ! newname.length ) { return "Usage: /renamegroup \nThis command must be used inside a group chat that you are owner of." } - //Are we in a group chat and are we the owner? - if ( ! f.rooms[room_id].room.get('isGroupRoom') ) { + // Are we in a group chat and are we the owner? + if ( ! room.room.get('isGroupRoom') ) { return "You must be in a group chat to use renamegroup." } - if ( ! f.rooms[room_id].room.get('isOwner') ) { - return "You must be the owner of the current group chat to use renamegroup." - } + if ( ! room.room.get('isOwner') ) { + return "You must be the owner of the current group chat to use renamegroup." + } - //Check that the length of the arguments is less than 120 bytes - if ( encodeURI(newname).split(/%..|./).length-1 > 120 ) { + // Check that the length of the arguments is less than 120 bytes + if ( unescape(encodeURIComponent(newname)).length > 120 ) { return "You entered a room name that was too long." } - //Set the group name - f.rooms[room_id].room.tmiRoom.session._depotApi.put("/rooms/"+[room_id],{display_name:newname}) + // Set the group name + room.room.tmiRoom.session._depotApi.put( + "/rooms/" + room.id, + {display_name:newname} + ) } /*FFZ.ffz_commands.massunban = function(room, args) { From 3a82ac173bb0ee545ba38a6af73679808898cda8 Mon Sep 17 00:00:00 2001 From: walle303 Date: Fri, 9 Dec 2016 22:41:36 +0000 Subject: [PATCH 3/3] Add return after command finishes --- src/commands.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands.js b/src/commands.js index 39d75387..c4dd7a14 100644 --- a/src/commands.js +++ b/src/commands.js @@ -476,6 +476,7 @@ FFZ.chat_commands.renamegroup = function(room, args) { "/rooms/" + room.id, {display_name:newname} ) + return( "Room renamed to \"" + newname + "\"" ) } /*FFZ.ffz_commands.massunban = function(room, args) {