forked from xditya/TeleBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Plugin - gita. By @TheShubhendra
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters