curious.dataclasses.search¶
Wrappers for Search objects.
Classes
MessageGroup(msgs) |
A small class that returns messages from a message group. |
SearchQuery(guild, NoneType] = None, …) |
Represents a search query to be sent to Discord. |
SearchResults(sq) |
An async iterator that can be used to iterate over the results of a search. |
-
class
curious.dataclasses.search.MessageGroup(msgs: typing.List[curious.dataclasses.message.Message])[source]¶ Bases:
objectA small class that returns messages from a message group.
-
class
curious.dataclasses.search.SearchResults(sq: curious.dataclasses.search.SearchQuery) → None[source]¶ Bases:
collections.abc.AsyncIteratorAn async iterator that can be used to iterate over the results of a search. This will automatically fill results, and return messages as appropriate.
The return type of iterating over this is a
MessageGroup, which contains the messages around the message that matched the search result.async for i in sr: print(i.before) # 2 messages from before print(i.message) # the message that matched print(i.after) # 2 messages from after
-
limit(limit=-1)[source]¶ Sets the maximum messages to fetch from this search result.
async for group in sr.limit(25): ...
Parameters: limit ( int) – The limit to set.Return type: SearchResultsReturns: This SearchResults.
-
await
fetch_next_page()[source]¶ Fetches the next page of results from the SearchQuery.
Return type: None
-
get_next()[source]¶ Gets the next page of results.
If no results were found, this will raise an IndexError, and you must fetch the next page with
SearchResults.fetch_next_page().Return type: MessageGroupReturns: A MessageGroupfor the next page of results, if applicable.
-
-
class
curious.dataclasses.search.SearchQuery(guild: typing.Union[curious.dataclasses.guild.Guild, NoneType] = None, channel: typing.Union[curious.dataclasses.channel.Channel, NoneType] = None) → None[source]¶ Bases:
objectRepresents a search query to be sent to Discord. This is a simple wrapper over the HTTP API.
For example, to search a channel called
generalfor messages with the contentheck:with ctx.guild.search as sq: sq.content = "heck" sq.channel = next(filter(lambda c: c.name == "general", ctx.guild.channels), None) async for result in sq.results: ... # do whatever with the messages returned.
You can get results out of the query in two ways:
sq = SearchQuery(ctx.guild) sq.content = "heck" # form 1 async for item in sq.results: ... # form 2 results = await sq.get_messages() for result in results: ...
It is recommended to use the
async forform, as this will automatically page the results and return the next page of results as soon as the current one is exhausted.Parameters: -
make_params()[source]¶ Return type: Dict[str,str]Returns: The dict of parameters to send for this request.
-
channel¶ The
Channelthat is being searched.Note
If this a DM, this will not be added in the params.
Getter: Gets the Channelto be searched.Setter: Sets the Channelto be searched.Return type: Optional[Channel]
-
content¶ The str content that is being searched.
Getter: Gets the strcontent to be searched.Setter: Sets the strcontent to be searched.Return type: str
-
results¶ A simple way of accessing the search results for a search query.
Return type: SearchResultsReturns: A SearchResultsrepresenting the results of this query.
-
await
execute(page=0)[source]¶ Executes the search query.
Warning
This is an internal method, used by the library. Use
get_messages()instead of this.Parameters: page ( int) – The page of results to return.Return type: List[List[Message]]Returns: A list of Messagewhich returns the results of the search query.
-
await
get_messages(page=0)[source]¶ Executes the search query and gets the messages for the specified page.
Parameters: page ( int) – The page of results to return.Return type: SearchResultsReturns: A SearchResultthat can be used to search the results.
-