| Conditions | 3 | 
| Total Lines | 75 | 
| Code Lines | 48 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import re  | 
            ||
| 33 | @command(description="to create fake tweets")  | 
            ||
| 34 | async def twitter(  | 
            ||
| 35 | self,  | 
            ||
| 36 | ctx: MessageContext,  | 
            ||
| 37 | content: CommandArg[str, Description["The content of the message"]]  | 
            ||
| 38 | ):  | 
            ||
| 39 | await ctx.interaction.ack()  | 
            ||
| 40 | |||
| 41 | for text_match, user_id in re.findall(  | 
            ||
| 42 | re.compile(r"(<@!(\d+)>)"), content  | 
            ||
| 43 | ):  | 
            ||
| 44 | content = content.replace(  | 
            ||
| 45 |                 text_match, f"@{await self.get_user(user_id)}" | 
            ||
| 46 | )  | 
            ||
| 47 | |||
| 48 | if len(content) > 280:  | 
            ||
| 49 | return "A tweet can be at maximum 280 characters long"  | 
            ||
| 50 | |||
| 51 | # download the profile picture and convert it into Image object  | 
            ||
| 52 | avatar = (await ctx.author.user.get_avatar()).resize((128, 128))  | 
            ||
| 53 | avatar = circular_avatar(avatar)  | 
            ||
| 54 | |||
| 55 | # create the tweet by pasting the profile picture into a white image  | 
            ||
| 56 | tweet = trans_paste(  | 
            ||
| 57 | avatar,  | 
            ||
| 58 | Image.new(  | 
            ||
| 59 | "RGBA",  | 
            ||
| 60 | (800, 250 + 50 * len(textwrap.wrap(content, 38))),  | 
            ||
| 61 | (255, 255, 255)  | 
            ||
| 62 | ),  | 
            ||
| 63 | box=(15, 15),  | 
            ||
| 64 | )  | 
            ||
| 65 | |||
| 66 | # add the fonts  | 
            ||
| 67 |         font_normal = ImageFont.truetype("NotoSans-Regular.ttf", 40) | 
            ||
| 68 |         font_small = ImageFont.truetype("NotoSans-Regular.ttf", 30) | 
            ||
| 69 |         font_bold = ImageFont.truetype("NotoSans-Bold.ttf", 40) | 
            ||
| 70 | |||
| 71 | # write the name and username on the Image  | 
            ||
| 72 | draw = ImageDraw.Draw(tweet)  | 
            ||
| 73 | draw.text(  | 
            ||
| 74 | (180, 20),  | 
            ||
| 75 | str(ctx.author.user),  | 
            ||
| 76 | fill=(0, 0, 0),  | 
            ||
| 77 | font=font_bold  | 
            ||
| 78 | )  | 
            ||
| 79 | draw.text(  | 
            ||
| 80 | (180, 70),  | 
            ||
| 81 |             f"@{ctx.author.user.username}", | 
            ||
| 82 | fill=(120, 120, 120),  | 
            ||
| 83 | font=font_normal  | 
            ||
| 84 | )  | 
            ||
| 85 | |||
| 86 | content = add_color_to_mentions(content)  | 
            ||
| 87 | |||
| 88 | # write the text  | 
            ||
| 89 | tweet = draw_multicolored_text(tweet, content, font_normal)  | 
            ||
| 90 | |||
| 91 | # write the footer  | 
            ||
| 92 | draw.text(  | 
            ||
| 93 | (30, tweet.size[1] - 60),  | 
            ||
| 94 | datetime.now().strftime(  | 
            ||
| 95 | "%I:%M %p · %d %b. %Y · Twitter for Discord"  | 
            ||
| 96 | ),  | 
            ||
| 97 | fill=(120, 120, 120),  | 
            ||
| 98 | font=font_small,  | 
            ||
| 99 | )  | 
            ||
| 100 | |||
| 101 | return Message(  | 
            ||
| 102 | embeds=[  | 
            ||
| 103 | Embed(title="Twitter for Discord").set_image(  | 
            ||
| 104 | url="attachment://image0.png"  | 
            ||
| 105 | )  | 
            ||
| 106 | ],  | 
            ||
| 107 | attachments=[tweet],  | 
            ||
| 108 | )  | 
            ||
| 196 |