Skip to content

Commit d93c9a4

Browse files
committed
Revert recent commits (that were meant to be in a pr):
Revert "parse alerts" This reverts commit 685700f. Revert "remove redundant arguments" This reverts commit 13aa853. Revert "fix: pass an actual session" This reverts commit 1a5932a. Revert "feat: create enum for classroom alerts" This reverts commit d3811f0. Revert "feat: add more parsing based on scratch html & add message property" This reverts commit 37e44cd. Revert "fix: classroom activity - some cases lead to same outcome" This reverts commit 576d33b. Revert "fix: remove redundant/commented-out code" This reverts commit 75c48a1.
1 parent 57c1c24 commit d93c9a4

File tree

4 files changed

+50
-230
lines changed

4 files changed

+50
-230
lines changed

scratchattach/site/activity.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ def _update_from_json(self, data: dict):
8080
else:
8181
recipient_username = None
8282

83-
default_case = True
84-
# Even if `activity_type` is an invalid value; it will default to 'user performed an action'
85-
83+
default_case = False
84+
"""Whether this is 'blank'; it will default to 'user performed an action'"""
8685
if activity_type == 0:
8786
# follow
8887
followed_username = data["followed_username"]
@@ -151,7 +150,13 @@ def _update_from_json(self, data: dict):
151150
self.project_id = project_id
152151
self.recipient_username = recipient_username
153152

154-
elif activity_type in (8, 9, 10):
153+
elif activity_type == 8:
154+
default_case = True
155+
156+
elif activity_type == 9:
157+
default_case = True
158+
159+
elif activity_type == 10:
155160
# Share/Reshare project
156161
project_id = data["project"]
157162
is_reshare = data["is_reshare"]
@@ -182,6 +187,9 @@ def _update_from_json(self, data: dict):
182187
self.project_id = parent_id
183188
self.recipient_username = recipient_username
184189

190+
elif activity_type == 12:
191+
default_case = True
192+
185193
elif activity_type == 13:
186194
# Create ('add') studio
187195
studio_id = data["gallery"]
@@ -208,7 +216,16 @@ def _update_from_json(self, data: dict):
208216
self.username = username
209217
self.gallery_id = studio_id
210218

211-
elif activity_type in (16, 17, 18, 19):
219+
elif activity_type == 16:
220+
default_case = True
221+
222+
elif activity_type == 17:
223+
default_case = True
224+
225+
elif activity_type == 18:
226+
default_case = True
227+
228+
elif activity_type == 19:
212229
# Remove project from studio
213230

214231
project_id = data["project"]
@@ -223,7 +240,13 @@ def _update_from_json(self, data: dict):
223240
self.username = username
224241
self.project_id = project_id
225242

226-
elif activity_type in (20, 21, 22):
243+
elif activity_type == 20:
244+
default_case = True
245+
246+
elif activity_type == 21:
247+
default_case = True
248+
249+
elif activity_type == 22:
227250
# Was promoted to manager for studio
228251
studio_id = data["gallery"]
229252

@@ -237,7 +260,13 @@ def _update_from_json(self, data: dict):
237260
self.recipient_username = recipient_username
238261
self.gallery_id = studio_id
239262

240-
elif activity_type in (23, 24, 25):
263+
elif activity_type == 23:
264+
default_case = True
265+
266+
elif activity_type == 24:
267+
default_case = True
268+
269+
elif activity_type == 25:
241270
# Update profile
242271
raw = f"{username} made a profile update"
243272

@@ -247,7 +276,10 @@ def _update_from_json(self, data: dict):
247276

248277
self.username = username
249278

250-
elif activity_type in (26, 27):
279+
elif activity_type == 26:
280+
default_case = True
281+
282+
elif activity_type == 27:
251283
# Comment (quite complicated)
252284
comment_type: int = data["comment_type"]
253285
fragment = data["comment_fragment"]
@@ -282,10 +314,12 @@ def _update_from_json(self, data: dict):
282314
self.comment_obj_title = comment_obj_title
283315
self.comment_id = comment_id
284316

317+
else:
318+
default_case = True
285319

286320
if default_case:
287321
# This is coded in the scratch HTML, haven't found an example of it though
288-
raw = f"{username} performed an action."
322+
raw = f"{username} performed an action"
289323

290324
self.raw = raw
291325
self.datetime_created = _time

scratchattach/site/alert.py

Lines changed: 0 additions & 176 deletions
This file was deleted.

scratchattach/site/session.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from bs4 import BeautifulSoup
3333

