Skip to content

Commit e453901

Browse files
committed
i am moron
1 parent 39a1a3b commit e453901

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

draft_review.py

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -55,72 +55,72 @@ def __init__(self, bot: commands.Bot):
5555
def cog_unload(self):
5656
self.fetch_draft.cancel()
5757

58-
@tasks.loop(seconds=60)
59-
async def fetch_draft(self, *args):
60-
channel = self.bot.get_channel(1150122572294410441) # channel ID goes here (draft-menders)
61-
62-
old_drafts = set(self.db.get_all_drafts().keys())
63-
try:
64-
populate_db(self.db)
65-
new_drafts = set(self.db.get_all_drafts().keys())
66-
new_pages = [x for x in new_drafts if x not in old_drafts]
58+
@tasks.loop(seconds=60)
59+
async def fetch_draft(self, *args):
60+
channel = self.bot.get_channel(1150122572294410441) # channel ID goes here (draft-menders)
61+
62+
old_drafts = set(self.db.get_all_drafts().keys())
63+
try:
64+
populate_db(self.db)
65+
new_drafts = set(self.db.get_all_drafts().keys())
66+
new_pages = [x for x in new_drafts if x not in old_drafts]
67+
68+
for page in new_pages:
69+
name = page[page.find('/', page.find('/') + 1) + 1:]
70+
user = page[page.find(':') + 1:page.find('/')]
71+
if re.fullmatch(good_url, page) is None:
72+
page_move.fix_url(page, user, name)
73+
continue
6774

68-
for page in new_pages:
69-
name = page[page.find('/', page.find('/') + 1) + 1:]
70-
user = page[page.find(':') + 1:page.find('/')]
71-
if re.fullmatch(good_url, page) is None:
72-
page_move.fix_url(page, user, name)
73-
continue
75+
user_params = {
76+
"action": "query",
77+
"list": "users",
78+
"ususers": user,
79+
"format": "json"
80+
}
81+
user_request = requests.get("https://2b2t.miraheze.org/w/api.php", params=user_params)
82+
user_json = user_request.json()
83+
user_id = str(user_json['query']['users'][0]['userid'])
7484

75-
user_params = {
76-
"action": "query",
77-
"list": "users",
78-
"ususers": user,
79-
"format": "json"
80-
}
81-
user_request = requests.get("https://2b2t.miraheze.org/w/api.php", params=user_params)
82-
user_json = user_request.json()
83-
user_id = str(user_json['query']['users'][0]['userid'])
85+
threads.update(channel.threads)
86+
async for thread in channel.archived_threads():
87+
threads.add(thread)
88+
thread = discord.utils.get(threads, name='Draft: ' + name)
8489

85-
threads.update(channel.threads)
86-
async for thread in channel.archived_threads():
87-
threads.add(thread)
88-
thread = discord.utils.get(threads, name='Draft: ' + name)
90+
draft_url = self.db.get_draft(page).url if self.db.get_draft(page) else None
91+
if not draft_url:
92+
continue
8993

90-
draft_url = self.db.get_draft(page).url if self.db.get_draft(page) else None
91-
if not draft_url:
92-
continue
93-
94-
# if no thread for this draft is found:
95-
if thread is None:
96-
embed = discord.Embed(
97-
title='Draft: ' + name,
98-
url=draft_url,
99-
color=discord.Color.from_rgb(36, 255, 0)
100-
)
101-
embed.set_author(
102-
name=user,
103-
url=f"https://2b2t.miraheze.org/wiki/User:{user.replace(' ', '_')}",
104-
icon_url=f"https://static.miraheze.org/2b2twiki/avatars/2b2twiki_{user_id}_l.png"
105-
)
94+
# if no thread for this draft is found:
95+
if thread is None:
96+
embed = discord.Embed(
97+
title='Draft: ' + name,
98+
url=draft_url,
99+
color=discord.Color.from_rgb(36, 255, 0)
100+
)
101+
embed.set_author(
102+
name=user,
103+
url=f"https://2b2t.miraheze.org/wiki/User:{user.replace(' ', '_')}",
104+
icon_url=f"https://static.miraheze.org/2b2twiki/avatars/2b2twiki_{user_id}_l.png"
105+
)
106106

107-
draft_message = await channel.send(embed=embed)
108-
new_thread = await channel.create_thread(
109-
name='Draft: ' + name,
110-
message=draft_message,
111-
reason="New draft"
112-
)
113-
threads.add(new_thread)
114-
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, new thread opened")
115-
# else if a thread is found but it is closed:
116-
elif thread.archived:
117-
await thread.unarchive()
118-
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, opened existing thread")
119-
else:
120-
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, thread already exists")
107+
draft_message = await channel.send(embed=embed)
108+
new_thread = await channel.create_thread(
109+
name='Draft: ' + name,
110+
message=draft_message,
111+
reason="New draft"
112+
)
113+
threads.add(new_thread)
114+
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, new thread opened")
115+
# else if a thread is found but it is closed:
116+
elif thread.archived:
117+
await thread.unarchive()
118+
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, opened existing thread")
119+
else:
120+
print(f"Found Draft:{user}/{name} at {datetime.datetime.now()}, thread already exists")
121121

122-
except requests.HTTPError as e:
123-
print(e)
122+
except requests.HTTPError as e:
123+
print(e)
124124

125125
@fetch_draft.before_loop
126126
async def before_fetch_draft(self):

0 commit comments

Comments
 (0)