Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 1fb557b

Browse files
committed
Add API Context to Plugin Context
updated idea of @zbarahal’s PR (PR #20) to reflect the current master.
1 parent f785ed9 commit 1fb557b

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from slackclient import SlackClient
2+
from rtmbot import RtmBot
3+
4+
client = None
5+
6+
def init(config):
7+
global client
8+
bot = RtmBot(config)
9+
client = bot.slack_client
10+
return bot
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import unicode_literals
2+
from client import client as sc
3+
4+
for user in sc.api_call("users.list")["members"]:
5+
print(user["name"], user["id"])

rtmbot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python
22
import sys
3+
import os
4+
sys.path.append(os.getcwd())
5+
36
from argparse import ArgumentParser
47

58
import yaml
6-
from rtmbot import RtmBot
9+
import client
710

811

912
def parse_args():
@@ -19,7 +22,7 @@ def parse_args():
1922
# load args with config path
2023
args = parse_args()
2124
config = yaml.load(open(args.config or 'rtmbot.conf', 'r'))
22-
bot = RtmBot(config)
25+
bot = client.init(config)
2326
try:
2427
bot.start()
2528
except KeyboardInterrupt:

rtmbot/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ def __init__(self, config):
4848
# initialize stateful fields
4949
self.last_ping = 0
5050
self.bot_plugins = []
51-
self.slack_client = None
51+
self.slack_client = SlackClient(self.token)
5252

5353
def _dbg(self, debug_string):
5454
if self.debug:
5555
logging.info(debug_string)
5656

5757
def connect(self):
5858
"""Convenience method that creates Server instance"""
59-
self.slack_client = SlackClient(self.token)
6059
self.slack_client.rtm_connect()
6160

6261
def _start(self):

0 commit comments

Comments
 (0)