2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 05:37:59 +00:00

Streamline .eslintrc

This commit is contained in:
Wojciech Pawlik 2020-05-04 23:32:00 +02:00
parent 0ab0b582ff
commit cf56ef66c5
No known key found for this signature in database
GPG Key ID: 7D763FCB7B36ADB5
8 changed files with 607 additions and 321 deletions

View File

@ -4,12 +4,27 @@
"sourceType": "script"
},
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"overrides": [
{
"files": "*.ts",
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off"
}
}
],
"rules": {
"indent": [
"error",

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"eslint.validate": ["javascript", "typescript"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}

View File

@ -27,13 +27,14 @@ module.exports = async ({ admin, amend, reason, userToWarn }) => {
{ amend }
);
// @ts-ignore
const recentWarns = warns.filter(isNewerThan(date - ms(expireWarnsAfter)));
const recentWarns = warns.filter(
isNewerThan(date.getTime() - ms(expireWarnsAfter))
);
const count = {
'-1': recentWarns.length + '/' + numberOfWarnsToBan,
0: `${recentWarns.length}/${numberOfWarnsToBan}, <b>last warning!</b>`,
1: `<b>banned</b> for receiving ${numberOfWarnsToBan} warnings!`
1: `<b>banned</b> for receiving ${numberOfWarnsToBan} warnings!`,
}[cmp(recentWarns.length + 1, numberOfWarnsToBan)];
const warnMessage = dedent(`

825
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"scripts": {
"postversion": "git push --atomic --follow-tags origin develop develop:master",
"start": "node index",
"lint": "eslint .",
"lint": "eslint --ext .ts --ext .js .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@ -49,6 +49,11 @@
},
"devDependencies": {
"@types/node": "^13.13.2",
"eslint": "^6.0.1"
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"prettier": "2.0.5"
}
}

18
typings/config.d.ts vendored
View File

@ -1,6 +1,6 @@
import type { InlineKeyboardMarkup } from 'telegraf/typings/telegram-types';
import type { InlineKeyboardMarkup } from "telegraf/typings/telegram-types";
export type InlineKeyboard = InlineKeyboardMarkup['inline_keyboard'];
export type InlineKeyboard = InlineKeyboardMarkup["inline_keyboard"];
/**
* String to be parsed by https://npmjs.com/millisecond,
@ -9,13 +9,12 @@ export type InlineKeyboard = InlineKeyboardMarkup['inline_keyboard'];
type ms = number | string;
export interface Config {
/**
* ID (number) or username (string) of master,
* the person who can promote and demote admins,
* and add the bot to groups.
*/
master: number | string | (number|string)[];
master: number | string | (number | string)[];
/**
* Telegram Bot token obtained from https://t.me/BotFather.
@ -23,7 +22,6 @@ export interface Config {
token: string;
chats?: {
/**
* Chat to send member join/leave notifications to.
* Pass false to disable this feature.
@ -35,18 +33,18 @@ export interface Config {
* Pass false to disable this feature.
*/
report?: number | false;
},
};
/**
* Which messages with commands should be deleted?
* Defaults to 'own' -- don't delete commands meant for other bots.
*/
deleteCommands?: 'all' | 'own' | 'none';
deleteCommands?: "all" | "own" | "none";
deleteCustom?: {
longerThan: number; // UTF-16 characters
after: ms;
},
};
/**
* Timeout before removing join and leave messages.
@ -62,7 +60,7 @@ export interface Config {
* over which messages get deleted
* Pass false to disable this feature.
*/
deleteWarnsAfter?: ms | { auto: (ms | false), manual: (ms | false) } | false;
deleteWarnsAfter?: ms | { auto: ms | false; manual: ms | false } | false;
/**
* Timeout before removing ban messages.
@ -109,7 +107,7 @@ export interface Config {
spamwatch?: {
token: string;
host?: string;
}
};
/**
* Inline keyboard to be added to warn message.

39
typings/context.d.ts vendored
View File

@ -1,31 +1,31 @@
import type { Context } from 'telegraf';
import type {
User,
Message,
ExtraReplyMessage,
} from 'telegraf/typings/telegram-types';
Message,
User,
} from "telegraf/typings/telegram-types";
import type { Context } from "telegraf";
interface DbUser {
status: 'member' | 'admin' | 'banned';
status: "member" | "admin" | "banned";
}
export interface ContextExtensions {
ban(options: {
admin: User,
reason: string,
userToBan: User,
admin: User;
reason: string;
userToBan: User;
}): Promise<Message>;
batchBan(options: {
admin: User,
reason: string,
targets: User[],
admin: User;
reason: string;
targets: User[];
}): Promise<Message>;
warn(options: {
admin: User,
amend?: boolean,
reason: string,
userToWarn: User,
mode: 'auto' | 'manual',
admin: User;
amend?: boolean;
reason: string;
userToWarn: User;
mode: "auto" | "manual";
}): Promise<Message>;
replyWithCopy(
content: Message,
@ -33,6 +33,7 @@ export interface ContextExtensions {
): Promise<Message>;
}
export type ExtendedContext = ContextExtensions & Context & {
from?: DbUser,
};
export type ExtendedContext = ContextExtensions &
Context & {
from?: DbUser;
};