Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
2.0 kB
2
Indexable
Never
# функция отправки поста
def send_post(bot, db, post, group, i, captcha_sid=None, captcha_key=None):
	check = None
	log = None
	text = post["text"]
	date = time.ctime(time.time())
	if "wall" in group:
		try: check = bot.method("wall.post", {
			"owner_id": f"-{group['id']}",
			"message": text,
			"attachments": post["attachments"],
			"captcha_sid": captcha_sid,
			"captcha_key": captcha_key
		})
		except Captcha as captcha: solve_captcha(captcha, bot, db, post, group, i)
		except Exception as e: log = f"Ошибка: {e}, группа: {group['id']}"
	elif "topic" in group:
		try: check = bot.method("board.createComment", {
			"group_id": group["id"],
			"topic_id": group["topic"],
			"message": text,
			"attachments": post["attachments"],
			"captcha_sid": captcha_sid,
			"captcha_key": captcha_key
		})
		except Captcha as captcha: solve_captcha(captcha, bot, db, post, group, i)
		except Exception as e: log = f"Ошибка: {e}, группа: {group['id']}, топик: {group['topic']}"
	elif "post" in group:
		try: check = bot.method("wall.createComment", {
			"owner_id": f"-{group['id']}",
			"post_id": group["post"],
			"message": text,
			"attachments": post["attachments"],
			"captcha_sid": captcha_sid,
			"captcha_key": captcha_key
		})
		except Captcha as captcha: solve_captcha(captcha, bot, db, post, group, i)
		except Exception as e: log = f"Ошибка: {e}, группа: {group['id']}, пост: {group['post']}"
	if check != None:
		if "wall" in group: post_type = f"пост {check['post_id']}"
		elif "topic" in group: post_type = f"коммент в топике {group['topic']}"
		elif "post" in group: post_type = f"коммент под постом {check['comment_id']}"
		log = f"{i}. Дата: {date}, бот: {db['name1']}, тип: {post_type}, группа: {group['id']}, id объявления: {post['id']}, раздел: {post['chapter']}"
	print(log)
	add_log(log)
Leave a Comment