2
私はPythonでボットを書きました。 定期的に動作を停止します。 仮想マシンは安定して動作します。 実行中のサービスは常にアクティブです。 Azureのサービス上の仮想マシン上のhttps://github.com/eternnoir/pyTelegramBotAPI私の電報はPythonで動作していません
ワークス(Ubuntuの16.04.5) -
私はこのライブラリを使用しています。
# -*- coding: utf-8 -*-
import re
import config
import telebot
bomg = "Бомж"
regRusLetters = re.compile("^[а-яА-Яё]+$")
bot = telebot.TeleBot(config.token)
def second_vowels(text):
pos = 0
i = 1
while i < len(text):
if text[i] in "ауоыиэяюёе":
pos = i
break
i = i + 1
return pos
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Пришли мне слово на Русском и я его бомжирую!")
@bot.message_handler(content_types=["text"])
def repeat_all_mesages(message):
response = "не могу бомжировать..."
text = message.text.lower()
if re.match(regRusLetters, text):
pos = second_vowels(text)
response = bomg + text[pos:]
bot.send_message(message.chat.id, response)
bot.polling(none_stop=True)
にsystemdを使用してサービスとして構成:
は、ここでのPythonスクリプトコードです。ここでbot.serviceファイルは次のとおりです。
[Unit]
Description=TelegramBot
After=network.target
[Service]
Type=idle
ExecStart=/usr/bin/python3.5 /home/rhanza/TelegramBot/bot.py
Restart=always
[Install]
WantedBy=multi-user.target
私は、SSLを介して接続し、プロセスの状態を確認すると、私は以下を参照してください。
status bot.service
● bot.service - TelegramBot
Loaded: loaded (/etc/systemd/system/bot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-12-16 21:06:31 UTC; 3min 8s ago
Main PID: 3823 (python3.5)
Tasks: 4
Memory: 19.2M
CPU: 930ms
CGroup: /system.slice/bot.service
└─3823 /usr/bin/python3.5 /home/rhanza/TelegramBot/bot.py &
Dec 16 21:06:31 botholder1 systemd[1]: bot.service: Service hold-off time over, scheduling restart.
Dec 16 21:06:31 botholder1 systemd[1]: Stopped TelegramBot.
Dec 16 21:06:31 botholder1 systemd[1]: Started TelegramBot.
ボットは常にものの、メッセージに応答しませんサービスは安定しています。 理由は何か、問題の解決方法はわかりません。 誰かが答えを伝えることはできますか?
ポイントを把握し、最小限のコード – Sean