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

refactor: replace deprecated String.prototype.substr() #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion scripts/check-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ for (const [file, matches] of found) {
for (const match of matches) {
let variableIndex = match.indexOf('$');
if (variableIndex >= 0) {
variablePrefixes.push(match.substr(0, variableIndex));
variablePrefixes.push(match.slice(0, variableIndex));
console.log(chalk.yellow(`⚠️ ${chalk.blue(file)}: Variable found in ${chalk.blue(match)} - skipping checks`));
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ export class IMClient extends Client {
if (logChannelId) {
const logChannel = guild.channels.get(logChannelId) as TextChannel;
if (logChannel) {
const content = message.content.substr(0, 1000) + (message.content.length > 1000 ? '...' : '');
const content = message.content.slice(0, 1000) + (message.content.length > 1000 ? '...' : '');

let json = JSON.stringify(data, null, 2);
if (json.length > 1000) {
json = json.substr(0, 1000) + '...';
json = json.slice(0, 1000) + '...';
}

const embed = this.msg.createEmbed({
Expand Down
2 changes: 1 addition & 1 deletion src/framework/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export abstract class Command {
const flag = this.flags[i];
const help = this.flagResolvers.get(flag.name).getHelp(context);
const descr = context.t(`cmd.${this.name}.self.flags.${flag.name}`);
info += `**--${flag.name}**\n${descr}\n` + (help ? `${help.substr(0, 800)}\n\n` : '\n');
info += `**--${flag.name}**\n${descr}\n` + (help ? `${help.slice(0, 800)}\n\n` : '\n');
}
for (let i = 0; i < this.args.length; i++) {
const arg = this.args[i];
Expand Down
2 changes: 1 addition & 1 deletion src/framework/commands/info/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class extends Command {
const cmd = {
...command,
usage: command.usage.replace('{prefix}', prefix),
info: command.getInfo(context).substr(0, 900)
info: command.getInfo(context).slice(0, 900)
};

embed.fields.push({
Expand Down
2 changes: 1 addition & 1 deletion src/framework/services/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class MessagingService extends IMService {
let color = options.color ? (options.color as number | string) : parseInt('00AE86', 16);
// Parse colors in hashtag/hex format
if (typeof color === 'string') {
const code = color.startsWith('#') ? color.substr(1) : color;
const code = color.startsWith('#') ? color.slice(1) : color;
color = parseInt(code, 16);
}

Expand Down
2 changes: 1 addition & 1 deletion src/invites/commands/invites/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export default class extends Command {
let text = customInvText + more + detailMsg;
const diff = text.length - 1024;
if (diff > 0) {
text = customInvText.substr(0, customInvText.length - diff - 3) + '...' + more;
text = customInvText.slice(0, -diff - 3) + '...' + more;
}

embed.fields.push({
Expand Down
2 changes: 1 addition & 1 deletion src/invites/services/Captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class CaptchaService extends IMService {
config.background = config.background || 'rgb(255,255,255)';
config.lineWidth = config.lineWidth || 2;
config.saveDir = config.saveDir || __dirname;
config.text = config.text || Math.random().toString().substr(2, config.size);
config.text = config.text || Math.random().toString().slice(2, 2 + config.size);
config.noise = config.noise !== false ? true : false;
config.noiseColor = config.noiseColor || config.color;
config.complexity = config.complexity || 3;
Expand Down
4 changes: 2 additions & 2 deletions src/moderation/commands/info/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class extends Command {
if (strikeText) {
embed.fields.push({
name: t('cmd.check.strikes.title'),
value: strikeText.substr(0, 1020)
value: strikeText.slice(0, 1020)
});
}

Expand All @@ -84,7 +84,7 @@ export default class extends Command {
if (punishmentText) {
embed.fields.push({
name: t('cmd.check.punishments.title'),
value: punishmentText.substr(0, 1020)
value: punishmentText.slice(0, 1020)
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/moderation/commands/mod/unhoist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class extends Command {
continue;
}

const newName = (NAME_DEHOIST_PREFIX + ' ' + name).substr(0, 32);
const newName = (NAME_DEHOIST_PREFIX + ' ' + name).slice(0, 32);
await guild
.editMember(member.user.id, { nick: newName }, 'Unhoist command')
.then(() => changed++)
Expand Down
4 changes: 2 additions & 2 deletions src/moderation/services/Moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class ModerationService extends IMService {
if (extra) {
extra
.filter((e) => !!e.value)
.forEach((e) => logEmbed.fields.push({ name: e.name, value: e.value.substr(0, 1024) }));
.forEach((e) => logEmbed.fields.push({ name: e.name, value: e.value.slice(0, 1024) }));
}
await this.client.logModAction(guild, logEmbed);
}
Expand Down Expand Up @@ -585,7 +585,7 @@ export class ModerationService extends IMService {
const strike = strikesCache.find((s) => s.type === type);
const amount = strike ? strike.amount : 0;

const newName = (NAME_DEHOIST_PREFIX + ' ' + name).substr(0, 32);
const newName = (NAME_DEHOIST_PREFIX + ' ' + name).slice(0, 32);
member.edit({ nick: newName }, 'Auto dehoist').catch(() => undefined);

await this.logViolationModAction(guild, member.user, type, amount, [
Expand Down
2 changes: 1 addition & 1 deletion src/music/models/ravedj/RaveDJ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class RaveDJ extends MusicPlatform {
}

public async getByLink(link: string): Promise<MusicItem> {
const id = link.substr(link.indexOf('.dj/') + 4);
const id = link.slice(link.indexOf('.dj/') + 4);

const url = `https://api.red.wemesh.ca/ravedj/${id}`;
const opts = {
Expand Down
2 changes: 1 addition & 1 deletion src/music/services/MusicService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class MusicService extends IMService {
private decodeHTMLEntities(str: string) {
return str.replace(/&#?[0-9a-zA-Z]+;?/g, (s) => {
if (s.charAt(1) === '#') {
const code = s.charAt(2).toLowerCase() === 'x' ? parseInt(s.substr(3), 16) : parseInt(s.substr(2), 10);
const code = s.charAt(2).toLowerCase() === 'x' ? parseInt(s.slice(3), 16) : parseInt(s.slice(2), 10);

if (isNaN(code) || code < -32768 || code > 65535) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ export function beautify(type: InternalSettingsTypes, value: any) {

default:
if (typeof value === 'string' && value.length > 1000) {
return '`' + value.substr(0, 1000) + '`...';
return '`' + value.slice(0, 1000) + '`...';
}
return `\`${value}\``;
}
Expand Down