forked from cpssd-students/steely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteelybot.py
executable file
·52 lines (40 loc) · 1.62 KB
/
steelybot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
from fbchat import log, Client
import imp
import config
import os
import random
class SteelyBot(Client):
def __init__(self, *args, **kwargs):
super(SteelyBot, self).__init__(*args, **kwargs)
self.plugins = {}
self.load_plugins()
def load_plugins(self):
for file in os.listdir('plugins'):
if file.startswith("_"):
continue
elif not file.endswith(".py"):
continue
plugin_path = os.path.join('plugins', file)
plugin = imp.load_source(file, plugin_path)
self.plugins[plugin.COMMAND] = plugin
def onMessage(self, author_id, message, thread_id, thread_type, **kwargs):
self.markAsDelivered(author_id, thread_id)
self.markAsRead(author_id)
if message in ('.list', '.help'):
commands = ', '.join((command for command in self.plugins.keys() if command))
self.sendMessage('available commands: ' + commands, thread_id=thread_id, thread_type=thread_type)
return
# run plugins that have no command
for plugin in self.plugins.values():
if not plugin.COMMAND:
plugin.main(self, author_id, message, thread_id, thread_type, **kwargs)
# run plugins that have a command
command, message = message.split(' ', 1)
if not command in self.plugins:
return
plugin = self.plugins[command]
plugin.main(self, author_id, message, thread_id, thread_type, **kwargs)
if __name__ == '__main__':
client = SteelyBot(config.EMAIL, config.PASSWORD)
client.listen()