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

pronouns: make base URL of links configurable #2438

Merged
merged 2 commits into from
Mar 30, 2023
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
28 changes: 20 additions & 8 deletions sopel/modules/pronouns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,41 @@
from sopel.config import types


BACKEND = 'https://pronouns.sopel.chat'
LOGGER = logging.getLogger(__name__)


class PronounsSection(types.StaticSection):
fetch_complete_list = types.BooleanAttribute('fetch_complete_list', default=True)
"""Whether to attempt fetching the complete list the web backend uses, at bot startup."""

link_base_url = types.ValidatedAttribute(
'link_base_url', default='https://pronouns.sopel.chat')
"""Base URL for links to pronoun info.

Defaults to an instance of https://github.com/sopel-irc/pronoun-service
hosted by the Sopel project, but it's easy to make your own instance
available at a custom domain using one of many free static site hosts.
"""


def configure(settings):
"""
| name | example | purpose |
| ---- | ------- | ------- |
| fetch_complete_list | True | Whether to attempt fetching the complete pronoun list from the web backend at startup. |
| link_base_url | https://pronouns.sopel.chat | Base URL for pronoun info links. |
"""
settings.define_section('pronouns', PronounsSection)
settings.pronouns.configure_setting(
'fetch_complete_list',
'Fetch the most current list of pronoun sets at startup?')
settings.pronouns.configure_setting(
'link_base_url',
'Base URL for pronoun info links:')


def setup(bot):
bot.config.define_section('pronouns', PronounsSection)
bot.settings.define_section('pronouns', PronounsSection)

# Copied from svelte-pronounisland, leaving a *lot* out.
# If ambiguous, the earlier one will be used.
Expand All @@ -56,7 +68,7 @@ def setup(bot):
'ey/em': 'ey/em/eir/eirs/eirself',
}

if not bot.config.pronouns.fetch_complete_list:
if not bot.settings.pronouns.fetch_complete_list:
return

# and now try to get the current list our fork of the backend uses
Expand Down Expand Up @@ -142,7 +154,7 @@ def pronouns(bot, trigger):
say_pronouns(bot, trigger.nick, pronouns)
else:
bot.reply("I don't know your pronouns! You can set them with "
"{}setpronouns".format(bot.config.core.help_prefix))
"{}setpronouns".format(bot.settings.core.help_prefix))
else:
pronouns = bot.db.get_nick_value(trigger.group(3), 'pronouns')
if pronouns:
Expand All @@ -152,12 +164,12 @@ def pronouns(bot, trigger):
# gender, but like… it's a bot.
bot.say(
"I am a bot. Beep boop. My pronouns are it/it/its/its/itself. "
"See {}/it for examples.".format(BACKEND)
"See {}/it for examples.".format(bot.settings.pronouns.link_base_url)
)
else:
bot.reply("I don't know {}'s pronouns. They can set them with "
"{}setpronouns".format(trigger.group(3),
bot.config.core.help_prefix))
bot.settings.core.help_prefix))


def say_pronouns(bot, nick, pronouns):
Expand All @@ -167,11 +179,11 @@ def say_pronouns(bot, nick, pronouns):
short = pronouns

bot.say(
"{nick}'s pronouns are {pronouns}. See {BACKEND}/{short} for examples."
"{nick}'s pronouns are {pronouns}. See {base_url}/{short} for examples."
.format(
nick=nick,
pronouns=pronouns,
BACKEND=BACKEND,
base_url=bot.settings.pronouns.link_base_url,
short=short,
)
)
Expand Down