-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateBot.py
More file actions
53 lines (42 loc) · 1.64 KB
/
StateBot.py
File metadata and controls
53 lines (42 loc) · 1.64 KB
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
53
import os
import botRuntime
# Returns the bot parameters
def getConfiguration():
# Get the collectd server address
collectdAddress = os.getenv("collectdAddress")
# Check if the `collectdAddress` environment variable
# exists.
if collectdAddress == None:
print("Missing collectd server address")
return None
# Get the collectd server port and check if the
# `collectdPort` environment variable exists
# and that it is an integer.
try:
collectdPort = os.getenv("collectdPort")
if collectdPort == None:
print("Missing collectd server port")
return None
collectdPort = int(collectdPort)
except ValueError:
print("An integer for the collectd server port is needed")
return None
# Get the clientID
clientID = os.getenv("clientID")
# Get the client secret
clientSecret = os.getenv("clientSecret")
# Get the access token
accessToken = os.getenv("accessToken")
# Get the base URL
baseURL = os.getenv("baseURL")
return {"address" : collectdAddress, "port" : collectdPort, "clientID" : clientID, "clientSecret" : clientSecret, "accessToken" : accessToken, "baseURL" : baseURL}
# Initializes the bot and starts it
def init():
# Get the configuration and check if it is valid
configuration = getConfiguration()
if configuration == None:
print("Exiting, invalid configuration...")
exit()
else:
botRuntime.botStart(configuration["address"], configuration["port"], configuration["clientID"], configuration["clientSecret"], configuration["accessToken"], configuration["baseURL"])
init()