inatcog package¶
Subpackages¶
- inatcog.commands package
- Submodules
- inatcog.commands.inat module
CommandsInatCommandsInat.clear_bot_prefixesCommandsInat.clear_eventCommandsInat.clear_serverCommandsInat.describeCommandsInat.describe_advancedCommandsInat.describe_autoobsCommandsInat.describe_cheatsheetCommandsInat.describe_datesCommandsInat.describe_dot_taxonCommandsInat.describe_glossaryCommandsInat.describe_groupsCommandsInat.describe_groups2CommandsInat.describe_macrosCommandsInat.describe_queryCommandsInat.describe_reactionsCommandsInat.describe_replyCommandsInat.describe_taxon_queryCommandsInat.dot_taxon_serverCommandsInat.format_event()CommandsInat.inatCommandsInat.inat_clearCommandsInat.inat_inspectCommandsInat.inat_setCommandsInat.inat_showCommandsInat.inat_testCommandsInat.set_active_roleCommandsInat.set_autoobsCommandsInat.set_autoobs_previewCommandsInat.set_autoobs_serverCommandsInat.set_autoobs_server_previewCommandsInat.set_beta_roleCommandsInat.set_bot_prefixesCommandsInat.set_dot_taxonCommandsInat.set_eventCommandsInat.set_event_roleCommandsInat.set_homeCommandsInat.set_inactive_roleCommandsInat.set_listenCommandsInat.set_manage_places_roleCommandsInat.set_manage_projects_roleCommandsInat.set_manage_users_roleCommandsInat.set_serverCommandsInat.show_autoobsCommandsInat.show_bot_prefixesCommandsInat.show_dot_taxonCommandsInat.show_eventsCommandsInat.show_homeCommandsInat.show_listenCommandsInat.show_serverCommandsInat.topic_advancedCommandsInat.topic_autoobsCommandsInat.topic_cheatsheetCommandsInat.topic_datesCommandsInat.topic_dot_taxonCommandsInat.topic_glossaryCommandsInat.topic_groupsCommandsInat.topic_groups2CommandsInat.topic_macrosCommandsInat.topic_queryCommandsInat.topic_reactionsCommandsInat.topic_replyCommandsInat.topic_taxon_query
- inatcog.commands.last module
CommandsLastCommandsLast.get_last_obs_from_history()CommandsLast.get_last_taxon_from_history()CommandsLast.lastCommandsLast.last_obsCommandsLast.last_obs_imgCommandsLast.last_obs_mapCommandsLast.last_obs_rankCommandsLast.last_obs_relatedCommandsLast.last_obs_taxonCommandsLast.last_obs_taxon_imageCommandsLast.last_taxonCommandsLast.last_taxon_imageCommandsLast.last_taxon_mapCommandsLast.last_taxon_rankCommandsLast.last_taxon_relatedCommandsLast.query_from_last_taxon()
- inatcog.commands.map module
- inatcog.commands.obs module
CommandsObsCommandsObs.lifeCommandsObs.linkCommandsObs.obsCommandsObs.obs_countCommandsObs.obs_imgCommandsObs.obs_lifelistCommandsObs.obs_mapCommandsObs.obs_maverickCommandsObs.obs_searchCommandsObs.tabulateCommandsObs.tabulate_maverickCommandsObs.topCommandsObs.top_identifiersCommandsObs.top_identifiers_aliasCommandsObs.top_observersCommandsObs.top_observers_aliasCommandsObs.top_speciesCommandsObs.top_species_alias
ObsResult
- inatcog.commands.place module
- inatcog.commands.project module
- inatcog.commands.search module
- inatcog.commands.taxon module
CommandsTaxonCommandsTaxon.bold4CommandsTaxon.bonapCommandsTaxon.image_aliasCommandsTaxon.relatedCommandsTaxon.speciesCommandsTaxon.taxonCommandsTaxon.taxon_bold4CommandsTaxon.taxon_imageCommandsTaxon.taxon_listCommandsTaxon.taxon_locCommandsTaxon.taxon_mapCommandsTaxon.taxon_meansCommandsTaxon.taxon_relatedCommandsTaxon.taxon_sciCommandsTaxon.taxon_searchCommandsTaxon.tnameCommandsTaxon.ttest
- inatcog.commands.user module
CommandsUserCommandsUser.iuserCommandsUser.meCommandsUser.myCommandsUser.my_idmapCommandsUser.my_inatyearCommandsUser.my_mapCommandsUser.my_obsCommandsUser.rankCommandsUser.userCommandsUser.user_addCommandsUser.user_add_idCommandsUser.user_inatyearCommandsUser.user_listCommandsUser.user_removeCommandsUser.user_remove_allCommandsUser.user_setCommandsUser.user_set_homeCommandsUser.user_set_knownCommandsUser.user_set_langCommandsUser.user_set_serverCommandsUser.user_show_settings()
- Module contents
- inatcog.tests package
Submodules¶
inatcog.api module¶
Module to access iNaturalist API.
- class inatcog.api.INatAPI[source]¶
Bases:
objectAccess the iNat API and assets via (api|static).inaturalist.org.
- await bulk_load_users_from_observers(user_ids: List)[source]¶
Bulk load users that are observers.
This method can be used to prime the cache prior to fetching multiple users at once by id, greatly reducing the API cost over an individual API call per user.
- await get_observations(*args, **kwargs)[source]¶
Query API for observations.
- Parameters:
*args –
If first positional argument is given, it is passed through as-is, appended to the /v1/observations endpoint.
**kwargs –
All kwargs are passed as params on the API call.
- await get_places(query: Union[int, str, list], refresh_cache=False, **kwargs)[source]¶
Get places for the specified ids or text query.
inatcog.checks module¶
Checks for iNatcog.
inatcog.client module¶
inatcog.common module¶
Module for common code.
inatcog.constants module¶
Module for constants.
inatcog.converters module¶
inatcog.embeds module¶
inatcog.help module¶
Custom iNat help module.
- class inatcog.help.INatHelp[source]¶
Bases:
RedHelpFormatterCustom help, with support for additional (non-command) help topics.
- await format_command_help(ctx, obj, help_settings: HelpSettings)[source]¶
- await get_bot_help_mapping(ctx, help_settings: HelpSettings)[source]¶
- await make_and_send_embeds(ctx, emb, help_settings: HelpSettings)[source]¶
inatcog.inatcog module¶
A cog for using the iNaturalist platform.
- class inatcog.inatcog.CompositeMetaClass(*args: Any, **kwargs: Unpack[_CogKwargs])[source]¶
Bases:
CogMeta,ABCMetaSee https://github.com/mikeshardmind/SinbadCogs/blob/v3/rolemanagement/core.py
- class inatcog.inatcog.INatCog(*args: Any, **kwargs: Any)[source]¶
Bases:
Listeners,Cog,CommandsEvent,CommandsInat,CommandsLast,CommandsMap,CommandsObs,CommandsPlace,CommandsProject,CommandsSearch,CommandsTaxon,CommandsUserCommands provided by inatcog.
- spam_intervals = [(datetime.timedelta(seconds=3), 5), (datetime.timedelta(seconds=20), 10), (datetime.timedelta(seconds=180), 45)]¶
inatcog.interfaces module¶
Module for abc interfaces.
inatcog.last module¶
Module for handling recent history.
- class inatcog.last.INatLinkMsg(cog)[source]¶
Bases:
objectGet INat link message from channel history supplemented with info from iNat.
- class inatcog.last.ObsLinkMsg(url: str, obs: Observation, ago: str, name: str)[source]¶
Bases:
NamedTupleDiscord & iNat fields from a recent observation link.
- ago: str¶
Alias for field number 2
- name: str¶
Alias for field number 3
- obs: Observation¶
Alias for field number 1
- url: str¶
Alias for field number 0
inatcog.listeners module¶
Listeners module for inatcog.
- class inatcog.listeners.Listeners(*_args)[source]¶
Bases:
INatEmbeds,MixinMetaListeners mixin for inatcog.
- await handle_member_reaction(emoji: PartialEmoji, member: Member, message: Message, action: str)[source]¶
Central handler for member reactions.
- maybe_get_reaction(payload: RawReactionActionEvent) Tuple[Member, Message][source]¶
Return reaction member & message if valid.
- class inatcog.listeners.PartialContext(bot: Red, guild: Guild, channel: ChannelType, author: User, message: Optional[Union[Message, PartialMessage]], command: Optional[str] = '', assume_yes: bool = True, interaction: Optional[Interaction] = None, inat_client: iNatClient = None)[source]¶
Bases:
objectPartial Context synthesized from objects passed into listeners.
- assume_yes: bool¶
- author: User¶
- channel: ChannelType¶
- command: Optional[str]¶
- guild: Guild¶
- inat_client: iNatClient¶
- interaction: Optional[Interaction]¶
- message: Optional[Union[Message, PartialMessage]]¶
inatcog.maps module¶
Module to make maps for iNat.
- class inatcog.maps.INatMapURL(api)[source]¶
Bases:
objectMake URL for iNat range map via /taxa/map interface on website.
- class inatcog.maps.MapCoords(zoom_level, center_lat, center_lon)¶
Bases:
tuple- center_lat¶
Alias for field number 1
- center_lon¶
Alias for field number 2
- zoom_level¶
Alias for field number 0
- class inatcog.maps.MapLink(title, url)¶
Bases:
tuple- title¶
Alias for field number 0
- url¶
Alias for field number 1
inatcog.obs_query module¶
Module to query iNat observations.
inatcog.obs module¶
Module to work with iNat observations.
- inatcog.obs.get_formatted_user_counts(user_counts: dict, base_url: str, species_only: bool = False, view: str = 'obs')[source]¶
Format per user observation & species counts.
inatcog.places module¶
Module to handle users.
inatcog.projects module¶
Module to handle projects.
- class inatcog.projects.UserProject(id: Any = None, uuid: str = None, banner_color: str = None, created_at: Any = _Nothing.NOTHING, description: str = None, header_image_url: str = None, hide_title: bool = None, icon: str = None, is_umbrella: bool = None, last_post_at: Any = None, location: Union[Dict, List, None, str] = None, observation_requirements_updated_at: Any = None, place_id: int = None, prefers_user_trust: bool = None, project_observation_rules: List[Dict] = _Nothing.NOTHING, project_type: str = None, rule_preferences: List[Dict] = _Nothing.NOTHING, search_parameters: List[Dict] = _Nothing.NOTHING, site_features: List[Dict] = _Nothing.NOTHING, slug: str = None, terms: str = None, title: str = None, updated_at: Any = None, user_ids: List[int] = _Nothing.NOTHING, admins=_Nothing.NOTHING, project_observation_fields=_Nothing.NOTHING, user=None)[source]¶
Bases:
ProjectA collection project for observations by specific users.
This class handles projects that include observations by members, with membership being managed either solely by the user, soley by the admins, or a combination of both:
Open membership, users join on the web:
members_only: True
do not set any “observed_by_user?” rules
Closed membership, admins edit the project to join users:
members_only: False
set at least one “observed_by_user?” rule
Closed membership, users join on web and admins edit project to “approve” join:
members_only: True
set at least one “observed_by_user?” rule
a user’s observations are included when both the user joins and the admin “approves” the join by adding a rule for them
- banner_color: str¶
- created_at: datetime¶
- description: str¶
- header_image_url: str¶
- hide_title: bool¶
- icon: str¶
- is_umbrella: bool¶
- last_post_at: Optional[datetime]¶
- location: Coordinates¶
- observation_requirements_updated_at: Optional[datetime]¶
- observed_by_ids()[source]¶
Valid observer user ids for the project.
TODO: clarify what the iNat code actually does for these cases and fix as needed. we implement, based on some reasonable assumptions:
for closed membership projects, exclude any user that has both an included rule (observed_by_user?) and an excluded rule (not_observed_by_user?)
- place_id: int¶
- prefers_user_trust: bool¶
- project_observation_rules: List[Dict]¶
- project_type: str¶
- rule_preferences: List[Dict]¶
- search_parameters: List[Dict]¶
- site_features: List[Dict]¶
- slug: str¶
- terms: str¶
- title: str¶
- updated_at: DateTime¶
- user_ids: List[int]¶
- await inatcog.projects.get_event_project(guild_config: Config, abbrev: str, client: iNatClient)[source]¶
inatcog.query module¶
Module to query iNat.
inatcog.search module¶
Module to search iNat site.
inatcog.taxa module¶
Module to work with iNat taxa.
- class inatcog.taxa.NameMatch(term: Optional[match], name: Optional[match], common: Optional[match])[source]¶
Bases:
NamedTupleMatch for each name field in Taxon matching a pattern.
- common: Optional[match]¶
Alias for field number 2
- name: Optional[match]¶
Alias for field number 1
- term: Optional[match]¶
Alias for field number 0
- await inatcog.taxa.format_place_taxon_counts(cog, place: Union[Place, str], taxon: Taxon = None, **kwargs)[source]¶
Format user observation & species counts for taxon.
- await inatcog.taxa.format_user_taxon_counts(cog, user: Union[User, str], taxon: Taxon = None, **kwargs)[source]¶
Format user observation & species counts for taxon.
- await inatcog.taxa.get_taxon_preferred_establishment_means(ctx, taxon)[source]¶
Get the preferred establishment means for the taxon.
- inatcog.taxa.match_pat(record, pat, scientific_name=False, locale=None)[source]¶
Match specified pattern.
- Parameters:
record (Taxon) – A candidate taxon to match.
pat (re.Pattern or str) – A pattern to match against each name field in the record.
scientific_name (bool) – Only search scientific name
locale (str) – Only search common names matching locale
- Returns:
A tuple of search results for the pat for each name in the record.
- Return type:
- inatcog.taxa.match_pat_list(record, pat_list, scientific_name=False, locale=None)[source]¶
Match all of a list of patterns.
- Parameters:
record (Taxon) – A candidate taxon to match.
exact (list) – A list of patterns to match.
- Returns:
A tuple of ORed search results for every pat for each name in the record, i.e. each name in the tuple is the match result from the first matching pattern.
- Return type:
- inatcog.taxa.match_taxon(taxon_query: TaxonQuery, records, scientific_name=False, locale=None)[source]¶
Match a single taxon for the given query among records returned by API.
- inatcog.taxa.score_match(taxon_query: TaxonQuery, record, all_terms, pat_list=None, scientific_name=False, locale=None)[source]¶
Score a matched record. A higher score is a better match. :param taxon_query: The query for the matched record being scored. :type taxon_query: TaxonQuery :param record: A candidate taxon to match. :type record: Taxon :param all_terms: A pattern matching all terms. :type all_terms: re.Pattern :param pat_list: A list of patterns to match. :type pat_list: list
- Returns:
score < 0 indicates the match is not a valid candidate. score >= 0 and score < 200 indicates a non-exact match score >= 200 indicates an exact match either on a phrase or the whole query
- Return type:
int
inatcog.taxon_query module¶
Module to query iNat taxa.
- class inatcog.taxon_query.INatTaxonQuery(cog)[source]¶
Bases:
objectQuery iNat for one or more taxa.
- await get_taxon_ancestor(ctx: Context, taxon, rank)[source]¶
Get Taxon ancestor for specified rank from a Taxon object.
- Parameters:
taxon (Taxon) – The taxon for which the ancestor at the specified rank is requested.
rank (str) – The rank of the ancestor to return.
- Returns:
A Taxon object for the matching ancestor, if any, else None.
- Return type:
Taxon
- await maybe_match_taxon(ctx: Context, taxon_query: TaxonQuery, ancestor_id: int = None, preferred_place_id: int = None, scientific_name: bool = False, locale: str = None)[source]¶
Get taxon and return a match, if any.
- await maybe_match_taxon_compound(ctx: Context, query: Query, preferred_place_id=None, scientific_name=False, locale=None)[source]¶
Get one or more taxa and return a match, if any.
Currently the grammar supports only one ancestor taxon and one child taxon.
- await query_paginated_taxa(ctx, query)[source]¶
Query for one or more taxa and return paginator for matching taxa, if any.
Notes:
In its original conception, this was used only for comma-delimited lists of taxon queries for map & related, or a list of taxon ancestor IDs. These had a small, definite number of elements (whatever the user typed, or all the ancestors of a taxon), were de-duplicated, and didn’t need to be paginated.
We want to go one step further here and return multiple taxa, whether or not multiple were given as input:
The return is then a paginator for all matching taxa.
- Which may be filtered in some fashion, e.g.
All taxa matching the supplied name(s).
For a given rank keyword.
And if there are no filters, then just all results matching the query.
The “rank” filter is baked into maybe_match_taxon_compound (I think) and needs to be pulled out of that.
In fact, most of that relates to selecting “one best” match, so really isn’t needed here.
inatcog.users module¶
Module to handle users.
- class inatcog.users.INatUserTable(cog)[source]¶
Bases:
objectLookup helper for registered iNat users.
inatcog.utils module¶
Utilities module.
- inatcog.utils.cache_busting_id()[source]¶
A unique id suitable to bust Discord’s cache of a URL unfurl.
Append this string to any URL that Discord previews as an embed (an “unfurl” in Discord parlance) to bust the cache.
The Discord URL unfurl is reported here to be cached “up to 30 minutes”:
Since that would be 4 digits, we’re generous and generate IDs from 0 through 9999, so should work to bust their cache for roughly 2.78 hours.
- inatcog.utils.get_cog(cog_or_ctx=typing.Union[redbot.core.commands.commands.Cog, redbot.core.commands.context.Context]) Cog[source]¶
- await inatcog.utils.get_dronefly_user(ctx: Context, user: Optional[Union[Member, User]] = None, anywhere: bool = True) User[source]¶
Get a Dronefly user with defaults supplied from the current context.
- await inatcog.utils.get_dronefly_user_defaults(ctx: Context, user: Optional[Union[Member, User]] = None, anywhere: bool = True) dict[source]¶
Return the user’s Dronefly defaults.
Defaults are supplied from the user’s own config, the guild config, or global config, whichever is applicable according to the following rules.
for each default: - if the user is known either in the guild scope (anywhere=False)
or globally (anywhere=True) and their user config has that default, use it
otherwise use a guild default - if ctx.guild if set and the guild config has that default,
use it
otherwise if the user’s config has home_server set and that guild has the default, use it
otherwise use a global default if there is one
- await inatcog.utils.get_home(ctx: Context, user: Optional[Union[Member, User]] = None, anywhere: bool = True) dict[source]¶
Get configured home place for user.
- await inatcog.utils.get_lang(ctx: Context, user: Optional[Union[Member, User]] = None, anywhere: bool = True) dict[source]¶
Get configured preferred language for user.
- await inatcog.utils.get_valid_user_config(cog_or_ctx: Union[Cog, Context], user: Union[Member, User], anywhere: bool = True)[source]¶
Return iNat user config if known in this server.
Note 1: Even if the user is known in another guild, they are not considered known anywhere until they permit it with ,user set known True. This setting is ignored if anywhere=False (e.g. permission checks).
Note 2: A user may be registered to a certain user id#, but the id# is invalid (e.g. account deleted). If that is the case, they’ll still have access to functions that only require that their user ID be known to the bot!
- await inatcog.utils.has_valid_user_config(cog_or_ctx: Union[Cog, Context], user: Union[Member, User], anywhere: bool = True)[source]¶
Check if user is known in the specified scope.
See Note 2 on get_valid_user_config() for how validity is determined (i.e. the config is considered valid even if the iNat account isn’t).
Module contents¶
INatCog init.