Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Convert slashCommands to typescript #25592

Merged
merged 66 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a3356ea
asciiarts slashCommands ts files
eduardofcabrera Jan 26, 2022
56b6e43
lint fix
eduardofcabrera Jan 26, 2022
67e339c
Convert to typescript the slash commands hide files
eduardofcabrera Jan 27, 2022
262eff6
Convert to typescript the slash commands invite all files
eduardofcabrera Jan 27, 2022
c421a14
Convert to typescript the kick slash commands files
eduardofcabrera Jan 27, 2022
c1fa55a
Convert to typescript the leave and part slahs commands files
eduardofcabrera Jan 27, 2022
e485ed2
Convert to typescript the msg slash commands files
eduardofcabrera Jan 27, 2022
c09127f
Convert to typescript the open slash commands files
eduardofcabrera Jan 28, 2022
f5aff79
Convert to typescript the status slash commands files
eduardofcabrera Jan 28, 2022
b044ab0
Convert to typescript the topic slash commands files
eduardofcabrera Jan 28, 2022
0f9eafa
Lint fix
eduardofcabrera Jan 29, 2022
b09aa23
Lint fix
eduardofcabrera Jan 29, 2022
568c305
Syntax fix
eduardofcabrera Jan 31, 2022
612e1b7
Converted the lib/topic file to two others files server and client
eduardofcabrera Jan 31, 2022
f618426
Convert the lib/status.ts file to others two files server and client
eduardofcabrera Jan 31, 2022
04f7d4f
Merge branch 'develop' into js_to_ts_slashCommands_msg
ostjen Feb 7, 2022
60d59c5
Changed if-else to a dict
eduardofcabrera Feb 9, 2022
5cecd48
Merge branch 'develop' into js_to_ts_slashCommands_open
eduardofcabrera Feb 9, 2022
5439c43
Merge branch 'develop' into js_to_ts_slashCommands_open
ostjen Feb 14, 2022
9505cd9
Merge branch 'develop' into js_to_ts_slashCommands_asciiarts
eduardofcabrera Feb 16, 2022
03da15d
Merge branch 'develop' into js_to_ts_slashCommands_hide
eduardofcabrera Feb 16, 2022
94782f1
Merge branch 'develop' into js_to_ts_slashCommands_inviteAll
eduardofcabrera Feb 16, 2022
d5b3087
Merge branch 'develop' into js_to_ts_slashCommands_kick
eduardofcabrera Feb 16, 2022
d94b836
Merge branch 'develop' into js_to_ts_slashCommands_leave
eduardofcabrera Feb 16, 2022
4bc4ae5
Merge branch 'develop' into js_to_ts_slashCommands_msg
eduardofcabrera Feb 16, 2022
e8a038d
Merge branch 'develop' into js_to_ts_slashCommands_open
eduardofcabrera Feb 16, 2022
c7a2d97
Merge branch 'develop' into js_to_ts_slashCommands_status
eduardofcabrera Feb 16, 2022
8249d50
Merge branch 'develop' into js_to_ts_slashCommands_topic
eduardofcabrera Feb 16, 2022
6f069b7
type fix
eduardofcabrera Feb 21, 2022
788230c
Type fix
eduardofcabrera Feb 21, 2022
766a3c2
Merge branch 'develop' into js_to_ts_slashCommands_open
eduardofcabrera Feb 21, 2022
026e077
Merge remote-tracking branch 'origin/develop' into js_to_ts_slashComm…
ggazzo May 4, 2022
f71a543
Merge remote-tracking branch 'origin/develop' into js_to_ts_slashComm…
ggazzo May 4, 2022
75d3dbc
Merge branch 'develop' into js_to_ts_slashCommands_asciiarts
pierre-lehnen-rc May 20, 2022
3002820
use IMessage
pierre-lehnen-rc May 20, 2022
f5fa414
Chore: Convert slashCommands to typescript
pierre-lehnen-rc May 20, 2022
5ecbf7a
Merge branch 'ts/slash-commands' into js_to_ts_slashCommands_asciiarts
pierre-lehnen-rc May 22, 2022
9d8ef04
fixed types
pierre-lehnen-rc May 22, 2022
95c6f9d
Merge pull request #24303 from RocketChat/js_to_ts_slashCommands_asci…
pierre-lehnen-rc May 22, 2022
4811199
Merge branch 'develop' into ts/slash-commands
pierre-lehnen-rc May 22, 2022
005db3e
Adjusting previously merged stuff
pierre-lehnen-rc May 22, 2022
9b82c15
Merge branch 'ts/slash-commands' into js_to_ts_slashCommands_hide
pierre-lehnen-rc May 22, 2022
4af62b8
Restored user language
pierre-lehnen-rc May 22, 2022
db21e16
Merge pull request #24309 from RocketChat/js_to_ts_slashCommands_hide
pierre-lehnen-rc May 22, 2022
c6b599b
Merge branch 'ts/slash-commands' into js_to_ts_slashCommands_inviteAll
pierre-lehnen-rc May 22, 2022
e75a857
Restored user language
pierre-lehnen-rc May 22, 2022
124ee2f
Removed unnecessary arguments
pierre-lehnen-rc May 22, 2022
07b3cb1
missed one line
pierre-lehnen-rc May 22, 2022
d30c7fa
type
pierre-lehnen-rc May 22, 2022
a72b7f7
Merge pull request #24315 from RocketChat/js_to_ts_slashCommands_invi…
pierre-lehnen-rc May 22, 2022
c385c1d
Merge branch 'develop' into js_to_ts_slashCommands_kick
pierre-lehnen-rc May 22, 2022
6bb8f4d
Merge branch 'ts/slash-commands' into js_to_ts_slashCommands_kick
pierre-lehnen-rc May 22, 2022
f0f168f
Restored user language
pierre-lehnen-rc May 22, 2022
f49721c
Removed files restored by merge
pierre-lehnen-rc May 22, 2022
9595975
Merge pull request #24317 from RocketChat/js_to_ts_slashCommands_kick
pierre-lehnen-rc May 22, 2022
e57f4de
Merge remote-tracking branch 'origin/js_to_ts_slashCommands_leave' in…
pierre-lehnen-rc May 22, 2022
50a5a3b
Restored user language on /leave
pierre-lehnen-rc May 22, 2022
5c6e193
Merge remote-tracking branch 'origin/js_to_ts_slashCommands_msg' into…
pierre-lehnen-rc May 22, 2022
a14ab6a
Restored user language /msg
pierre-lehnen-rc May 22, 2022
997f168
Merge remote-tracking branch 'origin/js_to_ts_slashCommands_open' int…
pierre-lehnen-rc May 22, 2022
9b3aa18
Adjusting types /open
pierre-lehnen-rc May 22, 2022
bb69a8b
Merge remote-tracking branch 'origin/js_to_ts_slashCommands_status' i…
pierre-lehnen-rc May 22, 2022
63e4a93
Merge remote-tracking branch 'origin/js_to_ts_slashCommands_topic' in…
pierre-lehnen-rc May 22, 2022
72c251d
Restored file removed by merge
pierre-lehnen-rc May 22, 2022
72625b7
ignore apps-engine mistype
pierre-lehnen-rc May 22, 2022
e421af7
Removed unnecessary index files
pierre-lehnen-rc May 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/meteor/app/apps/server/bridges/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Utilities } from '../../lib/misc/Utilities';
import { AppServerOrchestrator } from '../orchestrator';

