Skip to content

Commit 5933077

Browse files
author
Pietro Albini
committed
Use HTML instead of Markdown in the default messages
Before this commit, Markdown was used in all the default messages. This was fine for most of them, but it causes problems in the `/help` command if someone puts any markdown special characters in the docstring of any commands. This commit switches all the default messages to forced HTML, because it supports escaping unwanted entities. Fixes: GH-51
1 parent 15bff6e commit 5933077

File tree

6 files changed

+87
-67
lines changed

6 files changed

+87
-67
lines changed

botogram/defaults.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def start_command(self, bot, chat):
3131
message.append("")
3232
message.append(bot._("Use /help to get a list of all the commands."))
3333

34-
chat.send("\n".join(message))
34+
chat.send("\n".join(message), syntax="html")
3535

3636
@decorators.help_message_for(start_command)
3737
def _start_command_help(bot):
@@ -45,19 +45,20 @@ def _start_command_help(bot):
4545
def help_command(self, bot, chat, args):
4646
commands = bot._get_commands()
4747
if len(args) > 1:
48-
message = [bot._("*Error!* The `/help` command allows up to one "
49-
"argument.")]
48+
message = [bot._("<b>Error!</b> The <code>/help</code> command "
49+
"allows up to one argument.")]
5050
elif len(args) == 1:
5151
if args[0] in commands:
5252
message = self._help_command_message(bot, commands, args[0])
5353
else:
54-
message = [bot._("*Unknown command:* `/%(name)s`",
54+
message = [bot._("<b>Unknown command:</b> "
55+
"<code>/%(name)s</code>",
5556
name=args[0]),
5657
bot._("Use /help to get a list of the commands.")]
5758
else:
5859
message = self._help_generic_message(bot, commands)
5960

60-
chat.send("\n".join(message))
61+
chat.send("\n".join(message), syntax="html")
6162

6263
def _help_generic_message(self, bot, commands):
6364
"""Generate an help message"""
@@ -74,7 +75,7 @@ def _help_generic_message(self, bot, commands):
7475

7576
# Show help on commands
7677
if len(commands) > 0:
77-
message.append(bot._("*This bot supports those commands:*"))
78+
message.append(bot._("<b>This bot supports those commands:</b>"))
7879
for name in sorted(commands.keys()):
7980
# Allow to hide commands in the help message
8081
if name in bot.hide_commands:
@@ -83,12 +84,13 @@ def _help_generic_message(self, bot, commands):
8384
func = commands[name]
8485
docstring = utils.docstring_of(func, bot, format=True) \
8586
.split("\n", 1)[0]
86-
message.append("/%s `-` %s" % (name, docstring))
87+
message.append("/%s <code>-</code> %s" % (name, docstring))
8788
message.append("")
88-
message.append(bot._("You can also use `/help <command>` to get "
89-
"help about a specific command."))
89+
message.append(bot._("You can also use <code>/help &lt;command&gt;"
90+
"</code> to get help about a specific "
91+
"command."))
9092
else:
91-
message.append(bot._("_This bot has no commands._"))
93+
message.append(bot._("<i>This bot has no commands.</i>"))
9294

9395
if len(bot.after_help):
9496
message.append("")
@@ -109,7 +111,7 @@ def _help_command_message(self, bot, commands, command):
109111

110112
func = commands[command]
111113
docstring = utils.docstring_of(func, bot, format=True)
112-
message.append("/%s `-` %s" % (command, docstring))
114+
message.append("/%s <code>-</code> %s" % (command, docstring))
113115

114116
# Show the owner informations
115117
if bot.owner:
@@ -125,8 +127,8 @@ def _help_command_help(bot):
125127
"""Get the help message of this command"""
126128
return "\n".join([
127129
bot._("Show this help message."),
128-
bot._("You can also use `/help <command>` to get help about a "
129-
"specific command."),
130+
bot._("You can also use <code>/help &lt;command&gt;</code> to get "
131+
"help about a specific command."),
130132
])
131133

132134
# An hook which displays "Command not found" if needed
@@ -148,7 +150,8 @@ def no_commands_hook(self, bot, chat, message):
148150
single_user = chat.type == "private"
149151
if mentioned or single_user:
150152
chat.send("\n".join([
151-
bot._("*Unknown command:* `/%(name)s`", name=command),
153+
bot._("<b>Unknown command:</b> <code>/%(name)s</code>",
154+
name=command),
152155
bot._("Use /help to get a list of the commands."),
153-
]))
156+
]), syntax="html")
154157
return True

