Conversation
| async def buttons_handler(ctx: BotContext[CommandEvent]): | ||
| m = await ctx.bot.prepare_response_message(ctx.event.message) | ||
| m.message = f"Please select an option:" | ||
| m.message = "Please select an option:" |
There was a problem hiding this comment.
Function buttons_handler refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| async def buttons_handler(ctx: BotContext[CommandEvent]): | ||
| m = await ctx.bot.prepare_response_message(ctx.event.message) | ||
| m.message = f"Please select an option:" | ||
| m.message = "Please select an option:" |
There was a problem hiding this comment.
Function buttons_handler refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| async def buttons_handler(ctx: BotContext[CommandEvent]): | ||
| m = await ctx.bot.prepare_response_message(ctx.event.message) | ||
| m.message = f"Please select an option:" | ||
| m.message = "Please select an option:" |
There was a problem hiding this comment.
Function buttons_handler refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| async def buttons_handler(ctx: BotContext[CommandEvent]): | ||
| m = await ctx.bot.prepare_response_message(ctx.event.message) | ||
| m.message = f"Please select an option:" | ||
| m.message = "Please select an option:" |
There was a problem hiding this comment.
Function buttons_handler refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| @app.on_community_update() | ||
| async def community_update_handler(ctx: BotContext[CommunityUpdatedEvent]): | ||
| print(ctx.event.community_id + " was updated") | ||
| print(f"{ctx.event.community_id} was updated") |
There was a problem hiding this comment.
Function community_update_handler refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| results = [] | ||
| for i in range(len(data[1])): | ||
| results.append( | ||
| InlineQueryResultArticle( | ||
| id=str(i), | ||
| title=data[1][i], | ||
| description=data[1][i], | ||
| input_message=InputMessageContent(data[2][i]), | ||
| article_url=data[3][i], | ||
| thumb_url="https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/1200px-Wikipedia-logo-v2.svg.png", | ||
| thumb_width=48, | ||
| thumb_height=48)) | ||
| results = [ | ||
| InlineQueryResultArticle( | ||
| id=str(i), | ||
| title=data[1][i], | ||
| description=data[1][i], | ||
| input_message=InputMessageContent(data[2][i]), | ||
| article_url=data[3][i], | ||
| thumb_url="https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/1200px-Wikipedia-logo-v2.svg.png", | ||
| thumb_width=48, | ||
| thumb_height=48, | ||
| ) | ||
| for i in range(len(data[1])) | ||
| ] |
There was a problem hiding this comment.
Function on_inline_query refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| async def buttons_handler(ctx: BotContext[CommandEvent]): | ||
| m = await ctx.bot.prepare_response_message(ctx.event.message) | ||
| m.message = f"Please select an option:" | ||
| m.message = "Please select an option:" |
There was a problem hiding this comment.
Function buttons_handler refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| @app.on_community_update() | ||
| async def community_update_handler(ctx: BotContext[CommunityUpdatedEvent]): | ||
| print(ctx.event.community_id + " was updated") | ||
| print(f"{ctx.event.community_id} was updated") |
There was a problem hiding this comment.
Function community_update_handler refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| else: | ||
| res = in_s | ||
| return res | ||
| return in_s[len(lstr):] if in_s.startswith(lstr) else in_s |
There was a problem hiding this comment.
Function _lstrip_str refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| subscription = await self.ws.subscribe( | ||
| return await self.ws.subscribe( | ||
| "/chat/queue/events", | ||
| callback=lambda event: callback(self._parse_event(event)), | ||
| ) | ||
| return subscription |
There was a problem hiding this comment.
Function ChatClient.subscribe_to_notifications refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| evt = self.build_object(MessageEvent, json_data) | ||
| # evt = MessageEvent.build_from_json(json_data) | ||
| return self.build_object(MessageEvent, json_data) | ||
| # evt = MessageEvent.build_from_json(json_data) | ||
| elif type == EventType.COMMAND.value: | ||
| evt = self.build_object(CommandEvent, json_data) | ||
| # evt = CommandEvent.build_from_json(json_data) | ||
| return self.build_object(CommandEvent, json_data) | ||
| # evt = CommandEvent.build_from_json(json_data) | ||
| elif type == EventType.CALLBACK_QUERY.value: | ||
| evt = self.build_object(CallbackQueryEvent, json_data) | ||
| # evt = CallbackQueryEvent.build_from_json(json_data) | ||
| return self.build_object(CallbackQueryEvent, json_data) | ||
| # evt = CallbackQueryEvent.build_from_json(json_data) | ||
| elif type == EventType.INLINE_QUERY.value: | ||
| evt = self.build_object(InlineQueryEvent, json_data) | ||
| return self.build_object(InlineQueryEvent, json_data) | ||
| else: | ||
| evt = self.build_object(ChatEvent, json_data) | ||
| # evt = ChatEvent.build_from_json(json_data) | ||
| return evt | ||
| return self.build_object(ChatEvent, json_data) | ||
| # evt = ChatEvent.build_from_json(json_data) |
There was a problem hiding this comment.
Function ChatClient._parse_event refactored with the following changes:
- Lift return into if (
lift-return-into-if)
| id = message.id | ||
| else: | ||
| id = message | ||
| id = message.id if isinstance(message, Message) else message |
There was a problem hiding this comment.
Function MessageController.reply refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if isinstance(message, Message): | ||
| id = message.id | ||
| else: | ||
| id = message | ||
|
|
||
| id = message.id if isinstance(message, Message) else message |
There was a problem hiding this comment.
Function MessageController.reply_text refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if isinstance(message, Message): | ||
| id = message.id | ||
| else: | ||
| id = message | ||
| id = message.id if isinstance(message, Message) else message |
There was a problem hiding this comment.
Function MessageController.edit_message_text refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if isinstance(message, Message): | ||
| id = message.id | ||
| else: | ||
| id = message | ||
| id = message.id if isinstance(message, Message) else message |
There was a problem hiding this comment.
Function MessageController.delete_message refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def from_json(self, data: JSONDict) -> "Group": | ||
| def from_json(cls, data: JSONDict) -> "Group": | ||
| if data is not None: | ||
| self.id = data.get("groupId") | ||
| self.name = data.get("groupName") | ||
| self.community_id = data.get("communityId") | ||
| self.enabled_free = data.get("enabledFree") | ||
| self.enabled_public = data.get("enabledPublic") | ||
| self.default_group = data.get("defaultGroup") | ||
| self.is_public = data.get("isPublic") | ||
| self.created_by = data.get("createdBy") | ||
| self.icon = data.get("icon") | ||
| self.group_logo_url = data.get("groupLogoUrl") | ||
| self.allowed_content = data.get("allowedContent") | ||
| self.created_at = data.get("createdAt") | ||
| self.updated_at = data.get("updatedAt") | ||
| return self | ||
| cls.id = data.get("groupId") | ||
| cls.name = data.get("groupName") | ||
| cls.community_id = data.get("communityId") | ||
| cls.enabled_free = data.get("enabledFree") | ||
| cls.enabled_public = data.get("enabledPublic") | ||
| cls.default_group = data.get("defaultGroup") | ||
| cls.is_public = data.get("isPublic") | ||
| cls.created_by = data.get("createdBy") | ||
| cls.icon = data.get("icon") | ||
| cls.group_logo_url = data.get("groupLogoUrl") | ||
| cls.allowed_content = data.get("allowedContent") | ||
| cls.created_at = data.get("createdAt") | ||
| cls.updated_at = data.get("updatedAt") | ||
| return cls |
There was a problem hiding this comment.
Function Group.from_json refactored with the following changes:
- The first argument to class methods should be
cls(class-method-first-arg-name)
| if data is None: | ||
| return None | ||
| return cls(app).from_json(data) | ||
| return None if data is None else cls(app).from_json(data) |
There was a problem hiding this comment.
Function SwitchObject.build_from_json refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| if app.auto_update_bot: | ||
| """Called when app start | ||
| if not app.auto_update_bot: | ||
| return | ||
| """Called when app start | ||
| This method registers the bot commands and updates the bot info | ||
| """ | ||
| # get all app commands | ||
| commands = self.app._register_commands or [] | ||
| description = self.app._bot_description or "" | ||
| # register the commands | ||
| self._info = BotInfo(description=description, id=self.id) | ||
| for command in commands: | ||
| command_name = command.command | ||
| if isinstance(command_name, str): | ||
| command_names = command_name.split(",") | ||
| else: | ||
| command_names = command_name | ||
|
|
||
| for c_name in command_names: | ||
| self.info.commands.append( | ||
| BotCommandInfo( | ||
| command=c_name, | ||
| description=command.description, | ||
| channel=command.channel, | ||
| ) | ||
| # get all app commands | ||
| commands = self.app._register_commands or [] | ||
| description = self.app._bot_description or "" | ||
| # register the commands | ||
| self._info = BotInfo(description=description, id=self.id) | ||
| for command in commands: | ||
| command_name = command.command | ||
| if isinstance(command_name, str): | ||
| command_names = command_name.split(",") | ||
| else: | ||
| command_names = command_name | ||
|
|
||
| for c_name in command_names: | ||
| self.info.commands.append( | ||
| BotCommandInfo( | ||
| command=c_name, | ||
| description=command.description, | ||
| channel=command.channel, | ||
| ) | ||
| ) | ||
|
|
||
| self.info = await self.update_bot_info(self.info) | ||
|
|
||
| pass | ||
| self.info = await self.update_bot_info(self.info) |
There was a problem hiding this comment.
Function Bot.on_app_start refactored with the following changes:
- Add guard clause (
last-if-guard) - Remove redundant pass statement (
remove-redundant-pass)
| return True | ||
|
|
||
| return await self.other(ctx) | ||
| return True if r1 else await self.other(ctx) |
There was a problem hiding this comment.
Function OrFilter.__call__ refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| return bool( | ||
| return ( |
There was a problem hiding this comment.
Function self_filter refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| return ( | ||
| ctx.event.message is not None | ||
| and ctx.event.message.user_id == ctx.user.id | ||
| ) |
There was a problem hiding this comment.
Function me_filter refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| return bool(ctx.event.message is not None and ctx.event.message.receiver_id == ctx.user.id) | ||
| return ( | ||
| ctx.event.message is not None | ||
| and ctx.event.message.receiver_id == ctx.user.id | ||
| ) |
There was a problem hiding this comment.
Function incoming_filter refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| return bool(ctx.event.community_id is not None) | ||
| return ctx.event.community_id is not None | ||
| if isinstance(community_id, str): | ||
| community_id = frozenset({community_id}) | ||
| else: | ||
| community_id = frozenset(community_id) | ||
| return bool(ctx.event.community_id in community_id) | ||
| return ctx.event.community_id in community_id |
There was a problem hiding this comment.
Function community.__call__ refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool [×2] (
remove-unnecessary-cast)
| return bool(ctx.event.channel_id is not None) | ||
| return ctx.event.channel_id is not None | ||
| if isinstance(channel_id, str): | ||
| channel_id = frozenset({channel_id}) | ||
| else: | ||
| channel_id = frozenset(channel_id) | ||
| return bool(ctx.event.channel_id in channel_id) | ||
| return ctx.event.channel_id in channel_id |
There was a problem hiding this comment.
Function channel.__call__ refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool [×2] (
remove-unnecessary-cast)
| return bool(ctx.event.group_id is not None) | ||
| return ctx.event.group_id is not None | ||
| if isinstance(group_id, str): | ||
| group_id = frozenset({group_id}) | ||
| else: | ||
| group_id = frozenset(group_id) | ||
| return bool(ctx.event.group_id in group_id) | ||
| return ctx.event.group_id in group_id |
There was a problem hiding this comment.
Function group.__call__ refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool [×2] (
remove-unnecessary-cast)
| if TYPE_CHECKING: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Lines 13-15 refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| if (self.event_types is not None) and (not context.event.type in self.event_types): | ||
| if ( | ||
| self.event_types is not None | ||
| and context.event.type not in self.event_types | ||
| ): | ||
| return False | ||
| if self.filter: | ||
| return await self.filter(context) | ||
| return True | ||
| return await self.filter(context) if self.filter else True |
There was a problem hiding this comment.
Function EventHandler.should_handle refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| if TYPE_CHECKING: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Lines 10-12 refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| if TYPE_CHECKING: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Lines 12-14 refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| if TYPE_CHECKING: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Lines 12-14 refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!