Code Monkey home page Code Monkey logo

telegram-captcha-bot's Introduction

Telegram-CAPTCHA-bot

English

一个 Telegram 机器人,通过点按钮的方式来判断加群者是否为真人。

如何使用

配置环境

需要 Python 3.7 和 Telethon 1.7.1 来运行机器人。如果你需要让机器人通过 SOCKS5 代理运行,还需要安装 PySocks

另外,你需要向 @BotFather 申请一个 Telegram 机器人的 token,并按照 Telegram 官网的步骤 申请 api_id 和 api_hash。

如果不申请 api_id 或 api_hash,也可以使用 archive 分支的方案,安装 Python 3.6+ 和 python-telegram-bot 的 的环境,并申请机器人 token。需要注意的是,这个方案无法做到在通过验证解封时回复到加群之前的封禁状态,因此无法防止被限制权限者退群重新加群来恢复权限的行为。这是因为 python-telegram-bot 库提供的 restrictChatMember 函数可选择的权限与人类的并不完全一致。

安装并运行

git clone https://github.com/lziad/Telegram-CAPTCHA-bot 
cd Telegram-CAPTCHA-bot
python3 -m venv ./venv
source ./venv/bin/activate
pip3 install -r requirements.txt
cp config.example.js config.json

之后修改 config.json,填入 tokenapi_idapi_hash 并根据需要修改群组设定,并去除所有注释行。完成后运行 main.py 即可,例如

nohup python3 main.py &

建议

  • Telethon 库使用 MTProto 协议直接向 Telegram 的服务器发送请求,后者的位置取决于申请 api_id 的账户所在区域(例如大多数亚洲用户位于 DC5,服务器位于新加坡)。如果条件允许,将机器人程序放在对应位置的服务器运行可以显著加快速度,参见官方文档
  • 有一些广告机器人会自动点击按钮。如果你的群组频繁被这类机器人*扰,可以考虑在 config.json 中设置 challenge_strict_modetrue。此时需要用户答对题目才能获得解封,如果答错封禁则不会解除。超时后的行为仍由 challenge_timeout_action 决定。别忘了把 msg_self_introduction 里“我比较仁慈……”云云的句子删掉。

开源协议

本项目使用 MIT 协议,原文见此处

致谢

感谢 Telegram 的开放性为这个项目带来的诸多便利。另外,如果没有那么多广告机器人,绝不会有这个项目,因此这个项目的诞生也要感谢那些坚持不懈、夜以继日发广告的机器人。

telegram-captcha-bot's People

Contributors

borschts avatar dependabot[bot] avatar fossifer avatar guanchishan avatar peterdavehello avatar scp-2000-wikimedia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

telegram-captcha-bot's Issues

关于删除验证消息问题

经过测试,在开启严格模式下,如果选择了错误的答案,验证消息不会超时自动删除,并且一律执行 “restrict” 操作,不会按照用户定义的 “challenge_timeout_action” 执行。

粵語翻譯唔正

應該係「本群開入群驗證」定係「本群開入群驗證」,而
唔係「本群開 左 入群驗證」。唔該修正

TypeError 导致bot不工作

部署完成并赋予了bot管理员权限后,当新用户通过invatation link进入group的时候bot不响应,此时python控制台输出的错误是

Traceback (most recent call last):
  File "/home/x/apps/Telegram-CAPTCHA-bot/venv/lib/python3.7/site-packages/telethon/client/updates.py", line 422, in _dispatch_update
    await callback(event)
  File "main.py", line 72, in challenge_user
    member = await bot(GetParticipantRequest(chat, target))
  File "/home/x/apps/Telegram-CAPTCHA-bot/venv/lib/python3.7/site-packages/telethon/client/users.py", line 34, in __call__
    await r.resolve(self, utils)
  File "/home/x/apps/Telegram-CAPTCHA-bot/venv/lib/python3.7/site-packages/telethon/tl/functions/channels.py", line 806, in resolve
    self.channel = utils.get_input_channel(await client.get_input_entity(self.channel))
  File "/home/x/apps/Telegram-CAPTCHA-bot/venv/lib/python3.7/site-packages/telethon/utils.py", line 248, in get_input_channel
    _raise_cast_fail(entity, 'InputChannel')
  File "/home/x/apps/Telegram-CAPTCHA-bot/venv/lib/python3.7/site-packages/telethon/utils.py", line 133, in _raise_cast_fail
    type(entity).__name__, target))
TypeError: Cannot cast InputPeerChat to any kind of InputChannel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.