forked from Yinzo/SmartQQBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigs.py
160 lines (133 loc) · 5.74 KB
/
Configs.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
# -*- coding: utf-8 -*-
# Code by Yinzo: https://github.com/Yinzo
# Origin repository: https://github.com/Yinzo/SmartQQBot
import ConfigParser
import os
class Configs:
def __init__(self):
self.conf = ConfigParser.ConfigParser()
self.config_path = "./config/QQBot_default.conf"
def update(self):
self.conf.read(self.config_path)
def check_config_files_exists(self):
if not os.path.isdir("./config"):
os.mkdir("./config")
if not os.path.exists(self.config_path):
with open(self.config_path, "w") as tmp:
tmp.close()
self.set_default()
def set_default(self):
pass
class DefaultConfigs(Configs):
def __init__(self):
Configs.__init__(self)
self.config_path = "./config/QQBot_default.conf"
if not os.path.isdir("./config"):
os.mkdir("./config")
if not os.path.exists(self.config_path):
with open(self.config_path, "w") as tmp:
tmp.close()
self.conf.read(self.config_path)
self.conf.add_section('global')
self.conf.add_section('pm')
self.conf.add_section('group')
self.conf.add_section('sess')
self.conf.set('global', 'connect_referer', 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
self.conf.set('global', 'smartQQ_url', 'http://w.qq.com/login.html')
self.conf.set('global', 'qrcode_path', './v.jpg')
self.conf.set('global', 'tucao_path', './data/tucao_save/')
self.conf.set('pm', 'use_private_config', '0')
self.conf.set('pm', "callout", "0")
self.conf.set('pm', "repeat", "0")
self.conf.set('pm', 'command_0arg', '0')
self.conf.set('pm', 'command_1arg', '0')
self.conf.set('group', 'use_private_config', '0')
self.conf.set('group', "callout", "0")
self.conf.set('group', "repeat", "0")
self.conf.set('group', "tucao", "0")
self.conf.set('group', "follow", "0")
self.conf.set('group', 'command_0arg', '0')
self.conf.set('group', 'command_1arg', '0')
self.conf.set('sess', 'use_private_config', '0')
self.conf.set('sess', 'callout', '0')
self.conf.write(open(self.config_path, "w"))
else:
self.conf.read(self.config_path)
class GroupConfig(Configs):
def __init__(self, group):
Configs.__init__(self)
self.group = group
self.config_file_name = str(group.gid) + ".conf"
self.config_path = "./config/group/" + self.config_file_name
self.global_config = DefaultConfigs()
self.check_config_files_exists()
self.conf.read(self.config_path)
def check_config_files_exists(self):
if not os.path.isdir("./config/group/"):
os.mkdir("./config/group/")
if not os.path.exists(self.config_path):
with open(self.config_path, "w") as tmp:
tmp.close()
self.set_default()
def set_default(self, all_off=False):
self.conf.read(self.config_path)
self.conf.add_section('group')
if all_off:
for option in self.global_config.conf.options('group'):
self.conf.set('group', option, '0')
else:
for option in self.global_config.conf.options('group'):
self.conf.set('group', option, self.global_config.conf.get('group', option))
self.conf.write(open(self.config_path, 'w'))
class PmConfig(Configs):
def __init__(self, pm):
Configs.__init__(self)
self.pm = pm
self.config_file_name = str(pm.tid) + ".conf"
self.config_path = "./config/pm/" + self.config_file_name
self.global_config = DefaultConfigs()
self.check_config_files_exists()
self.conf.read(self.config_path)
def check_config_files_exists(self):
if not os.path.isdir("./config/pm/"):
os.mkdir("./config/pm/")
if not os.path.exists(self.config_path):
with open(self.config_path, "w") as tmp:
tmp.close()
self.set_default()
def set_default(self, all_off=False):
self.conf.read(self.config_path)
self.conf.add_section('pm')
if all_off:
for option in self.global_config.conf.options('pm'):
self.conf.set('pm', option, '0')
else:
for option in self.global_config.conf.options('pm'):
self.conf.set('pm', option, self.global_config.conf.get('pm', option))
self.conf.write(open(self.config_path, "w"))
class SessConfig(Configs):
def __init__(self, sess):
Configs.__init__(self)
self.sess = sess
self.config_file_name = str(sess.tid) + ".conf"
self.config_path = "./config/sess/" + self.config_file_name
self.global_config = DefaultConfigs()
self.check_config_files_exists()
self.conf.read(self.config_path)
def check_config_files_exists(self):
if not os.path.isdir("./config/sess/"):
os.mkdir("./config/sess/")
if not os.path.exists(self.config_path):
with open(self.config_path, "w") as tmp:
tmp.close()
self.set_default()
def set_default(self, all_off=False):
self.conf.read(self.config_path)
self.conf.add_section('sess')
if all_off:
for option in self.global_config.conf.options('sess'):
self.conf.set('sess', option, '0')
else:
for option in self.global_config.conf.options('sess'):
self.conf.set('sess', option, self.global_config.conf.get('sess', option))
self.conf.write(open(self.config_path, "w"))