Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion command #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cogs/conversioncog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from discord.ext import commands
from unit_converter.converter import convert, converts


class ConversionCog(commands.Cog):
def __init__(self, bot):
self.bot = bot # This line in the constructor is required

@commands.command()
async def convert(
self, ctx, inputunit, outputunit
): # the ctx parameter is short for 'context'
"""type your input and output units"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an accurate description of how the command works? It seems as though the input isn't just a unit, but is actually a quantity with a unit. Remember that although you have read the documentation or examples for the convert function you imported from unit-converter, your users have not, and neither have other programmers who may be viewing and working with your code. Make sure you use variable names and include documentation that is accurate to the way your code works! 😄

save = convert(inputunit, outputunit)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try and use variable names that accurately describe the data to which they refer. This benefits you and others who might try and read, edit, and/or improve your code in the future 🙂


await ctx.send(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be nice as an embed. Try the following after adding import discord to the top of your file

embed = discord.Embed(title="Unit Conversion")
embed.add_field(name="Input Quantity", value=inputunit)
embed.add_field(name="Output Unit", value=outputunit)
embed.add_field(name="Result", value=save)

await ctx.send(embed=embed)

Feel free to give it some colour if you'd like 🙂 it is up to you.

"You are converting from "
+ inputunit
+ " to "
+ str(save)
+ " "
+ outputunit
)


def setup(bot):
bot.add_cog(ConversionCog(bot))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ polling
pillow
google
pyquery
unit-converter