mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-28 13:11:56 +00:00
Added sanity checks in commands
This commit is contained in:
parent
3501478828
commit
cf4c17deaf
@ -313,32 +313,44 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
|||||||
|
|
||||||
case "/nick":
|
case "/nick":
|
||||||
// Change user display name
|
// Change user display name
|
||||||
promise = matrixService.setDisplayName(args);
|
if (args) {
|
||||||
|
promise = matrixService.setDisplayName(args);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$scope.feedback = "Usage: /nick <display_name>";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/kick":
|
case "/kick":
|
||||||
var matches = args.match(/^(\S+?)( +(.*))?$/);
|
// Kick a user from the room with an optional reason
|
||||||
if (matches.length === 2) {
|
if (args) {
|
||||||
promise = matrixService.setMembership($scope.room_id, matches[1], "leave");
|
var matches = args.match(/^(\S+?)( +(.*))?$/);
|
||||||
|
if (matches.length === 2) {
|
||||||
|
promise = matrixService.setMembership($scope.room_id, matches[1], "leave");
|
||||||
|
}
|
||||||
|
else if (matches.length === 4) {
|
||||||
|
promise = matrixService.setMembershipObject($scope.room_id, matches[1], {
|
||||||
|
membership: "leave",
|
||||||
|
reason: matches[3] // TODO: we need to specify resaon in the spec
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (matches.length === 4) {
|
|
||||||
promise = matrixService.setMembershipObject($scope.room_id, matches[1], {
|
if (!promise) {
|
||||||
membership: "leave",
|
|
||||||
reason: matches[3] // TODO: we need to specify resaon in the spec
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$scope.feedback = "Usage: /kick <userId> [<reason>]";
|
$scope.feedback = "Usage: /kick <userId> [<reason>]";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/ban":
|
case "/ban":
|
||||||
// Ban a user from the room with optional reason
|
// Ban a user from the room with an optional reason
|
||||||
var matches = args.match(/^(\S+?)( +(.*))?$/);
|
if (args) {
|
||||||
if (matches) {
|
var matches = args.match(/^(\S+?)( +(.*))?$/);
|
||||||
promise = matrixService.ban($scope.room_id, matches[1], matches[3]);
|
if (matches) {
|
||||||
|
promise = matrixService.ban($scope.room_id, matches[1], matches[3]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if (!promise) {
|
||||||
$scope.feedback = "Usage: /ban <userId> [<reason>]";
|
$scope.feedback = "Usage: /ban <userId> [<reason>]";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -348,29 +360,35 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
|||||||
// FIXME: this feels horribly asymmetrical - why are we banning via RPC
|
// FIXME: this feels horribly asymmetrical - why are we banning via RPC
|
||||||
// and unbanning by editing the membership list?
|
// and unbanning by editing the membership list?
|
||||||
// Why can't we specify a reason?
|
// Why can't we specify a reason?
|
||||||
var matches = args.match(/^(\S+)$/);
|
if (args) {
|
||||||
if (matches) {
|
var matches = args.match(/^(\S+)$/);
|
||||||
// Reset the user membership to "leave" to unban him
|
if (matches) {
|
||||||
promise = matrixService.setMembership($scope.room_id, matches[1], "leave");
|
// Reset the user membership to "leave" to unban him
|
||||||
|
promise = matrixService.setMembership($scope.room_id, matches[1], "leave");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if (!promise) {
|
||||||
$scope.feedback = "Usage: /unban <userId>";
|
$scope.feedback = "Usage: /unban <userId>";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/op":
|
case "/op":
|
||||||
// Define the power level of a user
|
// Define the power level of a user
|
||||||
var matches = args.match(/^(\S+?)( +(\d+))?$/);
|
if (args) {
|
||||||
var powerLevel = 50; // default power level for op
|
var matches = args.match(/^(\S+?)( +(\d+))?$/);
|
||||||
if (matches) {
|
var powerLevel = 50; // default power level for op
|
||||||
var user_id = matches[1];
|
if (matches) {
|
||||||
if (matches.length === 4) {
|
var user_id = matches[1];
|
||||||
powerLevel = parseInt(matches[3]);
|
if (matches.length === 4) {
|
||||||
}
|
powerLevel = parseInt(matches[3]);
|
||||||
if (powerLevel !== NaN) {
|
}
|
||||||
promise = matrixService.setUserPowerLevel($scope.room_id, user_id, powerLevel);
|
if (powerLevel !== NaN) {
|
||||||
|
promise = matrixService.setUserPowerLevel($scope.room_id, user_id, powerLevel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!promise) {
|
if (!promise) {
|
||||||
$scope.feedback = "Usage: /op <userId> [<power level>]";
|
$scope.feedback = "Usage: /op <userId> [<power level>]";
|
||||||
}
|
}
|
||||||
@ -378,11 +396,14 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
|||||||
|
|
||||||
case "/deop":
|
case "/deop":
|
||||||
// Reset the power level of a user
|
// Reset the power level of a user
|
||||||
var matches = args.match(/^(\S+)$/);
|
if (args) {
|
||||||
if (matches) {
|
var matches = args.match(/^(\S+)$/);
|
||||||
promise = matrixService.setUserPowerLevel($scope.room_id, args, undefined);
|
if (matches) {
|
||||||
|
promise = matrixService.setUserPowerLevel($scope.room_id, args, undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if (!promise) {
|
||||||
$scope.feedback = "Usage: /deop <userId>";
|
$scope.feedback = "Usage: /deop <userId>";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user