Skip to content

Commit

Permalink
New Plugin
Browse files Browse the repository at this point in the history
Add new Plugin - gita. By @TheShubhendra
  • Loading branch information
xditya authored Jan 25, 2021
2 parents 2976932 + a74f2d1 commit 32f9e8f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
"value": "",
"required": false
},
"GITA_CLIENT_ID": {
"description": "Needed for gita plugin. Follow https://bhagavadgita.io to get yours.",
"value":"",
"required": false
},
"GITA_CLIENT_SECRET":{
"description": "Needed for gita plugin. Follow https://bhagavadgita.io to get yours.",
"value":"",
"required": false
},
"HEROKU_API_KEY": {
"description": "Go to https://dashboard.heroku.com/account, scroll down and press Reveal API.Required for updater to work.",
"value": "",
Expand Down
55 changes: 55 additions & 0 deletions telebot/plugins/gita.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Author: Shubhendra Kushwaha (@TheShubhendra)
# Email: [email protected]
import pygita

from telebot import CMD_HELP
from telebot.telebotConfig import Var
from telebot.utils import admin_cmd


CLIENT_ID = Var.GITA_CLIENT_ID
CLIENT_SECRET = Var.GITA_CLIENT_SECRET
"""Get API crendentials from https://bhagavadgita.io."""


@telebot.on(admin_cmd(pattern="gita +(.*) +(.*)$"))
async def gita(event):
"""To get a specific verse from a specific chapter in English."""
if CLIENT_ID is None or CLIENT_SECRET is None:
await event.edit(
"`Please add required GITA_CLIENT_SECRET and GITA_CLIENT_ID env var`"
)
return
pygita.auth(CLIENT_ID, CLIENT_SECRET)
try:
chapter_number = int(event.pattern_match.group(1))
verse_number = int(event.pattern_match.group(2))
except ValueError:
return
verse = pygita.get_verse(chapter_number, verse_number, language="en")
await event.edit(f"**{verse.text}** {verse.meaning}")


@telebot.on(admin_cmd(pattern="gita +(.*) +(.*) hi$"))
async def gita_hindi(event):
"""To get a specific verse from a specific chapter in Hindi."""
if CLIENT_ID is None or CLIENT_SECRET is None:
await event.edit(
"`Please add required GITA_CLIENT_SECRET and GITA_CLIENT_ID env var`"
)
return
pygita.auth(CLIENT_ID, CLIENT_SECRET)
chapter_number = int(event.pattern_match.group(1))
verse_number = int(event.pattern_match.group(2))
verse = pygita.get_verse(chapter_number, verse_number, language="hi")
await event.edit(f"**{verse.text}** {verse.meaning}")

CMD_HELP.update(
{
"gita": "**gita**\
\n\n**Syntax : **`.verse <chapter_number> <verse_number>`\
\n**Usage :** Get a specific verse from a particular chapter\
\n\n**Syntax : **`.verse <chapter_number> <verse_number> hi`\
\n**Usage :** Get a specific verse from a particular chapter in hindi.\n"
}
)
2 changes: 2 additions & 0 deletions telebot/telebotConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ class Config(object):
MAX_SPAM = int(os.environ.get("MAX_SPAM", 3))
# Lydia API
LYDIA_API = os.environ.get("LYDIA_API", None)
GITA_CLIENT_ID = os.environ.get("GITA_CLIENT_ID", None)
GITA_CLIENT_SECRET = os.environ.get("GITA_CLIENT_SECRET", None)
FBAN_GROUP_ID = os.environ.get("FBAN_GROUP_ID", None)
if FBAN_GROUP_ID:
FBAN_GROUP_ID = int(FBAN_GROUP_ID)
Expand Down

0 comments on commit 32f9e8f

Please sign in to comment.