-
Notifications
You must be signed in to change notification settings - Fork 1
/
Reporter.py
60 lines (48 loc) · 1.63 KB
/
Reporter.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
58
59
60
#
# Reporter.py
# Botpy
#
# Created by Ashish Ahuja on 5th October 2017.
#
#
import logging
class Reporter:
def __init__(self, bot_name, error_rooms, report_rooms, bot_link):
self.bot_name = bot_name
self.error_rooms = error_rooms
self.report_rooms = report_rooms
self.bot_link = bot_link
self.reports = list()
self.pending_reports = list()
def get_start_link(self):
return "\[ [" + self.bot_name + "](" + self.bot_link + ") ]"
def report(self, message, error_rooms=False):
room_list = self.report_rooms
if error_rooms:
room_list.extend(self.error_rooms)
for each_room in room_list:
report = Report(self.get_start_link() + ' ' + message, each_room)
report.report()
self.reports.append(report)
self.pending_reports.append(report)
def check_message_for_report(self, message):
logging.info(message)
logging.debug('yo')
if message.startswith(' [ <a href="'):
logging.debug('bingo')
for each_report in self.pending_reports:
logging.debug('in')
if message.room.id == each_report.room.id:
logging.debug('woohoo')
each_report.message_id = message.id
self.pending_reports.remove(each_report)
break
return True
return False
class Report:
def __init__(self, message, room):
self.message = message
self.room = room
self.message_id = -1
def report(self):
self.room.send_message(self.message)