-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
152 lines (115 loc) · 3.92 KB
/
app.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
import json
import sys
from ConfigHandler import ConfigHandler
import os
import sqlite3
from Databaseconn import Databaseconn
from EventHandler import EventHandler
import TwitchAPIConn
from TadaLogger import tadaLogger
channel = ""
clientID = ""
clientSecret = ""
eventHandler: EventHandler = None
# Existing code...
def start_twitch():
tadalogger = tadaLogger()
#check if config file exists
if not os.path.exists("config.json"):
tadalogger.logwarning("Config json file does not exist. please create and edit it.")
exit()
# Usage example
config_handler = ConfigHandler()
config_handler.load_config('config.json')
tadalogger.loginfo("startup", "checking for database file...")
# Check if database file exists
if not os.path.exists(f"{config_handler.channel}.db"):
tadalogger.logwarning("startup", "Database file not found. Creating new file...")
# Create a new database file
conn = sqlite3.connect(f"{config_handler.channel}.db")
tadalogger.logwarning("startup", f"Database file created. as {config_handler.channel}.db")
else:
tadalogger.loginfo("startup", "Database file found.")
# Create event handler
eventHandler = EventHandler()
eventHandler.assign_to_logger(tadalogger)
dbconn = Databaseconn(eventHandler, config_handler.channel)
eventHandler.assign_to_twitch(TwitchAPIConn)
eventHandler.assign_to_DBConn(dbconn)
eventHandler.assign_to_config(config_handler)
# run app
# connect to twitch
TwitchAPIConn.run(
config_handler.clientID,
config_handler.clientSecret,
eventHandler)
if __name__ == "__main__":
defaultconfig = {
"channel": "",
"clientID": "",
"clientSecret": "",
"Super_Moderators": [
"channel_owner"
],
"worker_update_rate": 60,
"Basic_Commands": True,
"Chat_log": True,
"Ban_log": True,
"Unban_log": True,
"Mini_games": True,
"Mini_games_pointsperwin": 100,
"Shoutout_Auto": True,
"Shoutout_Soft": True,
"Shoutout_Message": "Check out {user} at https://twitch.tv/{user} !",
"Shoutout_list": [
"target_user1"
],
"faq": True,
"faq_list": [
"question1",
"question2"
],
"rules": True,
"rules_list": [
"rule1",
"rule2"
],
"lastwhereChannel": 3,
"wherelocations": [
"tech basement",
"Avalon puris",
"Tara Shadow Mission",
"Tailteann Shadow Mission",
"Ably Dungeon",
"Ciar Dungeon",
"Rundal Dungeon",
"Glenn",
"Crom Bas",
"Tir Chonaill",
"Dunbarton"
]
}
if not os.path.exists("config.json"):
print("startup Config json file does not exist. creating config. please edit this file.")
config_temp = json.dumps(defaultconfig, indent=4)
with open("config.json", 'w') as file:
file.write(config_temp)
exit()
# check config for channel name, id and secert
with open("config.json", 'r') as file:
config_data = json.load(file)
exitapp = False
if config_data['channel'] == "":
print("startup channel name is empty. please edit config file.")
exitapp = True
if config_data['clientID'] == "":
print("startup clientID is empty. please edit config file.")
exitapp = True
if config_data['clientSecret'] == "":
print("startup clientSecret is empty. please edit config file.")
exitapp = True
if exitapp:
exit()
start_twitch()
print("Close application and try again")
sys.exit()