This repository has been archived by the owner on Sep 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
run.py
185 lines (168 loc) · 5.79 KB
/
run.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import schedule
import time
import sqlite3
from reconbot.tasks import esi_notification_task
from reconbot.notifiers.caching import CachingNotifier
from reconbot.notifiers.slack import SlackNotifier
from reconbot.notifiers.discord import DiscordNotifier
from reconbot.notifiers.discordwebhook import DiscordWebhookNotifier
from reconbot.notifiers.splitter import SplitterNotifier
from reconbot.notifiers.filter import FilterNotifier
from reconbot.apiqueue import ApiQueue
from reconbot.esi import ESI
from reconbot.sso import SSO
# Configuration
# ESI notification endpoint cache timer in minutes
notification_caching_timer = 10
# Slack bot integration API key
slack_apis = {
'example': {
'api_key': 'xxxx-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx',
'username': 'reconbot',
},
}
# Discord bot integration API key and channel
discord = {
'personal': {
'token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'channel_id': 'xxxxxxxxxxxxxxxxxx'
},
'my-webhook': {
'url': 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
}
# Eve online SSO application Client ID and Secret Key, used to get access
# tokens for ESI API. Get them on:
# https://developers.eveonline.com/applications
sso_app = {
'client_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'secret_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
# A dictionary of API key groups.
# Get refresh tokens for your characters by following Fuzzwork's guide:
# https://www.fuzzwork.co.uk/2017/03/14/using-esi-google-sheets/
eve_apis = {
'fc-team': {
'notifications': {
'whitelist': None, # allow all notification types
},
'characters': {
'ccp-example-1': {
'character_name': 'CCP Example',
'character_id': 11111111,
'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
'ccp-example-2': {
'character_name': 'CCP Example 2',
'character_id': 33333333,
'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
},
},
'logistics-team': {
'notifications': {
'whitelist': [ # Allow only specified notification types
'SovStructureDestroyed',
'SovStructureReinforced',
'StructureUnderAttack',
'OwnershipTransferred',
'StructureOnline',
'StructureFuelAlert',
'StructureAnchoring',
'StructureServicesOffline',
'StructureLostShields',
'StructureLostArmor',
'TowerAlertMsg',
'StationServiceEnabled',
'StationServiceDisabled',
'OrbitalReinforced',
'OrbitalAttacked',
'SovAllClaimAquiredMsg',
'SovStationEnteredFreeport',
'SovAllClaimLostMsg',
'SovStructureSelfDestructRequested',
'SovStructureSelfDestructFinished',
'StationConquerMsg',
'notificationTypeMoonminingExtractionStarted',
'MoonminingExtractionFinished',
'MoonminingLaserFired',
],
},
'characters': {
'ccp-example-3': {
'character_name': 'CCP Example 3',
'character_id': 55555555,
'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
'ccp-example-4': {
'character_name': 'CCP Example 4',
'character_id': 77777777,
'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
},
}
}
my_slack_channels = CachingNotifier(
SplitterNotifier([
SlackNotifier(
slack_apis['example']['api_key'],
slack_apis['example']['username'],
'#fc',
'online'
),
SlackNotifier(
slack_apis['example']['api_key'],
slack_apis['example']['username'],
'#logistics',
'all'
)
]),
duration=3600
)
my_discord_channels = CachingNotifier(
SplitterNotifier([
DiscordNotifier(
discord['personal']['token'],
discord['personal']['channel_id']
),
DiscordWebhookNotifier(
discord['my-webhook']['url']
)
]),
duration=3600
)
def api_to_sso(api):
return SSO(
sso_app['client_id'],
sso_app['secret_key'],
api['refresh_token'],
api['character_id']
)
api_queue_fc = ApiQueue(list(map(api_to_sso, eve_apis['fc-team']['characters'].values())))
api_queue_logistics = ApiQueue(list(map(api_to_sso, eve_apis['logistics-team']['characters'].values())))
def notifications_job_fc():
esi_notification_task(
eve_apis['fc-team']['notifications'],
api_queue_fc,
'slack',
my_slack_channels
)
def notifications_job_logistics():
esi_notification_task(
eve_apis['logistics-team']['notifications'],
api_queue_logistics,
'discord',
my_discord_channels
)
def run_and_schedule(characters, notifications_job):
"""
Runs a job immediately to avoid having to wait for the delay to end,
and schedules the job to be run continuously.
"""
notifications_job()
schedule.every(notification_caching_timer/len(characters)).minutes.do(notifications_job)
run_and_schedule(eve_apis['fc-team']['characters'], notifications_job_fc)
run_and_schedule(eve_apis['logistics-team']['characters'], notifications_job_logistics)
while True:
schedule.run_pending()
time.sleep(1)