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:
object
A small class that returns messages from a message group.
-
class
curious.dataclasses.search.
SearchResults
(sq: curious.dataclasses.search.SearchQuery) → None[source]¶ Bases:
collections.abc.AsyncIterator
An 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: SearchResults
Returns: 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: MessageGroup
Returns: A MessageGroup
for 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:
object
Represents a search query to be sent to Discord. This is a simple wrapper over the HTTP API.
For example, to search a channel called
general
for 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 for
form, 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
Channel
that is being searched.Note
If this a DM, this will not be added in the params.
Getter: Gets the Channel
to be searched.Setter: Sets the Channel
to be searched.Return type: Optional
[Channel
]
-
content
¶ The str content that is being searched.
Getter: Gets the str
content to be searched.Setter: Sets the str
content to be searched.Return type: str
-
results
¶ A simple way of accessing the search results for a search query.
Return type: SearchResults
Returns: A SearchResults
representing 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 Message
which 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: SearchResults
Returns: A SearchResult
that can be used to search the results.
-