From 96d557b6357bee43f2bdca5bad0aab008e45af76 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 2 Oct 2018 20:49:46 +0530 Subject: [PATCH] Add start command and base config --- .gitignore | 2 ++ bot.py | 37 +++++++++++++++++++++++++++++++++++++ sample.config.py | 6 ++++++ 3 files changed, 45 insertions(+) create mode 100644 .gitignore create mode 100644 bot.py create mode 100644 sample.config.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..225083f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.py +__pycache__/ diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..92a8955 --- /dev/null +++ b/bot.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import logging +import telegram +from telegram.ext import Updater, CommandHandler + +try: + import config +except ImportError: + print("Missing Config. Exiting.") + exit() + + +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \ + %(message)s', level=logging.INFO) + + +def start(bot, update): + chat_id = update.message.chat_id + if chat_id != config.master_id: + text = "You need to host your own instance! \ Source: \ + https://gitlab.com/ceda_ei/pc-monitor-bot" + bot.send_message(chat_id=chat_id, text=text) + return + + custom_keyboard = [['/state', '/screenshot'], ['/lock', '/video']] + reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) + bot.send_message(chat_id=chat_id, text="What to do?", + reply_markup=reply_markup) + + +updater = Updater(token=config.api_key) +dispatcher = updater.dispatcher + +start_handler = CommandHandler('start', start) +dispatcher.add_handler(start_handler) +updater.start_polling() diff --git a/sample.config.py b/sample.config.py new file mode 100644 index 0000000..e81d659 --- /dev/null +++ b/sample.config.py @@ -0,0 +1,6 @@ +# Create a new bot by messaging @BotFather and follow the instructions +# Replace the key by the actual token recieved from BotFather +api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx" + +# Replace 123456789 with your own user id. +master_id = 123456789