export class AppCommandsBridge extends CommandBridge {
disabledCommands: Map<string, object>;
disabledCommands: Map<string, typeof slashCommands.commands[string]>;

// eslint-disable-next-line no-empty-function
constructor(private readonly orch: AppServerOrchestrator) {
Expand Down Expand Up @@ -40,7 +40,7 @@ export class AppCommandsBridge extends CommandBridge {
throw new Error(`The command is not currently disabled: "${cmd}"`);
}

slashCommands.commands[cmd] = this.disabledCommands.get(cmd);
slashCommands.commands[cmd] = this.disabledCommands.get(cmd) as typeof slashCommands.commands[string];
this.disabledCommands.delete(cmd);

this.orch.getNotifier().commandUpdated(cmd);
Expand All @@ -59,11 +59,13 @@ export class AppCommandsBridge extends CommandBridge {
return;
}

if (typeof slashCommands.commands[cmd] === 'undefined') {
const commandObj = slashCommands.commands[cmd];

if (typeof commandObj === 'undefined') {
throw new Error(`Command does not exist in the system currently: "${cmd}"`);
}

this.disabledCommands.set(cmd, slashCommands.commands[cmd]);
this.disabledCommands.set(cmd, commandObj);
delete slashCommands.commands[cmd];

this.orch.getNotifier().commandDisabled(cmd);
Expand All @@ -87,7 +89,9 @@ export class AppCommandsBridge extends CommandBridge {
item.callback = this._appCommandExecutor.bind(this);
item.providesPreview = command.providesPreview;
item.previewer = command.previewer ? this._appCommandPreviewer.bind(this) : item.previewer;
item.previewCallback = command.executePreviewItem ? this._appCommandPreviewExecutor.bind(this) : item.previewCallback;
item.previewCallback = (
command.executePreviewItem ? this._appCommandPreviewExecutor.bind(this) : item.previewCallback
) as typeof slashCommands.commands[string]['previewCallback'];

slashCommands.commands[cmd] = item;
this.orch.getNotifier().commandUpdated(cmd);
Expand All @@ -107,7 +111,9 @@ export class AppCommandsBridge extends CommandBridge {
callback: this._appCommandExecutor.bind(this),
providesPreview: command.providesPreview,
previewer: !command.previewer ? undefined : this._appCommandPreviewer.bind(this),
previewCallback: !command.executePreviewItem ? undefined : this._appCommandPreviewExecutor.bind(this),
previewCallback: (!command.executePreviewItem ? undefined : this._appCommandPreviewExecutor.bind(this)) as
| typeof slashCommands.commands[string]['previewCallback']
| undefined,
};

slashCommands.commands[command.command.toLowerCase()] = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function SlackBridgeImport(command, params, item) {
});
throw error;
}
return SlackBridgeImport;
}

slashCommands.add('slackbridge-import', SlackBridgeImport);
20 changes: 0 additions & 20 deletions apps/meteor/app/slashcommand-asciiarts/lib/gimme.js

This file was deleted.

19 changes: 19 additions & 0 deletions apps/meteor/app/slashcommand-asciiarts/lib/gimme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meteor } from 'meteor/meteor';
import type { IMessage } from '@rocket.chat/core-typings';

