def handle_alarmdegistir(update: Update): #logging.error('Alarm switched') if MiscMessageListener.alarm_state == True: MiscMessageListener.alarm_state = False TelegramBotManager().bot.send_message( chat_id=update.message.chat_id, text=f'Alarm Durumu: KAPALI') else: MiscMessageListener.alarm_state = True TelegramBotManager().bot.send_message( chat_id=update.message.chat_id, text=f'Alarm Durumu: ACIK')
def handle_capture(update: Update): # Define the duration (in seconds) of the video capture here capture_duration = 10 cap = cv2.VideoCapture(0) # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('output.avi', fourcc, 30.0, (640, 480)) start_time = time.time() while (int(time.time() - start_time) < capture_duration): ret, frame = cap.read() if ret == True: frame = cv2.flip(frame, 0) # write the flipped frame out.write(frame) cv2.imshow('frame', frame) # if cv2.waitKey(1) & 0xFF == ord('q'): # break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows() telegram_id = BotUtil.get_telegram_id(update) func_result, bot_result = get_file_stream(telegram_id=telegram_id, file_name="output.avi") TelegramBotManager().bot.send_video(chat_id=update.message.chat_id, video=func_result)
def handle_getfile(update: Update): telegram_id = BotUtil.get_telegram_id(update) file_name = BotUtil.get_message_arguments(update) func_result, bot_result = get_file_stream(telegram_id=telegram_id, file_name=file_name) TelegramBotManager().bot.send_document(chat_id=update.message.chat_id, document=func_result)
def handle_exec(update: Update): telegram_id = BotUtil.get_telegram_id(update) command = BotUtil.get_message_arguments(update) func_result, bot_result = exec_cmd_bot(telegram_id=telegram_id, command=command) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=func_result)
def handle_test44(update: Update): custom_keyboard = [['top-left', 'top-right'], ['bottom-left', 'bottom-right']] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text="Custom Keyboard Test", reply_markup=reply_markup)
def handle_getvideo(update: Update): telegram_id = BotUtil.get_telegram_id(update) video_len = int(BotUtil.get_message_arguments(update)) Util.capture_video(video_len) func_result, bot_result = get_file_stream(telegram_id=telegram_id, file_name='out.avi') TelegramBotManager().bot.send_document(chat_id=update.message.chat_id, document=func_result)
def handle_help(self, update: Update): result = "" for command in self.__help__: result += "<b>{0}</b> -> {1}\n\n".format(command, self.__help__[command]) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=result, parse_mode='html')
def initialize(self): try: #print("GPIO listener is initialized!") message = 'Alarm sistemi baslatildi.' TelegramBotManager().send_broadcast_message(message, None) global button global blueled GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering GPIO.setup(25, GPIO.IN) # set GPIO25 as input (sensor) GPIO.setup(22, GPIO.OUT) # set GPIO22 as an output (LED) GPIO.setup(23, GPIO.OUT) # set GPIO22 as an output (ALARM) button = Button(25) except Exception as e: logging.error(str(e)) TelegramBotManager().send_broadcast_message(text='Exception' + str(e), user_access=None)
def check_and_update(): server_version = UpdateService.get_server_commit_number() current_version = Util.get_setting('current_version', 'update', int) if server_version != current_version: TelegramBotManager().send_broadcast_message('Bot is updating to new version!', UserAccessMode.ADMIN) ServiceManager().stop_services() UpdateService.update_program() Util.set_setting(server_version, 'current_version', 'update') print('Program is updated!') Util.restart_program()
def run_service(self): try: GPIO.output(22, GPIO.LOW) global blueled blueled = blueled + 1 if (blueled % 2) == 0: #logging.error('BB0\n') GPIO.output(23, GPIO.HIGH) blueled = 0 else: #logging.error('BB1\n') GPIO.output(23, GPIO.LOW) #logging.error('Alarm State'+ str(MiscMessageListener.alarm_state)) if MiscMessageListener.alarm_state == True: if GPIO.input(25): # if port 25 == 1 GPIO.output(22, GPIO.HIGH) global button button.wait_for_press() message = "Hareket algilandi! Video cekiliyor..." TelegramBotManager().send_broadcast_message( text=message, user_access=None) filter_result = BotDatabase().filter( Tables.USERS, lambda row: row[UsersTableMap.ACCESS] == UsersAccessMode.ADMIN) #logging.error('Capturing video\n') Util.capture_video(5) if filter_result.count > 0: for user in filter_result.rows: if UsersTableMap.CHAT_ID in user: chat_id = user[UsersTableMap.CHAT_ID] #Util.capture_video(5) file = open('out.avi', 'rb') TelegramBotManager().bot.send_document( chat_id=chat_id, document=file, timeout=300) #logging.error('blue led '+ str(blueled)+'\n') except Exception as e: TelegramBotManager().send_broadcast_message(text='Exception' + str(e), user_access=None) logging.error('Gpio run service error' + str(e))
def handle(cls, update: Update): file_id, file_folder = cls.get_file_id(update) bot: Bot = TelegramBotManager().bot if file_id is not None: file = bot.get_file(file_id) cls.download_file(file, file_folder) bot.send_message(chat_id=update.message.chat_id, text="File is downloaded!") return True else: return False
def handle_get_ip(update: Update): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36', } data = requests.get('https://ip-adresim.net/', headers=headers) data = BeautifulSoup(data.content) data = data.select('.mycurrentip')[0].text TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=f'Ip Address:{data}')
def handle_news(update: Update): rss_data = requests.get( "http://www.haberturk.com/rss/manset.xml".strip()) soup = BeautifulSoup(rss_data.content, 'lxml') descriptions = soup.find_all("description") descriptions = [ descriptions[i].string for i in range(len(descriptions)) if i > 0 and i < 4 ] text = "\n\n".join(descriptions) # text = map(lambda x: str(x)+"\n\n", descriptions) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=str(text))
def handle_register(update: Update): telegram_id = BotUtil.get_telegram_id(update) if Users.is_user_exist(telegram_id) is False: message = "You are new user" _user = BotUtil.get_user_data(update) Users.add_new_user(_user) BotDatabase().save() else: _user = Users.get_user(telegram_id) message = "Welcome back {0} {1}!!".format( _user[UsersTableMap.FIRST_NAME], _user[UsersTableMap.LAST_NAME]) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=message)
def handle_register(update: Update): telegram_id = BotUtil.get_telegram_id(update) if DatabaseManager().userTableManager.record_is_exist( "Users", "telegram_id", telegram_id) is False: message = "You are new user" _user = BotUtil.get_user_data(update) DatabaseManager().userTableManager.insert_data("Users", _user) else: _user = DatabaseManager().userTableManager.select( "Users", {"telegram_id": telegram_id})[0] message = "Welcome back {0} {1}!!".format(_user.first_name, _user.last_name) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=message)
def handle_exchange(self, update: Update): result = self.get_exchange_data() TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=result)
def handle_python(update: Update): telegram_id = BotUtil.get_telegram_id(update) cmd = BotUtil.get_message_arguments(update) func_result, bot_result = exec_python(telegram_id=telegram_id, cmd=cmd) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=bot_result)
def handle_shutdown(update: Update): telegram_id = BotUtil.get_telegram_id(update) func_result, bot_result = shutdown_bot(telegram_id=telegram_id) TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=bot_result)
def handle_temperature(update: Update): res, output, error = Util.execute("vcgencmd measure_temp") TelegramBotManager().bot.send_message(chat_id=update.message.chat_id, text=output)
import os import logging from Core.Util.Util import Util from Core.TelegramBotManager import TelegramBotManager import atexit from Files.Database import DatabaseManager if __name__ == '__main__': try: program_path = os.path.dirname(__file__) if program_path is not '': os.chdir(program_path) logging.basicConfig( filename=Util.get_abs_file_name("hasobot.log"), format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) TelegramBotManager().initialize() # initialize bot and start except Exception as e: logging.error(str(e)) @atexit.register def on_exit(): DatabaseManager.DatabaseManager().close()
import os import logging from Core.Util.Util import Util from Core.TelegramBotManager import TelegramBotManager if __name__ == '__main__': try: program_path = os.path.dirname(__file__) if program_path is not '': os.chdir(program_path) logging.basicConfig(filename=Util.get_abs_file_name("hasobot.log"), format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) TelegramBotManager().initialize() except Exception as e: logging.error(str(e))