This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SlackObject is an abstraction of the unified behavior of Slack related objects
- Loading branch information
1 parent
ae702e1
commit ae5794f
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .api import SlackAPI | ||
from .channel import SlackChannel | ||
|
||
__version__ = '0.2.16' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from .api import SlackObject, SlackAPI | ||
|
||
class SlackChannel(SlackObject): | ||
|
||
def __init__(self, token, id): | ||
super().__init__(id, token) | ||
|
||
self.data = self.api.channels.info(channel=id)['channel'] | ||
|
||
def __getattr__(self, name): | ||
return self.data[name] | ||
|
||
@classmethod | ||
def from_name(cls, token, name): | ||
if isinstance(token, SlackAPI): | ||
api = token | ||
elif isinstance(token, string): | ||
api = SlackAPI.get_object(token) | ||
else: | ||
raise TypeError | ||
return cls(api, api.channels_id(name)) | ||
|
||
def send(self, message, **kwargs): | ||
params = { | ||
'channel': self.id, | ||
'text': message, | ||
'as_user': True | ||
} | ||
params.update(kwargs) | ||
self.api.chat.postMessage(**params) |