async def demotecmd(self, demt): """Command .demote for demote user to admin rights.\nUse: .demote <@ or reply>.""" if demt.chat: try: reply = await demt.get_reply_message() chat = await demt.get_chat() if not chat.admin_rights and not chat.creator: return await utils.answer(demt, self.strings('not_admin', demt)) if reply: user = await utils.get_user(await demt.get_reply_message()) else: args = utils.get_args(demt) if not args: return await utils.answer(demt, self.strings('demote_none', demt)) user = await demt.client.get_entity(args[0]) if not user: return await utils.answer(demt, self.strings('who', demt)) try: if demt.is_channel: await demt.client(EditAdminRequest(demt.chat_id, user.id, DEMOTE_RIGHTS, "")) else: await demt.client(EditChatAdminRequest(demt.chat_id, user.id, False)) except: return await utils.answer(demt, self.strings('no_rights', demt)) else: return await utils.answer(demt, self.strings('demoted', demt).format(user.first_name)) except: return await utils.answer(demt, self.strings('wtf_is_it')) else: return await utils.answer(demt, self.strings('this_isn`t_a_chat', demt))
async def demotecmd(self, demt): """Команда .demote понижает пользователя в правах администратора.\nИспользование: .demote <@ или реплай>.""" if demt.chat: try: chat = await demt.get_chat() admin = chat.admin_rights creator = chat.creator if not admin and not creator: await utils.answer(demt, self.strings('not_admin', demt)) return if demt.is_reply: user = await utils.get_user(await demt.get_reply_message()) else: args = utils.get_args(demt) if not args: return await utils.answer( demt, self.strings('demote_none', demt)) user = await self.client.get_entity(args[0]) if not user: return await utils.answer(demt, self.strings('who', demt)) logger.debug(user) try: if demt.is_channel: await self.client( EditAdminRequest(demt.chat_id, user.id, DEMOTE_RIGHTS, "")) else: await self.client( EditChatAdminRequest(demt.chat_id, user.id, False)) except: await utils.answer(demt, self.strings('no_rights', demt)) else: await self.allmodules.log("demote", group=demt.chat_id, affected_uids=[user.id]) await utils.answer( demt, self.strings('demoted', demt).format( utils.escape_html(user.first_name))) except: await utils.answer(demt, self.strings('wtf_is_it')) return else: await utils.answer(demt, self.strings('this_isn`t_a_chat', demt)) return
async def demotecmd(self, message): """Снять админку""" if message.is_reply: user = await utils.get_user(await message.get_reply_message()) else: args = utils.get_args(message) if len(args) == 0: return await utils.answer(message, self.strings("demote_none", message)) if args[0].isdigit(): who = int(args[0]) else: who = args[0] user = await self.client.get_entity(who) if not user: return await utils.answer(message, self.strings("who", message)) logger.debug(user) try: if message.is_channel: await self.client( EditAdminRequest( message.chat_id, user.id, ChatAdminRights(post_messages=None, add_admins=None, invite_users=None, change_info=None, ban_users=None, delete_messages=None, pin_messages=None, edit_messages=None), "")) else: await self.client( EditChatAdminRequest(message.chat_id, user.id, False)) except BadRequestError: await utils.answer(message, self.strings("not_admin", message)) else: await self.allmodules.log("demote", group=message.chat_id, affected_uids=[user.id]) await utils.answer( message, self.strings("demoted", message).format( utils.escape_html(user.first_name), user.id))
async def run(tgsQ, cfg): logger.info("Starting Telethon Self-Bot") try: client = await TelegramClient('anon', int(cfg["api_id"]), cfg["api_hash"]).start() except Exception as e: logger.error("Telethon was unable to start:\n" + str(e)) return while True: if not tgsQ.empty(): todoChat = tgsQ.get() chatMap = utils.get_chatmap() try: chat = await client( CreateChatRequest(users=[cfg["bot_username"]], title=todoChat.title)) except Exception as e: logger.error( "Telethon was unable to create a group with name {}:\n{}". format(todoChat.title, str(e))) continue try: await client( EditChatAdminRequest(int('-' + str(chat.chats[0].id)), cfg["bot_username"], is_admin=True)) except Exception as e: logger.error( "Telethon was unable to give admin permission to the bot. " "Please give the WTT bot admin permission in {}".format( todoChat.title)) logger.info('Created new chat "{}"'.format(todoChat.title)) tgID = '-' + str(chat.chats[0].id) chatMap[tgID] = {"waID": todoChat.waID, "title": todoChat.title} utils.save_chatmap(chatMap) tgsQ.task_done() await asyncio.sleep(0.5)
async def demotecmd(self, message): """Команда .demote понижает пользователя в правах администратора.\nИспользование: .demote <@ или реплай>.""" if not message.is_private: try: reply = await message.get_reply_message() chat = await message.get_chat() if not chat.admin_rights and not chat.creator: return await utils.answer( message, self.strings('not_admin', message)) if reply: user = await message.client.get_entity(reply.sender_id) else: args = utils.get_args_raw(message) if not args: return await utils.answer( message, self.strings('demote_none', message)) user = await message.client.get_entity( args if not args.isnumeric() else int(args)) try: if message.is_channel: await message.client( EditAdminRequest(message.chat_id, user.id, DEMOTE_RIGHTS, "")) else: await message.client( EditChatAdminRequest(message.chat_id, user.id, False)) except ChatAdminRequiredError: return await utils.answer( message, self.strings('no_rights', message)) else: return await utils.answer( message, self.strings('demoted', message).format(user.first_name)) except ValueError: return await utils.answer(message, self.strings('no_args')) else: return await utils.answer( message, self.strings('this_isn`t_a_chat', message))
async def demotecmd(self, demt): """Команда .demote понижает пользователя в правах администратора.\nИспользование: .demote <@ или реплай>.""" if demt.chat: try: reply = await demt.get_reply_message() chat = await demt.get_chat() if not chat.admin_rights and not chat.creator: return await utils.answer(demt, self.strings('not_admin', demt)) if reply: user = await utils.get_user(await demt.get_reply_message()) else: args = utils.get_args(demt) if not args: return await utils.answer( demt, self.strings('demote_none', demt)) user = await demt.client.get_entity(args[0]) if not user: return await utils.answer(demt, self.strings('who', demt)) try: if demt.is_channel: await demt.client( EditAdminRequest(demt.chat_id, user.id, DEMOTE_RIGHTS, "")) else: await demt.client( EditChatAdminRequest(demt.chat_id, user.id, False)) except: return await utils.answer(demt, self.strings('no_rights', demt)) else: return await utils.answer( demt, self.strings('demoted', demt).format(user.first_name)) except: return await utils.answer(demt, self.strings('wtf_is_it')) else: return await utils.answer(demt, self.strings('this_isn`t_a_chat', demt))
def create_birthday_chat(client, config, birthday_guy, responsible_guy, employees): congratulators_usernames = [] for employee in employees: if employee.username != birthday_guy.username: congratulators_usernames.append(employee.username) updates = client( CreateChatRequest(users=congratulators_usernames, title=config["TITLE_TEMPLATE"].format( name=birthday_guy.name, day=birthday_guy.birthday.day, month=birthday_guy.birthday.month, year=birthday_guy.birthday.year))) birthday_chat = updates.chats[0] # Setting responsible_guy as admin client(ToggleChatAdminsRequest(chat_id=birthday_chat.id, enabled=True)) client( EditChatAdminRequest(chat_id=birthday_chat.id, user_id=responsible_guy.username, is_admin=1)) # Sending greeting message client.send_message( birthday_chat, config["GREETING_MESSAGE"].format( name=birthday_guy.name, responsible_guy_name=responsible_guy.name, responsible_guy_username=responsible_guy.username)) # Deleting myself in case its my birthday if birthday_guy.username == config["MyUsername"]: client( DeleteChatUserRequest(chat_id=birthday_chat.id, user_id=config["MyUsername"])) return 0