Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit b1881a8

Browse files
committed
Merge branch 'develop' into release
2 parents f7f66c9 + 4a4fe7b commit b1881a8

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

BugReporter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import subprocess
3+
import logging
34
from os.path import exists
45

56
class __reporter__:
@@ -24,7 +25,12 @@ def bug(self, tag, message=None, custom_prop={}):
2425
class BugReporter:
2526
def __init__(self, file_path = 'bugs.json'):
2627
if exists(file_path):
27-
self.reports = json.load(open(file_path))
28+
try:
29+
self.reports = json.load(open(file_path, encoding='utf8'))
30+
except Exception as ex:
31+
logging.exception(f'Exception while trying to parse "{file_path}".')
32+
logging.warning('skipping parse bugs file.')
33+
self.reports = dict()
2834
else:
2935
self.reports = dict()
3036
self.file_path = file_path
@@ -36,7 +42,7 @@ def __call__(self, group):
3642
return reporter
3743

3844
def dump(self):
39-
json.dump(self.reports, open(self.file_path, 'w'), indent = 2, ensure_ascii = False)
45+
json.dump(self.reports, open(self.file_path, 'w', encoding='utf8'), indent = 2, ensure_ascii = False)
4046

4147
def dumps(self):
4248
return json.dumps(self.reports, indent = 2, ensure_ascii = False)

default-strings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
],
3131
"time-limit-error": "Sorry, I can not answer you right now because of time limitation between two request, try again 2 mins later.",
3232
"unknown": "Unknown command",
33-
"unknown-msg": "Sorry, I can't chat with anyone right now!"
33+
"unknown-msg": "Sorry, I can't chat with anyone right now!",
34+
"edited-message": "Sorry this bot can not handle edited messages, please resend your message"
3435
},
3536
"fa-ir": {
3637
"welcome": [
@@ -68,6 +69,7 @@
6869
],
6970
"time-limit-error": ".با عرض پوزش اکنون به دلیل محدودیت زمان بین تو درخواست نمی توانم به شما پاسخ دهم. بعد از دو دقیقه مجددا تلاش کنید",
7071
"unknown": "متأسفم، دستوری که وارد کردید صحیح نیست",
71-
"unknown-msg": "!متأسفم، در حال حاضر نمی توانم با کاربران چت کنم"
72+
"unknown-msg": "!متأسفم، در حال حاضر نمی توانم با کاربران چت کنم",
73+
"edited-message": "با عرض پوزش این ربات در حال حاضر از ویرایش پیام پشتیبانی نمی کند"
7274
}
7375
}

main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from telegram.utils.helpers import DEFAULT_NONE
2020
from telegram.bot import Bot
2121
from telegram.ext import *
22+
from telegram.error import NetworkError
2223
from dateutil.parser import parse
2324
from datetime import datetime, timedelta
2425
from threading import Timer
@@ -118,6 +119,14 @@ def __init__(
118119
self.__check__ = True
119120
self.reporter = bug_reporter if bug_reporter else None
120121

122+
def handle_edited_msg(u: Update, c:CallbackContext):
123+
#TODO: Handle editing messages
124+
# Handle messages editing in /send_all could be usefull
125+
# labels: enhancement
126+
u.edited_message.reply_text(self.strings['edited-message'])
127+
128+
self.dispatcher.add_handler(MessageHandler(Filters.update.edited_message,handle_edited_msg))
129+
121130
@self.command
122131
def start(update: Update, _: CallbackContext):
123132
chat = update.effective_chat
@@ -266,8 +275,6 @@ def set_interval(u: Update, c: CallbackContext):
266275
self.interval = int(c.args[0])
267276
self.__set_data__(
268277
'interval', self.interval, self.data_db)
269-
#TODO: exception on message editing
270-
# labels: bug
271278
u.message.reply_text('✅ Interval changed to'+str(self.interval))
272279
return
273280
u.message.reply_markdown_v2('❌ Bad command, use `/set_interval {new interval in seconds}`')
@@ -847,6 +854,9 @@ def error_handler(update: object, context: CallbackContext) -> None:
847854
logging.error(msg = "Exception while handling an update:",
848855
exc_info = context.error)
849856

857+
if type(context.error) is type(NetworkError):
858+
return
859+
850860
# traceback.format_exception returns the usual python message about an exception, but as a
851861
# list of strings rather than a single string, so we have to join them together.
852862
tb_list = traceback.format_exception(
@@ -856,7 +866,7 @@ def error_handler(update: object, context: CallbackContext) -> None:
856866
s = traceback.extract_tb(tb)
857867
f = s[-1]
858868
lineno = f.lineno
859-
filename = f.filename
869+
filename = os.path.basename(f.filename)
860870
exception_type = type(context.error).__name__
861871
if self.reporter:
862872
self.reporter.bug(f'L{lineno}@{filename}: {exception_type}',tb_string, {'line':lineno, 'file':filename})
@@ -1138,7 +1148,7 @@ def index(self):
11381148
max-height: 30%;
11391149
margin: auto;
11401150
background-color: #f39c12;
1141-
color: #641e16;
1151+
color: black;
11421152
border-radius: 10px;
11431153
padding: 10px;
11441154
overflow-x: auto;
@@ -1163,7 +1173,7 @@ def index(self):
11631173
lineno = content['custom-prop']['line']
11641174
filename = content['custom-prop']['file']
11651175
if os.path.exists(filename):
1166-
link = f' <a href="https://github.com/bsimjoo/Telegram-RSS-Bot/blob/main/{filename}#L{lineno}">🔸L{lineno}@{filename}</a></h3>'
1176+
link = f' <a href="https://github.com/bsimjoo/Telegram-RSS-Bot/blob/main/{filename}#L{lineno}">🔸may be here: L{lineno}@{filename}</a></h3>'
11671177
res+=f'<h3>&bull;Tag: <kbd>"{tag}"</kbd> Count: {content["count"]} {link}</h3>'
11681178
res+=f'<pre>{content["message"]}</pre>'
11691179

0 commit comments

Comments
 (0)