def cmd(update, context): user = User(update.effective_user.id) if (user.is_admin()): my_cmd = update.message.text print(my_cmd) output = subprocess.check_output(my_cmd, shell=True) user.send_message(output.decode("utf-8"), prefix="`", suffix="`", parse_mode="Markdown", reply_to=update.effective_message.message_id, chat_id=update.effective_chat.id) else: user.send_message("Sorry, you aren't admin", chat_id=update.effective_chat.id)
def cmd_admin_update(update, context): """ treatment of command /adminupdate Exec `git pull` Exec `killall bot.py` :param update: :type update: telegram.Update :param context: :type context: telegram.ext.CallbackContext """ u = User(update.effective_user.id) if u.is_admin(): update.message.text = "git pull" cmd(update, context) cmd_admin_kill(update, context)
def cmd_help(update, context): """ treatment of command /help Send help information to user :param update: :type update: telegram.Update :param context: :type context: telegram.ext.CallbackContext """ u = User(update.effective_user.id) text = "" if len(context.args) == 1 and context.args[0] == "botcmd": ttt = [] for cmd in command_list.values(): if len(cmd) >= 2 \ and cmd[0] not in ttt \ and cmd[1][0] == 'user': ttt.append(cmd[0] + " - " + cmd[1][2]) ttt.sort() text = "\n".join(ttt) else: right = ['user'] if u.is_admin(): right.append('admin') for r in right: ttt = [] for cmd in command_list.values(): for v in cmd[1:]: if v[0] == r: ttt.append("/" + cmd[0] + " `" + v[1] + "`\n " + v[2]) ttt.sort() text += "\n\n*" + r + " usage* : \n" + "\n".join(ttt) text += "\n\nYour telegram id is `" + str( update.effective_user.id) + "`\n" text += "Your chat id is `" + str(update.effective_chat.id) + "`\n" u.send_message(text, chat_id=update.effective_chat.id, parse_mode="Markdown")
def cmd_admin_kill(update, context): """ treatment of command /adminkill Exec `killall bot.py` :param update: :type update: telegram.Update :param context: :type context: telegram.ext.CallbackContext """ user = User(update.effective_user.id) if user.is_admin(): subprocess.check_output("killall bot.py", shell=True) user.send_message("Kill is apparently failed", chat_id=update.effective_chat.id) else: user.send_message("Sorry, you aren't admin", chat_id=update.effective_chat.id)
def cmdhelp(update, context): """ treatment of command /help Send help information to user :param update: :type update: telegram.Update :param context: :type context: telegram.ext.CallbackContext """ d = [ ["help", "", "Show this help"], ["help", "botcmd", "Show command list in format for BotFather"], ["getgapsnotes", "[<annee> [<cours> ...]]", "Show GAPS notes"], [ "setgapscredentials", "<username> <password>", "Set credentials for GAPS" ], ["unsetgapscredentials", "", "Clear credentials for GAPS"], ["checkgapsnotes", "", "Check if you have new notes"], ["cleargapsnotes", "", "Clear cache of GAPS notes"], [ "calendar", "\\[<YYYY-MM-DD>]", "Get your planning for a specific day" ], ] d_admin_all = [ ["help", "admin", "Show admin help"], ] d_admin = [ ["adminkill", "", "Kill the bot"], ["adminupdate", "", "Update bot by git"], ] user = User(update.effective_user.id) text = "" if len(context.args) == 1 and context.args[0] == "botcmd": ttt = [] for cmd in d: if not cmd[0] in ttt: text += "" + cmd[0] + " - " + cmd[2] + "\n" ttt.append(cmd[0]) else: text += "Usage :" if user.is_admin() and len( context.args) == 1 and context.args[0] == "admin": d += d_admin_all + d_admin elif user.is_admin(): d += d_admin_all for cmd in d: textnew = "\n/" + cmd[0] + " " + cmd[1] + " - " + cmd[2] if len(text) + len( textnew) >= telegram.constants.MAX_MESSAGE_LENGTH: user.send_message(text, chat_id=update.effective_chat.id) text = textnew else: text += textnew text += "\n\nYour telegram id is `" + str( update.effective_user.id) + "`\n" text += "Your chat id is `" + str(update.effective_chat.id) + "`\n" user.send_message(text, chat_id=update.effective_chat.id, parse_mode="Markdown")