-
Notifications
You must be signed in to change notification settings - Fork 47
/
start.py
38 lines (32 loc) · 1.24 KB
/
start.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
"""
This plugin creates a convenient start() method and attaches it directly
to the client. More complex bots will likely want to create their own
initialization plugin, so StartPlugin stays out of the way unless you
call the start() method. However, the start() method is very convenient
for demos and tutorials, and illustrates the basic steps for initializing
a bot.
"""
from spockbot.plugins.base import PluginBase
class StartPlugin(PluginBase):
requires = ('Auth', 'Event', 'Net')
events = {
'event_start': 'start_session_and_connect',
}
defaults = {
'username': 'Bot',
'password': None,
'host': 'localhost',
'port': 25565,
}
def __init__(self, ploader, settings):
super(StartPlugin, self).__init__(ploader, settings)
setattr(ploader, 'start', self.start)
def start(self, host=None, port=None):
self.host = host or self.settings['host']
self.port = port or self.settings['port']
self.auth.username = self.settings['username']
self.auth.password = self.settings['password']
self.event.event_loop()
def start_session_and_connect(self, _, __):
if self.auth.start_session():
self.net.connect(self.host, self.port)