-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
120 lines (63 loc) · 3.09 KB
/
bot.py
File metadata and controls
120 lines (63 loc) · 3.09 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from email import message
import logging
import os
import redditscraper
from telegram import InputMediaPhoto, __version__ as TG_VER
from dotenv import load_dotenv
load_dotenv()
try:
from telegram import __version_info__
except ImportError:
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, "
f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
)
from telegram import ForceReply, Update
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters, CallbackContext
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)
# Define a few command handlers. These usually take the two arguments update and
# context.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /start is issued."""
user = update.effective_user
await update.message.reply_html(
rf"Hi {user.mention_html()}!",
reply_markup=ForceReply(selective=True),
)
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /help is issued."""
await update.message.reply_text("Help!")
async def getMeme(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /help is issued."""
link_urls = await redditscraper.scan_posts()
medias = []
caption = 'Caption : ' + link_urls[1] + '\nPosted By : ' + link_urls[2]
medias.append(InputMediaPhoto(media=link_urls[0],caption = caption))
await context.bot.send_media_group(chat_id='-1001766901487', media=medias )
# await context.bot.send_document(chat_id = update.message.chat_id, document=links)
async def callback_minute(context: CallbackContext):
link_urls = await redditscraper.scan_posts()
medias = []
caption = '✍Title : ' + link_urls[1] + '\n🧒Posted By : ' + link_urls[2] + '\n\n👉@linuxmeme'
medias.append(InputMediaPhoto(media=link_urls[0],caption = caption))
await context.bot.send_media_group(chat_id='-1001478693451', media=medias )
# await context.bot.send_message(chat_id='-1001766901487', text='One message every minute')
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Echo the user message."""
await context.bot.send_message(chat_id=-1001766901487, text="I'm sorry Dave I'm afraid I can't do that.")
def main() -> None:
"""Start the bot."""
# Create the Application and pass it your bot's token.
application = Application.builder().token(os.environ.get('TELEGRAM_API')).build()
job_queue = application.job_queue
job_minute = job_queue.run_repeating(callback_minute, interval=86400, first=10)
application.run_polling()
if __name__ == "__main__":
main()