@@ -117,7 +117,7 @@ def __init__(
117117 self .source = source
118118 self .interval = self .__get_data__ ('interval' , 5 * 60 , data_db )
119119 self .__check__ = True
120- self .reporter = bug_reporter if bug_reporter else None
120+ self .bug_reporter = bug_reporter if bug_reporter else None
121121
122122 def handle_edited_msg (u : Update , c :CallbackContext ):
123123 #TODO: Handle editing messages
@@ -413,7 +413,7 @@ def preview(u: Update, c: CallbackContext):
413413 else :
414414 logging .error ('UNKNOWN MSG TYPE FOUND\n ' + str (msg ))
415415 c .bot .send_message (self .ownerID , 'UNKNOWN MSG TYPE FOUND\n ' + str (msg ))
416- self .reporter .bug ('unknown type message in preview' , 'UNKNOWN MSG TYPE FOUND\n ' + str (msg ))
416+ self .bug_reporter .bug ('unknown type message in preview' , 'UNKNOWN MSG TYPE FOUND\n ' + str (msg ))
417417
418418 if c .user_data .get ('had-error' ):
419419 c .user_data ['last-message' ] = u .message .reply_text (
@@ -854,7 +854,7 @@ def error_handler(update: object, context: CallbackContext) -> None:
854854 logging .error (msg = "Exception while handling an update:" ,
855855 exc_info = context .error )
856856
857- if type (context .error ) is type ( NetworkError ):
857+ if isinstance (context .error , NetworkError ):
858858 return
859859
860860 # traceback.format_exception returns the usual python message about an exception, but as a
@@ -868,8 +868,8 @@ def error_handler(update: object, context: CallbackContext) -> None:
868868 lineno = f .lineno
869869 filename = os .path .basename (f .filename )
870870 exception_type = type (context .error ).__name__
871- if self .reporter :
872- self .reporter .bug (f'L{ lineno } @{ filename } : { exception_type } ' ,tb_string , { ' line' : lineno , ' file' : filename } )
871+ if self .bug_reporter :
872+ self .bug_reporter .bug (f'L{ lineno } @{ filename } : { exception_type } ' , tb_string , line = lineno , file = filename )
873873
874874 # Build the message with some markup and additional information about what happened.
875875 # You might need to add some logic to deal with messages longer than the 4096 character limit.
@@ -1125,12 +1125,15 @@ def idle(self):
11251125
11261126 if main_config .get ('bug-reporter' , 'off' ) in ('online' , 'offline' ):
11271127 import BugReporter
1128- bug_reporter = BugReporter .BugReporter ()
1129- reporter = bug_reporter ('Telegram_RSS_Bot' )
1128+ bugs_file = main_config .get ('bugs-file' ,'bugs.json' )
1129+ use_git = main_config .getboolean ('use-git' ,False )
1130+ git = main_config .get ('git-command' ,'git' )
1131+ git_source = main_config .get ('git-source' )
1132+ bug_reporter = BugReporter .BugReporter (bugs_file , use_git , git , git_source )
11301133
11311134 if main_config .get ('bug-reporter' ) == 'online' :
11321135 try :
1133- import cherrypy #user can ignore installing this mudole just if doesn't need reporting on http
1136+ import cherrypy #user can ignore installing this module just if doesn't need reporting on http
11341137
11351138 class root :
11361139
@@ -1140,50 +1143,53 @@ def index(self):
11401143 <head>
11411144 <style>
11421145 html, body{
1143- background-color: #17202a ;
1146+ background-color: #1b2631 ;
11441147 color: #d6eaf8;
11451148 }
11461149 pre, ssh-pre{
11471150 width:80%;
11481151 max-height: 30%;
11491152 margin: auto;
1150- background-color: #f39c12 ;
1151- color: black ;
1153+ background-color: #873600 ;
1154+ color: white ;
11521155 border-radius: 10px;
11531156 padding: 10px;
11541157 overflow-x: auto;
11551158 white-space: pre-wrap;
11561159 word-wrap: break-word;
11571160 }
1161+ a:visited{
1162+ color: #a569bd
1163+ }
11581164 </style>
11591165 </head>
1160- <body><h1>Bugs</h1><hr>
1161- <p><b>What is this page?</b> This project uses a simple web
1162- server to report bugs (exceptions) in a running application.
1163- <p><b>What are groups?</b> Because of this project can be forked
1164- so each fork can have its own bugs. Although it is sometimes
1165- difficult to distinguish between original project bugs and forged
1166- projects, groups are a simple way to separate these bugs.<p>'''
1167-
1168- for group , reporter in bug_reporter .reports .items ():
1169- res += f'<h2>Group: { group } </h2><hr>'
1170- for tag , content in reporter ['tags' ].items ():
1166+ <body><h1 style="background-color: #d6eaf8; border-radius:10px; color:black">🐞 Bugs</h1>
1167+ <p><b>What is this?</b> This project uses a simple web
1168+ server to report bugs (exceptions) in a running application.</p>
1169+ <h6><a href="/json">Show raw JSON</a></h6>'''
1170+
1171+ if bug_reporter .bugs_count :
1172+ res += f'<h2>😔 { bug_reporter .bugs_count } bug(s) found</h2>'
1173+ for tag , content in bug_reporter .bugs .items ():
11711174 link = ''
1172- if 'file' in content [ 'custom-prop' ] :
1173- lineno = content ['custom-prop' ][ ' line' ]
1174- filename = content ['custom-prop' ][ ' file' ]
1175+ if 'file' in content and bug_reporter . use_git :
1176+ lineno = content ['line' ]
1177+ filename = content ['file' ]
11751178 if os .path .exists (filename ):
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>'
1179+ link = f' <a href="{ bug_reporter . git_source } / blob/{ bug_reporter . commit } /{ filename } #L{ lineno } ">🔸may be here: L{ lineno } @{ filename } </a></h3>'
11771180 res += f'<h3>•Tag: <kbd>"{ tag } "</kbd> Count: { content ["count" ]} { link } </h3>'
1178- res += f'<pre>{ content ["message" ]} </pre>'
1181+ if content ["message" ]:
1182+ res += f'<pre>{ content ["message" ]} </pre>'
1183+ else :
1184+ res += '<h1 align="center">😃 NO 🐞 FOUND 😉</h1>'
11791185
1180- res += '<h3 align="center"><a href="/json">Raw JSON</a></h3>< /body></html>'
1186+ res += '</body></html>'
11811187 return res
11821188
11831189 @cherrypy .expose
11841190 @cherrypy .tools .json_out ()
11851191 def json (self ):
1186- return bug_reporter .reports
1192+ return bug_reporter .data
11871193
11881194 conf = main_config .get ('reporter-config-file' ,'Bug-reporter.conf' )
11891195 if os .path .exists (conf ):
@@ -1209,7 +1215,7 @@ def json(self):
12091215 sys .exit ()
12101216
12111217 bot_handler = BotHandler (token , main_config .get ('source' ,'https://pcworms.blog.ir/rss/' ), env ,
1212- chats_db , data_db , strings , reporter )
1218+ chats_db , data_db , strings , bug_reporter )
12131219 bot_handler .run ()
12141220 bot_handler .idle ()
12151221 if bug_reporter :
0 commit comments