-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
91 lines (71 loc) · 2.92 KB
/
main.py
File metadata and controls
91 lines (71 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import asyncio
from pyrogram import Client, filters, idle
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
API_ID = 123456 # put api id here
API_HASH = "" # your telegram acc api hash
BOT_TOKEN = "" # telegram bot token
VTRADING_CHAT_ID = -100123456789 # Replace with your actual group ID
REMINDER_IMAGE_URL = "" #put any image link here(use a online db)
# === Reminder message ===
REMINDER_MESSAGE = (
#put your recurring message here
)
REMINDER_BUTTONS = InlineKeyboardMarkup([
#put buttons below your message here
[
InlineKeyboardButton("🌐 Website", url=""),
],
[
InlineKeyboardButton("𝕏 Twitter", url=""),
InlineKeyboardButton("💬 Discord", url=""),
],
[
InlineKeyboardButton("🔗 Linktree", url="")
]
])
app = Client("vtrading_reminder_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
last_message_id = None # Global variable to store last sent message ID
async def send_reminder_every_hour():
global last_message_id
while True:
try:
# Delete the previous message if it exists
if last_message_id:
try:
await app.delete_messages(chat_id=VTRADING_CHAT_ID, message_ids=last_message_id)
print("[INFO] Previous reminder deleted.")
except Exception as e:
print(f"[WARN] Could not delete previous message: {e}")
# Send new reminder with image
sent_message = await app.send_photo(
chat_id=VTRADING_CHAT_ID,
photo=REMINDER_IMAGE_URL,
caption=REMINDER_MESSAGE,
reply_markup=REMINDER_BUTTONS,
)
print(f"Sent message object type: {type(sent_message)}")
print(f"Sent message: {sent_message}")
message_id = getattr(sent_message, "message_id", None)
if message_id is None:
print("[ERROR] sent_message has no message_id attribute:", sent_message)
else:
last_message_id = message_id
except Exception as e:
print(f"[ERROR] Failed to send reminder: {e}")
await asyncio.sleep(3600)
@app.on_message(filters.command("start_reminder") & filters.user(5906045989))
async def manual_start(client, message):
await message.reply("Reminder loop started!")
asyncio.create_task(send_reminder_every_hour())
@app.on_message(filters.command("id", prefixes="!") & filters.group)
async def get_chat_id(client, message):
await message.reply(f"Chat ID: `{message.chat.id}`")
@app.on_message(filters.command("start") & filters.private)
async def on_start(client, message):
await message.reply("Reminder Bot is running.")
async def main():
async with app:
asyncio.create_task(send_reminder_every_hour())
await idle()
if __name__ == "__main__":
asyncio.run(main())