Commit Graph
69 Commits
Author SHA1 Message Date
khazhykandGitHub a309088ae4 Add fetch_message_fast using history endpoint 2020-09-07 23:04:11 -04:00
khazhykandGitHub 6349d37a97 [commands] add require_var_positional 2020-09-07 22:24:48 -04:00
khazhykandRapptz b1fae0861a add read-only cached_messages property to Client
For those of us who want access to this sweet trove of zero hop messages
2019-04-17 22:41:59 -04:00
khazhyk 7845bfb79b terminate iterators immediately once out of data
if len(data) < 100, either limit was less than 100, or we ran
out of results, in both cases, we should terminate the lookup.

This fixes, e.g., hangs in audit_logs(limit=999999), and will
reduce the number of fetch calls for any case where limit is
greater than the number of results. (Prior, would just kinda
loop calling audit-logs)
2019-04-07 23:03:01 -07:00
khazhyk 52c45da0bc simplify AuditLogIterator ordering
rename reverse to oldest_first and remove cases where messages would
be ordered differently from the order we fetch audit log entries,
similar to HistoryIterator
2019-04-07 22:46:41 -07:00
khazhyk 366dc4855b simplify HistoryIterator message ordering
rename reverse -> oldest_first, which is more obvious what it does.
Then, honor it entirely - if you specify no `after` endpoint, we default
to the beginning of message history, similar to how `before` defaults to
the end of message history.

This is a breaking change, and will change the behavior of any iterator
that previously would have been returning messages in a weird order for
limits over 100

`for msg in history(reversed=True, limit=300)` would return the newest
300 messages, in a messed up order (100..0, 200..100, 300..200).
`for msg in history(oldest_first=True, limit=300)` will now return the
oldest 300 messages in order. And so on.

`for msg in history(after=msg)` is unchanged, this previously would
return the oldest 100 messages after `msg`, oldest->newest order, and
still will.
2019-04-07 22:46:40 -07:00
khazhyk 7078b665a3 allow passing 0 for logs_from parameters 2019-04-07 22:18:30 -07:00
khazhykandRapptz c30b016bb5 Support webp in _get_mime_type_for_image
untested
2018-11-24 23:18:11 -05:00
khazhykandRapptz 2c7a855e11 Revert "Ensure gif avatar urls end in .gif"
This reverts commit 456390f417.

This commit isn't needed anymore - the image proxy now properly
handles gifs that do not end in .gif
2018-07-20 04:14:21 -04:00
khazhykandRapptz 2321ae8d97 [commands] raise ConversionError on Converter error
This assumes that a Converter class raising non-CommandError
is a programmer error. Makes this type of error easier to
disambiguate from a generic BadArgument.
2018-07-20 04:14:20 -04:00
khazhyk 9d301f7cae Store guild, unavailable tuple in ready as well
This should fix userbots.

Fixes: 74380cd ("don't drop guild_available/join before ready")
2018-06-30 23:26:33 -07:00
khazhykandRapptz 74380cd72a don't drop guild_available/join before ready
large guilds that recieved GUILD_CREATE events prior to READY would
never dispatch guild_available/join. This is inconsistent with
smaller guilds and makes these events unreliable. Dispatch the
"delayed" guilds after they've been chunked, prior to ready.
2018-06-29 21:48:31 -04:00
khazhykandRapptz 0ef866a704 [commands] Fix MissingRequiredArgument param handling
Documentation was incorrect, and we were throwing
away the param we were passing.
2018-01-06 17:23:58 -05:00
khazhyk 456390f417 Ensure gif avatar urls end in .gif
This is a workaround for discord having trouble animating gifs if
the url does not end in exactly `.gif`. Since avatar_url is common
for thumbnails etc., adding this workaround here is handy, and
likely restores expected behavior (animated avatars animating).
2018-01-06 01:29:16 -05:00
khazhykandRapptz 54ea52c86f Prefix sha to fix leading zeros being stripped
/dist.py:352: UserWarning: Normalizing '1.0.0a1402+0965847' to '1.0.0a1402+965847'
2017-11-21 17:54:55 -05:00
khazhykandRapptz ebecb90c96 is_avatar_animated should always return bool
Was returning None when User.avatar was None
2017-10-24 00:16:44 -04:00
khazhyk 98a054e19e Use local version identifer for SHA
local version identifier seems to be the only PEP440
way to add arbitrary string to the version. Makes
pip stop complaining about invalid version label.
2017-10-14 20:41:45 -07:00
khazhykandRapptz c3a727ac7e Show sha1 for development versions. 2017-10-14 15:23:32 -04:00
khazhykandRapptz 0a588fac1c allow trailing null bytes in uploaded jpegs 2017-07-25 06:09:41 -04:00
khazhykandRapptz 2c4876f2e7 add Guild.icon_url_as
Guild icons can also be up to 1024px, jpg, png, or webp
2017-07-25 06:09:41 -04:00
khazhykandRapptz 12ca0d9b16 avatar_url_as improvements
static_format will only apply to static (not animated) avatars. Makes
it easier to grab gif-or-'format' of an avatar. Defaults to 'webp'

