@@ -219,7 +219,7 @@ frappe.Chat = Class.extend({ | |||
data.owner = 'bot'; | |||
} | |||
data.content = frappe.markdown(data.content); | |||
data.content = frappe.markdown(data.content.substr(0, 1000)); | |||
} | |||
@@ -15,7 +15,6 @@ def get_list(arg=None): | |||
frappe.form_dict['user'] = frappe.session['user'] | |||
# set all messages as read | |||
frappe.db.begin() | |||
frappe.db.sql("""UPDATE `tabCommunication` set seen = 1 | |||
where | |||
communication_type in ('Chat', 'Notification') | |||
@@ -27,18 +26,22 @@ def get_list(arg=None): | |||
frappe.local.flags.commit = True | |||
fields = '''name, owner, modified, content, communication_type, | |||
comment_type, reference_doctype, reference_name''' | |||
if frappe.form_dict.contact == 'Bot': | |||
return frappe.db.sql("""select * from `tabCommunication` | |||
return frappe.db.sql("""select {0} from `tabCommunication` | |||
where | |||
comment_type = 'Bot' | |||
and reference_doctype = 'User' | |||
and reference_name = %(user)s | |||
order by creation desc | |||
limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1) | |||
limit %(limit_start)s, %(limit_page_length)s""".format(fields), | |||
frappe.local.form_dict, as_dict=1) | |||
if frappe.form_dict.contact == frappe.session.user: | |||
# return messages | |||
return frappe.db.sql("""select * from `tabCommunication` | |||
return frappe.db.sql("""select {0} from `tabCommunication` | |||
where | |||
communication_type in ('Chat', 'Notification') | |||
and comment_type != 'Bot' | |||
@@ -47,7 +50,8 @@ def get_list(arg=None): | |||
or reference_name=%(user)s | |||
or owner=reference_name) | |||
order by creation desc | |||
limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1) | |||
limit %(limit_start)s, %(limit_page_length)s""".format(fields), | |||
frappe.local.form_dict, as_dict=1) | |||
else: | |||
return frappe.db.sql("""select * from `tabCommunication` | |||
where | |||
@@ -56,7 +60,8 @@ def get_list(arg=None): | |||
and ((owner=%(contact)s and reference_name=%(user)s) | |||
or (owner=%(contact)s and reference_name=%(contact)s)) | |||
order by creation desc | |||
limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1) | |||
limit %(limit_start)s, %(limit_page_length)s""".format(fields), | |||
frappe.local.form_dict, as_dict=1) | |||
@frappe.whitelist() | |||
def get_active_users(): | |||
@@ -14,7 +14,7 @@ execute:frappe.reload_doc('custom', 'doctype', 'custom_field') #2015-10-19 | |||
execute:frappe.reload_doc('core', 'doctype', 'page') #2013-13-26 | |||
execute:frappe.reload_doc('core', 'doctype', 'report') #2014-06-03 | |||
execute:frappe.reload_doc('core', 'doctype', 'translation') #2016-03-03 | |||
execute:frappe.reload_doc('core', 'doctype', 'version') #2014-02-21 | |||
execute:frappe.reload_doc('core', 'doctype', 'version') #2016-12-28 | |||
execute:frappe.reload_doc('email', 'doctype', 'email_alert') #2014-07-15 | |||
execute:frappe.reload_doc('desk', 'doctype', 'todo') #2014-12-31-1 | |||
execute:frappe.reload_doc('custom', 'doctype', 'property_setter') #2014-12-31-1 | |||
@@ -333,7 +333,7 @@ | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"default": "1", | |||
"default": "0", | |||
"fieldname": "show_section_headings", | |||
"fieldtype": "Check", | |||
"hidden": 0, | |||
@@ -362,7 +362,7 @@ | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"default": "1", | |||
"default": "0", | |||
"fieldname": "line_breaks", | |||
"fieldtype": "Check", | |||
"hidden": 0, | |||
@@ -653,7 +653,7 @@ | |||
"issingle": 0, | |||
"istable": 0, | |||
"max_attachments": 0, | |||
"modified": "2016-12-29 14:40:24.569123", | |||
"modified": "2016-12-30 15:12:46.182376", | |||
"modified_by": "Administrator", | |||
"module": "Print", | |||
"name": "Print Format", | |||
@@ -36,7 +36,9 @@ class BotParser(object): | |||
def format_list(self, data): | |||
'''Format list as markdown''' | |||
return ', '.join(['[{name}](#Form/{doctype}/{name})'.format(doctype=self.get_doctype(), | |||
return _('I found these: ') + ', '.join([' [{title}](#Form/{doctype}/{name})'.format( | |||
title = d.title or d.name, | |||
doctype=self.get_doctype(), | |||
name=d.name) for d in data]) | |||
def get_doctype(self): | |||
@@ -46,7 +48,7 @@ class BotParser(object): | |||
class ShowNotificationBot(BotParser): | |||
'''Show open notifications''' | |||
def get_reply(self): | |||
if self.has("whatsup", "what's up", "wassup", "whats up"): | |||
if self.has("whatsup", "what's up", "wassup", "whats up", 'notifications', 'open tasks'): | |||
n = get_notifications() | |||
open_items = sorted(n.get('open_count_doctype').items()) | |||
@@ -78,10 +80,27 @@ class GetOpenListBot(BotParser): | |||
class ListBot(BotParser): | |||
def get_reply(self): | |||
if self.startswith('list', 'show'): | |||
if self.query.endswith(' ' + _('list')) and self.startswith(_('list')): | |||
self.query = _('list') + ' ' + self.query.replace(' ' + _('list'), '') | |||
if self.startswith(_('list'), _('show')): | |||
like = None | |||
if ' ' + _('like') + ' ' in self.query: | |||
self.query, like = self.query.split(' ' + _('like') + ' ') | |||
self.tables = self.reply.identify_tables(self.query.split(None, 1)[1]) | |||
if self.tables: | |||
return self.format_list(frappe.get_list(self.get_doctype())) | |||
doctype = self.get_doctype() | |||
meta = frappe.get_meta(doctype) | |||
fields = ['name'] | |||
if meta.title_field: | |||
fields.append('`{0}` as title'.format(meta.title_field)) | |||
filters = {} | |||
if like: | |||
filters={ | |||
meta.title_field or 'name': ('like', '%' + like + '%') | |||
} | |||
return self.format_list(frappe.get_list(self.get_doctype(), fields=fields, filters=filters)) | |||
class CountBot(BotParser): | |||
def get_reply(self): | |||
@@ -193,6 +212,7 @@ help_text = """Hello {0}, I am a K.I.S.S Bot, not AI, so be kind. I can try answ | |||
- "todo": list my todos | |||
- "show customers": list customers | |||
- "show customers like giant": list customer containing giant | |||
- "locate shirt": find where to find item "shirt" | |||
- "open issues": find open issues, try "open sales orders" | |||
- "how many users": count number of users | |||