Skip to content

Instantly share code, notes, and snippets.

@poeti8
Created April 25, 2021 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poeti8/133796200d66049c9bd58e6265a52f68 to your computer and use it in GitHub Desktop.
Save poeti8/133796200d66049c9bd58e6265a52f68 to your computer and use it in GitHub Desktop.
the-guard-banfiles-plugin
'use strict';
const Composer = require('telegraf/composer');
const blacklisted_files = [ 'apk', 'exe', 'scr', 'bat', 'cmd', 'vbs', 'pif' ];
module.exports = Composer.mount('document', (ctx, next) =>
ctx.from.status !== 'admin' &&
blacklisted_files.includes(
ctx.message.document.file_name.split('.').pop())
? Promise.all([
ctx.ban({
admin: ctx.botInfo,
reason: 'Blacklisted file.',
userToBan: ctx.from }),
ctx.deleteMessage() ])
: next());
@Mrs-Feathers
Copy link

Mrs-Feathers commented Jul 23, 2022

Hello! how can i update this for the updated version of the bot? when added, it just says there is a problem with composer. however, the other plugin you made called captcha.ts works perfectly. infact, that plugin is the only one that works period and is very hard to read so i am unable to help by making other plugins. the plugin wiki seems to be out of date as well, so as a beginner programmer, i'm not sure where to go to proceed. its possible i could help if you were able to write a very basic plugin such as a welcome script to welcome someone when they join. with that, i could figure out how the bot works and be able to help more with porting all known plugins i have stored for this bot over to the new version. any help would be appreciated.

@Mrs-Feathers
Copy link

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './composer' is not defined by "exports" in /root/the-guard-bot/node_modules/telegraf/package.json
at new NodeError (node:internal/errors:387:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:439:9)
at packageExportsResolve (node:internal/modules/esm/resolve:718:3)
at resolveExports (node:internal/modules/cjs/loader:493:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:533:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/root/the-guard-bot/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1022:19)
at require (node:internal/modules/cjs/helpers:102:18) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

@MKRhere
Copy link

MKRhere commented Aug 18, 2022

Fix:

const { Composer } = require("telegraf");

Telegraf no longer allows importing from internal paths that aren't explicitly exported.

@C0rn3j
Copy link

C0rn3j commented Sep 18, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment