forked from PhABC/antiScamBot_slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·75 lines (52 loc) · 2.15 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re, sys, time, os, subprocess
import pickle as pk
from rtmbot.bin.run_rtmbot import main
from Settings import initSettings
def editConf(Settings):
'Will edit the rtmbot.con'
#Reading lines of rtmbot.conf
with open('rtmbot.conf',"r") as outfile:
conf = outfile.readlines()
#Chaging 3rd line to add current token
conf[2] = " SLACK_TOKEN: \"{}\"\n".format(Settings['SLACK_BOT_TOKEN'])
#Editing rtmbot.conf with SLACK_BOT_TOKEN as SLACK_TOKEN
with open('rtmbot.conf',"w") as outfile:
outfile.writelines(conf)
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
# sys.exit(main())
try:
while True: # super hacky, added this to reboot if connection fails
try: #Will restart after 5 seconds if goes down
#If settings not instantiated
if not os.path.isfile('Settings.txt'):
Settings = initSettings()
#Ediit rtmbot.conf file to add bot token
editConf(Settings)
else:
#Checking if Settings.txt is empty or bad
try:
with open('Settings.txt', 'rb') as f:
Settings = pk.loads(f.read())
except:
cont = input(['\nIt seems like your Settings.txt file is bad. Press 1 if you ' +
'want to create a new Settings.txt file, otherwise press 0 : ' ][0])
if cont == '1':
Settings = initSettings()
editConf(Settings)
else:
print('Aborting.')
quit()
#Running bot
print('\nAntiscam Bot Initiation.')
main()
except Exception as ex:
#Printing error and restart message
print('\nError : ') ; print(ex)
print('\nRESTARTING IN 5 SECONDS.\n')
#Restart after 5 seocnds
time.sleep(5)
except KeyboardInterrupt:
pass