def init(update,context): chat = chat_object(update) get_group = GroupRepository().getById(chat.id) max_warn = get_group['max_warn'] current_time = datetime.datetime.utcnow().isoformat() default_warn = 1 languages(update,context) if update.message.reply_to_message: reason = update.message.text[5:] user = user_reply_object(update) get_user = UserRepository().getUserByGroup([user.id,chat.id]) warn_count = get_user['warn_count'] if get_user is not None else 0 if warn_count != max_warn: buttons = [] buttons.append(InlineKeyboardButton('➖ 1', callback_data='downWarn')) buttons.append(InlineKeyboardButton('➕ 1', callback_data='upWarn')) buttons.append(InlineKeyboardButton(languages.button_remove, callback_data='removeWarn')) menu = build_menu(buttons,3) if get_user: default_warn_count = 0 username = "******"+user.username data = [(username,current_time,user.id)] UserRepository().update(data) data_mtm = [(user.id, chat.id, default_warn_count)] UserRepository().add_into_mtm(data_mtm) data_warn = [(user.id,chat.id)] UserRepository().updateWarn(data_warn) if reason: msg = languages.warn_with_reason.format(mention_html(user.id, user.first_name),chat.title,chat.id,reason) update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML') else: msg = languages.warn_user.format(mention_html(user.id, user.first_name),chat.title,chat.id) update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML') log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id) if reason: log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason) telegram_loggers(update,context,log_txt) else: username = "******"+user.username data = [(user.id,username,current_time,current_time)] UserRepository().add(data) data_mtm = [(user.id, chat.id, default_warn)] UserRepository().add_into_mtm(data_mtm) if reason: message(update,context,languages.warn_with_reason.format(username,chat.title,chat.id,reason)) else: message(update,context,languages.warn_user.format(username,chat.title,chat.id)) log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id) if reason: log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason) telegram_loggers(update,context,log_txt) else: ban_user_reply(update,context) buttons = [] buttons.append(InlineKeyboardButton('Remove', callback_data='removeWarn')) menu = build_menu(buttons,2) msg = languages.warn_user_max.format(user.username,chat.title) update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML') else: message(update,context,languages.error_response_user_msg)
def init(update, context): languages(update, context) bot = bot_object(update, context) chat = update.effective_chat reply = update.message.reply_to_message if reply is not None: if reply.from_user.id == bot.id: message(update, context, languages.bot_ban) else: ban_text = languages.ban_message.format( user=reply.from_user.username or reply.from_user.first_name, userid=reply.from_user.id, chat=chat.title) logs_text = Strings.BAN_LOG.format( username=reply.from_user.username or reply.from_user.first_name, id=reply.from_user.id, chat=chat.title) delete_message_reply(update, context) ban_user_reply(update, context) message(update, context, ban_text) telegram_loggers(update, context, logs_text) formatter = "Ban eseguito da: {} nella chat {}".format( update.message.from_user.id, chat.title) sys_loggers("[BAN_LOGS]", formatter, False, True) else: ban_argument = update.message.text[5:] is_user_id = Try.of(lambda: int(ban_argument)).valueOf() is not None if ban_argument[0] is '@': username = ban_argument Try.of(lambda: ban_user_by_username(update, context, username)) \ .catch(lambda err: ban_error(update, context, username = username)) \ .map(lambda x : ban_success(update, context, chat, username = username)) elif is_user_id: userid = ban_argument Try.of(lambda: ban_user_by_id(update, context, userid)) \ .catch(lambda err: ban_error(update, context, id = userid)) \ .map(lambda x : ban_success(update, context, chat, id = userid)) else: message(update, context, languages.ban_error.format(ban_argument)) return
def init(update, context): user = user_reply_object(update) chat = chat_object(update) get_user = UserRepository().getUserByGroup([user.id, chat.id]) get_group = GroupRepository().getById(chat.id) warn_count = get_user['warn_count'] if get_user is not None else 0 max_warn = get_group['max_warn'] default_warn = 1 if warn_count != max_warn: if get_user: default_warn_count = 0 username = "******" + user.username data = [(username, user.id)] UserRepository().update(data) data_mtm = [(user.id, chat.id, default_warn_count)] UserRepository().add_into_mtm(data_mtm) data_warn = [(user.id, chat.id)] UserRepository().updateWarn(data_warn) message( update, context, "{} was warned by the group {}".format(username, chat.title)) log_txt = "#Log {} was warned by the group {}".format( username, chat.title) telegram_loggers(update, context, log_txt) else: username = "******" + user.username data = [(user.id, username, default_warn)] UserRepository().add(data) data_mtm = [(user.id, chat.id, default_warn)] UserRepository().add_into_mtm(data_mtm) message( update, context, "{} was warned by the group {}".format(username, chat.title)) log_txt = "#Log {} was warned by the group {}".format( username, chat.title) telegram_loggers(update, context, log_txt) else: ban_user_reply(update, context) message( update, context, "User @{} has reached the maximum number\n of warns in the {} group and has been banned" .format(user.username, chat.title))
def init(update,context): motivation = update.message.text[2:].strip() reply = update.message.reply_to_message if reply is not None: if motivation != "": user_id = reply.from_user.id save_date = datetime.datetime.utcnow().isoformat() operator_id = update.message.from_user.id data = [(user_id,motivation,save_date,operator_id)] SuperbanRepository().add(data) ban_user_reply(update,context) delete_message_reply(update,context) logs_text = Strings.SUPERBAN_LOG.format(user_id,motivation,save_date,operator_id) msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nGo to: https://squirrel-network.online/knowhere'.format(user_id,user_id) message(update,context,msg) telegram_loggers(update,context,logs_text) formatter = "Superban eseguito da: {}".format(update.message.from_user.id) sys_loggers("[SUPERBAN_LOGS]",formatter,False,False,True) else: message(update,context,"You need to specify a reason for the <b>superban!</b>") else: message(update,context,"You must use this command in response to a user!")
def init(update, context): languages(update, context) bot = bot_object(update, context) chat = update.effective_chat reply = update.message.reply_to_message if reply is not None: user_status = reply_member_status_object(update, context) user = reply.from_user row = GroupRepository().getById(chat.id) if user.id == bot.id: text = "I can't ban myself!" message(update, context, text) elif user_status.status == 'administrator' or user_status.status == 'creator': message(update, context, "I can't <i>ban</i> an administrator or creator!") else: if row['ban_message']: parsed_message = row['ban_message'].replace( '{first_name}', user.first_name).replace( '{chat}', update.message.chat.title).replace( '{username}', "@" + user.username).replace( '{mention}', mention_html(user.id, user.first_name)).replace( '{userid}', str(user.id)) ban_text = "{}".format(parsed_message) else: ban_text = languages.ban_message.format( user=reply.from_user.username or reply.from_user.first_name, userid=reply.from_user.id, chat=chat.title) #Log Ban logs_text = Strings.BAN_LOG.format( username=reply.from_user.username or reply.from_user.first_name, id=reply.from_user.id, chat=chat.title) delete_message_reply(update, context) ban_user_reply(update, context) message(update, context, ban_text) telegram_loggers(update, context, logs_text) formatter = "Ban eseguito da: {} nella chat {}".format( update.message.from_user.id, chat.title) sys_loggers("[BAN_LOGS]", formatter, False, True) else: ban_argument = update.message.text[5:] is_user_id = Try.of(lambda: int(ban_argument)).valueOf() is not None if ban_argument[0] == '@': username = ban_argument Try.of(lambda: ban_user_by_username(update, context, username)) \ .catch(lambda err: ban_error(update, context, username = username)) \ .map(lambda x : ban_success(update, context, username = username)) elif is_user_id: userid = ban_argument Try.of(lambda: ban_user_by_id(update, context, userid)) \ .catch(lambda err: ban_error(update, context, id = userid)) \ .map(lambda x : ban_success(update, context, id = userid)) else: message( update, context, "Sintassi del comando errata o utente non riconosciuto: {}". format(ban_argument)) return