GithubHelp home page GithubHelp logo

hdcola / telegram-forward-bot Goto Github PK

View Code? Open in Web Editor NEW
12.0 0.0 4.0 95 KB

将你的发言匿名转发到群聊的机器人

License: MIT License

Python 98.68% Shell 1.32%
python-telegram-bot python3 telegram-bot

telegram-forward-bot's Introduction

telegram-forward-bot

将你的发言匿名转发到群聊的机器人

这个机器人的作用就是让群里的人通过机器人说话,目标是:

  • 完全匿名了发言者的信息
  • 规避公共群的个人信息被存档的问题
  • 防止群中有他人的帐号出现问题,泄漏你的个人信息
  • 通过对发出的内容加入顶和踩的功能让大家为匿名发送什么逐渐达成共识
  • 用Bot完成群管理员和Bot管理员的日常设置和操作
  • Bot支持对非普通文本的发言附带可随时定制的反馈投票按钮

注意,一个帐户注册后,你的userid是永远不变的,所以telegram并不真正安全。

我的机器人都运行在RaspberryPi上,可以来 https://t.me/RaspberryPiCN 讨论机器人的使用和有关RaspberryPi的内容。

安装

建议使用venv环境,本项目必须使用Python3,本人不打算再在Python2中做任何测试

python3 -m venv py3
source py3/bin/activate
pip install python-telegram-bot

使用

mkdir -p ~/.config/forwardbot/

将项目中的config.json复制到这个目录中。你也可以把配置文件放到你自己喜欢的地方。

配置

config.json中配置你的信息

{
    "Admin": 0,                   // 管理员用户ID(通常为8~9位数字)
    "Token": "",                  // Bot的Token
    "Feedback": false,            // 是否打开转发时的Feedback
    "Update_shell": "",           // 执行升级的脚本路径,用以支持 /update 命令
    "Restart_shell": "",          // 执行重启服务的脚本路径,用以支持 /restart 命令
    "Publish_Group_ID": []        // 群ID(如:@channel)列表
}

有几种典型的使用方法:

  • Admin/Publish_Group_ID相同时,你就可以做最简单的测试
  • 可以在Publish_Group_ID中加入多个群或频道,这时发送的内容会发到多个你指定的频道里去,列表支持数字、字符串混合

管理员命令

当你是Publish_Group_ID中第一个群的管理员时,你可以向Bot发送以下管理指令

  • /help 显示帮助
  • /feedbackon 关闭所有匿名发送的反馈
  • /feedbackoff 打开所有匿名发送的反馈

当你是Bot管理员时,你可以向Bot发送以下管理指令

  • /Admin Bot重启、查看配置、升级更新等功能
  • /setfeedback 设置反馈按钮,每个按钮的文字用逗号分开
  • /setanswer 设置反馈按钮按下后的提示信息,应该和铵钮数量相同,用逗号分开

运行

手工运行

python main.py

会从~/.config/forwardbot/目录中读取配置文件和存取data。

也可以使用

python main.py -c /usr/local/etc/forwardbot

来指定配置文件和data的存储路径。

配置systemd运行

在你的venv或Python环境中安装systemd支持,你需要提前确认一下你的操作系统是不是支持systemd。

pip install systemd-python

修改forwardbot_service.service中的内容

[Unit]
## 修改为你的说明
Description=Telegram Forward Bot Service

[Service]
## 修改venv和main.py以及config.json目录的路径
ExecStart=/usr/bin/python path/to/your/main.py -c /home/pi/fbot/tssd
Restart=on-failure
Type=notify

[Install]
WantedBy=default.target

先将forwardbot_service.service文件放入~/.config/systemd/user/然后使用以下命令

查看所有的service配置

systemctl --user list-unit-files 

确定识别后,重新加载一下配置(每次更新service文件后都需要重新加载)

systemctl --user daemon-reload

启动/停止/查看/重启 service

systemctl --user start forwardbot_service
systemctl --user stop forwardbot_service
systemctl --user status forwardbot_service
systemctl --user restart forwardbot_service

可以查看服务的output

journalctl --user-unit forwardbot_service

如果一切正常,先enable service,再打开当前用户的开机启动

systemctl --user enable forwardbot_service
sudo loginctl enable-linger $USER

如果你不想放到你的用户下运行,可以放到System中。测试都正常后,执行以下操作

sudo mv ~/.config/systemd/user/forwardbot_service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/forwardbot_service
sudo chmod 644 /etc/systemd/system/forwardbot_service
sudo systemctl daemon-reload
sudo systemctl enable forwardbot_service
sudo systemctl start forwardbot_service

感谢

telegram-forward-bot's People

Contributors

hdcola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.