async def set_silence(message: aiogram.types.Message): logging.info( f"Handle message <{message.message_id}> from @{message.from_user.username}" ) chat_id = message.chat.id try: if message.chat.type == "private": await bot.send_message(message.chat.id, "Эта команда доступна только чате!") elif message.chat.type == "group": user_session = ConfigFunctions.get_user(message) chat_session = ChatManager.get_chat(chat_id) silence = chat_session[ 'silence'] if 'silence' in chat_session else False if await CheckUserForbidden(user_session, message, silence): return flag = False arguments = message.text.split(' ')[1:] if len(arguments) > 0: flag = arguments[0].lower() == 'on' chat_session['silence'] = flag Config.Save() await bot.send_message( message.chat.id, "Режим молчания включен." if flag else "Режим молчания выключен.") except Exception as exc: logging.info(f"Exception: {exc}") traceback.print_exc() await NotificateAdmins(exc)
async def save_joke(message: aiogram.types.Message): logging.info( f"Handle message <{message.message_id}> from @{message.from_user.username}" ) chat_id = message.chat.id user_session = ConfigFunctions.get_user(message) chat_session = ChatManager.get_chat(chat_id) silence = chat_session['silence'] if 'silence' in chat_session else False if await CheckUserForbidden(user_session, message, silence): return try: if message.chat.type == "private": if not silence: await bot.send_message(message.chat.id, Templates.wrong_chat_joke) elif message.chat.type == "group": arguments = message.text.split(' ')[1:] name = "captainkazah" count = Config.data['TELEGRAM']['CHATS_DEFAULT'] if len(arguments) > 0: name = arguments[0].strip().strip('@') if len(arguments) > 1: count = int(arguments[1].strip()) messages = ChatManager.get_messages(message.chat.id, count, name) if len(messages) > 0: is_serega = len( [mes for mes in messages if mes['from'] == "captainkazah"]) > 0 text = "\n\n".join([ f"{mes['date']} {mes['from']}:\n{mes['text']}" for mes in messages ]) text = f"Chat: {message.chat.title}\n\n{text}" GoogleForm.StoreJoke(message.from_user.username, text, is_serega) if not silence: await bot.send_message( message.chat.id, Templates.save_tamplate_multy.format( count=len(messages))) else: if not silence: await bot.send_message(message.chat.id, Templates.save_fail_tamplate) except Exception as exc: logging.info(f"Exception: {exc}") traceback.print_exc() if not silence: await bot.send_message(chat_id, Templates.exception.format(exception=exc)) await NotificateAdmins(exc)
async def main_dialogue(message: aiogram.types.Message): logging.info( f"Handle message <{message.message_id}> from @{message.from_user.username}" ) chat_id = message.chat.id try: if message.chat.type == "private": await DialogueManager.start(bot, message.chat.id, Dialogues.main_dialogue) elif message.chat.type == "group": user_session = ConfigFunctions.get_user(message) chat_session = ChatManager.get_chat(chat_id) silence = chat_session[ 'silence'] if 'silence' in chat_session else False if await CheckUserForbidden(user_session, message, silence): return if not silence: await bot.send_message( message.chat.id, "Эта команда доступна только в личной переписке!") except Exception as exc: logging.info(f"Exception: {exc}") traceback.print_exc() await NotificateAdmins(exc)
async def send_welcome(message: aiogram.types.Message): logging.info( f"Handle message <{message.message_id}> from @{message.from_user.username}" ) chat_id = message.chat.id user_session = ConfigFunctions.get_user(message) chat_session = ChatManager.get_chat(chat_id) silence = chat_session['silence'] if 'silence' in chat_session else False if await CheckUserForbidden(user_session, message, silence): return try: if message.chat.type == 'private': await bot.send_message(chat_id, Templates.private_intro) elif message.chat.type == "group": ChatManager.init_chat(message.chat.id) await bot.send_message( chat_id, Templates.public_intro.format( message_default=Config.data['TELEGRAM']['CHATS_DEFAULT'], message_max=Config.data['TELEGRAM']['CHATS_LIMIT'])) except Exception as exc: logging.info(f"Exception: {exc}") traceback.print_exc() await NotificateAdmins(exc)
def getSettings(self): # configLoc does not need to be passed self.volume, self.musicLoc = ConfigFunctions.getSettings(configLoc)
def changeAudioVolume(self): self.volume = self.audioSlider.value() self.player.setVolume(self.volume) self.changeSpeakerImg() ConfigFunctions.updateConfig(self.volume, self.musicLoc, configLoc)
def getDirectory(self): # open dialog, check if user has file, move file to music Folder dir = QFileDialog.getExistingDirectory(self, "Select Directory") if not dir == '': self.musicLoc = dir ConfigFunctions.updateConfig(self.volume, dir, configLoc)
async def NotificateAdmins(exc): admins = ConfigFunctions.get_admins() for admin in admins: await bot.send_message(admin['id'], Templates.exception_admin.format(exception=exc))