1
1
import http .client
2
2
import logging
3
3
4
- from telegram import Update , ParseMode
5
- from telegram .ext import TypeHandler , CallbackContext , CommandHandler
4
+ from telegram import Update , ParseMode , InlineKeyboardMarkup , InlineKeyboardButton
5
+ from telegram .ext import TypeHandler , CallbackContext , CommandHandler , MessageHandler , Filters
6
6
7
7
from bot import settings
8
8
from bot .const import TELEGRAM_BOT_TOKEN , DATABASE_FILE
9
9
from bot .github import GithubHandler
10
+ from bot .githubapi import github_api
10
11
from bot .githubupdates import GithubUpdate , GithubAuthUpdate
11
12
from bot .menu import reply_menu
12
13
from bot .persistence import Persistence
13
14
from bot .text import HELP_ADD_REPO
15
+ from bot .utils import decode_first_data_entity , deep_link , reply_data_link_filter
14
16
from bot .webhookupdater import WebhookUpdater
15
17
16
18
http .client .HTTPConnection .debuglevel = 5
@@ -61,6 +63,37 @@ def test_handler(update: Update, context: CallbackContext):
61
63
pass
62
64
63
65
66
+ def reply_handler (update : Update , context : CallbackContext ):
67
+ msg = update .effective_message
68
+
69
+ if msg .text [0 ] == '!' :
70
+ return
71
+
72
+ data = decode_first_data_entity (msg .reply_to_message .entities )
73
+
74
+ if not data :
75
+ return
76
+
77
+ issue_type , repo , number , author = data
78
+
79
+ access_token = context .user_data .get ('access_token' )
80
+
81
+ if not access_token :
82
+ msg .reply_text (f'Cannot reply to { issue_type } , since you are not logged in. '
83
+ f'Press button below to go to a private chat with me and login.\n \n '
84
+ f'<i>This message will self destruct in 30 sec.</i>' ,
85
+ reply_markup = InlineKeyboardMarkup ([[
86
+ InlineKeyboardButton ('Login' , url = deep_link (context .bot , 'login' ))
87
+ ]]),
88
+ parse_mode = ParseMode .HTML )
89
+ return
90
+
91
+ if issue_type == 'issue' :
92
+ text = f'@{ author } { msg .text_markdown } '
93
+
94
+ github_api .add_issue_comment (repo , number , text , access_token = access_token )
95
+
96
+
64
97
if __name__ == '__main__' :
65
98
persistence = Persistence (DATABASE_FILE )
66
99
updater = WebhookUpdater (TELEGRAM_BOT_TOKEN ,
@@ -78,6 +111,9 @@ def test_handler(update: Update, context: CallbackContext):
78
111
dp .add_handler (CommandHandler ('login' , login_handler ))
79
112
dp .add_handler (CommandHandler ('test' , test_handler ))
80
113
114
+ dp .add_handler (MessageHandler (Filters .reply & reply_data_link_filter , reply_handler ,
115
+ channel_post_updates = False , edited_updates = False ))
116
+
81
117
settings .add_handlers (dp )
82
118
83
119
github_handler = GithubHandler (dp )
0 commit comments