Skip to content

Commit 6f2bf20

Browse files
author
Pietro Albini
committed
Add rich formatting to default messages
1 parent ae37d8a commit 6f2bf20

File tree

6 files changed

+82
-101
lines changed

6 files changed

+82
-101
lines changed

botogram/defaults.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def start_command(self, bot, chat):
2828
message = []
2929
if bot.about:
3030
message.append(bot.about)
31+
message.append("")
3132
message.append(bot._("Use /help to get a list of all the commands."))
3233

3334
chat.send("\n".join(message))
@@ -44,14 +45,15 @@ def _start_command_help(bot):
4445
def help_command(self, bot, chat, args):
4546
commands = bot._get_commands()
4647
if len(args) > 1:
47-
message = [bot._("Error: the /help command allows up to one "
48+
message = [bot._("*Error!* The `/help` command allows up to one "
4849
"argument.")]
4950
elif len(args) == 1:
5051
if args[0] in commands:
5152
message = self._help_command_message(bot, commands, args[0])
5253
else:
53-
message = [bot._("Unknown command: /%(name)s.", name=args[0]),
54-
bot._("Use /help for a list of commands.")]
54+
message = [bot._("*Unknown command:* `/%(name)s`",
55+
name=args[0]),
56+
bot._("Use /help to get a list of the commands.")]
5557
else:
5658
message = self._help_generic_message(bot, commands)
5759

@@ -72,19 +74,21 @@ def _help_generic_message(self, bot, commands):
7274

7375
# Show help on commands
7476
if len(commands) > 0:
75-
message.append(bot._("Available commands:"))
77+
message.append(bot._("*This bot supports those commands:*"))
7678
for name in sorted(commands.keys()):
7779
# Allow to hide commands in the help message
7880
if name in bot.hide_commands:
7981
continue
8082

8183
func = commands[name]
82-
docstring = utils.docstring_of(func, bot).split("\n", 1)[0]
83-
message.append("/%s - %s" % (name, docstring))
84-
message.append(bot._("You can also use '/help <command>' to get "
84+
docstring = utils.docstring_of(func, bot, format=True) \
85+
.split("\n", 1)[0]
86+
message.append("/%s `-` %s" % (name, docstring))
87+
message.append("")
88+
message.append(bot._("You can also use `/help <command>` to get "
8589
"help about a specific command."))
8690
else:
87-
message.append(bot._("No commands available."))
91+
message.append(bot._("_This bot has no commands._"))
8892

8993
if len(bot.after_help):
9094
message.append("")
@@ -104,8 +108,8 @@ def _help_command_message(self, bot, commands, command):
104108
message = []
105109

106110
func = commands[command]
107-
docstring = utils.docstring_of(func, bot)
108-
message.append("/%s - %s" % (command, docstring))
111+
docstring = utils.docstring_of(func, bot, format=True)
112+
message.append("/%s `-` %s" % (command, docstring))
109113

110114
# Show the owner informations
111115
if bot.owner:
@@ -121,7 +125,7 @@ def _help_command_help(bot):
121125
"""Get the help message of this command"""
122126
return "\n".join([
123127
bot._("Show this help message."),
124-
bot._("You can also use '/help <command>' to get help about a "
128+
bot._("You can also use `/help <command>` to get help about a "
125129
"specific command."),
126130
])
127131

@@ -144,7 +148,7 @@ def no_commands_hook(self, bot, chat, message):
144148
single_user = chat.type == "private"
145149
if mentioned or single_user:
146150
chat.send("\n".join([
147-
bot._("Unknown command: /%(name)s", name=command),
148-
bot._("Use /help for a list of commands"),
151+
bot._("*Unknown command:* `/%(name)s`", name=command),
152+
bot._("Use /help to get a list of the commands."),
149153
]))
150154
return True

botogram/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def format_docstr(docstring):
119119
return "\n".join(result)
120120

121121

122-
def docstring_of(func, bot=None, component_id=None):
122+
def docstring_of(func, bot=None, component_id=None, format=False):
123123
"""Get the docstring of a function"""
124124
# Get the correct function from the hook
125125
if hasattr(func, "_botogram_hook"):
@@ -139,6 +139,9 @@ def docstring_of(func, bot=None, component_id=None):
139139
else:
140140
docstring = "No description available."
141141

142+
if format:
143+
docstring = "_%s_" % docstring
144+
142145
return format_docstr(docstring)
143146

144147

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Changes
4444
* Renamed ``Bot.init_shared_memory`` to :py:meth:`botogram.Bot.prepare_memory`
4545
* Renamed ``Component.add_shared_memory_initializer`` to
4646
:py:meth:`botogram.Component.add_memory_preparer`
47+
* Changed default messages to include rich formatting
4748

4849
Bug fixes
4950
---------

i18n/botogram.pot

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Translations template for botogram.
2-
# Copyright (C) 2015 Pietro Albini <[email protected]>
2+
# Copyright (C) 2016 Pietro Albini <[email protected]>
33
# This file is distributed under the same license as the botogram project.
4-
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
55
#
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: botogram 1.0.dev0\n"
99
"Report-Msgid-Bugs-To: https://github.com/pietroalbini/botogram/issues\n"
10-
"POT-Creation-Date: 2015-12-01 15:29+0100\n"
10+
"POT-Creation-Date: 2016-03-22 22:09+0100\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <[email protected]>\n"
1414
"MIME-Version: 1.0\n"
1515
"Content-Type: text/plain; charset=utf-8\n"
1616
"Content-Transfer-Encoding: 8bit\n"
17-
"Generated-By: Babel 2.1.1\n"
17+
"Generated-By: Babel 2.2.0\n"
1818

1919
#: botogram/defaults.py:32
2020
msgid "Use /help to get a list of all the commands."
@@ -29,49 +29,40 @@ msgid "This shows a greeting message."
2929
msgstr ""
3030

3131
#: botogram/defaults.py:48
32-
msgid "Error: the /help command allows up to one argument."
32+
msgid "*Error!* The `/help` command allows up to one argument."
3333
msgstr ""
3434

35-
#: botogram/defaults.py:54
35+
#: botogram/defaults.py:54 botogram/defaults.py:151
3636
#, python-format
37-
msgid "Unknown command: /%(name)s."
37+
msgid "*Unknown command:* `/%(name)s`"
3838
msgstr ""
3939

40-
#: botogram/defaults.py:55
41-
msgid "Use /help for a list of commands."
40+
#: botogram/defaults.py:56 botogram/defaults.py:152
41+
msgid "Use /help to get a list of the commands."
4242
msgstr ""
4343

44-
#: botogram/defaults.py:76
45-
msgid "Available commands:"
44+
#: botogram/defaults.py:77
45+
msgid "*This bot supports those commands:*"
4646
msgstr ""
4747

48-
#: botogram/defaults.py:85 botogram/defaults.py:125
49-
msgid "You can also use '/help <command>' to get help about a specific command."
48+
#: botogram/defaults.py:88 botogram/defaults.py:128
49+
msgid "You can also use `/help <command>` to get help about a specific command."
5050
msgstr ""
5151

52-
#: botogram/defaults.py:88
53-
msgid "No commands available."
52+
#: botogram/defaults.py:91
53+
msgid "_This bot has no commands._"
5454
msgstr ""
5555

56-
#: botogram/defaults.py:97 botogram/defaults.py:114
56+
#: botogram/defaults.py:100 botogram/defaults.py:117
5757
#, python-format
5858
msgid "Please contact %(owner)s if you have problems with this bot."
5959
msgstr ""
6060

61-
#: botogram/defaults.py:124
61+
#: botogram/defaults.py:127
6262
msgid "Show this help message."
6363
msgstr ""
6464

65-
#: botogram/defaults.py:148
66-
#, python-format
67-
msgid "Unknown command: /%(name)s"
68-
msgstr ""
69-
70-
#: botogram/defaults.py:149
71-
msgid "Use /help for a list of commands"
72-
msgstr ""
73-
74-
#: botogram/utils.py:109
65+
#: botogram/utils.py:138
7566
msgid "No description available."
7667
msgstr ""
7768

i18n/langs/en.po

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# English translations for botogram.
2-
# Copyright (C) 2015 Pietro Albini <[email protected]>
2+
# Copyright (C) 2016 Pietro Albini <[email protected]>
33
# This file is distributed under the same license as the botogram project.
4-
# Pietro Albini <[email protected]>, 2015.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
55
#
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: botogram 1.0.dev0\n"
99
"Report-Msgid-Bugs-To: https://github.com/pietroalbini/botogram/issues\n"
10-
"POT-Creation-Date: 2015-12-01 15:29+0100\n"
10+
"POT-Creation-Date: 2016-03-22 22:09+0100\n"
1111
"PO-Revision-Date: 2015-08-01 17:20+0200\n"
1212
"Last-Translator: Pietro Albini <[email protected]>\n"
1313
"Language: en\n"
@@ -16,7 +16,7 @@ msgstr ""
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=utf-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
19-
"Generated-By: Babel 2.1.1\n"
19+
"Generated-By: Babel 2.2.0\n"
2020

2121
#: botogram/defaults.py:32
2222
msgid "Use /help to get a list of all the commands."
@@ -31,49 +31,40 @@ msgid "This shows a greeting message."
3131
msgstr ""
3232

3333
#: botogram/defaults.py:48
34-
msgid "Error: the /help command allows up to one argument."
34+
msgid "*Error!* The `/help` command allows up to one argument."
3535
msgstr ""
3636

37-
#: botogram/defaults.py:54
37+
#: botogram/defaults.py:54 botogram/defaults.py:151
3838
#, python-format
39-
msgid "Unknown command: /%(name)s."
39+
msgid "*Unknown command:* `/%(name)s`"
4040
msgstr ""
4141

42-
#: botogram/defaults.py:55
43-
msgid "Use /help for a list of commands."
42+
#: botogram/defaults.py:56 botogram/defaults.py:152
43+
msgid "Use /help to get a list of the commands."
4444
msgstr ""
4545

46-
#: botogram/defaults.py:76
47-
msgid "Available commands:"
46+
#: botogram/defaults.py:77
47+
msgid "*This bot supports those commands:*"
4848
msgstr ""
4949

50-
#: botogram/defaults.py:85 botogram/defaults.py:125
51-
msgid "You can also use '/help <command>' to get help about a specific command."
50+
#: botogram/defaults.py:88 botogram/defaults.py:128
51+
msgid "You can also use `/help <command>` to get help about a specific command."
5252
msgstr ""
5353

54-
#: botogram/defaults.py:88
55-
msgid "No commands available."
54+
#: botogram/defaults.py:91
55+
msgid "_This bot has no commands._"
5656
msgstr ""
5757

58-
#: botogram/defaults.py:97 botogram/defaults.py:114
58+
#: botogram/defaults.py:100 botogram/defaults.py:117
5959
#, python-format
6060
msgid "Please contact %(owner)s if you have problems with this bot."
6161
msgstr ""
6262

63-
#: botogram/defaults.py:124
63+
#: botogram/defaults.py:127
6464
msgid "Show this help message."
6565
msgstr ""
6666

67-
#: botogram/defaults.py:148
68-
#, python-format
69-
msgid "Unknown command: /%(name)s"
70-
msgstr ""
71-
72-
#: botogram/defaults.py:149
73-
msgid "Use /help for a list of commands"
74-
msgstr ""
75-
76-
#: botogram/utils.py:109
67+
#: botogram/utils.py:138
7768
msgid "No description available."
7869
msgstr ""
7970

i18n/langs/it.po

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Italian translations for botogram.
2-
# Copyright (C) 2015 Pietro Albini <[email protected]>
2+
# Copyright (C) 2016 Pietro Albini <[email protected]>
33
# This file is distributed under the same license as the botogram project.
4-
# Pietro Albini <[email protected]>, 2015.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
55
#
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: botogram 1.0.dev0\n"
99
"Report-Msgid-Bugs-To: https://github.com/pietroalbini/botogram/issues\n"
10-
"POT-Creation-Date: 2015-12-01 15:29+0100\n"
10+
"POT-Creation-Date: 2016-03-22 22:09+0100\n"
1111
"PO-Revision-Date: 2015-08-01 17:06+0200\n"
1212
"Last-Translator: Pietro Albini <[email protected]>\n"
1313
"Language: it\n"
@@ -16,7 +16,7 @@ msgstr ""
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=utf-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
19-
"Generated-By: Babel 2.1.1\n"
19+
"Generated-By: Babel 2.2.0\n"
2020

2121
#: botogram/defaults.py:32
2222
msgid "Use /help to get a list of all the commands."
@@ -31,49 +31,40 @@ msgid "This shows a greeting message."
3131
msgstr "Questo comando visualizza un messaggio di benvenuto."
3232

3333
#: botogram/defaults.py:48
34-
msgid "Error: the /help command allows up to one argument."
35-
msgstr "Errore: il comando /help non accetta più di un argomento."
34+
msgid "*Error!* The `/help` command allows up to one argument."
35+
msgstr "*Errore!* Il comando `/help` non accetta più di un argomento."
3636

37-
#: botogram/defaults.py:54
37+
#: botogram/defaults.py:54 botogram/defaults.py:151
3838
#, python-format
39-
msgid "Unknown command: /%(name)s."
40-
msgstr "Comando sconosciuto: /%(name)s"
39+
msgid "*Unknown command:* `/%(name)s`"
40+
msgstr "*Comando sconosciuto:* `/%(name)s`"
4141

42-
#: botogram/defaults.py:55
43-
msgid "Use /help for a list of commands."
44-
msgstr "Utilizza /help per la lista dei comandi."
42+
#: botogram/defaults.py:56 botogram/defaults.py:152
43+
msgid "Use /help to get a list of the commands."
44+
msgstr "Utilizza /help per ottenere la lista dei comandi."
4545

46-
#: botogram/defaults.py:76
47-
msgid "Available commands:"
48-
msgstr "Comandi disponibili:"
46+
#: botogram/defaults.py:77
47+
msgid "*This bot supports those commands:*"
48+
msgstr "*Questo bot supporta i seguenti comandi:*"
4949

50-
#: botogram/defaults.py:85 botogram/defaults.py:125
51-
msgid "You can also use '/help <command>' to get help about a specific command."
52-
msgstr "Puoi anche usare '/help <comando>' per ottenere aiuto su un comando."
50+
#: botogram/defaults.py:88 botogram/defaults.py:128
51+
msgid "You can also use `/help <command>` to get help about a specific command."
52+
msgstr "Puoi anche usare `/help <comando>` per ottenere aiuto su un comando."
5353

54-
#: botogram/defaults.py:88
55-
msgid "No commands available."
56-
msgstr "Nessun comando disponibile."
54+
#: botogram/defaults.py:91
55+
msgid "_This bot has no commands._"
56+
msgstr "_Questo bot non ha comandi._"
5757

58-
#: botogram/defaults.py:97 botogram/defaults.py:114
58+
#: botogram/defaults.py:100 botogram/defaults.py:117
5959
#, python-format
6060
msgid "Please contact %(owner)s if you have problems with this bot."
6161
msgstr "Contatta %(owner)s se hai problemi con questo bot."
6262

63-
#: botogram/defaults.py:124
63+
#: botogram/defaults.py:127
6464
msgid "Show this help message."
6565
msgstr "Visualizza questo messaggio di aiuto."
6666

67-
#: botogram/defaults.py:148
68-
#, python-format
69-
msgid "Unknown command: /%(name)s"
70-
msgstr "Comando sconosciuto: /%(name)s"
71-
72-
#: botogram/defaults.py:149
73-
msgid "Use /help for a list of commands"
74-
msgstr "Utilizza /help per la lista dei comandi."
75-
76-
#: botogram/utils.py:109
67+
#: botogram/utils.py:138
7768
msgid "No description available."
7869
msgstr "Nessuna descrizione disponibile."
7970

0 commit comments

Comments
 (0)