-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
57 lines (43 loc) · 1.49 KB
/
main.py
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
from discord import Webhook, RequestsWebhookAdapter
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import MessageEntity
import os
import re
from dotenv import load_dotenv
load_dotenv()
from code_carbon import code_command
REGEX_URL = '(https?://\S+)'
def start(update, context):
update.message.reply_text("Hey Flutter Cuba ")
def share_url_callback(update, context):
text_with_url = update.message.text
matches_urls = re.findall(REGEX_URL, text_with_url)
for url in matches_urls:
webhook = Webhook.from_url(
url=os.getenv("DISCORD_WEBHOOK"),
adapter=RequestsWebhookAdapter(),
)
webhook.send(url, username='fluttercuba-bot')
update.message.reply_text("compartiendo url...")
def main():
"""Start the bot."""
updater = Updater(os.getenv("TELEGRAM_TOKEN"))
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(code_command)
url_handler = MessageHandler(
Filters.text & (Filters.entity(MessageEntity.URL) |
Filters.entity(MessageEntity.TEXT_LINK)),
share_url_callback)
dp.add_handler(url_handler)
updater.start_webhook(
listen="0.0.0.0",
port=os.getenv("PORT"),
url_path=os.getenv("TELEGRAM_TOKEN"),
)
updater.bot.set_webhook(
"https://fluttercubabot.herokuapp.com/" + os.getenv("TELEGRAM_TOKEN"),
)
updater.idle()
if __name__ == '__main__':
main()