Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wikipedia: use say() instead of reply() when reporting a URL error #2315

Merged
merged 1 commit into from
Jul 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
SnoopJ marked this conversation as resolved.
Show resolved Hide resolved
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