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
1 parent
b174dbe
commit bff4dca
Showing
4 changed files
with
184 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,26 +1,54 @@ | ||
from telegram import Bot, Update | ||
from telegram.ext import run_async | ||
|
||
from utils import Constants | ||
from database import InsertOperations | ||
|
||
class StartHandler: | ||
def __init__(self, start_messages: dict): | ||
self.__messages = start_messages | ||
|
||
class Handler: | ||
def __init__(self, handler_messages: dict): | ||
self.__messages = handler_messages | ||
|
||
class StartHandler(Handler): | ||
@run_async | ||
def start(self, bot: Bot, update: Update): | ||
chat_id = update.message.chat_id | ||
user_id = update.message.user_id | ||
bot.sendMessage(chat_id, self.__messages["welcome"]) | ||
import os | ||
import pickle | ||
|
||
effective_user = update.effective_user | ||
user_id = effective_user.id | ||
username = effective_user.username | ||
name = effective_user.first_name | ||
user_path = Constants.P_USERS_PATH + user_id + '/' | ||
db_insert: InsertOperations = InsertOperations() | ||
if not os.path.exists(user_path): | ||
os.mkdir(user_path) | ||
with open(user_path + Constants.P_USERS_FILE, "wb") as user_info: | ||
pickle.dump(Constants.D_USER_DICT, user_info) | ||
db_insert.registerNewUser(user_id=user_id, username=username, name=name) | ||
|
||
|
||
class HelpHandler: | ||
def __init__(self, help_messages: dict): | ||
self.__messages = help_messages | ||
# bot.sendMessage(chat_id, self.__messages["welcome"]) | ||
|
||
|
||
class HelpHandler(Handler): | ||
@run_async | ||
def help(self, bot: Bot, update: Update, args: list): | ||
chat_id = update.message.chat_id | ||
if len(args) == 0: | ||
print("no args") | ||
else: | ||
bot.sendMessage(chat_id, self.__messages["help"]) | ||
|
||
|
||
class DeveloperHandler(Handler): | ||
@run_async | ||
def develop(self, bot: Bot, update: Update): | ||
# to do | ||
|
||
|
||
class VideoIDHandler(Handler): | ||
@run_async | ||
def video_handler(self, bot: Bot, update: Update): | ||
video_id = update.message.text | ||
|
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,7 @@ | ||
class Constants: | ||
P_USERS_PATH = "user_data/" | ||
P_USERS_FILE = "user_info.json" | ||
|
||
D_USER_DICT = {"state": 0, | ||
"is_downloading_video": False, | ||
"pending_videos": 0} |