如何使用电报-cli从电报中的超级组中删除帖子? [英] How can I delete a post from a supergroup in telegram with telegram-cli?

查看:69
本文介绍了如何使用电报-cli从电报中的超级组中删除帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个电报群,我们有一个规则说在早上 23 点到 7 点之间没有人必须在群里留言,我想删除这些时间之间的群消息.谁能告诉我如何使用电报 cli 或任何其他电报客户端来做到这一点?

we have a group in telegram and we have a rule says no one must leave a message in group between 23 to 7 am , I wanna delete messages comes to group between these times automatically . could anyone tell me how I can do that with telegram cli or any other telegram client?

推荐答案

使用新版本的 telegram-cli.它不是完全开源的,但您可以从其站点下载二进制文件.你也可以在那里找到一些例子.

Use new version of telegram-cli. It's not fully open source, but you can download a binary from its site. Also you can find some examples there.

我希望以下 JavaScript 代码段能帮助您实现目标.

I hope the following snippet in JavaScript will help you to achieve your goal.

var spawn = require('child_process').spawn;
var readline = require('readline');

// delay between restarts of the client in case of failure
const RESTARTING_DELAY = 1000;

// the main object for a process of telegram-cli
var tg;

function launchTelegram() {
  tg = spawn('./telegram-cli', ['--json', '-DCR'],
             { stdio: ['ipc', 'pipe', process.stderr] });
  readline.createInterface({ input: tg.stdout }).on('line', function(data) {
    try {
      var obj = JSON.parse(data);
    } catch (err) {
      if (err.name == 'SyntaxError') {
        // sometimes client sends not only json, plain text process is not
        // necessary, just output for easy debugging
        console.log(data.toString());
      } else {
        throw err;
      }
    }
    if (obj) {
      processUpdate(obj);
    }
  });
  tg.on('close', function(code) {
    // sometimes telegram-cli fails due to bugs, then try to restart it
    // skipping problematic messages
    setTimeout(function(tg) {
      tg.kill(); // the program terminates by sending double SIGINT
      tg.kill();
      tg.on('close', launchTelegram); // start again for updates
                                      // as soon as it is finished
    }, RESTARTING_DELAY, spawn('./telegram-cli', { stdio: 'inherit' }));
  });
}

function processUpdate(upd) {
  var currentHour = Date.now().getHours();
  if (23 <= currentHour && currentHour < 7 &&
      upd.ID='UpdateNewMessage' && upd.message_.can_be_deleted_) {
    // if the message meets certain criteria, send a command to telegram-cli to
    // delete it
    tg.send({
      'ID': 'DeleteMessages',
      'chat_id_': upd.message_.chat_id_,
      'message_ids_': [ upd.message_.id_ ]
    });
  }
}

launchTelegram(); // just launch these gizmos

我们通过 --json 键激活 JSON 模式.telegram-cli 将下划线附加到对象中的所有字段.查看完整架构中的所有可用方法.

We activate JSON mode passing --json key. telegram-cli appends underscore to all fields in objects. See all available methods in full schema.

这篇关于如何使用电报-cli从电报中的超级组中删除帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