def _get_response(self, chat_message: str, room: Room, user_name: str) -> Optional[str]: """ Fetch response from database to send to chat. :param str chat_message: Raw message sent by user. :param Room room: Chatango room. :param str user_name: User responsible for triggering command. :returns: Optional[str] """ cmd, args = self._parse_command(chat_message[1::]) command = session.query(Command).filter(Command.command == cmd).first() if command is not None: response = self.create_message( command.type, command.response, command=cmd, args=args, room=room, user_name=user_name, ) room.message(response, html=True) else: self._giphy_fallback(chat_message, room)
def _bot_status_check(room: Room) -> None: """ Check bot status. :param Room room: Chatango room. :returns: None """ room.message("hellouughhgughhg?")
def _trademark(room: Room, message: Message) -> None: """ Replace "TM" chats with a trademark symbol. :param Room room: Current Chatango room object. :param Message message: User submitted `tm` to be replaced. :returns: None """ message.delete() room.message("™")
def _trademark(room: Room, message: Message) -> None: """ Trademark symbol helper. :param Room room: Chatango room. :param Message message: User submitted `tm` to be replaced. :returns: None """ message.delete() room.message("™")
def _create_link_preview(room: Room, url: str) -> None: """ Generate link preview for Instagram post URL. :param Room room: Chatango room. :param str url: URL of an Instagram post. :returns: None """ preview = create_instagram_preview(url) room.message(preview)
def _giphy_fallback(message: str, room: Room) -> None: """ Default to Giphy for non-existent commands. :param str message: Command triggered by a user. :param Room room: Current Chatango room object. :returns: None """ query = message.replace("!", "").lower().strip() if len(query) > 1: response = giphy_image_search(query) room.message(response)
def ban_user(room: Room, message: Message) -> None: """ Ban and delete chat history of a user. :param Room room: Chatango room object. :param Message message: User submitted message. :returns: None """ LOGGER.warning( f"BANNED user: username={message.user.name} ip={message.ip}") room.clear_user(message.user) room.ban_user(message.user)
def _wave_back(room: Room, user_name: str) -> None: """ Wave back at user. :param Room room: Chatango room. :param str user_name: User name of Chatango user who waved. :returns: None """ if user_name == "broiestbro": room.message( f"stop talking to urself and get some friends u f****n loser jfc kys @broiestbro" ) else: room.message(f"@{user_name} *waves*")
def _wave_back(room: Room, user_name: str, bot_username) -> None: """ Wave back at user. :param Room room: Current Chatango room object. :param str user_name: Username of Chatango user who waved. :returns: None """ if user_name == bot_username: room.message( f"stop talking to urself and get some friends u f****n loser jfc kys @{bot_username}" ) else: room.message(f"@{user_name} *waves*")
def ban_word(room: Room, message: Message, user_name: str, silent=False) -> None: """ Remove banned word and warn offending user. :param Room room: Current Chatango room object. :param Message message: Message sent by user. :param str user_name: User responsible for triggering command. :param bool silent: Whether offending user should be warned. :returns: None """ message.delete() if silent is not True: room.message(f"DO NOT SAY THAT WORD @{user_name.upper()} :@")
def _check_blacklisted_users(room: Room, user_name: str, message: Message) -> None: """ Ban and delete chat history of blacklisted user. :param Room room: Chatango room name. :param str user_name: Chatango username to validate against blacklist. :param Message message: User submitted message. :returns: None """ if user_name in CHATANGO_BLACKLISTED_USERS: room.ban(message) reply = emojize( f":wave: @{user_name} lmao pz fgt have fun being banned forever :wave:", use_aliases=True, ) room.message(reply)
def _create_link_preview(room: Room, chat_message: str) -> None: """ Generate link preview for URL. :param Room room: Current Chatango room object. :param str chat_message: URL of an Instagram post. :returns: None """ if (".jpg" not in chat_message and ".png" not in chat_message and ".gif" not in chat_message and ".jpeg" not in chat_message and ".mp4" not in chat_message and ".JPG" not in chat_message and ".PNG" not in chat_message and ".GIF" not in chat_message and ".JPEG" not in chat_message and ".MP4" not in chat_message and "twitter" not in chat_message and "youtube" not in chat_message): link_preview = extract_url(chat_message) if link_preview: room.message(link_preview, html=True)
def _process_command(self, chat_message: str, room: Room, user_name: str, message: Message) -> None: """ Determines if message is a bot command. :param str chat_message: Raw message sent by user. :param Room room: Chatango room object. :param str user_name: User responsible for triggering command. :param Message message: Chatango message object to be parsed. :returns: None """ ignored_user_message = check_ignored_users(user_name, message.ip) if ignored_user_message: room.message(ignored_user_message, html=True) elif re.match(r"^!!.+$", chat_message): return self._giphy_fallback(chat_message[2::], room) elif re.match(r"^!ein+$", chat_message): return self._get_response("!ein", room, user_name) elif re.match(r"^!\S+", chat_message): return self._get_response(chat_message, room, user_name)
def _process_command(self, chat_message: str, room: Room, user_name: str, message: Message) -> None: """Determines if message is a bot command.""" if re.match(r"^!!.+", chat_message): return self._giphy_fallback(chat_message[2::], room) elif re.match(r"^!ein+", chat_message): return self._get_response("!ein", room, user_name) elif re.match(r"^!.+", chat_message): return self._get_response(chat_message, room, user_name) elif chat_message == "bro?": self._bot_status_check(room) elif "@broiestbro" in chat_message.lower( ) and "*waves*" in chat_message.lower(): self._wave_back(room, user_name) elif chat_message.replace("!", "").strip() == "no u": self._ban_word(room, message, user_name, silent=True) elif "petition" in chat_message and "competition" not in chat_message and user_name != "broiestbro": room.message( "SIGN THE PETITION: \ https://www.change.org/p/nhl-exclude-penguins-from-bird-team-classification \ https://i.imgur.com/nYQy0GR.jpg", ) elif chat_message.endswith("only on aclee"): room.message("™") elif chat_message.lower() == "tm": self._trademark(room, message) elif chat_message.lower().replace("'", "") == "anyway heres wonderwall": room.message( "https://i.imgur.com/Z64dNAn.jpg https://www.youtube.com/watch?v=bx1Bh8ZvH84" ) # elif re.search(r"instagram.com/p/[a-zA-Z0-9_-]+", message.body): # self._create_link_preview(room, message.body) LOGGER.info( f"[{room.room_name}] [{user_name}] [{message.ip}]: {message.body}")
def _process_phrase(self, chat_message: str, room: Room, user_name: str, message: Message, bot_username: str) -> None: """ Search database for non-command phrases which elicit a response. :param str chat_message: A non-command chat which may prompt a response. :param Room room: Current chatango room object. :param str user_name: User responsible for triggering command. :param Message message: Chatango message object to be parsed. :param str bot_username: Username of the currently-running bot. :returns: None """ if f"@{bot_username}" in chat_message and "*waves*" in chat_message: self._wave_back(room, user_name, bot_username) elif chat_message == "no u": ban_word(room, message, user_name, silent=True) elif ("petition" in chat_message and "competition" not in chat_message and user_name.upper() not in CHATANGO_BOTS): room.message( "SIGN THE PETITION: \ https://www.change.org/p/nhl-exclude-penguins-from-bird-team-classification \ https://i.imgur.com/nYQy0GR.jpg", ) elif chat_message.endswith("only on aclee"): room.message("™") elif chat_message.lower() == "tm": self._trademark(room, message) else: fetched_phrase = (session.query(Phrase).filter( Phrase.phrase == chat_message).one_or_none()) if fetched_phrase is not None: room.message(fetched_phrase.response)
def _get_response(self, chat_message: str, room: Room, user_name: str): """ Fetch response from database to send to chat. :param str chat_message: Raw message sent by user. :param Room room: Current Chatango room object. :param str user_name: User responsible for triggering command. """ cmd, args = self._parse_command(chat_message[1::].strip()) command = session.query(Command).filter(Command.command == cmd).first() if command is not None and command.type not in ("reserved", "reddit"): response = self.create_message( command.type, command.response, command=cmd, args=args, room=room, user_name=user_name, ) room.message(response, html=True) else: self._giphy_fallback(chat_message, room)
def check_blacklisted_users(room: Room, user_name: str, message: Message) -> None: """ Ban and delete chat history of blacklisted user. :param Room room: Chatango room object. :param str user_name: Chatango username to validate against blacklist. :param Message message: User submitted message. :returns: None """ if user_name in CHATANGO_BLACKLISTED_USERS: reply = emojize( f":wave: @{user_name} lmao pz fgt have fun being banned forever :wave:", use_aliases=True, ) LOGGER.warning( f"BANNED user: username={message.user.name} ip={message.ip}") room.message(reply) room.clear_user(message.user) room.ban_user(message.user) elif (message.ip is not None and message.ip.startswith(CHATANGO_EGGSER_IP) and message.user.name.lower() not in CHATANGO_EGGSER_USERNAME_WHITELIST): ban_user(room, message) elif is_user_anon(user_name) and "raiders" in message.body.lower(): ban_user(room, message) elif is_user_anon(user_name) and "tigger" in message.body.lower(): ban_user(room, message) elif is_user_anon(user_name) and "wordle" in message.body.lower(): ban_user(room, message) elif "wordle" in message.body.lower() and "tomorrow" in message.body.lower( ): ban_user(room, message) elif "is the wordle" in message.body.lower(): ban_user(room, message)