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

style: use prettier config and require curly #38

Merged
merged 1 commit into from
Feb 3, 2022
Merged
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
20 changes: 12 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"curly": [1, "all"]
}
}
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
],
"scripts": {
"test": "ts-node src",
"lint": "eslint . --ext .ts --max-warnings=0",
"fix": "npm run lint -- --fix",
"build": "rimraf dist && tsc",
"fix": "npm run lint -- --fix",
"postinstall": "husky install",
"format": "prettier --write src/**/*.ts",
"lint": "eslint . --ext .ts --max-warnings=0",
"preversion": "echo \"export const version = \\\"\"$npm_new_version\"\\\"\" > src/constants.ts"
},
"dependencies": {
Expand All @@ -35,6 +35,7 @@
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.2",
"prettier": "^2.5.1",
Expand All @@ -47,4 +48,4 @@
"npm run format"
]
}
}
}
8 changes: 6 additions & 2 deletions src/handlers/command_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export class CommandHandler extends MessageHandler {
}

async check(client: TelegramClient, event: NewMessageEvent) {
if (!(await super.check(client, event))) return false
if (!(await super.check(client, event))) {
return false
}
const { text } = event.message
if (!['\\', '>'].includes(text[0])) return false
if (!['\\', '>'].includes(text[0])) {
return false
}
const command = text.split(/\s/)[0].slice(1)
return this.name == command || !!this.opts?.aliases?.includes(command)
}
Expand Down
21 changes: 15 additions & 6 deletions src/handlers/message_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ export class MessageHandler extends Handler {
}

async check(_client: TelegramClient, event: NewMessageEvent) {
if (this.out !== undefined && this.out !== event.message.out) return false
if (!event.message.out) return false
if (this.scope !== undefined && this.scope !== 'all')
if (this.scope == 'group' && !event.isGroup) return false
else if (this.scope == 'private' && !event.isPrivate) return false
else if (!event.isChannel) return false
if (this.out !== undefined && this.out !== event.message.out) {
return false
}
if (!event.message.out) {
return false
}
if (this.scope !== undefined && this.scope !== 'all') {
if (this.scope == 'group' && !event.isGroup) {
return false
} else if (this.scope == 'private' && !event.isPrivate) {
return false
} else if (!event.isChannel) {
return false
}
}
return true
}

Expand Down
15 changes: 11 additions & 4 deletions src/module_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ export function managerModule(manager: ModuleManager): Module {
handlers: [
new CommandHandler('install', async (client, event) => {
const reply = await event.message.getReplyMessage()
if (!reply) return
if (!reply) {
return
}
const { media } = reply
if (
!(media instanceof Api.MessageMediaDocument) ||
!(media.document instanceof Api.Document) ||
media.document.mimeType != 'application/javascript' ||
media.document.size > 5000
)
) {
return
}
const result = await client.downloadMedia(media, {})
const spec = join(
__dirname,
Expand Down Expand Up @@ -75,7 +78,9 @@ export function managerModule(manager: ModuleManager): Module {
})
}),
new CommandHandler('disable', async (_client, event, args) => {
if (args.length == 0) return
if (args.length == 0) {
return
}
let disabled = 0
for (const arg of args) {
if (!manager.disabled.has(arg)) {
Expand All @@ -93,7 +98,9 @@ export function managerModule(manager: ModuleManager): Module {
})
}),
new CommandHandler('enable', async (_client, event, args) => {
if (args.length == 0) return
if (args.length == 0) {
return
}
let enabled = 0
for (const arg of args) {
if (manager.disabled.has(arg)) {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export async function whois(
} else {
whois += 'Could not resolve whois'
}
if (escape_) whois = escape(whois)
if (escape_) {
whois = escape(whois)
}
return whois
}

Expand Down
14 changes: 10 additions & 4 deletions src/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const util: Module = {
new CommandHandler(
'shell',
async (_client, event, args, input) => {
if (args.length < 1) return
if (args.length < 1) {
return
}
const command = args[0]
args = args.slice(1)
let { text } = event.message
Expand All @@ -34,16 +36,18 @@ const util: Module = {
const proc = exec(text, (_err, stdout, stderr) => {
wrap(async () => {
await displayPid
if (stdout.length > 0 && stdout.length <= 4096)
if (stdout.length > 0 && stdout.length <= 4096) {
await event.message.reply({
message: pre(stdout),
parseMode: 'html'
})
if (stderr.length > 0 && stderr.length <= 4096)
}
if (stderr.length > 0 && stderr.length <= 4096) {
await event.message.reply({
message: pre(stderr),
parseMode: 'html'
})
}
})
}).on('exit', code => {
wrap(async () => {
Expand Down Expand Up @@ -155,7 +159,9 @@ const util: Module = {
}
}
}
if (info.length == 0) return
if (info.length == 0) {
return
}
await event.message.edit({
text: event.message.text + '\n\n' + info,
parseMode: 'html'
Expand Down