-
Notifications
You must be signed in to change notification settings - Fork 0
/
BugReporter.py
139 lines (110 loc) · 4.27 KB
/
BugReporter.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import discord
from settings import REPORT_TO_DEVS as dev_list
from functions import reply_to_command, has_admin_rights
from database import engine, Abuser
from sqlalchemy.orm import sessionmaker
# Github issue creation
from github import Github
from github_key import token as access_token
Session = sessionmaker(bind=engine)
session = Session()
class BugReporter(object):
def __init__(self, client):
self.client = client
""" Send a bug report over DM to the developers
Params:
Message message - The message used to invoke the command
String report - The text contents for the bug report
Returns:
void
"""
async def report_bug(self, message, report):
server = next(iter(self.client.servers))
# Check if the person reporting the bug is on the block list
resultset = session.query(Abuser).filter_by(discord_id = message.author.id)
count = resultset.count()
if count == 0:
msg = "Bugreport from {}: {}".format(message.author.name, report)
for dev in dev_list:
user = server.get_member(dev)
await self.client.send_message(user, msg)
resp = "{}: HE-ROES NEV-ER DIE, M.O.X. CAN NEV-ER BE CON-QUERED. BUT M.O.X. DOES NEED MAIN-TEN-ANCE. THANK YOU FOR THIS RE-MIN-DER!".format(message.author.mention)
await reply_to_command(self.client, message, resp)
return
""" Adds a discord_id to the abusers table as long as the user is not already included in
a record.
Params:
Message message - The message used to invoke the command
String abuser_mention - A mentionable representation of a user as string
Returns:
void
"""
async def add_abuser(self, message, abuser_mention):
if has_admin_rights(message.author) or message.author.id in dev_list:
server = next(iter(self.client.servers))
abuser_id = abuser_mention[2:-1]
resultset = session.query(Abuser).filter_by(discord_id = abuser_id)
count = resultset.count()
if count == 0:
# User wasn't in the abuse list yet, so let's add him
abuser = Abuser(discord_id = abuser_id)
session.add(abuser)
session.commit()
reply = "I THINK THERE-FORE I AT-TACK! {} HAD THEIR PRI-VI-LEGE PURGED.".format(abuser_mention)
await reply_to_command(self.client, message, reply)
return
""" Looks up an abuser record and deletes it if it exists.
Params:
Message message - A message object containing the message
used to invoke the command
String abuser_mention - A mentionable representation of a user as string
Returns:
void
"""
async def remove_abuser(self, message, abuser_mention):
if has_admin_rights(message.author) or message.author.id in dev_list:
server = next(iter(self.client.servers))
abuser_id = abuser_mention[2:-1]
resultset = session.query(Abuser).filter_by(discord_id = abuser_id)
count = resultset.count()
if count == 1:
# User was in the list, so let's remove him
session.query(Abuser).filter_by(discord_id = abuser_id).delete()
session.commit()
else:
reply = "{}: TAR-GET COULD NOT GET AC-QUIRED. ALL OP-ER-ATIONS WITH-IN NOR-MAL PA-RA-MA-TERS.".format(message.author.mention)
await reply_to_command(self.client, message, reply)
return
reply = "THE ONLY WIN-NING MOVE IS NOT TO PLAY. FUNC-TIO-NA-LI-TIES RE-STORED FOR {}".format(abuser_mention)
await reply_to_command(self.client, message, reply)
return
""" Creates a github issue.
Params:
Message message - The message used to invoke the command
String title - The title for the github issue
String body - The body for the github issue
Returns:
void
"""
async def create_issue(self, message, title, body):
if message.author.id in dev_list:
g = Github(login_or_token=access_token)
found = None
# Attempt to find the discord repository
for repo in g.get_user().get_repos():
if repo.name == "DiscordBot":
found = repo
# Only continue if the repo is found
if found is not None:
try:
issue = found.create_issue(title=title, body=body)
except:
raise
return
reply = "MAIN-TEN-ANCE RE-PORT UP-LOAD-ED. THANK YOU {}".format(message.author.mention)
await reply_to_command(self.client, message, reply)
return
else:
reply = "CON-NEC-TION TO EX-TER-NAL SER-VICE FAILED. CHECK API STA-TUS"
await reply_to_command(self.client, message, reply)
return