This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.py
149 lines (138 loc) · 6.35 KB
/
report.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
140
141
142
143
144
145
146
147
148
149
from aiohttp import ClientSession as HTTP
from ext import Extension as Super
import load
import mwclient
FLAG_REPORT = 0
FLAG_UNREPORT = 1
FLAG_RESOLVE = 2
class Extension(Super):
def __init__(self, bot, config):
super(Extension, self).__init__(bot, config)
self.temp = load.load_data('report')
self.register_commands('report', 'unreport', 'resolve', 'kocka')
self.mw = mwclient.Site('vstf.wikia.com', path='/')
self.mw.login(config['username'], config['password'])
for t in ['w', 's', 'p', 'b']:
if not t in self.temp:
if t == 'w' or t == 'b':
self.temp[t] = []
else:
self.temp[t] = {}
self.message = False
def report_message(self, t, p=''):
return {
'w': '{{{{badwiki|{0}}}}}'.format('}}\n{{badwiki|'.join(self.temp['w'])),
's': '== {0} ==\n{{{{Report spam|{0}|Spam|{1}|{{{{subst:REVISIONUSER}}}}|~~~~~}}}}'.format(p, '|'.join(self.temp['s'].get(p, []))),
'p': '== {0} ==\n{{{{Report profile|{0}|Spam|{1}|{{{{subst:REVISIONUSER}}}}|~~~~~}}}}'.format(p, '|'.join(self.temp['p'].get(p, []))),
'b': '\n'.join([ ('* [[w:c:{0}:Special:Contribs/{1}|{1}]]'.format(x.split(':')[0], ':'.join(x.split(':')[1:]))) for x in self.temp['b'] ])
}[t]
async def update_report(self, msg=None):
load.write_data('report', self.temp)
m = """__**Report message**__\nThis message is where new reports accumulate\n"""
if len(self.temp['w']) > 0:
m += '**Spam wikis**```%s```' % self.report_message('w')
if len(self.temp['s']) > 0:
for k, v in self.temp['s'].items():
if len(v) > 0:
m += """**Spam users: %s**```%s```""" % (k, self.report_message('s', k))
if len(self.temp['p']) > 0:
for k, v in self.temp['p'].items():
if len(v) > 0:
m += '**Spam profiles: %s**```%s```' % (k, self.report_message('p', k))
if len(self.temp['b']) > 0:
m += """**XRumer spam**```%s```""" % self.report_message('b')
if not self.message:
self.message = await self.bot.get_channel(self.config['bind_channel']).send(m)
else:
await self.message.edit(content=m)
if(msg):
await self.reply(msg, 'Reports updated!', True)
def modify_array(self, array, el, flag, nosplit=False):
# Don't ask. Please just don't ask.
if nosplit:
el = [el]
else:
el = el.split('|')
# Python y u do dis
def temp(array):
del array[:]
for e in el:
[
lambda: array.append(e.replace('_', ' ')) if not e in array else False,
lambda: array.remove(e.replace('_', ' ')) if e in array else False,
lambda: temp(array)
][flag]()
async def webhook(self, user, flag, target):
action = ''
if flag == FLAG_REPORT:
action = 'reported'
elif flag == FLAG_UNREPORT:
action = 'unreported'
elif flag == FLAG_RESOLVE:
action = 'resolved'
await self.bot.get_channel(self.config['log_channel']).send('%s %s %s.' % (user.name, action, target))
async def base_report(self, message, params, flag):
params.append('')
t = params[0].lower()
if t == 'w':
for e in params[1].split('|'):
split = e.split(':')
if len(split) > 1 and split[1] == 'f':
split[0] = split[0] + '||fandom'
self.modify_array(self.temp[t], split[0], flag, nosplit=True)
if flag == FLAG_RESOLVE:
await self.webhook(message.author, flag, 'wiki reports')
else:
await self.webhook(message.author, flag, 'wiki(s): %s' % params[1])
await self.update_report(message)
elif t == 's' or t == 'p':
wiki = params[1].lower()
if not wiki in self.temp[t]:
self.temp[t][wiki] = []
name = 'spam'
if t == 'p':
name = 'spam profiles'
users = ' '.join(params[2:]).strip()
self.modify_array(self.temp[t][wiki], users, flag)
if flag == FLAG_RESOLVE:
await self.webhook(message.author, flag, '%s from %s' % (name, wiki))
else:
await self.webhook(message.author, flag, '%s from %s: %s' % (name, wiki, users))
await self.update_report(message)
elif t == 'b' or t == 'x':
wiki = params[1]
split = wiki.split(':')
if len(split) >= 2:
wiki = split[0].lower()
params[2] = ':'.join(split[1:])
users = wiki + ':' + ' '.join(params[2:]).strip()
self.modify_array(self.temp['b'], users, flag)
await self.webhook(message.author, flag, 'XRumer spam: %s' % users)
await self.update_report(message)
elif flag == FLAG_RESOLVE:
self.modify_array(self.temp['b'], wiki + ':' + ' '.join(params[2:]).strip(), flag)
await self.webhook(message.author, flag, 'XRumer spam')
await self.update_report(message)
else:
await self.reply(message, 'Format for biglist spam is `!report b wiki:user`!')
else:
await self.reply(message, 'Invalid report type!', True)
async def command_report(self, message, params):
await self.base_report(message, params, FLAG_REPORT)
async def command_unreport(self, message, params):
await self.base_report(message, params, FLAG_UNREPORT)
async def command_resolve(self, message, params):
await self.base_report(message, params, FLAG_RESOLVE)
async def command_kocka(self, message, params):
if(message.author == self.bot.master):
params.append('')
page = self.mw.Pages['Report:' + {
'w': 'Wiki',
's': 'Spam',
'p': 'User profile headers',
'b': 'Spam/Biglist'
}[params[0]]]
text = page.text()
text += '\n' + self.report_message(params[0], params[1])
page.save(text, summary='Moving reports of Wikia Watchers')
await self.base_report(message, params, FLAG_RESOLVE)