MY HAOSE BLOG!!!

使用Telegram-cli 自动发消息。。。

使用Telegram-cli 自动发消息

如今越来越多的网站使用Telegram Bot签到,telegram-cli 是一个Telegram的非官方客户端,可以实现在终端中访问Telegram,本文使用telegram-cli+crontab完成了自动签到  #### 在 CentOS 下安装 telegram-cli

快速编译安装



cd ~/
git clone --recursive https://github.com/vysheng/tg.git && cd tg
yum install jansson-devel lua-devel readline-devel libconfig-devel libevent-devel
./configure
make

将编译生成的bin/telegram-clitg-server.pub移动到同一目录下,这里创建一个mytg目录 > 不必在 https://my.telegram.org/apps 上获取publickey,除非此项目自带的key已经过时

mkdir mytg
cp bin/telegram-cli mytg/
cp tg-server.pub mytg/
cd mytg

mytg中创建telegram.config配置文件,并放入以下内容

vim telegram.config
default_profile = "mytg";

mytg = {
   config_directory = "./";
};

运行telegram-cli

./telegram-cli -k tg-server.pub -c telegram.config

   这里使用一个脚本文件来快速发送消息,新建~/tg/mytg/telegram_standalone.sh

vim ~/tg/mytg/telegram_standalone.sh
#!/bin/bash

MAIN_DIRECTORY="/root/tg/mytg/"
USER=$1
SUBJECT=$2
TEXT=$3

cd $MAIN_DIRECTORY
if [[ $? -ne 0 ]]; then
       echo "Error to enter in the main directory"
       exit 1
fi

./telegram-cli -k tg-server.pub -c telegram.config -WR -e "msg $USER $SUBJECT" || exit 1

exit 0

修改脚本权限

chmod +x ~/tg/mytg/telegram_standalone.sh

修改系统时区

如果使用国外VPS执行crontab定期任务,务必修改时区并重启crontab服务

修改为北京时区

ntpdate -u cn.pool.ntp.org
timedatectl set-timezone Asia/Shanghai

重启crontab服务

service crond restart

新建crontab任务

将vim设为默认文本编辑器

export VISUAL=vim

export EDITOR=vim

新建crontab任务,运行

crontab -e

将打开vim,进入Insert编辑模式,放入以下内容

* 10 * * * /root/tg/mytg/telegram_standalone.sh username 签到

其中,username 可修改为Telegram中任意Bot的id,签到 为向该Bot发送的签到指令,可任意修改,以上脚本每天上午10点会自动执行。

运行crontab -l 可查看目前创建的crontab任务。

假如你的账号添加了太多Telegram群组,telegram-cli可能无法接收/发送所有消息,可以使用dialog_list来加载会话列表或使用-w参数启动telegram-cli,使程序启动后会话列表先加载再发出信息。

关于telegram-cli更多的启动参数详见 https://github.com/vysheng/tg/wiki/Telegram-CLI-Arguments

Supported commands

Messaging

  • msg <peer> Text - sends message to this peer

  • fwd <user> <msg-seqno> - forward message to user. You can see message numbers starting client with -N

  • chat_with_peer <peer> starts one on one chat session with this peer. /exit or /quit to end this mode.

  • add_contact <phone-number> <first-name> <last-name> - tries to add contact to contact-list by phone

  • rename_contact <user> <first-name> <last-name> - tries to rename contact. If you have another device it will be a fight

  • mark_read <peer> - mark read all received messages with peer

  • delete_msg <msg-seqno> - deletes message (not completly, though)

  • restore_msg <msg-seqno> - restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion

Multimedia

  • send_photo <peer> <photo-file-name> - sends photo to peer

  • send_video <peer> <video-file-name> - sends video to peer

  • send_text <peer> <text-file-name> - sends text file as plain messages

  • load_photo/load_video/load_video_thumb/load_audio/load_document/load_document_thumb <msg-seqno> - loads photo/video/audio/document to download dir

  • view_photo/view_video/view_video_thumb/view_audio/view_document/view_document_thumb <msg-seqno> - loads photo/video to download dir and starts system default viewer

  • fwd_media <msg-seqno> send media in your message. Use this to prevent sharing info about author of media (though, it is possible to determine user_id from media itself, it is not possible get access_hash of this user)

  • set_profile_photo <photo-file-name> - sets userpic. Photo should be square, or server will cut biggest central square part

Group chat options

  • chat_info <chat> - prints info about chat

  • chat_add_user <chat> <user> - add user to chat

  • chat_del_user <chat> <user> - remove user from chat

  • rename_chat <chat> <new-name>

  • create_group_chat <chat topic> <user1> <user2> <user3> ... - creates a groupchat with users, use chat_add_user to add more users

  • chat_set_photo <chat> <photo-file-name> - sets group chat photo. Same limits as for profile photos.

Search

  • search <peer> pattern - searches pattern in messages with peer

  • global_search pattern - searches pattern in all messages

Secret chat

  • create_secret_chat <user> - creates secret chat with this user

  • visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one

  • set_ttl <secret_chat> <ttl> - sets ttl to secret chat. Though client does ignore it, client on other end can make use of it

  • accept_secret_chat <secret_chat> - manually accept secret chat (only useful when starting with -E key)

Stats and various info

  • user_info <user> - prints info about user

  • history <peer> [limit] - prints history (and marks it as read). Default limit = 40

  • dialog_list - prints info about your dialogs

  • contact_list - prints info about users in your contact list

  • suggested_contacts - print info about contacts, you have max common friends

  • stats - just for debugging

  • show_license - prints contents of GPLv2

  • help - prints this help

  • get_self - get our user info

Card

  • export_card - print your 'card' that anyone can later use to import your contact

  • import_card <card> - gets user by card. You can write messages to him after that.

Other

  • quit - quit

  • safe_quit - wait for all queries to end then quit


打赏

0分/0个投票

TOP


评论列表


发表评论
来宾的头像

«   2024年6月   »
12
3456789
10111213141516
17181920212223
24252627282930
TOP 搜索
TOP 控制面板
您好,欢迎到访网站!
  [查看权限]
TOP 网站分类
TOP 热门评分
TOP 最高评分
TOP 最新评分
TOP 你好,朋友
真是美好的一天!
TOP 站点信息
  • 文章总数:5538
  • 页面总数:3
  • 分类总数:4
  • 标签总数:6
  • 评论总数:36
  • 浏览总数:8188776
返回顶部
haose888
返回顶部