diff options
| author | Rapptz <[email protected]> | 2017-01-20 19:26:56 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-20 19:28:43 -0500 |
| commit | 4c981ee6315f43b28d99a84851d3f6138738a77f (patch) | |
| tree | 18c252f0c09b3eade7964d5c4941f52c7dc9906a /discord/relationship.py | |
| parent | Add ClientUser.premium boolean. (diff) | |
| download | discord.py-4c981ee6315f43b28d99a84851d3f6138738a77f.tar.xz discord.py-4c981ee6315f43b28d99a84851d3f6138738a77f.zip | |
Add support for relationships.
Diffstat (limited to 'discord/relationship.py')
| -rw-r--r-- | discord/relationship.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/discord/relationship.py b/discord/relationship.py new file mode 100644 index 00000000..a9132aee --- /dev/null +++ b/discord/relationship.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015-2016 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from .enums import RelationshipType, try_enum + +import asyncio + +class Relationship: + """Represents a relationship in Discord. + + A relationship is like a friendship, a person who is blocked, etc. + Only non-bot accounts can have relationships. + + Attributes + ----------- + user: :class:`User` + The user you have the relationship with. + type: :class:`RelationshipType` + The type of relationship you have. + """ + + __slots__ = ('type', 'user', '_state') + + def __init__(self, *, state, data): + self._state = state + self.type = try_enum(RelationshipType, data['type']) + self.user = state.store_user(data['user']) + + def __repr__(self): + return '<Relationship user={0.user!r} type={0.type!r}>'.format(self) + + @asyncio.coroutine + def delete(self): + """|coro| + + Deletes the relationship. + + Raises + ------ + HTTPException + Deleting the relationship failed. + """ + + yield from self._state.http.remove_relationship(self.user.id) + + @asyncio.coroutine + def accept(self): + """|coro| + + Accepts the relationship request. e.g. accepting a + friend request. + + Raises + ------- + HTTPException + Accepting the relationship failed. + """ + + yield from self._state.http.add_relationship(self.user.id) |