Skip to content

Commit

Permalink
Added support for other entrypoints than /start (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Wessel Hissink <[email protected]>
  • Loading branch information
WesSec and Wessel Hissink authored Mar 23, 2020
1 parent 5090133 commit 081d8b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This is a TelegramBot made to add series to [Sonarr](https://github.com/Sonarr/Sonarr) or movies to [Radarr](https://github.com/Radarr/Radarr) with a couple of commands.

## HOW IT WORKS
You can start the bot with sending `/start` or just `start`. At any time you can stop with the bot by sending `/stop` or `stop`.<br/>The first time you use `start` you will be asked to enter your password you set in the config file. You will only need to do this one time. The chatId will be saved to a file and be checked there every time.<br/>There will be made a log to the logfile when you enter a wrong password: timestamp, username and entered password.<br/>The next steps will be made clear by the bot.
You can start the bot with sending `/start` or just `start` (other entrypoints can be set in config). At any time you can stop with the bot by sending `/stop` or `stop`.<br/>The first time you use `start` you will be asked to enter your password you set in the config file. You will only need to do this one time. The chatId will be saved to a file and be checked there every time.<br/>There will be made a log to the logfile when you enter a wrong password: timestamp, username and entered password.<br/>The next steps will be made clear by the bot.

## SCREENSHOTS
<div style="float: left">
Expand Down
24 changes: 13 additions & 11 deletions addarr.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env python3

import datetime
import logging
import re
import time

import yaml
from telegram import *
from telegram.ext import *
import sonarr as sonarr
import radarr as radarr
import logging, json
import yaml
import time
import datetime

import radarr as radarr
import sonarr as sonarr
from definitions import CONFIG_PATH, LANG_PATH, CHATID_PATH, LOG_PATH

log = logging
log.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', filename=LOG_PATH,
filemode='a',
filemode='a',
level=logging.INFO)

SERIE_MOVIE_AUTH, READ_CHOICE, GIVE_OPTION = range(3)
Expand All @@ -34,15 +36,15 @@ def main():
open(LOG_PATH, 'w').close() #clear logfile at startup of script
auth_handler = CommandHandler('auth', auth)
conversationHandler = ConversationHandler(
entry_points=[CommandHandler('start', start),
MessageHandler(Filters.regex('^(Start|start)$'), start)],
entry_points=[CommandHandler(config['entrypoint'], start),
MessageHandler(Filters.regex(re.compile(r'' + config['entrypoint'] + '', re.IGNORECASE)), start)],

states={
SERIE_MOVIE_AUTH: [MessageHandler(Filters.text, choiceSerieMovie)],
READ_CHOICE: [MessageHandler(Filters.regex(f'^({transcript["Movie"]}|{transcript["Serie"]})$'), search)],
GIVE_OPTION: [MessageHandler(Filters.regex(f'({transcript["Add"]})'), add),
MessageHandler(Filters.regex(f'({transcript["Next result"]})'), nextOpt),
MessageHandler(Filters.regex(f'({transcript["New"]})'), start)],
MessageHandler(Filters.regex(f'({transcript["Next result"]})'), nextOpt),
MessageHandler(Filters.regex(f'({transcript["New"]})'), start)],
},

fallbacks=[CommandHandler('stop', stop),
Expand Down
3 changes: 2 additions & 1 deletion config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ telegram:
password: password

#Language
language: en #'en' or 'nl'
language: en #'en' or 'nl'
entrypoint: start #start or a custom entrypoint

0 comments on commit 081d8b2

Please sign in to comment.