Add API Context to Plugin Context
updated idea of @zbarahal’s PR (PR #20) to reflect the current master.
This commit is contained in:
parent
f785ed9a14
commit
1fb557b178
4 changed files with 21 additions and 4 deletions
10
client.py
Normal file
10
client.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from slackclient import SlackClient
|
||||
from rtmbot import RtmBot
|
||||
|
||||
client = None
|
||||
|
||||
def init(config):
|
||||
global client
|
||||
bot = RtmBot(config)
|
||||
client = bot.slack_client
|
||||
return bot
|
5
docs/example-plugins/directAPIcall.py
Normal file
5
docs/example-plugins/directAPIcall.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
from client import client as sc
|
||||
|
||||
for user in sc.api_call("users.list")["members"]:
|
||||
print(user["name"], user["id"])
|
|
@ -1,9 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import yaml
|
||||
from rtmbot import RtmBot
|
||||
import client
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
@ -19,7 +22,7 @@ def parse_args():
|
|||
# load args with config path
|
||||
args = parse_args()
|
||||
config = yaml.load(open(args.config or 'rtmbot.conf', 'r'))
|
||||
bot = RtmBot(config)
|
||||
bot = client.init(config)
|
||||
try:
|
||||
bot.start()
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
@ -48,7 +48,7 @@ class RtmBot(object):
|
|||
# initialize stateful fields
|
||||
self.last_ping = 0
|
||||
self.bot_plugins = []
|
||||
self.slack_client = None
|
||||
self.slack_client = SlackClient(self.token)
|
||||
|
||||
def _dbg(self, debug_string):
|
||||
if self.debug:
|
||||
|
@ -56,7 +56,6 @@ class RtmBot(object):
|
|||
|
||||
def connect(self):
|
||||
"""Convenience method that creates Server instance"""
|
||||
self.slack_client = SlackClient(self.token)
|
||||
self.slack_client.rtm_connect()
|
||||
|
||||
def _start(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue