Skip to content

Commit

Permalink
wikipedia: use say() instead of reply() when reporting a URL error
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoopJ committed Jul 22, 2022
1 parent 71380df commit 103e9c8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sopel/modules/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def mw_search(server, query, num):
return None


def say_snippet(bot, trigger, server, query, show_url=True):
def say_snippet(bot, trigger, server, query, show_url=True, commanded=False):
page_name = query.replace('_', ' ')
query = quote(query.replace(' ', '_'))
url = 'https://{}/wiki/{}'.format(server, query)
Expand All @@ -188,8 +188,11 @@ def say_snippet(bot, trigger, server, query, show_url=True):
# see https://github.com/sopel-irc/sopel/issues/2259
snippet = re.sub(r"\s+", " ", snippet)
except KeyError:
if show_url:
bot.reply("Error fetching snippet for \"{}\".".format(page_name))
msg = 'Error fetching snippet for "{}".'.format(page_name)
if commanded:
bot.reply(msg)
else:
bot.say(msg)
return

msg = '{} | "{}'.format(page_name, snippet)
Expand Down Expand Up @@ -223,7 +226,7 @@ def say_section(bot, trigger, server, query, section):

snippet = mw_section(server, query, section)
if not snippet:
bot.reply("Error fetching section \"{}\" for page \"{}\".".format(section, page_name))
bot.say('Error fetching section "{}" for page "{}".'.format(section, page_name))
return

msg = '{} - {} | "{}"'.format(page_name, section.replace('_', ' '), snippet)
Expand Down Expand Up @@ -309,7 +312,7 @@ def wikipedia(bot, trigger):
return plugin.NOLIMIT
else:
query = query[0]
say_snippet(bot, trigger, server, query)
say_snippet(bot, trigger, server, query, commanded=True)


@plugin.command('wplang')
Expand Down

0 comments on commit 103e9c8

Please sign in to comment.