-
Notifications
You must be signed in to change notification settings - Fork 14
/
start.py
54 lines (44 loc) · 1.88 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import threading, time, logging, os, sys, codecs
from bot import Bot
from reactbot import ReactBot
#
from pb_logging import PBLogger
if __name__ == "__main__":
# See here for logging documentation https://docs.python.org/2/howto/logging.html
# Set the name for the logger
# Add custom log handler to logger
logger = PBLogger('PantherBot')
# Checks if the system's encoding type is utf-8 and changes it to utf-8 if it isnt (its not on Windows by default) # noqa: 501
if sys.stdout.encoding != 'utf-8':
sys.stdout = codecs.getwriter('utf-8')(sys.stdout, 'strict')
if sys.stderr.encoding != 'utf-8':
sys.stderr = codecs.getwriter('utf-8')(sys.stderr, 'strict')
# Initializes our primary bot
# This is the reactive bot known as "PantherBot," and is responsible for all message detection and immediate reactions
logger.info("Initializing bot")
token = os.environ.get('PB_TOKEN')
# List of all bots running in current process.
BOT_LIST = []
react_bot = ReactBot(token, bot_name="PantherBot")
BOT_LIST.append(react_bot)
bot_thread = threading.Thread(target=react_bot.WEBSOCKET.run_forever, kwargs={"ping_interval":30, "ping_timeout":10})
logger.info("Beginning thread")
bot_thread.start()
proactive_bot = Bot(token, bot_name="PantherBot")
count_interval = 0
while True:
try:
time.sleep(1)
count_interval += 1
if count_interval % 600 is 0:
for b in BOT_LIST:
if b.WEBSOCKET != None:
b.pb_cooldown = True
if count_interval % 86400 is 0:
logger.info("Proactive still alive")
if count_interval >= 86400:
count_interval = 0
except KeyboardInterrupt:
logger.info("Keyboard Interrupt")
react_bot.close()
break