Sourcery refactored master branch - #1
Conversation
| def create_chat(self, name, about="", rules="", members=[], public=False, join_moderation=False, default_role="member"): | ||
| return self.http_session.get( | ||
| url="{}/chats/createChat".format(self.api_base_url), | ||
| url=f"{self.api_base_url}/chats/createChat", |
There was a problem hiding this comment.
Function create_chat refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| i = 1 | ||
| row = [] | ||
| for button in args: | ||
| for i, button in enumerate(args, start=1): | ||
| row.append(button.to_dic()) | ||
| if i % self.buttons_in_row == 0: | ||
| self.keyboard.append(row) | ||
| row = [] | ||
| i += 1 |
There was a problem hiding this comment.
Function InlineKeyboardMarkup.add refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| btn_array = [] | ||
| for button in args: | ||
| btn_array.append(button.to_dic()) | ||
| btn_array = [button.to_dic() for button in args] |
There was a problem hiding this comment.
Function InlineKeyboardMarkup.row refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| result = {} | ||
| for key in self.styles.keys(): | ||
| result[key] = self.styles[key].to_dic() | ||
| result = {key: self.styles[key].to_dic() for key in self.styles.keys()} |
There was a problem hiding this comment.
Function Format.to_json refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="User command: {}".format(event.data['text'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"User command: {event.data['text']}", | ||
| ) |
There was a problem hiding this comment.
Function test_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Private user command: {}".format(event.data['text'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Private user command: {event.data['text']}", | ||
| ) |
There was a problem hiding this comment.
Function private_command_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was pinned".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was pinned", | ||
| ) |
There was a problem hiding this comment.
Function pinned_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was unpinned".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was unpinned", | ||
| ) |
There was a problem hiding this comment.
Function unpinned_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was edited".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was edited", | ||
| ) |
There was a problem hiding this comment.
Function edited_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was deleted".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was deleted", | ||
| ) |
There was a problem hiding this comment.
Function deleted_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| text="Reply to message: {}".format(msg_id), | ||
| reply_msg_id=msg_id | ||
| text=f"Reply to message: {msg_id}", | ||
| reply_msg_id=msg_id, |
There was a problem hiding this comment.
Function reply_to_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
3fbea40 to
ffec9d6
Compare
| name=self.name if self.name is not None else requests.get(url="{}/self/get".format(self.api_base_url), | ||
| params={"token": self.token} | ||
| ).json().get('nick'), | ||
| # name=self.name, | ||
| name=self.name | ||
| if self.name is not None | ||
| else requests.get( | ||
| url=f"{self.api_base_url}/self/get", params={"token": self.token} | ||
| ) | ||
| .json() | ||
| .get('nick'), | ||
| version=self.version if self.version is not None else 'base', | ||
| uin="" if self.uin is None else self.uin, | ||
| library_version=version | ||
| library_version=version, |
There was a problem hiding this comment.
Function Bot.user_agent refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
This removes the following comments ( why? ):
# name=self.name,
| if response: | ||
| if "description" in response.json() and response.json()["description"] == 'Invalid token': | ||
| raise InvalidToken(response.json()) | ||
| if ( | ||
| response | ||
| and "description" in response.json() | ||
| and response.json()["description"] == 'Invalid token' | ||
| ): | ||
| raise InvalidToken(response.json()) |
There was a problem hiding this comment.
Function Bot._start_polling refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| url="{}/events/get".format(self.api_base_url), | ||
| url=f"{self.api_base_url}/events/get", | ||
| params={ | ||
| "token": self.token, | ||
| "pollTime": poll_time_s, | ||
| "lastEventId": last_event_id | ||
| "lastEventId": last_event_id, | ||
| }, | ||
| timeout=poll_time_s + self.timeout_s | ||
| timeout=poll_time_s + self.timeout_s, |
There was a problem hiding this comment.
Function Bot.events_get refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/self/get".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/self/get", | ||
| params={"token": self.token}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.self_get refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/messages/sendText".format(self.api_base_url), | ||
| url=f"{self.api_base_url}/messages/sendText", |
There was a problem hiding this comment.
Function Bot.send_text refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/getPendingUsers".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/getPendingUsers", | ||
| params={"token": self.token, "chatId": chat_id}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.get_chat_pending_users refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/blockUser".format(self.api_base_url), | ||
| url=f"{self.api_base_url}/chats/blockUser", | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "userId": user_id, | ||
| "delLastMessages": str(del_last_messages).lower() | ||
| "delLastMessages": str(del_last_messages).lower(), | ||
| }, | ||
| timeout=self.timeout_s | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.chat_block_user refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/unblockUser".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "userId": user_id | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/unblockUser", | ||
| params={"token": self.token, "chatId": chat_id, "userId": user_id}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.chat_unblock_user refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/resolvePending".format(self.api_base_url), | ||
| url=f"{self.api_base_url}/chats/resolvePending", | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "approve": str(approve).lower(), | ||
| "userId": user_id, | ||
| "everyone": str(everyone).lower() | ||
| "everyone": str(everyone).lower(), | ||
| }, | ||
| timeout=self.timeout_s | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.chat_resolve_pending refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/setTitle".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "title": title | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/setTitle", | ||
| params={"token": self.token, "chatId": chat_id, "title": title}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.set_chat_title refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/setAbout".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "about": about | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/setAbout", | ||
| params={"token": self.token, "chatId": chat_id, "about": about}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.set_chat_about refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/setRules".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "rules": rules | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/setRules", | ||
| params={"token": self.token, "chatId": chat_id, "rules": rules}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.set_chat_rules refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/files/getInfo".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "fileId": file_id | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/files/getInfo", | ||
| params={"token": self.token, "fileId": file_id}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.get_file_info refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/pinMessage".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "msgId": msg_id | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/pinMessage", | ||
| params={"token": self.token, "chatId": chat_id, "msgId": msg_id}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.pin_message refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| url="{}/chats/unpinMessage".format(self.api_base_url), | ||
| params={ | ||
| "token": self.token, | ||
| "chatId": chat_id, | ||
| "msgId": msg_id | ||
| }, | ||
| timeout=self.timeout_s | ||
| url=f"{self.api_base_url}/chats/unpinMessage", | ||
| params={"token": self.token, "chatId": chat_id, "msgId": msg_id}, | ||
| timeout=self.timeout_s, |
There was a problem hiding this comment.
Function Bot.unpin_message refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Private user command: {}".format(event.data['text'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Private user command: {event.data['text']}", | ||
| ) |
There was a problem hiding this comment.
Function private_command_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was pinned".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was pinned", | ||
| ) |
There was a problem hiding this comment.
Function pinned_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was unpinned".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was unpinned", | ||
| ) |
There was a problem hiding this comment.
Function unpinned_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was edited".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was edited", | ||
| ) |
There was a problem hiding this comment.
Function edited_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| bot.send_text(chat_id=event.data['chat']['chatId'], text="Message {} was deleted".format(event.data['msgId'])) | ||
| bot.send_text( | ||
| chat_id=event.data['chat']['chatId'], | ||
| text=f"Message {event.data['msgId']} was deleted", | ||
| ) |
There was a problem hiding this comment.
Function deleted_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| text="Reply to message: {}".format(msg_id), | ||
| reply_msg_id=msg_id | ||
| text=f"Reply to message: {msg_id}", | ||
| reply_msg_id=msg_id, |
There was a problem hiding this comment.
Function reply_to_message_cb refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!