简体   繁体   English

恢复和暂停 python 脚本(电视节目)

[英]Resume and pause python script (telethon)

I apologize from the start for my English...我从一开始就为我的英语道歉...

Hello, I'm a little new, rather what I did here is my best and greatest work.你好,我有点新,我在这里所做的是我最好和最伟大的工作。 Of course I did not do it on my own, I was inspired by many other works, Forums, Forums and forums.当然我不是自己做的,我受到了许多其他作品的启发,论坛、论坛和论坛。 In the program below, if it can be called a program.在下面的程序中,如果它可以称为程序。 I need to do, say, a little "pause" and "continue" system if I can.如果可以的话,我需要做一些“暂停”和“继续”系统。 I would do this myself, but I have no idea how, I spent half a day, trying various methods.我自己会这样做,但我不知道如何,我花了半天时间,尝试了各种方法。 I think it was working, or not, I don't know... For example, I put that when the program stops to print me "paused" and when it starts back to write "continuing"... But that's all that was going on after we added this system... Because the program wasn't working... And I don't know where I'm wrong... If anyone can help me, I'd be grateful... And if you can, tell me where to add that piece of program.我认为它是否有效,我不知道......例如,我把它当程序停止打印我“暂停”并且当它开始写“继续”时......但仅此而已在我们添加这个系统后正在继续......因为程序无法运行......而且我不知道我错在哪里......如果有人可以帮助我,我将不胜感激......并且如果可以,请告诉我在哪里添加该程序。 In the middle, at the beginning or at the end.在中间,在开头或结尾。 As far as you can see, there are quite a few imported things... And I'm not even sure if I need most of them... The only library imported by me is Regex "re":).正如你所看到的,有很多导入的东西......而且我什至不确定我是否需要它们中的大部分......我导入的唯一库是Regex“re”:)。

import re
from telethon import TelegramClient, sync, events
from telethon.tl.types import Channel
from telethon.tl.types import ChatForbidden
from telethon.tl.types import InputPeerChat
from telethon.tl.functions.messages import SendMessageRequest
from telethon.tl.types import PeerUser, PeerChat, PeerChannel


api_id = *******
api_hash = '***************************'

client = TelegramClient('Test', api_id, api_hash).start()

#entity_v2 = client.get_entity('searaseara') #Success

me = client.get_me()   
#print(me.stringify())


@client.on(events.NewMessage(incoming=True, pattern=r'\d*\s*\bне выкуплено\b.*\b1CALL\b|\d*\s*\bотправлено\b.*\b1CALL\b|\d*\s*\bоплачено\b.*\b1CALL\b|\d*\s*\bнекорректный\b.*\b1CALL\b|\d*\s*\bотменено\b.*\b1CALL\b|\d*\s*\bвыкуплено\b.*\b1CALL\b|\d*\s*\bотказ\b.*\b1CALL\b|Пропущеный звонок с номера\b'))
async def handler(event):
    await event.respond(message="+")

client.run_until_disconnected()

Just use python simple if只需使用 python 简单如果

s = off
if s == "on":
    #Do_sth

and you can control this(turning on or off) with getting message from your client(telegram)并且您可以通过从您的客户(电报)获取消息来控制它(打开或关闭)

@client.on(events.NewMessage(pattern="turn"))
async def handler(event):
    txt = event.raw_text
    global s
    if txt == "turnon":
        s = "on"
    if txt == "turnoff":
        s = "off"

In the meantime, I found a little Solution, How can I pause the program and get it to continue, only it's a little problem.与此同时,我找到了一个小解决方案,我怎样才能暂停程序并让它继续,只是它是一个小问题。 For example, this program responds with "+" to messages containing the words in the pattern... But if in the meantime, the program is paused, and more messages come in, which the program usually should have responded to, for example 2, 3, 4, 5 and so on, when I take it out of the pause, it sends pluses for each message... For example, the program responds to the message "123" with "+".例如,该程序对包含模式中单词的消息以“+”响应......但是如果在此期间程序暂停,并且有更多消息进入,程序通常应该响应,例如 2 , 3, 4, 5 等等,当我把它从暂停中取出时,它会为每条消息发送加号......例如,程序用“+”响应消息“123”。 A small example below how the program usually works:下面是该程序通常如何工作的一个小示例:

  1. Sender: 123发件人:123
  2. Me:+我:+
  3. Sender: 123发件人:123
  4. Me:+我:+
  5. Sender: 123发件人:123
  6. Me:+我:+
  7. Sender: 123发件人:123
  8. Me:+我:+
  9. Sender: 123发件人:123
  10. Me:+我:+

Another example when the program is on pause then I remove it from pause after receiving a few messages:另一个例子是程序处于暂停状态,然后我在收到几条消息后将其从暂停中删除:

  1. Sender: 123发件人:123
  2. Sender: 123发件人:123
  3. Sender: 123发件人:123
  4. Sender: 123发件人:123
  5. Sender: 123发件人:123
  6. Sender: 123发件人:123
  7. Sender: 123发件人:123
  8. Me:+我:+
  9. Me:+我:+
  10. Me:+我:+
  11. Me:+我:+
  12. Me:+我:+
  13. Me:+我:+
  14. Me:+我:+
import re
from telethon import TelegramClient, sync, events
from telethon.tl.types import Channel
from telethon.tl.types import ChatForbidden
from telethon.tl.types import InputPeerChat
from telethon.tl.functions.messages import SendMessageRequest
from telethon.tl.types import PeerUser, PeerChat, PeerChannel


api_id = 5531856
api_hash = '94a4bf4ea16117ddf5dc5ffa61d54dbf'


###################################################
#I added this section
def debug_signal_handler(signal, frame):
    import pdb
    pdb.set_trace()
import signal
signal.signal(signal.SIGINT, debug_signal_handler)
###################################################








client = TelegramClient('Test', api_id, api_hash).start()

#entity_v2 = client.get_entity('searaseara') #Success

me = client.get_me()   
print(me.stringify())



@client.on(events.NewMessage(incoming=True, pattern=r'\d*\s*\bне выкуплено\b.*\b1CALL\b|\d*\s*\bотправлено\b.*\b1CALL\b|\d*\s*\bоплачено\b.*\b1CALL\b|\d*\s*\bнекорректный\b.*\b1CALL\b|\d*\s*\bотменено\b.*\b1CALL\b|\d*\s*\bвыкуплено\b.*\b1CALL\b|\d*\s*\bотказ\b.*\b1CALL\b|Пропущеный звонок с номера\b'))
async def handler(event):
    await event.respond(message="+")


client.run_until_disconnected()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM