Прошу помочь, я с этим уже два часа вожусь
Terminated by other getupdates request; make sure that only one bot instance is running
from threading import Lock
class ResourceContainer:
_instance = None
_lock = Lock()
def __new__(cls):
with cls._lock:
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
def __init__(self):
self._db_connection = None
self._message_broker_connection = None
self._config = {}
def get_db_connection(self):
return self._db_connection
def set_db_connection(self, connection):
self._db_connection = connection
def get_message_broker_connection(self):
return self._message_broker_connection
def set_message_broker_connection(self, connection):
self._message_broker_connection = connection
def get_config(self):
return self._config
def set_config(self, config):
self._config = configdef foo():
container = ResourceContainer()
db_conn = container.get_db_connection()
# use db_conn
def bar():
container = ResourceContainer()
config = container.get_config()
# use configimport time
import logging
from aiogram import Bot, Dispatcher, executor, types
TOKEN = ""
bot = Bot(token=TOKEN)
dp = Dispatcher(bot=bot)
text_for_user = "Напоминаю - 123, {})"
@dp.message_handler(commands = ["start"])
async def start_handler(message: types.message):
user_name = message.from_user.first_name
user_id = message.from_user.id
user_full_name - message.from_user.full_name
logging.info(f'{user_id=} {user_full_name=} {time.asctime()}')
await message.reply(f"123, {user_full_name}")
for i in range(10):
time.sleep(2)
await bot.send_message(user_id, text_for_user.format(user_name))
if __name__ == '__main__':
executor.start_polling(dp, skip_updates = True)в качестве базы данных решено было использовать монгу.
async function sendTelegram(send_text) {
var chat_id = '-*****************'; // Номер группы Телеграм
// Токен, бот должен состоять в группе, куда шлем уведомления:
var bot_token = '*******************************************';
var url_obj = new URL('https://api.telegram.org/bot'+bot_token+'/sendMessage');
url_obj.searchParams.set('time', new Date().getTime());
var max_send_count = 3; var send_status = false;
do {
max_send_count--;
try {
var response = await (await fetch(url_obj.href, {
'method': 'POST',
'headers': {
'Content-Type': 'application/json; charset=UTF-8'
},
'body': JSON.stringify({
'chat_id': chat_id,
'text': send_text,
'parse_mode': 'HTML'
})
})).json();
if (response.ok) {
send_status = true;
console.log('Уведомление успешно отправлено в группу Телеграм:');
console.dir(response);
}
else {
console.log('Произошла ошибка при отправке уведомления в группу Телеграм:');
console.dir(response);
await new Promise(function(s) { setTimeout(s, 1000); });
}
}
catch (err) {
console.log('Произошла ошибка при отправке уведомления в группу Телеграм:');
console.error(err);
await new Promise(function(s) { setTimeout(s, 1000); });
}
} while (!send_status && max_send_count > 0);
if (!send_status) {
alert('Не удалось отправить уведомление в Телеграм, детали см. в консоли.');
}
return send_status;
}