# Part of Odoo. See LICENSE file for full copyright and licensing details. import itertools import random from markupsafe import Markup from odoo import models, _ from odoo.tools import html_escape class MailBot(models.AbstractModel): _name = 'mail.bot' _description = 'Mail Bot' def _apply_logic(self, record, values, command=None): """ Apply bot logic to generate an answer (or not) for the user The logic will only be applied if odoobot is in a chat with a user or if someone pinged odoobot. :param record: the discuss channel where the user message was posted/odoobot will answer. :param values: msg_values of the message_post or other values needed by logic :param command: the name of the called command if the logic is not triggered by a message_post """ record.ensure_one() odoobot_id = self.env['ir.model.data']._xmlid_to_res_id("base.partner_root") if values.get("author_id") == odoobot_id or values.get("message_type") != "comment" and not command: return body = values.get("body", "").replace("\xa0", " ").strip().lower().strip(".!") if answer := self._get_answer(record, body, values, command): record.sudo().message_post( author_id=odoobot_id, body=answer, message_type="comment", silent=True, subtype_xmlid="mail.mt_comment", ) @staticmethod def _get_style_dict(): return { "new_line": Markup("
"), "bold_start": Markup(""), "bold_end": Markup(""), "command_start": Markup(""), "command_end": Markup(""), "document_link_start": Markup(""), "document_link_end": Markup(""), "slides_link_start": Markup(""), "slides_link_end": Markup(""), "paperclip_icon": Markup("