def rules_remove(self, bot: Bot, update: Update): """Remove rules for a group Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object """ chat_id = update.message.chat_id from_user = update.message.from_user group_data = data.get(self.group_data_set) if not group_data.get(chat_id, None) or not group_data[chat_id].get( 'rules', None): bot.send_message( chat_id=chat_id, text= 'This group has no rules defined, use /rules_define to add them.' ) return group_data[chat_id]['rules'] = '' data.save(self.group_data_set, group_data) bot.send_message( chat_id=chat_id, text='{user} has set removed the groups rules.'.format( user=get_user_link(from_user)), parse_mode=ParseMode.MARKDOWN)
def register(self, bot: Bot, update: Update): """Register the chat_id for admins and supporters Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object """ user = update.message.from_user chat_id = update.message.chat_id builtin_data = data.get(self.data_set_name) register_as = '' if '{}'.format(user.username) in ADMINS: if not builtin_data.get('admin_chat_ids', None): builtin_data['admin_chat_ids'] = {} builtin_data['admin_chat_ids'][chat_id] = user.to_dict() register_as = 'Admin' if '{}'.format(user.username) in SUPPORTER: if not builtin_data.get('supporter_chat_ids', None): builtin_data['supporter_chat_ids'] = {} builtin_data['supporter_chat_ids'][chat_id] = user.to_dict() register_as += ' Supporter' if not register_as: return data.save(self.data_set_name, builtin_data) update.message.reply_text( f'You have been registered as {register_as.strip()}')
def rules_define(self, bot: Bot, update: Update): """Define new rules for a group Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object """ split_text = update.message.text.split(' ', 1) if len(split_text) < 2: update.message.reply_text('You forgot to give me the rules.') return elif len(split_text[1]) > 4000: update.message.reply_text( 'Rules must be less than 4000 characters.') return text = split_text[1] chat_id = update.message.chat_id from_user = update.message.from_user group_data = data.get(self.group_data_set) if not group_data.get(chat_id, None): group_data[chat_id] = {} group_data[chat_id]['rules'] = text data.save(self.group_data_set, group_data) bot.send_message(chat_id=chat_id, text='{user} has set new /rules.'.format( user=get_user_link(from_user)), parse_mode=ParseMode.MARKDOWN)
def unwarn(self, bot: Bot, update: Update, wanted_user: User = None): """Remove all warnings from a user Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object wanted_user (:obj:`telegram.user.User`): Telegram User object of the user which should be warned """ if update.message.reply_to_message is None: update.message.reply_text( 'You have to reply to a message from a user to warn him.') return chat_id = update.message.chat_id from_user = update.message.from_user wanted_user = wanted_user or update.message.reply_to_message.from_user group_data = data.get(self.group_data_set) if not group_data.get(chat_id, None) or not group_data[chat_id].get( wanted_user.id, None): bot.send_message(chat_id=chat_id, text='{wanted_user} was never warned.'.format( wanted_user=get_user_link(wanted_user)), parse_mode=ParseMode.MARKDOWN) return group_data[chat_id][wanted_user.id] = 0 data.save(self.group_data_set, group_data) bot.send_message( chat_id=chat_id, text='{from_user} removed {wanted_user} warnings.'.format( from_user=get_user_link(from_user), wanted_user=get_user_link(wanted_user)), parse_mode=ParseMode.MARKDOWN)
def turn_off(self, telegram_user: str): """Turn download mode off Args: telegram_user (:obj:`str`): The telegram users user_id """ mode_dict = data.get(self.data_set_name) mode_dict[telegram_user] = {'on': False, 'zip': False} data.save(self.data_set_name, mode_dict)
def turn_on(self, telegram_user: str, zip_mode: bool = False): """Turn download mode on Args: telegram_user (:obj:`str`): The telegram users user_id zip_mode: (:obj:`bool`): If the downloads shall be zipped """ mode_dict = data.get(self.data_set_name) mode_dict[telegram_user] = {'on': True, 'zip': zip_mode} data.save(self.data_set_name, mode_dict)
def warn(self, bot: Bot, update: Update, wanted_user: User = None): """Strike a user After 3 strikes he is banned Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object wanted_user (:obj:`telegram.user.User`): Telegram User object of the user which should be warned """ if update.message.reply_to_message is None: update.message.reply_text( 'You have to reply to a message from this user to warn him.') return chat_id = update.message.chat_id from_user = update.message.from_user wanted_user = wanted_user or update.message.reply_to_message.from_user group_data = data.get(self.group_data_set) if not group_data.get(chat_id, None): group_data[chat_id] = {} if not group_data[chat_id].get(wanted_user.id, None): group_data[chat_id][wanted_user.id] = 1 else: if group_data[chat_id][wanted_user.id] == 'banned': bot.send_message( chat_id=chat_id, text='{wanted_user} was already banned.'.format( wanted_user=get_user_link(wanted_user)), parse_mode=ParseMode.MARKDOWN) return else: group_data[chat_id][wanted_user.id] += 1 if group_data[chat_id][wanted_user.id] == 3: self.ban(bot, update) return bot.send_message( chat_id=chat_id, text= ('{wanted_user} was warned by {from_user}\n User has now {warns} waning/s. With 3 warnings user ' 'gets banned.').format(from_user=get_user_link(from_user), wanted_user=get_user_link(wanted_user), warns=group_data[chat_id][wanted_user.id]), parse_mode=ParseMode.MARKDOWN) data.save(self.group_data_set, group_data)
def ban(self, bot: Bot, update: Update): """Ban a user Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object """ if update.message.reply_to_message is None: update.message.reply_text( 'You have to reply to a message from this user to ban him.') return chat_id = update.message.chat_id from_user = update.message.from_user wanted_user = update.message.reply_to_message.from_user group_data = data.get(self.group_data_set) if not group_data.get(chat_id, None): group_data[chat_id] = {} if not group_data[chat_id].get(wanted_user.id, None): group_data[chat_id][wanted_user.id] = 'banned' else: if group_data[chat_id][wanted_user.id] == 'banned': bot.send_message( chat_id=chat_id, text='{wanted_user} was already banned.'.format( wanted_user=get_user_link(wanted_user)), parse_mode=ParseMode.MARKDOWN) return else: group_data[chat_id][wanted_user.id] = 'banned' now = datetime.datetime.now() bot.kick_chat_member(chat_id=chat_id, user_id=wanted_user.id, until_date=now + datetime.timedelta(seconds=5)) bot.send_message(chat_id=chat_id, text='{wanted_user} was banned by {from_user}'.format( from_user=get_user_link(from_user), wanted_user=get_user_link(wanted_user)), parse_mode=ParseMode.MARKDOWN) data.save(self.group_data_set, group_data)
def register(self, bot: Bot, update: Update): """Register the chat_id for admins and supporters Args: bot (:obj:`telegram.bot.Bot`): Telegram Api Bot Object. update (:obj:`telegram.update.Update`): Telegram Api Update Object """ user = update.message.from_user chat_id = update.message.chat_id builtin_data = data.get(self.data_set_name) if '@{}'.format(user.username) in ADMINS: if not builtin_data.get('admin_chat_ids', None): builtin_data['admin_chat_ids'] = {} builtin_data['admin_chat_ids'][chat_id] = user.to_dict() if '@{}'.format(user.username) in SUPPORTER: if not builtin_data.get('supporter_chat_ids', None): builtin_data['supporter_chat_ids'] = {} builtin_data['supporter_chat_ids'][chat_id] = user.to_dict() data.save(self.data_set_name, builtin_data)