Skip to content

Commit

Permalink
add currency module
Browse files Browse the repository at this point in the history
  • Loading branch information
K-E-N-W-A-Y committed Apr 27, 2020
1 parent 7379e26 commit 909559f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@
"required": false
},
"SCREENSHOT_API": {
"description": "api key from 'https://screenshotlayer.com'",
"description": "get API key from 'https://screenshotlayer.com'",
"required": false

},
"CURRENCY_API": {
"description": "get API key from 'https://free.currencyconverterapi.com'",
"required": false

},
"G_DRIVE_PARENT_ID": {
"description": "GDrive Folder ID",
Expand Down
4 changes: 3 additions & 1 deletion config.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ DOWN_PATH = "downloads/"
PREFERRED_LANGUAGE = ""


# api key from 'https://screenshotlayer.com'
# get API key from 'https://screenshotlayer.com'
SCREENSHOT_API = ""

# get API Key from 'https://free.currencyconverterapi.com/'
CURRENCY_API = ""

# GDrive Folder ID
G_DRIVE_PARENT_ID = ""
Expand Down
2 changes: 2 additions & 0 deletions userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Config:

SCREENSHOT_API = os.environ.get("SCREENSHOT_API", None)

CURRENCY_API = os.environ.get("CURRENCY_API", None)

G_DRIVE_CLIENT_ID = os.environ.get("G_DRIVE_CLIENT_ID", None)

G_DRIVE_CLIENT_SECRET = os.environ.get("G_DRIVE_CLIENT_SECRET", None)
Expand Down
4 changes: 2 additions & 2 deletions userge/plugins/admin/gadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ async def pin_msgs(message: Message):
)
return

if silent_pin:
elif silent_pin:

try:
message_id = message.reply_to_message.message_id
Expand Down Expand Up @@ -1184,7 +1184,7 @@ async def chatpic_func(message: Message):
" `do .help gpic for more info` ⚠", del_in=0)
return

if gpic_del:
elif gpic_del:

try:
await userge.delete_chat_photo(chat_id)
Expand Down
56 changes: 56 additions & 0 deletions userge/plugins/utils/currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.


from requests import get
from emoji import get_emoji_regexp
from userge import userge, Message, Config

CHANNEL = userge.getCLogger(__name__)


@userge.on_cmd("cr", about={
'header': "use this to convert currency & get exchange rate",
'description': "Convert currency & get exchange rates.",
'examples': ".cr 1 BTC USD"})
async def cur_conv(message: Message):
"""
this function can get exchange rate results
"""
if Config.CURRENCY_API is None:
await message.edit(
"`Oops!!\nget the API from` (HERE)[https://free.currencyconverterapi.com] "
"`& add it to Heroku config vars` (`CURRENCY_API`)", del_in=0)
return

filterinput = get_emoji_regexp().sub(u'', message.input_str)
curcon = filterinput.upper().split()

if len(curcon) == 3:
amount, currency_to, currency_from = curcon
else:
await message.edit("`something went wrong!! do .help cr`")
return

if amount.isdigit():
data = get(
f"https://free.currconv.com/api/v7/convert?apiKey={Config.CURRENCY_API}&q={currency_from}_{currency_to}&compact=ultra"
).json()
result = data[f'{currency_from}_{currency_to}']
result = float(amount) / float(result)
result = round(result, 5)
await message.edit(
"**CURRENCY EXCHANGE RATE RESULT:**\n\n"
f"`{amount}` **{currency_to}** = `{result}` **{currency_from}**")
await CHANNEL.log("`cr` command executed sucessfully")

else:
await message.edit(
r"`This seems to be some alien currency, which I can't convert right now.. (⊙_⊙;)`"
, del_in=0)
return
2 changes: 1 addition & 1 deletion userge/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
__version_mjaor__ = 0
__version_minor__ = 1
__version_micro__ = 3
__version_beta__ = 14
__version_beta__ = 15

__version__ = "{}.{}.{}".format(__version_mjaor__,
__version_minor__,
Expand Down

0 comments on commit 909559f

Please sign in to comment.