Skip to content

Commit

Permalink
Prefer substring over substr, remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Dec 31, 2021
1 parent 7a30b26 commit e322af1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function generateBotErrorMessage(error: unknown) {
msg += `: ${error}`;
break;
case "string":
msg += `: ${String(error).substr(0, 50)}`;
msg += `: ${String(error).substring(0, 50)}`;
break;
default:
msg += "!";
Expand Down Expand Up @@ -384,7 +384,7 @@ export class Composer<C extends Context> implements MiddlewareObj<C> {
if (cmd.startsWith("/")) {
throw new Error(
`Do not include '/' when registering command handlers (use '${
cmd.substr(1)
cmd.substring(1)
}' not '${cmd}')`,
);
}
Expand All @@ -394,14 +394,13 @@ export class Composer<C extends Context> implements MiddlewareObj<C> {
return this.on(":entities:bot_command").filter(
(ctx): ctx is CommandContext<C> => {
const msg = ctx.message ?? ctx.channelPost;
const txt = msg.text ?? msg.caption;
const entities = msg.entities ?? msg.caption_entities;
return entities.some((e) => {
const txt = msg.text;
return msg.entities.some((e) => {
if (e.type !== "bot_command") return false;
if (e.offset !== 0) return false;
const cmd = txt.substring(1, e.length);
if (noAtCommands.has(cmd) || atCommands.has(cmd)) {
ctx.match = txt.substr(cmd.length + 1).trimStart();
ctx.match = txt.substring(cmd.length + 1).trimStart();
return true;
}
const index = cmd.indexOf("@");
Expand All @@ -410,7 +409,7 @@ export class Composer<C extends Context> implements MiddlewareObj<C> {
if (atTarget !== ctx.me.username) return false;
const atCommand = cmd.substring(0, index);
if (noAtCommands.has(atCommand)) {
ctx.match = txt.substr(cmd.length + 1).trimStart();
ctx.match = txt.substring(cmd.length + 1).trimStart();
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ApiClient<R extends RawApi> {
if (this.options.apiRoot.endsWith("/")) {
throw new Error(
`Remove the trailing '/' from the 'apiRoot' option (use '${
this.options.apiRoot.substr(
this.options.apiRoot.substring(
0,
this.options.apiRoot.length - 1,
)
Expand Down

0 comments on commit e322af1

Please sign in to comment.