This is for a similar usecase to avatar_url_as(format=None), except
one can specify the non-animated format, instead of always using
webp.

add User.avatar_is_animated property.

add validation for avatar_url_as, since invalid arguments result in
a url which will return 415, which can be confusing for a user. (They
just see a blank page)

Discord accepts size=16-2048, but images cap at 1024px, so accept 16-1024
Discord accepts "jpg", "jpeg", "png", "gif", and "webp", *unless* the
avatar is not animated, in which case "gif" is not supported. :\
2017-07-25 06:09:40 -04:00
khazhykandRapptz f1e08cccac Add bulk argument to TextChannel.purge
bulk=False will never use bulk message delete. Useful e.g. for
using the purge interface for deleting the bot's own messages.
2017-07-24 00:11:05 -04:00
khazhyk 62cdfbdbcd Raise in HTTPClient.request when out of retries
Raise after loop completes without returning with most recent values
for r, data. This is a bit less fragile than checking tries < 4, since
changing the retry count requires changing values in multiple places.
(There seemed to already be handling in the 502 retry, tries <= 5,
which always evaluated to true, e.g.)
Previously, once out of retries, we would always return None without
raising.
This won't NameError so long as we make at least one HTTP request.
2017-07-22 20:10:28 -07:00
khazhyk 2850995062 Retry on 500 in HTTPClient.request
Discord official client retries on 500, so worst case scenario, we're
not any worse than the official client which seriously outnumbers us.
2017-07-22 20:10:25 -07:00
khazhykandRapptz fc22d288be [commands] unload cog submodules
When unloading cogs, currently we do not remove submodules from
sys.modules, meaning they will not be reloaded. Removing here
makes new imports reload from file. Of course, any already imported
modules will still hold a reference to the old module, since they
will not re-import it, and will not be forcably unloaded.
2017-07-07 18:02:29 -04:00
khazhyk 94eb938d29 handle Game.name being None
re #221, Game.name can still be None, which will cause TypeError on
str(game).

Currently discord does not treat these weird statuses uniformly, with it
showing as playing a game on mobile, but not playing a game on desktop. It
may be useful to know users are in this weird state.
2017-07-03 23:14:16 -07:00
khazhyk 6c01250c39 [commands] fix unloading incorrect cogs
unload_extension would incorrectly unload cogs/listeners
of other extensions if the name of one was a prefix of
another.
2017-07-03 20:56:04 -07:00
khazhykandGitHub bca72e64d6 [commands] clean up remove_cog documentation
remove_cog always returns None, even if the cog is found.
2017-07-03 19:02:00 -07:00
khazhykandRapptz b1117262da [commands] Run global checks in help formatter.
Help formatter was not checking global bot-level checks, resulting in
showing commands a user did not have permission for with
show_check_failure disabled.
2016-12-16 14:39:25 -05:00
khazhykandRapptz c8fd8a9e1a Fix crash on duplicate or out of order reactions.
Eventual consistency ftw
2016-11-30 16:47:00 -05:00
khazhyk 8bd242f00b Fix crash on reaction remove.
Discord can sometimes send integer 0 as the emoji id instead of
null to signify a non-custom emoji, which was causing a crash due
to a 'is not None' check assuming the reaction was for an emoji
with id 0. Probably a discord bug, but preferable to handle here
rather than crash users.
2016-11-05 21:46:07 -07:00
khazhykandRapptz 4d87b2f817 Inject full Emoji to Reaction if we have it.
Reaction objects with custom Emoji are partial. If we know of this Emoji
(can find it on this client) then inject it. Otherwise, leave it as a
hollow Emoji. We can still react with a hollow Emoji, but can't get other
metadata about it.
2016-11-03 04:39:45 -04:00
khazhyk c4acc0e1a1 Add support for reactions.
Reactions can be be standard emojis, or custom server emojis.

Adds
 - add/remove_reaction
 - get_reaction_users
 - Messages have new field reactions
 - new events - message_reaction_add, message_reaction_remove
 - new permission - add_reactions