import { slashCommands } from '../../utils/lib/slashCommand';
/*
* Gimme is a named function that will replace /gimme commands
* @param {Object} message - The message object
*/

function Gimme(_command: 'gimme', params: string, item: IMessage): void {
const msg = item;
msg.msg = `༼ つ ◕_◕ ༽つ ${params}`;
Meteor.call('sendMessage', msg);
}

slashCommands.add('gimme', Gimme, {
description: 'Slash_Gimme_Description',
params: 'your_message_optional',
});
20 changes: 0 additions & 20 deletions apps/meteor/app/slashcommand-asciiarts/lib/lenny.js

This file was deleted.

19 changes: 19 additions & 0 deletions apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../utils/lib/slashCommand';
/*
* Lenny is a named function that will replace /lenny commands
* @param {Object} message - The message object
*/

function LennyFace(_command: 'lennyface', params: string, item: IMessage): void {
const msg = item;
msg.msg = `${params} ( ͡° ͜ʖ ͡°)`;
Meteor.call('sendMessage', msg);
}

slashCommands.add('lennyface', LennyFace, {
description: 'Slash_LennyFace_Description',
params: 'your_message_optional',
});
20 changes: 0 additions & 20 deletions apps/meteor/app/slashcommand-asciiarts/lib/shrug.js

This file was deleted.

19 changes: 19 additions & 0 deletions apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../utils/lib/slashCommand';
/*
* Shrug is a named function that will replace /shrug commands
* @param {Object} message - The message object
*/

function Shrug(_command: 'shrug', params: string, item: IMessage): void {
const msg = item;
msg.msg = `${params} ¯\\_(ツ)_/¯`;
Meteor.call('sendMessage', msg);
}

slashCommands.add('shrug', Shrug, {
description: 'Slash_Shrug_Description',
params: 'your_message_optional',
});
20 changes: 0 additions & 20 deletions apps/meteor/app/slashcommand-asciiarts/lib/tableflip.js

This file was deleted.

19 changes: 19 additions & 0 deletions apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../utils/lib/slashCommand';
/*
* Tableflip is a named function that will replace /Tableflip commands
* @param {Object} message - The message object
*/

function Tableflip(_command: 'tableflip', params: string, item: IMessage): void {
const msg = item;
msg.msg = `${params} (╯°□°)╯︵ ┻━┻`;
Meteor.call('sendMessage', msg);
}

