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" "sourceType": "script"
}, },
"env": { "env": {
"browser": true,
"commonjs": true,
"es6": true, "es6": true,
"node": true "node": true
}, },
"extends": "eslint:recommended", "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": { "rules": {
"indent": [ "indent": [
"error", "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 } { amend }
); );
// @ts-ignore const recentWarns = warns.filter(
const recentWarns = warns.filter(isNewerThan(date - ms(expireWarnsAfter))); isNewerThan(date.getTime() - ms(expireWarnsAfter))
);
const count = { const count = {
'-1': recentWarns.length + '/' + numberOfWarnsToBan, '-1': recentWarns.length + '/' + numberOfWarnsToBan,
0: `${recentWarns.length}/${numberOfWarnsToBan}, <b>last warning!</b>`, 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)]; }[cmp(recentWarns.length + 1, numberOfWarnsToBan)];
const warnMessage = dedent(` 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": { "scripts": {
"postversion": "git push --atomic --follow-tags origin develop develop:master", "postversion": "git push --atomic --follow-tags origin develop develop:master",
"start": "node index", "start": "node index",
"lint": "eslint .", "lint": "eslint --ext .ts --ext .js .",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
@ -49,6 +49,11 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^13.13.2", "@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, * String to be parsed by https://npmjs.com/millisecond,
@ -9,13 +9,12 @@ export type InlineKeyboard = InlineKeyboardMarkup['inline_keyboard'];
type ms = number | string; type ms = number | string;
export interface Config { export interface Config {
/** /**
* ID (number) or username (string) of master, * ID (number) or username (string) of master,
* the person who can promote and demote admins, * the person who can promote and demote admins,
* and add the bot to groups. * 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. * Telegram Bot token obtained from https://t.me/BotFather.
@ -23,7 +22,6 @@ export interface Config {
token: string; token: string;
chats?: { chats?: {
/** /**
* Chat to send member join/leave notifications to. * Chat to send member join/leave notifications to.
* Pass false to disable this feature. * Pass false to disable this feature.
@ -35,18 +33,18 @@ export interface Config {
* Pass false to disable this feature. * Pass false to disable this feature.
*/ */
report?: number | false; report?: number | false;
}, };
/** /**
* Which messages with commands should be deleted? * Which messages with commands should be deleted?
* Defaults to 'own' -- don't delete commands meant for other bots. * Defaults to 'own' -- don't delete commands meant for other bots.
*/ */
deleteCommands?: 'all' | 'own' | 'none'; deleteCommands?: "all" | "own" | "none";
deleteCustom?: { deleteCustom?: {
longerThan: number; // UTF-16 characters longerThan: number; // UTF-16 characters
after: ms; after: ms;
}, };
/** /**
* Timeout before removing join and leave messages. * Timeout before removing join and leave messages.
@ -62,7 +60,7 @@ export interface Config {
* over which messages get deleted * over which messages get deleted
* Pass false to disable this feature. * 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. * Timeout before removing ban messages.
@ -109,7 +107,7 @@ export interface Config {
spamwatch?: { spamwatch?: {
token: string; token: string;
host?: string; host?: string;
} };
/** /**
* Inline keyboard to be added to warn message. * 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 { import type {
User,
Message,
ExtraReplyMessage, ExtraReplyMessage,
} from 'telegraf/typings/telegram-types'; Message,
User,
} from "telegraf/typings/telegram-types";
import type { Context } from "telegraf";
interface DbUser { interface DbUser {
status: 'member' | 'admin' | 'banned'; status: "member" | "admin" | "banned";
} }
export interface ContextExtensions { export interface ContextExtensions {
ban(options: { ban(options: {
admin: User, admin: User;
reason: string, reason: string;
userToBan: User, userToBan: User;
}): Promise<Message>; }): Promise<Message>;
batchBan(options: { batchBan(options: {
admin: User, admin: User;
reason: string, reason: string;
targets: User[], targets: User[];
}): Promise<Message>; }): Promise<Message>;
warn(options: { warn(options: {
admin: User, admin: User;
amend?: boolean, amend?: boolean;
reason: string, reason: string;
userToWarn: User, userToWarn: User;
mode: 'auto' | 'manual', mode: "auto" | "manual";
}): Promise<Message>; }): Promise<Message>;
replyWithCopy( replyWithCopy(
content: Message, content: Message,
@ -33,6 +33,7 @@ export interface ContextExtensions {
): Promise<Message>; ): Promise<Message>;
} }
export type ExtendedContext = ContextExtensions & Context & { export type ExtendedContext = ContextExtensions &
from?: DbUser, Context & {
}; from?: DbUser;
};