2016-10-27 21:36:32 -07:00
khazhyk 158ac6bb50 Add around parameter to LogsFromIterator. 2016-10-16 18:10:49 -07:00
khazhyk e2667a6f66 Refactor LogsFromIterator 2016-10-16 17:25:00 -07:00
khazhyk 98d8c855d8 Fix typo in change_presence validation message 2016-10-15 15:54:50 -07:00
Khazhismel adf74eef76 Update Client documentation. 2016-10-02 14:06:49 -07:00
Khazhismel 6344504dfc Emoji.url uses api url. 2016-08-06 16:54:07 -07:00
Khazhismel 14c8aed1a3 Add emoji url property 2016-08-02 17:37:31 -07:00
Khazhismel 504fbaafd5 Clean up Emoji documentation. 2016-08-01 21:05:51 -07:00
Khazhismel c72c23278d [commands] Add custom emoji converter. 2016-07-31 22:39:45 -07:00
Khazhismel c5a989eeb2 Add custom emoji support. 2016-07-31 22:39:43 -07:00
Khazhismel KumykovandRapptz 33a69681fc [commands] Dispatch command_error on command exec error.
Provide fallback on_command_error - will only fire if no cog handlers and
no local handler.
Propagate exceptions in checks and argument parsing to bot.
2016-06-04 21:22:10 -04:00
Khazhismel KumykovandRapptz 492c9afffb logs_from improvements for after param.
- Properly support 'after' alone
- Properly support both 'before' and 'after'
- Add optional 'reverse' parameter to sort messages oldest->newest to
  1) provide a sorted result set for 'after'
  2) give flexibility when using both 'before' and 'after'
2016-05-20 18:11:57 -04:00
Khazhismel KumykovandRapptz 8e5347f4ed Allow datetime in limit parameters for logs_from.
Add time_snowflake to convert a datetime to a "snowflake".
2016-05-20 18:11:56 -04:00
Khazhismel KumykovandRapptz 7bdddc37a0 Retry send_file on 502.
Rename _rate_limit_helper to _retry_helper
2016-05-20 18:11:56 -04:00
Khazhismel KumykovandRapptz a1b5cefc8b Add move_role
move_role will only send changed roles.
discord will accept trying to move to position 0, or trying to move the
everyone role. It will result in unexpected changes, so we prohibit it.
2016-05-20 18:11:55 -04:00
Khazhismel Kumykov 7bae6dc5bc Fix changing own nickname without manage_nicknames
Use @me/nick rather than id when changing own nickname - this only
requires change_nicknames rather than manage.
2016-04-30 20:34:02 -04:00
Khazhismel Kumykov 29b01f20ba Fix Member.display_name returning None
If Member.nick was None, getattr would happily return None, not the
default value.
2016-04-29 15:13:15 -04:00
Khazhismel Kumykov a2a5dc5997 Add optional server parameter to utils.oauth_url 2016-04-15 21:04:33 -04:00
Khazhismel 84f1342b85 Fix chunk requests not actually being batched. 2016-04-11 11:53:54 -04:00
Khazhismel Kumykov 9f722731dd Fix typo in Role.created_at 2016-04-09 02:33:09 -04:00
Khazhismel Kumykov 160cbc81e7 Clarify channel-specific permissions documentation.
Manage Roles and Manage Channels is renamed to "Manage Permissions" and
"Manage Channel" in the discord UI, clarify which fields in the Permission
object those map to.
2016-04-05 14:30:04 -04:00
Khazhismel Kumykov 0e91ef79ef Fix handling of unavailable servers in READY 2016-04-04 23:45:05 -04:00
Khazhismel Kumykov 5f776f369d Add default avatar property to User. 2016-03-31 14:38:03 -04:00
Khazhismel KumykovandRapptz f1736bc08f Move ffmpeg process cleanup to player thread 2016-03-25 18:32:02 -04:00
Khazhismel fc2127789a Support ytsearch and playlists in youtube_dl_player 2016-03-09 21:19:12 -05:00
KhazhismelandRapptz 612aa4d107 Add util method to extract creation date from discord ids 2016-03-06 03:40:16 -05:00
Khazhismel KumykovandRapptz ef57873f80 Clean up zombies
self.process.communicate(timeout=0.100) will block

zombies probably would be cleaned up anyways but in a non deterministic fashion by the garage collector
2016-03-02 23:25:20 -05:00
Khazhismel bbe6455eb9 Guild member add will include deaf and mute now, do not provide default values 2016-01-12 11:49:22 -05:00
Khazhismel 000e7e57ea Change member constructor to not rely on order of json data object 2016-01-12 11:45:59 -05:00
Khazhismel ac3e583b05 Add missing argument in _rate_limit_helper 2015-12-26 17:01:35 -05:00
Khazhismel 0aa46e6def Add game data class, replace game_id. 2015-12-23 21:28:18 -05:00
Khazhismel ec23434162 Mentions are now <@id> *only* - remove mentions array on send and edit message 2015-12-23 20:59:41 -05:00
Khazhismel e8a06b7ee9 Insert options before pipe:1 in ffmpeg player, otherwise they are ignored 2015-12-23 18:00:44 -05:00
Khazhismel bb433990e8 None author param in wait_for_message allows any author 2015-12-22 03:51:45 -05:00
Khazhismel 0176517453 Provide server/channel id/name as Object if client not joined to server. 2015-11-29 21:58:17 -05:00
KhazhismelandRapptz 52d3457443 Add send_typing command to allow sending typing updates. 2015-11-19 23:16:47 -05:00
KhazhismelandRapptz fcc540ec44 Add before and after params to logs_from. 2015-11-16 19:06:14 -05:00