Authenticating¶
The client object allows you to manipulate a user object that is logged in. Each client object represents a logged in user on which you can do a set of operations and requests. This gives you more interactivity with the website beyond simply getting random page. You can track, untrack pages and get the updates to those pages.
The client also supports __enter__ and __exit__ as means to temporarily replace the module’s session with the client’s. See snippets for an example.
Client¶
- class moddb.client.Client(username, password)[source]¶
Login the user to moddb through the library, this allows user to see guest comments and see private groups they are part of. In addition, this can be used for a lot of the operation
- Parameters:
- Raises:
ValueError – The password or username was incorrect
- add_comment(page, text, *, comment=None)[source]¶
Add a comment to a page.
- Parameters:
- Returns:
The page’s updated object containing the new comment and any other new data that has been posted since then
- Return type:
Any
- add_member_to_thread(thread, member)[source]¶
Add a member to a conversation
- Parameters:
thread (Union[Thread, ThreadThumbnail]) – The thread to add add a member to
member (Member) – The member to add
- Returns:
Whether adding the member was succesful. This will not update the thread.
- Return type:
- add_review(page, rating, *, text=None, has_spoilers=False)[source]¶
Rate and review a page. If you rating is below 3 or above 8 you will be asked to also provide a review or else the request will not be made. This is also used to edit existing reviews.
- Parameters:
- Raises:
ModdbException – An error occured trying to review the page.
- Returns:
True of the review was successfuly submitted.
- Return type:
- clear_updates(category)[source]¶
Clear all updates for a specific category of watched. This method will conduct two requests because the clear update request requires a hash generated by moddb.
- delete_comment(comment)[source]¶
This will delete the supplied comment provided you have the correct permissions. This is an expensive request because if how moddb works. It needs to make two requests in order to get the correct hash to delete the comment. In addition, it may fail if the comment has changed location (page number) from what the object says. It is recommended to use a newly created comment object that is less than 30 minutes old.
- Parameters:
comment (Comment) – The comment to delete
- Raises:
ModdbException – An error occured while trying to delete the comment
- Returns:
True if the comment was successfully deleted
- Return type:
- delete_review(review)[source]¶
Delete your review on the given page. This function will do two requests in order to delete your review.
- Parameters:
review (Review) – The review you wish to delete
- Raises:
ModdbException – An error occured while trying to delete the review
- Returns:
True if the review was successfully deleted
- Return type:
- dislike_comment(comment)[source]¶
Dislike a comment, if the comment has already been disliked nothing will happen.
- Parameters:
comment (Comment) – The comment to dislike
- Raises:
ModdbException – An error has occured while trying to dislike the comment
- Returns:
True if comment has been successfully disliked.
- Return type:
- edit_comment(comment, new_text)[source]¶
Edit the contents of a comment. You can only edit your comment 120 minutes after it has been posted
- Parameters:
- Raises:
ModdbException – An error has occured trying to edit the comment
- Returns:
True if the comment was successfully edited
- Return type:
- get_friend_requests()[source]¶
Get the current friend requests the user has.
- Returns:
List of requests (thumbnail like objects with extra methods)
- Return type:
List[Request]
- get_threads(query=None, read=None, replied=None, sent_items=False, sort=None)[source]¶
Get all the messages this user has sent or received. This does not return threads you have left.
- Parameters:
query (Optional[str]) – Optional query to filter messages
read (Optional[bool]) – True to filter only read message, false to filter unread, None to allow both
replied (Optional[bool]) – True to filter messages where you are the last message, False for messages where another user is the last message, None for both.
sent_items (
bool
) – Get only the threads you have startedsort (Tuple[str, str]) – Optional sort tuple to order threads
- Returns:
Thread typed thumbnails
- Return type:
List[ThreadThumbnail]
- get_updates()[source]¶
Get the current updates the user has for models they are subscribed to.
- Returns:
List of updates (thumbnail like objects with extra methods and an extra attribute)
- Return type:
List[Update]
- get_watched(category, page=1)[source]¶
Get a list of thumbnails of watched items based on the type parameters. Eventually, you’ll also be able to paginate your mods.
- Parameters:
- Returns:
List of watched things
- Return type:
- leave_thread(thread)[source]¶
Leave a thread, you will not get any more notifications on this thread.
- Parameters:
thread (Union[Thread, ThreadThumbnail]) – The thread to leave
- Returns:
Whether leaving the thread was successful
- Return type:
- like_comment(comment)[source]¶
Like a comment, if the comment has already been liked nothing will happen.
- Parameters:
comment (Comment) – The comment to like
- Raises:
ModdbException – An error has occured while trying to like the comment
- Returns:
True if the comment has been successfully liked
- Return type:
- mark_all_read()[source]¶
Mark all threads as read.
- Returns:
True if all threads have been marked as read
- Return type:
- membership(page)[source]¶
Join/leave a team
- Parameters:
page (Union[Group, Team]) – The team/group you want to join. Will not work if you don’t have permissions
- Raises:
ModdbException – An error has occured while trying to join/leave the group/team
- Returns:
True if the group/team has been successfully joined, False if the group/team has been successfully left.
- Return type:
- parse_thread(thread)[source]¶
Parse a thread thumbnail into a full thread object.
- Parameters:
thread (ThreadThumbnail) – The thumbnail to parse
- Returns:
The parsed thread and its messages
- Return type:
- reply_to_thread(thread, text)[source]¶
Add an additional message to an exiting thread
- Parameters:
thread (Union[Thread, ThreadThumbnail]) – The thread to add the message to
text (str) – The text to send
- Returns:
The updated thread containing the new message. It is recommended to use this object as it also contains a new hash for sending another message
- Return type:
- report(page)[source]¶
Report a page. This can take any object that has an id and url attribute.
- Parameters:
page (Any) – The page to report
- Raises:
ModdbException – An error has occured while trying to report the page
- Returns:
True if the page has been successfully reported
- Return type:
- send_message(members, name, message)[source]¶
Send a message and start a thread with one or more members
- send_request(member)[source]¶
Send a friend request to a user. You will not instantly become friends with them, they will have to accept the friend request you sent them first.
- Parameters:
member (Member) – The member you wish to send a friend request to
- Raises:
ModdbException – An error has occured trying to send a friend request to that user
- Returns:
True if the user was succesfully sent a friend request
- Return type:
- tracking(page)[source]¶
Follow/unfollow this page.
- undelete_comment(comment)[source]¶
This will undelete the supplied comment provided you have the correct permissions. This is an expensive request because of how moddb works. It needs to make three requests in order to get the correct hash to undelete the comment. In addition, it may fail if the comment has changed location (page number) from what the object says. It is recommended to use a newly created comment object that is less than 30 minutes old.
- Parameters:
comment (Comment) – The comment to undelete
- Raises:
ModdbException – An error occured while trying to undelete the comment
- Returns:
True if the comment was successfully undeleted
- Return type:
- unfriend(member)[source]¶
Unfriend this member if you are friends with them.
- Parameters:
member (Member) – The member you wish to unfriend
- Raises:
ModdbException – An error has occured trying to unfriend this user
- Returns:
True if the user was succesfully unfriended
- Return type:
ThreadThumbnail¶
Thread¶
- class moddb.client.Thread(html)[source]¶
A thread is a conversation between two or more members in which one or more messages can be sent.
Sorting
id - when the message was sent, asc is oldest, desc is most recent
name - order alphabetically, asc is a-z, desc is z-a
hasread - order by whether or the message has been read, asc is unread first, desc is read first
hasreplied - order by whether or not you have replied to the message, asc us unreplied first, desc is replied first
- members¶
All the members participating in the thread. Note: The thumbnail of the member who fetched the message will always be first and will have their name attribute be ‘you’ instead of the username
- Type:
List[Tumbnail]
Message¶
Update¶
- class moddb.client.Update(**attrs)[source]¶
An update object. Which is basically just a fancy thumbnail with a couple extra attributes and methods.
- date¶
A date related to this timestamp if it exists. Can be None
- Type:
- type¶
The type of the resource, mandatory attribute
- Type:
- updates¶
A list of thumbnail objects of the things thave have been posted (new files, new images)
- Type:
List[Thumbnail]
- clear()[source]¶
Clears all updates
- Raises:
ModdbException – An error has occured while trying to clear the updates for this page
- Returns:
True if the updates were successfully cleared
- Return type:
- parse()¶
Uses the Thumbnail’s mandatory attributes to get the full html of the model and parse them with the appropriate object.
- Returns:
The model that was parsed, can be any model from the list of the ThumbnailType enum.
- Return type:
Any
- unfollow()[source]¶
Unfollows the page. This will also clear the updates
- Raises:
ModdbException – An error has occured while trying to unfollow this page
- Returns:
True if the page was successfully unfollowed
- Return type:
Request¶
- class moddb.client.Request(**attrs)[source]¶
A thumbnail with two extra methods used to clear and accept requests.
- date¶
A date related to this timestamp if it exists. Can be None
- Type:
- type¶
The type of the resource, mandatory attribute
- Type:
- accept()[source]¶
Accept the friend request.
- Raises:
ModdbException – An error has occured while trying to accept the request
- Returns:
True if the request was successfully accepted
- Return type:
- decline()[source]¶
Decline the friend request
- Raises:
ModdbException – An error has occured while trying to decline the request
- Returns:
True if the page was successfully declined
- Return type:
- parse()¶
Uses the Thumbnail’s mandatory attributes to get the full html of the model and parse them with the appropriate object.
- Returns:
The model that was parsed, can be any model from the list of the ThumbnailType enum.
- Return type:
Any