-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodreport.py
executable file
·105 lines (86 loc) · 3.12 KB
/
modreport.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
import json
import sys
import string
import firestore
import matrix
import downvotes
import privatemsg
import newposts
import modlog
from pythorhead import Lemmy
def run(user, pw, instance, room, muser, mpw, mserver, dv, pm, reports, np, ml, ml_pm, live):
posted_reports = { }
posted_reports["posts"] = []
posted_reports["comments"] = []
doc = f'{user}.{instance}'
if live:
posted_reports = firestore.get("modreports", doc)
if posted_reports is None:
posted_reports = {}
if "posts" not in posted_reports:
posted_reports["posts"] = []
if "comments" not in posted_reports:
posted_reports["comments"] = []
#print(posted_reports)
lemmy = Lemmy(f'https://{instance}', raise_exceptions=True)
try:
lemmy.log_in(user, pw)
except Exception as e:
print(f'login failed: {e}\n')
sys.exit(1)
if np == "TRUE":
newposts.run(lemmy, live, room, muser, mpw, mserver)
if dv == "TRUE":
downvotes.run(lemmy, live)
if pm == "TRUE":
privatemsg.run(lemmy, live, room, muser, mpw, mserver)
if ml == "TRUE":
if ml_pm == "TRUE":
pm_modlogs = True
else:
pm_modlogs = False
modlog.run(lemmy, user, instance, live, room, muser, mpw, mserver, pm_modlogs)
if reports != "TRUE":
# not getting reports so nothing more to do
return
try:
reports = lemmy.post.report_list(unresolved_only = "true")
except Exception as e:
print(f'cannot get post reports: {e}\n')
sys.exit(1)
if reports is not None:
for report in reports:
if posted_reports["posts"] and (report["post_report"]["id"] in posted_reports["posts"]):
print(f'id {report["post_report"]["id"]} already posted')
continue
#print(report)
rtxt = f'Report: {report["post_report"]["reason"]}\n'
rtxt += f'Community: {report["community"]["name"]}\n'
rtxt += f'Post: {report["post"]["ap_id"]} {report["post"]["name"]}\n'
rtxt += f'Comments: {report["counts"]["comments"]} 👍{report["counts"]["upvotes"]} 👎{report["counts"]["downvotes"]}\n'
print(rtxt)
if live:
matrix.post(rtxt, room, muser, mpw, mserver)
posted_reports["posts"].append(report["post_report"]["id"])
try:
reports = lemmy.comment.report_list(unresolved_only = "true")
#print(reports)
except Exception as e:
print(f'cannot get comment reports: {e}\n')
sys.exit(1)
if reports is not None:
for report in reports:
if posted_reports["comments"] and (report["comment_report"]["id"] in posted_reports["comments"]):
print(f'id {report["comment_report"]["id"]} already posted')
continue
rtxt = f'Report: {report["comment_report"]["reason"]}\n'
rtxt += f'Community: {report["community"]["name"]}\n'
rtxt += f'Comment: {report["comment"]["content"]}\n'
rtxt += f'Replies: {report["counts"]["child_count"]} 👍{report["counts"]["upvotes"]} 👎{report["counts"]["downvotes"]}\n'
print(rtxt)
if live:
matrix.post(rtxt, room, muser, mpw, mserver)
posted_reports["comments"].append(report["comment_report"]["id"])
if live:
firestore.set("modreports", doc, posted_reports)