34-
from . import activity, classroom, forum, studio, user, project, backpack_asset, alert
34+
from . import activity, classroom, forum, studio, user, project, backpack_asset
3535
# noinspection PyProtectedMember
3636
from ._base import BaseSiteComponent
3737
from ..cloud import cloud, _base
@@ -265,9 +265,7 @@ def classroom_alerts(self, _classroom: Optional[classroom.Classroom | int] = Non
265265
params={"page": page, "ascsort": ascsort, "descsort": descsort},
266266
headers=self._headers, cookies=self._cookies).json()
267267

268-
alerts = [alert.EducatorAlert.from_json(alert_data, self) for alert_data in data]
269-
270-
return alerts
268+
return data
271269

272270
def clear_messages(self):
273271
"""

scratchattach/utils/enums.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"""
55
from __future__ import annotations
66

7-
from dataclasses import dataclass
87
from enum import Enum
8+
from dataclasses import dataclass
9+
910
from typing import Optional, Callable, Iterable
1011

1112

12-
@dataclass
13+
@dataclass(init=True, repr=True)
1314
class Language:
1415
name: str = None
1516
code: str = None
@@ -43,7 +44,7 @@ def apply_func(x):
4344

4445
if apply_func(_val) == value:
4546
return item_obj
46-
47+
4748
except TypeError:
4849
pass
4950

@@ -166,7 +167,7 @@ def all_of(cls, attr_name: str = "name", apply_func: Optional[Callable] = None)
166167
return super().all_of(attr_name, apply_func)
167168

168169

169-
@dataclass
170+
@dataclass(init=True, repr=True)
170171
class TTSVoice:
171172
name: str
172173
gender: str
@@ -194,40 +195,3 @@ def find(cls, value, by: str = "name", apply_func: Optional[Callable] = None) ->
194195
def all_of(cls, attr_name: str = "name", apply_func: Optional[Callable] = None) -> Iterable:
195196
return super().all_of(attr_name, apply_func)
196197

197-
198-
@dataclass
199-
class AlertType:
200-
id: int
201-
message: str
202-
203-
204-
class AlertTypes(_EnumWrapper):
205-
# Reference: https://github.com/TimMcCool/scratchattach/issues/304#issuecomment-2800110811
206-
# NOTE: THE TEXT WITHIN THE BRACES HERE MATTERS! IF YOU WANT TO CHANGE IT, MAKE SURE TO EDIT `site.alert.EducatorAlert`!
207-
ban = AlertType(0, "{username} was banned.")
208-
unban = AlertType(1, "{username} was unbanned.")
209-
excluded_from_homepage = AlertType(2, "{username} was excluded from homepage")
210-
excluded_from_homepage2 = AlertType(3, "{username} was excluded from homepage") # for some reason there are duplicates
211-
notified = AlertType(4, "{username} was notified by a Scratch Administrator. Notification type: {notification_type}")
212-
autoban = AlertType(5, "{username} was banned automatically")
213-
autoremoved = AlertType(6, "{project} by {username} was removed automatically")
214-
project_censored2 = AlertType(7, "{project} by {username} was censored.") # <empty #7>
215-
project_censored = AlertType(20, "{project} by {username} was censored.")
216-
project_uncensored = AlertType(8, "{project} by {username} was uncensored.")
217-
project_reviewed2 = AlertType(9, "{project} by {username} was reviewed by a Scratch Administrator.") # <empty #9>
218-
project_reviewed = AlertType(10, "{project} by {username} was reviewed by a Scratch Administrator.")
219-
project_deleted = AlertType(11, "{project} by {username} was deleted by a Scratch Administrator.")
220-
user_deleted2 = AlertType(12, "{username} was deleted by a Scratch Administrator") # <empty #12>
221-
user_deleted = AlertType(17, "{username} was deleted by a Scratch Administrator")
222-
studio_reviewed2 = AlertType(13, "{studio} was reviewed by a Scratch Administrator.") # <empty #13>
223-
studio_reviewed = AlertType(14, "{studio} was reviewed by a Scratch Administrator.")
224-
studio_deleted = AlertType(15, "{studio} was deleted by a Scratch Administrator.")
225-
email_confirm2 = AlertType(16, "The email address of {username} was confirmed by a Scratch Administrator") # <empty #16>
226-
email_confirm = AlertType(18, "The email address of {username} was confirmed by a Scratch Administrator") # no '.' in HTML
227-
email_unconfirm = AlertType(19, "The email address of {username} was set as not confirmed by a Scratch Administrator")
228-
automute = AlertType(22, "{username} was automatically muted by our comment filters. The comment they tried to post was: {comment}")
229-
default = AlertType(-1, "{username} had an admin action performed.") # default case
230-
231-
@classmethod
232-
def find(cls, value, by: str = "id", apply_func: Optional[Callable] = None) -> AlertType:
233-
return super().find(value, by, apply_func)

0 commit comments

Comments
 (0)