Fixes #62
v3 API #91
charlhakeem/simplematrixbotlib:v3 into v3
246b83cdba
to 6b26fe3df9
@ -29,4 +36,1 @@
content["m.relates_to"]
except KeyError:
content["m.relates_to"] = {} # type: ignore
content["m.relates_to"]["m.in_reply_to"] = { # type: ignore
Won't this cause a KeyError?
6b26fe3df9
to 723e85803e
Is the v3 branch currently suitable for running a basic bot for development purposes? The Bot class appears to be incomplete, and example bots fail to start.
Is the v3 branch currently suitable for running a basic bot for development purposes? The Bot class appears to be incomplete, and example bots fail to start.
Yes, it is suitable, though incomplete. The examples are from version 2 and out of date. See the README.md for an updated example.
723e85803e
to 1b29ea19bd
@ -27,2 +73,3 @@
})
if reply_to_event_id:
try:
This approach is easier to extend , e.g. for threads. Please revert this chunk
@ -20,3 +58,2 @@
async def send_text(self, message_body: str, reply_to_event_id: Optional[str] = None):
async def send_text(self, message_body: str, _markdown: Optional[bool] = False, reply_to_event_id: Optional[str] = None):
Can you change you replace _markdown with format_as_markdown: bool ?
@ -27,0 +66,4 @@
md = markdown.markdown(message_body,
extensions=["sane_lists", "fenced_code", "nl2br"])
content["body"] = strip_html(md)
What is the purpose of stripping html?
The body field should only contain unformatted plain text, with all formatting and styling reserved for the formatted_body field.
Does that break html codeblocks? e.g.
"""
text here
<p>my html</p>
more text
"""
I've reverted the HTML stripping, as it seemed unnecessary and was causing issues. The current behavior should now align with the v2 version.
@ -41,0 +114,4 @@
"url": resp.content_uri
}
if not filetype == "file":
Checking for each file type instead of using guards would be more appropriate in this case.
c54708ec66
to ee72ad7490
ee72ad7490
to 53911ec2b1
@ -14,2 +15,4 @@
def __repr__(self):
return self.body
def get_body(self):
Formatted body and body should be decoupled. The user should have an easy way to fetch the body, a way to check if the body is formatted, and a way to get the formatted body.
Instead of get_body(), I suggest a get_formatted_body method. This method should have a parameter of something like with_reply_markup, determining whether or not to include . If there is no formatted body, it should return None.
This method is intended for scenarios where the user requires quick access to a message's text content. If the raw text is needed, user can simply retrieve message.body or message.formatted_body without utilizing this method.
@ -16,0 +20,4 @@
return re.sub(r'<mx-reply>.*?</mx-reply>', '', self.formatted_body)
return self.body
def command(self, command: str, case_sensitive: bool = True):
Version 3 will not support a command method.
It was unreliable with some messages, and barely an improvement over str.startswith()
@ -16,0 +31,4 @@
if regex:
return bool(re.search(string, body, 0 if case_sensitive else re.IGNORECASE))
if not isinstance(string, str):
string should only be a string. If the library user needs to check multiple strings, they can make multiple calls.
If needed, accepted types can be expanded at a later date.
Removing support for Iterables would reduce the usefulness of the contains method. It is easier and more readable to pass a predefined list of words directly to contains for matching than to manually create a for loop and call the method in each iteration.
@ -18,3 +40,4 @@
def __repr__(self):
return f"{self.room_id}: {self.name}"
async def send_text(self, message_body: str, format_as_markdown: bool = False, reply_to_event_id: Optional[str] = None, room_id: Optional[str] = None):
Can you add the appropriate response/error return type?
@ -38,3 +71,4 @@
content=content
)
async def send_media(self, filepath: str, filetype: Optional[str] = None, room_id: Optional[str] = None):
Can you use the string Literal type as part of the filetype type?
@ -41,0 +105,4 @@
if filetype in ("video", "audio"):
content["info"]["duration"] = int(float(await ffprobe(filepath, "format=duration") * 1000))
elif filetype in ("image", "video"):
These are not exclusive, should be a second if, not elif
@ -41,0 +129,4 @@
The room id of the destination of the message.
"""
if not event_id:
event_id = self.event_id
There is no event_id attribute on Room. event_id should be required
@ -41,0 +157,4 @@
uri : str
The geo URI scheme of the location.
description : str, optional
Rename to location_description
@ -41,0 +203,4 @@
question : str
The content of the question to be sent.
answers : list
Should this be Iterable[str]? Same in the signature
@ -41,0 +251,4 @@
The room id of the destination of the poll.
"""
if not event_id:
event_id = self.event_id
event_id should be mandatory
@ -41,0 +284,4 @@
room_id = self.room_id
if not user_id:
user_id = self.user_id
user_id should be required
@ -41,0 +304,4 @@
room_id = self.room_id
if not user_id:
user_id = self.user_id
user_id should be required
@ -41,0 +327,4 @@
room_id = self.room_id
if not user_id:
user_id = self.user_id
user_id should be required
@ -41,0 +347,4 @@
room_id = self.room_id
if not user_id:
user_id = self.user_id
user_id should be required
@ -41,0 +370,4 @@
room_id = self.room_id
if not event_id:
event_id = self.event_id
event_id should be required
@ -41,0 +396,4 @@
room_id = self.room_id
if not event_id:
event_id = self.event_id
event_id should be required
@ -41,0 +414,4 @@
if format_as_markdown:
md = markdown.markdown(message_body,
extensions=["sane_lists", "fenced_code", "nl2br"])
body = strip_html(md)
Remove strip_html
@ -41,0 +445,4 @@
room_id = self.room_id
if not user_id:
user_id = self.user_id
user_id should be required
@ -41,0 +454,4 @@
await self.client.room_put_state(room_id, "m.room.power_levels", content)
async def get_room_state(self, room_id: Optional[str] = None):
Remove, out of scope
@ -41,0 +490,4 @@
await self.client.room_leave(room_id)
if forget:
await self.client.room_forget(room_id)
Return Tuple of something like (Leave response/error, Optional[forget response/error])
@ -41,2 +492,4 @@
if forget:
await self.client.room_forget(room_id)
async def join(self):
Move this to the Bot class and add a room_id parameter
53911ec2b1
to cdb8c2b998
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.
No due date set.
No dependencies set.
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?