-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7349ac3
Showing
25 changed files
with
1,353 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Deploy to Heroku | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: akhileshns/[email protected] | ||
with: | ||
heroku_api_key: ${{secrets.HEROKU_API_KEY}} | ||
heroku_email: ${{secrets.HEROKU_EMAIL}} | ||
heroku_app_name: ${{secrets.HEROKU_APP_NAME}} | ||
usedocker: true | ||
docker_heroku_process_type: worker | ||
stack: "container" | ||
region: "eu" | ||
env: | ||
HD_CONFIG_ENV_URL: ${{secrets.CONFIG_ENV_URL}} |
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,12 @@ | ||
config.env | ||
*.pyc | ||
downloads/* | ||
download/* | ||
data* | ||
.vscode | ||
.idea | ||
*.json | ||
log.txt | ||
accounts/* | ||
drive_list | ||
/temp.py |
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,12 @@ | ||
FROM python:3.9-slim | ||
|
||
WORKDIR /usr/src/app | ||
RUN chmod 777 /usr/src/app | ||
|
||
RUN apt-get -qq update | ||
|
||
COPY requirements.txt . | ||
RUN pip3 install --no-cache-dir -r requirements.txt | ||
COPY . . | ||
|
||
CMD ["bash","start.sh"] |
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
<p align="center"> | ||
|
||
<img width="200" src="https://cdn.dribbble.com/users/1501052/screenshots/5468049/searching_tickets.gif" alt="SearchX"> | ||
|
||
</p> | ||
|
||
|
||
<p align="center"> | ||
|
||
## This is a Telegram Bot written in Python for searching data on Google Drive. Supports multiple Shared Drives (TDs). | ||
|
||
</p> | ||
|
||
|
||
### [Manual](https://github.com/l3v11/SearchX/wiki) | ||
|
||
Guide for deploying the bot | ||
|
||
### [Commands](https://github.com/l3v11/SearchX/wiki/Bot-Commands) | ||
|
||
List of commands for the bot | ||
|
||
### [Changelog](https://github.com/l3v11/SearchX/wiki/Changelog) | ||
|
||
List of changes made to the bot | ||
|
||
### [FAQ](https://github.com/l3v11/SearchX/wiki/Frequently-Asked-Questions) | ||
|
||
Read this if you have any queries | ||
|
||
### [Credits](https://github.com/l3v11/SearchX/wiki/Credits) | ||
|
||
List of contributors of the bot |
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,113 @@ | ||
import logging | ||
import os | ||
import time | ||
import random | ||
import string | ||
import requests | ||
|
||
import telegram.ext as tg | ||
|
||
from dotenv import load_dotenv | ||
from telegraph import Telegraph | ||
|
||
if os.path.exists('log.txt'): | ||
with open('log.txt', 'r+') as f: | ||
f.truncate(0) | ||
|
||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||
handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()], | ||
level=logging.INFO) | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
def get_config(name: str): | ||
return os.environ[name] | ||
|
||
CONFIG_ENV_URL = os.environ.get('CONFIG_ENV_URL', None) | ||
if CONFIG_ENV_URL is not None: | ||
res = requests.get(CONFIG_ENV_URL) | ||
if res.status_code == 200: | ||
with open('config.env', 'wb+') as f: | ||
f.write(res.content) | ||
f.close() | ||
else: | ||
LOGGER.error(f"Failed to load config.env file [{res.status_code}]") | ||
|
||
load_dotenv('config.env') | ||
|
||
AUTHORIZED_CHATS = set() | ||
|
||
try: | ||
auths = get_config('AUTHORIZED_CHATS') | ||
auths = auths.split(" ") | ||
for chats in auths: | ||
AUTHORIZED_CHATS.add(int(chats)) | ||
except: | ||
pass | ||
|
||
try: | ||
BOT_TOKEN = get_config('BOT_TOKEN') | ||
OWNER_ID = int(get_config('OWNER_ID')) | ||
except KeyError: | ||
LOGGER.error("BOT_TOKEN and/or OWNER_ID var is missing") | ||
exit(1) | ||
|
||
try: | ||
if len(get_config('DRIVE_TOKEN')) == 0 or str(get_config('DRIVE_TOKEN')).lower() == "empty": | ||
LOGGER.error("DRIVE_TOKEN var is missing") | ||
exit(1) | ||
with open('token.json', 'wt') as f: | ||
f.write(get_config('DRIVE_TOKEN').replace("\n","")) | ||
except: | ||
LOGGER.error("Failed to create token.json file") | ||
exit(1) | ||
|
||
try: | ||
DRIVE_LIST_URL = get_config('DRIVE_LIST_URL') | ||
if len(DRIVE_LIST_URL) == 0: | ||
DRIVE_LIST_URL = None | ||
else: | ||
res = requests.get(DRIVE_LIST_URL) | ||
if res.status_code == 200: | ||
with open('drive_list', 'wb+') as f: | ||
f.write(res.content) | ||
f.close() | ||
else: | ||
LOGGER.error(f"Failed to load drive_list file [{res.status_code}]") | ||
raise KeyError | ||
except KeyError: | ||
pass | ||
|
||
DRIVE_NAME = [] | ||
DRIVE_ID = [] | ||
INDEX_URL = [] | ||
|
||
if os.path.exists('drive_list'): | ||
with open('drive_list', 'r+') as f: | ||
lines = f.readlines() | ||
for line in lines: | ||
temp = line.strip().split() | ||
DRIVE_NAME.append(temp[0].replace("_", " ")) | ||
DRIVE_ID.append(temp[1]) | ||
try: | ||
INDEX_URL.append(temp[2]) | ||
except IndexError: | ||
INDEX_URL.append(None) | ||
|
||
if DRIVE_ID: | ||
pass | ||
else: | ||
LOGGER.error("drive_list file is missing") | ||
exit(1) | ||
|
||
# Generate Telegraph Token | ||
sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8)) | ||
LOGGER.info("Generating TELEGRAPH_TOKEN using '" + sname + "' name") | ||
telegraph = Telegraph() | ||
telegraph.create_account(short_name=sname) | ||
telegraph_token = telegraph.get_access_token() | ||
telegra_ph = Telegraph(access_token=telegraph_token) | ||
|
||
updater = tg.Updater(token=BOT_TOKEN, use_context=True) | ||
bot = updater.bot | ||
dispatcher = updater.dispatcher |
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,33 @@ | ||
from telegram.ext import CommandHandler | ||
|
||
from bot import AUTHORIZED_CHATS, dispatcher, updater | ||
from bot.modules import auth, list, shell | ||
from bot.helper.telegram_helper.bot_commands import BotCommands | ||
from bot.helper.telegram_helper.filters import CustomFilters | ||
from bot.helper.telegram_helper.message_utils import * | ||
|
||
def start(update, context): | ||
if CustomFilters.authorized_user(update) or CustomFilters.authorized_chat(update): | ||
if update.message.chat.type == "private": | ||
sendMessage(f"Access granted", context.bot, update) | ||
else: | ||
sendMessage(f"This is a bot for searching data on Google Drive", context.bot, update) | ||
else: | ||
sendMessage(f"Access denied", context.bot, update) | ||
|
||
def log(update, context): | ||
send_log_file(context.bot, update) | ||
|
||
def main(): | ||
start_handler = CommandHandler(BotCommands.StartCommand, start, run_async=True) | ||
log_handler = CommandHandler(BotCommands.LogCommand, log, | ||
filters=CustomFilters.owner_filter, run_async=True) | ||
|
||
dispatcher.add_handler(start_handler) | ||
dispatcher.add_handler(log_handler) | ||
|
||
updater.start_polling() | ||
LOGGER.info("Bot started") | ||
updater.idle() | ||
|
||
main() |
Empty file.
Empty file.
Oops, something went wrong.