Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6292 from matrix-org/t3chguy/ts/9
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jul 1, 2021
2 parents 8520a11 + 30d027d commit 04902fa
Show file tree
Hide file tree
Showing 15 changed files with 495 additions and 444 deletions.
3 changes: 2 additions & 1 deletion src/CountlyAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { randomString } from "matrix-js-sdk/src/randomstring";
import { IContent } from "matrix-js-sdk/src/models/event";

import { getCurrentLanguage } from './languageHandler';
import PlatformPeg from './PlatformPeg';
Expand Down Expand Up @@ -868,7 +869,7 @@ export default class CountlyAnalytics {
roomId: string,
isEdit: boolean,
isReply: boolean,
content: {format?: string, msgtype: string},
content: IContent,
) {
if (this.disabled) return;
const cli = MatrixClientPeg.get();
Expand Down
4 changes: 2 additions & 2 deletions src/HtmlUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ interface IOpts {
stripReplyFallback?: boolean;
returnString?: boolean;
forComposerQuote?: boolean;
ref?: React.Ref<any>;
ref?: React.Ref<HTMLSpanElement>;
}

export interface IOptsReturnNode extends IOpts {
returnString: false;
returnString: false | undefined;
}

export interface IOptsReturnString extends IOpts {
Expand Down
15 changes: 10 additions & 5 deletions src/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1181,23 +1181,23 @@ export const Commands = [
];

// build a map from names and aliases to the Command objects.
export const CommandMap = new Map();
export const CommandMap = new Map<string, Command>();
Commands.forEach(cmd => {
CommandMap.set(cmd.command, cmd);
cmd.aliases.forEach(alias => {
CommandMap.set(alias, cmd);
});
});

export function parseCommandString(input: string) {
export function parseCommandString(input: string): { cmd?: string, args?: string } {
// trim any trailing whitespace, as it can confuse the parser for
// IRC-style commands
input = input.replace(/\s+$/, '');
if (input[0] !== '/') return {}; // not a command

const bits = input.match(/^(\S+?)(?:[ \n]+((.|\n)*))?$/);
let cmd;
let args;
let cmd: string;
let args: string;
if (bits) {
cmd = bits[1].substring(1).toLowerCase();
args = bits[2];
Expand All @@ -1208,6 +1208,11 @@ export function parseCommandString(input: string) {
return { cmd, args };
}

interface ICmd {
cmd?: Command;
args?: string;
}

/**
* Process the given text for /commands and return a bound method to perform them.
* @param {string} roomId The room in which the command was performed.
Expand All @@ -1216,7 +1221,7 @@ export function parseCommandString(input: string) {
* processing the command, or 'promise' if a request was sent out.
* Returns null if the input didn't match a command.
*/
export function getCommand(input: string) {
export function getCommand(input: string): ICmd {
const { cmd, args } = parseCommandString(input);

if (CommandMap.has(cmd) && CommandMap.get(cmd).isEnabled()) {
Expand Down
Loading

0 comments on commit 04902fa

Please sign in to comment.