Skip to content

Commit

Permalink
[welcome] Switch to context based handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kshatriya-abhay committed Jun 17, 2020
1 parent ba9bf85 commit 5fd534a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions SaitamaRobot/modules/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def send(update, message, keyboard, backup_message):

@run_async
@loggable
def new_member(bot: Bot, update: Update, job_queue: JobQueue):
def new_member(update: Update, context: CallbackContext):
bot, job_queue = context.bot, context.job_queue
chat = update.effective_chat
user = update.effective_user
msg = update.effective_message
Expand Down Expand Up @@ -359,7 +360,8 @@ def left_member(update: Update, context: CallbackContext):

@run_async
@user_admin
def welcome(bot: Bot, update: Update, args: List[str]):
def welcome(update: Update, context: CallbackContext):
args = context.args
chat = update.effective_chat
# if no args, show current replies.
if not args or args[0].lower() == "noformat":
Expand Down Expand Up @@ -403,7 +405,8 @@ def welcome(bot: Bot, update: Update, args: List[str]):

@run_async
@user_admin
def goodbye(bot: Bot, update: Update, args: List[str]):
def goodbye(update: Update, context: CallbackContext):
args = context.args
chat = update.effective_chat

if not args or args[0] == "noformat":
Expand Down Expand Up @@ -449,7 +452,7 @@ def goodbye(bot: Bot, update: Update, args: List[str]):
@run_async
@user_admin
@loggable
def set_welcome(bot: Bot, update: Update) -> str:
def set_welcome(update: Update, context: CallbackContext) -> str:
chat = update.effective_chat
user = update.effective_user
msg = update.effective_message
Expand All @@ -472,7 +475,7 @@ def set_welcome(bot: Bot, update: Update) -> str:
@run_async
@user_admin
@loggable
def reset_welcome(bot: Bot, update: Update) -> str:
def reset_welcome(update: Update, context: CallbackContext) -> str:
chat = update.effective_chat
user = update.effective_user

Expand All @@ -488,7 +491,7 @@ def reset_welcome(bot: Bot, update: Update) -> str:
@run_async
@user_admin
@loggable
def set_goodbye(bot: Bot, update: Update) -> str:
def set_goodbye(update: Update, context: CallbackContext) -> str:
chat = update.effective_chat
user = update.effective_user
msg = update.effective_message
Expand All @@ -509,7 +512,7 @@ def set_goodbye(bot: Bot, update: Update) -> str:
@run_async
@user_admin
@loggable
def reset_goodbye(bot: Bot, update: Update) -> str:
def reset_goodbye(update: Update, context: CallbackContext) -> str:
chat = update.effective_chat
user = update.effective_user

Expand All @@ -525,7 +528,8 @@ def reset_goodbye(bot: Bot, update: Update) -> str:
@run_async
@user_admin
@loggable
def welcomemute(bot: Bot, update: Update, args: List[str]) -> str:
def welcomemute(update: Update, context: CallbackContext) -> str:
args = context.args
chat = update.effective_chat
user = update.effective_user
msg = update.effective_message
Expand Down Expand Up @@ -566,7 +570,8 @@ def welcomemute(bot: Bot, update: Update, args: List[str]) -> str:
@run_async
@user_admin
@loggable
def clean_welcome(bot: Bot, update: Update, args: List[str]) -> str:
def clean_welcome(update: Update, context: CallbackContext) -> str:
args = context.args
chat = update.effective_chat
user = update.effective_user

Expand Down Expand Up @@ -598,7 +603,8 @@ def clean_welcome(bot: Bot, update: Update, args: List[str]) -> str:

@run_async
@user_admin
def cleanservice(bot: Bot, update: Update, args: List[str]) -> str:
def cleanservice(update: Update, context: CallbackContext) -> str:
args = context.args
chat = update.effective_chat # type: Optional[Chat]
if chat.type != chat.PRIVATE:
if len(args) >= 1:
Expand Down Expand Up @@ -748,17 +754,17 @@ def __chat_settings__(chat_id, user_id):
*Example:* user joined chat, user left chat.
""".format(WELC_HELP_TXT)

NEW_MEM_HANDLER = MessageHandler(Filters.status_update.new_chat_members, new_member, pass_job_queue=True)
NEW_MEM_HANDLER = MessageHandler(Filters.status_update.new_chat_members, new_member)
LEFT_MEM_HANDLER = MessageHandler(Filters.status_update.left_chat_member, left_member)
WELC_PREF_HANDLER = CommandHandler("welcome", welcome, pass_args=True, filters=Filters.group)
GOODBYE_PREF_HANDLER = CommandHandler("goodbye", goodbye, pass_args=True, filters=Filters.group)
WELC_PREF_HANDLER = CommandHandler("welcome", welcome, filters=Filters.group)
GOODBYE_PREF_HANDLER = CommandHandler("goodbye", goodbye, filters=Filters.group)
SET_WELCOME = CommandHandler("setwelcome", set_welcome, filters=Filters.group)
SET_GOODBYE = CommandHandler("setgoodbye", set_goodbye, filters=Filters.group)
RESET_WELCOME = CommandHandler("resetwelcome", reset_welcome, filters=Filters.group)
RESET_GOODBYE = CommandHandler("resetgoodbye", reset_goodbye, filters=Filters.group)
WELCOMEMUTE_HANDLER = CommandHandler("welcomemute", welcomemute, pass_args=True, filters=Filters.group)
CLEAN_SERVICE_HANDLER = CommandHandler("cleanservice", cleanservice, pass_args=True, filters=Filters.group)
CLEAN_WELCOME = CommandHandler("cleanwelcome", clean_welcome, pass_args=True, filters=Filters.group)
WELCOMEMUTE_HANDLER = CommandHandler("welcomemute", welcomemute, filters=Filters.group)
CLEAN_SERVICE_HANDLER = CommandHandler("cleanservice", cleanservice, filters=Filters.group)
CLEAN_WELCOME = CommandHandler("cleanwelcome", clean_welcome, filters=Filters.group)
WELCOME_HELP = CommandHandler("welcomehelp", welcome_help)
WELCOME_MUTE_HELP = CommandHandler("welcomemutehelp", welcome_mute_help)
BUTTON_VERIFY_HANDLER = CallbackQueryHandler(user_button, pattern=r"user_join_")
Expand Down

0 comments on commit 5fd534a

Please sign in to comment.