本文整理汇总了Python中slackbot.bot.Bot类的典型用法代码示例。如果您正苦于以下问题:Python Bot类的具体用法?Python Bot怎么用?Python Bot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
pid = os.getpid()
f = open(os.getcwd() + '/slackbot.pid', 'w')
f.write(str(pid))
f.close()
bot = Bot()
bot.run()
示例2: slackbot_init
def slackbot_init():
"""
Thread target for initializing slackbot
"""
logger.info('Initializing slackbot')
bot = Bot()
bot.run()
示例3: main
def main():
from slackbot import settings
from slackbot.bot import Bot
from .plugins.weather import OpenWeatherMap
settings.open_weather_map = OpenWeatherMap()
bot = Bot()
bot.run()
示例4: main
def main():
kw = {
"format": "[%(asctime)s] %(message)s",
"datefmt": "%m/%d/%Y %H:%M:%S",
"level": logging.DEBUG if settings.DEBUG else logging.INFO,
"stream": sys.stdout,
}
logging.basicConfig(**kw)
logging.getLogger("requests.packages.urllib3.connectionpool").setLevel(logging.WARNING)
bot = Bot()
bot.run()
示例5: main
def main():
"""Then main Bot application"""
if not conf.API_TOKEN or not conf.SPEAKER_IP:
print(
"Slack API token or Sonos speaker IP not set.\n"
"Please add configure it before running Sonlack. Exiting..."
)
sys.exit(0)
bot = Bot()
print("Sonlack is rocking now. Enjoy your favorite music...")
bot.run()
示例6: main
def main():
try:
settings.zendesk_class = Zendesk(
settings.ZENDESK_APP,
settings.ZENDESK_USER,
settings.ZENDESK_PASS,
)
except AttributeError:
print('Missing SLACKBOT_ZENDESK_APP, SLACKBOT_ZENDESK_USER or SLACKBOT_ZENDESK_PASS environment variable')
sys.exit(1)
print("starting bot...")
bot = Bot()
bot.run()
示例7: VBot
class VBot(object):
def __init__(self):
logging.info('initializing')
self.bot = Bot()
self.dispatcher = Dispatcher()
logging.info('initialization finished')
def run(self):
logging.info('starting bot')
self.bot.run()
def answer(self, message, query):
self.dispatcher.dispatch(message, query)
示例8: main
def main():
global snakebot_config
logging.basicConfig()
curr_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(curr_dir)
snakebot_config = ConfigParser.ConfigParser()
snakebot_config.read("config.ini")
settings.API_TOKEN = snakebot_config.get("slack", "API_TOKEN")
settings.PLUGINS = ["snakebot"] #Overwrites other plugins. Don't need upload for instance.
bot = Bot()
print "[[ Snakebot online ]]"
bot.run()
示例9: main
def main():
logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
sys.path.append("plugins")
if 'SLACKBOT_API_TOKEN' not in os.environ:
print "'SLACKBOT_API_TOKEN' environment variable not set. Exiting..."
exit(1)
bot = Bot()
bot.run()
示例10: main
def main():
try:
settings.jira_class = JiraWrapper(
settings.JIRA_SERVER,
settings.JIRA_PROJECTS,
settings.JIRA_USERNAME,
settings.JIRA_PASSWORD,
)
settings.ALLOWED_PROJECTS = settings.JIRA_PROJECTS.split(',')
settings.ALLOWED_PROJECTS = [project.upper() for project in settings.ALLOWED_PROJECTS]
except AttributeError:
print('Missing JIRA_SERVER, JIRA_PROJECTS, JIRA_USERNAME or JIRA_PASSWORD environment variable')
sys.exit(1)
print("starting bot...")
bot = Bot()
bot.run()
示例11: main
def main():
global lunchotron_config
logging.basicConfig()
curr_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(curr_dir)
lunchotron_config = ConfigParser.ConfigParser()
lunchotron_config.read("config.ini")
settings.API_TOKEN = lunchotron_config.get("slack", "API_TOKEN")
settings.gPlaces = GooglePlaces(lunchotron_config.get("google-places", "API_TOKEN"))
settings.gmaps = googlemaps.Client(lunchotron_config.get("google-places", "API_TOKEN"))
settings.location = lunchotron_config.get("google-places", "location")
settings.PLUGINS = ["lunchotron"] #Overwrites other plugins. Don't need upload for instance.
bot = Bot()
print "[[ lunchotron online ]]"
bot.run()
示例12: main
def main():
try:
settings.jira_class = JiraWrapper(
settings.JIRA_SERVER,
settings.JIRA_USERNAME,
settings.JIRA_PASSWORD,
)
settings.ALLOWED_PROJECTS = settings.JIRA_PROJECTS.split(',')
settings.ALLOWED_PROJECTS = [project.upper() for project in settings.ALLOWED_PROJECTS]
except AttributeError:
print('Missing JIRA_SERVER, JIRA_PROJECTS, JIRA_USERNAME or JIRA_PASSWORD environment variable')
sys.exit(1)
# Jira allows a limited number of queries, but jira module we are using is
# not giving us that info. So we cache.
settings.CACHE = ExpiringDict(max_len=500, max_age_seconds=30)
print("starting bot...")
bot = Bot()
bot.run()
示例13: __init__
def __init__(self):
logging.basicConfig(level=logging.INFO)
self.muted_rooms = set()
self.handlers = {}
self.plugins = []
if 'PLUGINS' in os.environ:
self._load_plugins(map(
str.strip,
os.environ['PLUGINS'].split(',')
))
self.bot = Bot()
示例14: Creep
class Creep():
def __init__(self):
logging.basicConfig(level=logging.INFO)
self.muted_rooms = set()
self.handlers = {}
self.plugins = []
if 'PLUGINS' in os.environ:
self._load_plugins(map(
str.strip,
os.environ['PLUGINS'].split(',')
))
self.bot = Bot()
# for k, v in self.bot._client.channels.iteritems():
# if 'name' in v and v['name'] == 'creep':
# self.bot._client.send_message(
# k, 'Creep reporting for duty!'
# )
def mute(self, room_id, timeout=10):
def unmute_room():
self.unmute(room_id)
self.muted_rooms.add(room_id)
Timer(timeout, unmute_room).start()
def unmute(self, room_id): # TODO
if room_id in self.muted_rooms:
self.muted_rooms.remove(room_id)
self.bot._client.send_message(
room_id, "I'm back baby!"
)
def run(self):
self.bot.run()
def handle_message(self, message):
body = message.body['text']
command = body.split(' ')[0] if ' ' in body else body
params = body[body.find(" ")+1:] if ' ' in body else None
logging.info("incoming message '%s'" % body)
if command in self.handlers:
handler = self.handlers[command]
try:
try:
chan = message.channel
except KeyError:
chan = None
result = handler(message=params, origin=chan)
message.reply(result)
except Exception:
logging.exception("Couldn't handle command '%s': " % command)
message.reply("Sorry, I got into trouble")
else:
message.reply(
"Unknown command: '%s'. "
'Run "help" for more info on available commands.' % body
)
def shutdown(self):
for plugin in self.plugins:
plugin.shutdown()
def _load_plugins(self, names):
for name in names:
try:
self._load_plugin(name)
except Exception:
logging.exception("Couldn't load plugin '%s':" % name)
def _load_plugin(self, name):
'''
assumes there's only one class per plugin
'''
plugin = __import__('plugins.%s' % name, fromlist=['plugins', ])
plugin_instance = None
for attribute in dir(plugin):
item = getattr(plugin, attribute)
if (inspect.isclass(item) and
issubclass(item, Plugin) and
not item == Plugin):
plugin_instance = item(self)
for handler_name in item.provides:
if handler_name in self.handlers.keys():
raise Exception("Can't load '%s': handler already "
"registered for '%s'" % (name,
handler_name))
self.handlers[handler_name] = _get_handler(handler_name,
plugin_instance)
self.plugins.append(plugin_instance)
logging.info("Finished loading '%s' plugin" % plugin_instance)