botogram/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def docstring_of(func, bot=None, component_id=None, format=False):
146146
docstring = "No description available."
147147

148148
if format:
149-
docstring = "_%s_" % docstring
149+
docstring = "<i>%s</i>" % docstring
150150

151151
return format_docstr(docstring)
152152

docs/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ botogram changelog
99

1010
Here you can see what changed in every botogram release.
1111

12+
.. _changelog-0.2.1:
13+
14+
botogram 0.2.1
15+
==============
16+
17+
*Bugfix release, not yet released*
18+
19+
* Fix ``/help`` command crash if using markdown bits in the docstring (`issue
20+
51`_)
21+
22+
.. _issue 51: https://github.com/pietroalbini/botogram/issues/51
23+
1224
.. _changelog-0.2:
1325

1426
botogram 0.2

i18n/botogram.pot

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ 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: 2016-03-22 22:09+0100\n"
10+
"POT-Creation-Date: 2016-03-30 22:31+0200\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <LL@li.org>\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.2.0\n"
17+
"Generated-By: Babel 2.1.1\n"
1818

1919
#: botogram/defaults.py:32
2020
msgid "Use /help to get a list of all the commands."
@@ -29,40 +29,42 @@ 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 "<b>Error!</b> The <code>/help</code> command allows up to one argument."
3333
msgstr ""
3434

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

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

44-
#: botogram/defaults.py:77
45-
msgid "*This bot supports those commands:*"
44+
#: botogram/defaults.py:78
45+
msgid "<b>This bot supports those commands:</b>"
4646
msgstr ""
4747

48-
#: botogram/defaults.py:88 botogram/defaults.py:128
49-
msgid "You can also use `/help <command>` to get help about a specific command."
48+
#: botogram/defaults.py:89 botogram/defaults.py:130
49+
msgid ""
50+
"You can also use <code>/help &lt;command&gt;</code> to get help about a "
51+
"specific command."
5052
msgstr ""
5153

52-
#: botogram/defaults.py:91
53-
msgid "_This bot has no commands._"
54+
#: botogram/defaults.py:93
55+
msgid "<i>This bot has no commands.</i>"
5456
msgstr ""
5557

56-
#: botogram/defaults.py:100 botogram/defaults.py:117
58+
#: botogram/defaults.py:102 botogram/defaults.py:119
5759
#, python-format
5860
msgid "Please contact %(owner)s if you have problems with this bot."
5961
msgstr ""
6062

61-
#: botogram/defaults.py:127
63+
#: botogram/defaults.py:129
6264
msgid "Show this help message."
6365
msgstr ""
6466

65-
#: botogram/utils.py:138
67+
#: botogram/utils.py:144
6668
msgid "No description available."
6769
msgstr ""
6870

i18n/langs/en.po

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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: 2016-03-22 22:09+0100\n"
10+
"POT-Creation-Date: 2016-03-30 22:31+0200\n"
1111
"PO-Revision-Date: 2015-08-01 17:20+0200\n"
1212
"Last-Translator: Pietro Albini <pietro@pietroalbini.io>\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.2.0\n"
19+
"Generated-By: Babel 2.1.1\n"
2020

2121
#: botogram/defaults.py:32
2222
msgid "Use /help to get a list of all the commands."
@@ -31,40 +31,41 @@ 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 "<b>Error!</b> The <code>/help</code> command allows up to one argument."
3535
msgstr ""
3636

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

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

46-
#: botogram/defaults.py:77
47-
msgid "*This bot supports those commands:*"
46+
#: botogram/defaults.py:78
47+
msgid "<b>This bot supports those commands:</b>"
4848
msgstr ""
4949

50-
#: botogram/defaults.py:88 botogram/defaults.py:128
51-
msgid "You can also use `/help <command>` to get help about a specific command."
50+
#: botogram/defaults.py:89 botogram/defaults.py:130
51+
msgid ""
52+
"You can also use <code>/help &lt;command&gt;</code> to get help about a "
53+
"specific command."
5254
msgstr ""
5355

54-
#: botogram/defaults.py:91
55-
msgid "_This bot has no commands._"
56+
#: botogram/defaults.py:93
57+
msgid "<i>This bot has no commands.</i>"
5658
msgstr ""
5759

58-
#: botogram/defaults.py:100 botogram/defaults.py:117
60+
#: botogram/defaults.py:102 botogram/defaults.py:119
5961
#, python-format
6062
msgid "Please contact %(owner)s if you have problems with this bot."
6163
msgstr ""
6264

63-
#: botogram/defaults.py:127
65+
#: botogram/defaults.py:129
6466
msgid "Show this help message."
6567
msgstr ""
6668

67-
#: botogram/utils.py:138
69+
#: botogram/utils.py:144
6870
msgid "No description available."
6971
msgstr ""
70-

i18n/langs/it.po

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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: 2016-03-22 22:09+0100\n"
10+
"POT-Creation-Date: 2016-03-30 22:31+0200\n"
1111
"PO-Revision-Date: 2015-08-01 17:06+0200\n"
1212
"Last-Translator: Pietro Albini <pietro@pietroalbini.io>\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.2.0\n"
19+
"Generated-By: Babel 2.1.1\n"
2020

2121
#: botogram/defaults.py:32
2222
msgid "Use /help to get a list of all the commands."
@@ -31,40 +31,42 @@ 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 "<b>Error!</b> The <code>/help</code> command allows up to one argument."
35+
msgstr "<b>Errore!</b> Il comando <code>/help</code> non accetta più di un argomento."
3636

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

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

46-
#: botogram/defaults.py:77
47-
msgid "*This bot supports those commands:*"
48-
msgstr "*Questo bot supporta i seguenti comandi:*"
46+
#: botogram/defaults.py:78
47+
msgid "<b>This bot supports those commands:</b>"
48+
msgstr "<b>Questo bot supporta i seguenti comandi:</b>"
4949

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."
50+
#: botogram/defaults.py:89 botogram/defaults.py:130
51+
msgid ""
52+
"You can also use <code>/help &lt;command&gt;</code> to get help about a "
53+
"specific command."
54+
msgstr "Puoi anche usare <code>/help &lt;comando&gt;</code> per ottenere aiuto su un comando."
5355

54-
#: botogram/defaults.py:91
55-
msgid "_This bot has no commands._"
56-
msgstr "_Questo bot non ha comandi._"
56+
#: botogram/defaults.py:93
57+
msgid "<i>This bot has no commands.</i>"
58+
msgstr "<i>Questo bot non ha comandi.</i>"
5759

58-
#: botogram/defaults.py:100 botogram/defaults.py:117
60+
#: botogram/defaults.py:102 botogram/defaults.py:119
5961
#, python-format
6062
msgid "Please contact %(owner)s if you have problems with this bot."
6163
msgstr "Contatta %(owner)s se hai problemi con questo bot."
6264

63-
#: botogram/defaults.py:127
65+
#: botogram/defaults.py:129
6466
msgid "Show this help message."
6567
msgstr "Visualizza questo messaggio di aiuto."
6668

67-
#: botogram/utils.py:138
69+
#: botogram/utils.py:144
6870
msgid "No description available."
6971
msgstr "Nessuna descrizione disponibile."
7072

0 commit comments

Comments
 (0)