slashCommands.add('tableflip', Tableflip, {
description: 'Slash_Tableflip_Description',
params: 'your_message_optional',
});
20 changes: 0 additions & 20 deletions apps/meteor/app/slashcommand-asciiarts/lib/unflip.js

This file was deleted.

19 changes: 19 additions & 0 deletions apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../utils/lib/slashCommand';
/*
* Unflip is a named function that will replace /unflip commands
* @param {Object} message - The message object
*/

function Unflip(_command: 'unflip', params: string, item: IMessage): void {
const msg = item;
msg.msg = `${params} ┬─┬ ノ( ゜-゜ノ)`;
Meteor.call('sendMessage', msg);
}

slashCommands.add('unflip', Unflip, {
description: 'Slash_TableUnflip_Description',
params: 'your_message_optional',
});
23 changes: 7 additions & 16 deletions apps/meteor/app/slashcommands-archiveroom/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { IMessage } from '@rocket.chat/core-typings';

import { Rooms, Messages } from '../../models/server';
import { slashCommands } from '../../utils/lib/slashCommand';
import { api } from '../../../server/sdk/api';
import { settings } from '../../settings/server';

function Archive(_command: 'archive', params: string, item: Record<string, string>): void | Function {
function Archive(_command: 'archive', params: string, item: IMessage): void {
let channel = params.trim();

let room;
Expand Down Expand Up @@ -61,20 +62,10 @@ function Archive(_command: 'archive', params: string, item: Record<string, strin
lng: settings.get('Language') || 'en',
}),
});

return Archive;
}

slashCommands.add(
'archive',
Archive,
{
description: 'Archive',
params: '#channel',
permission: 'archive-room',
},
undefined,
false,
undefined,
undefined,
);
slashCommands.add('archive', Archive, {
description: 'Archive',
params: '#channel',
permission: 'archive-room',
});
19 changes: 6 additions & 13 deletions apps/meteor/app/slashcommands-bridge/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { IMessage } from '@rocket.chat/core-typings';

import { slashCommands } from '../../utils/lib/slashCommand';
import { matrixClient } from '../../federation-v2/server/matrix-client';

function Bridge(_command: 'bridge', stringParams: string, item: Record<string, string>): void {
function Bridge(_command: 'bridge', stringParams: string, item: IMessage): void {
if (_command !== 'bridge' || !Match.test(stringParams, String)) {
return;
}
Expand All @@ -29,15 +30,7 @@ function Bridge(_command: 'bridge', stringParams: string, item: Record<string, s
}
}

slashCommands.add(
'bridge',
Bridge,
{
description: 'Invites_an_user_to_a_bridged_room',
params: '#command #user',
},
undefined,
false,
undefined,
undefined,
);
slashCommands.add('bridge', Bridge, {
description: 'Invites_an_user_to_a_bridged_room',
params: '#command #user',
});
21 changes: 7 additions & 14 deletions apps/meteor/app/slashcommands-create/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { IMessage } from '@rocket.chat/core-typings';

import { settings } from '../../settings/server';
import { Rooms } from '../../models/server';
import { slashCommands } from '../../utils/lib/slashCommand';
import { api } from '../../../server/sdk/api';

function Create(_command: 'create', params: string, item: Record<string, string>): void {
function Create(_command: 'create', params: string, item: IMessage): void {
function getParams(str: string): string[] {
const regex = /(--(\w+))+/g;
const result = [];
Expand Down Expand Up @@ -53,16 +54,8 @@ function Create(_command: 'create', params: string, item: Record<string, string>
Meteor.call('createChannel', channelStr, []);
}

slashCommands.add(
'create',
Create,
{
description: 'Create_A_New_Channel',
params: '#channel',
permission: ['create-c', 'create-p'],
},
undefined,
false,
undefined,
undefined,
);
slashCommands.add('create', Create, {
description: 'Create_A_New_Channel',
params: '#channel',
permission: ['create-c', 'create-p'],
});
1 change: 0 additions & 1 deletion apps/meteor/app/slashcommands-help/index.ts

This file was deleted.

14 changes: 3 additions & 11 deletions apps/meteor/app/slashcommands-help/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ function Help(_command: 'help', _params: string, item: IMessage): void {
});
}

slashCommands.add(
'help',
Help,
{
description: 'Show_the_keyboard_shortcut_list',
},
undefined,
false,
undefined,
undefined,
);
slashCommands.add('help', Help, {
description: 'Show_the_keyboard_shortcut_list',
});
Loading