Welcome to mirror list, hosted at ThFree Co, Russian Federation.

code.py « access « expansions - github.com/alkorgun/blacksmith-2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 282588da10eeb64fb1888964a7cd183dbee703e2 (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# coding: utf-8

#  BlackSmith mark.2
# exp_name = "access" # /code.py v.x3
#  Id: 20~3c
#  Code © (2011) by WitcherGeralt [alkorgun@gmail.com]

class expansion_temp(expansion):

	def __init__(self, name):
		expansion.__init__(self, name)

	AccessFile = dynamic % ("access.db")
	ChatAccessFile = "access.db"

	accessDesc = (
		"Visitor", # 0
		"Participant", # 1
		"Member", # 2
		"Moder", # 3
		"Member/Moder", # 4
		"Admin", # 5
		"Owner", # 6
		"Chief", # 7
		"God" # 8
					)

	def get_acc(self, access):
		if access > 8:
			access = "%d (Gandalf)" % (access)
		elif access < 0:
			access = "%d (f7u12)" % (access)
		else:
			access = "%d (%s)" % (access, self.accessDesc[access])
		return access

	def command_get_access(self, stype, source, body, disp):
		if not body:
			answer = self.AnsBase[0] % self.get_acc(get_access(source[1], source[2]))
		elif Chats.has_key(source[1]):
			if Chats[source[1]].isHere(body):
				answer = self.AnsBase[1] % (body, self.get_acc(get_access(source[1], body)))
			elif Galist.has_key(body):
				answer = self.AnsBase[1] % (body, self.get_acc(Galist.get(body, 0)))
			elif Chats[source[1]].alist.has_key(body):
				answer = self.AnsBase[1] % (body, str(Chats[source[1]].alist.get(body, 0)))
			else:
				answer = self.AnsBase[2] % (body)
		elif Galist.has_key(body):
			answer = self.AnsBase[1] % (body, self.get_acc(Galist.get(body, 0)))
		else:
			answer = self.AnsBase[2] % (body)
		Answer(answer, stype, source, disp)

	def command_get_galist(self, stype, source, body, disp):
		if Galist:
			ls = sorted([(acc, user) for user, acc in Galist.iteritems()], reverse = True)
			if stype == Types[1]:
				answer = AnsBase[11]
			Message(source[0], self.AnsBase[5] + enumerated_list("%s - %d" % (user, acc) for acc, user in ls), disp)
		else:
			answer = self.AnsBase[3]
		if locals().has_key(Types[6]):
			Answer(answer, stype, source, disp)

	def command_get_lalist(self, stype, source, body, disp):
		if Chats.has_key(source[1]):
			if Chats[source[1]].alist:
				ls = sorted([(acc, user) for user, acc in Chats[source[1]].alist.iteritems()], reverse = True)
				if stype == Types[1]:
					answer = AnsBase[11]
				Message(source[0], self.AnsBase[5] + enumerated_list("%s - %d" % (user, acc) for acc, user in ls), disp)
			else:
				answer = self.AnsBase[4]
		else:
			answer = AnsBase[0]
		if locals().has_key(Types[6]):
			Answer(answer, stype, source, disp)

	def command_set_access(self, stype, source, body, disp):

		def set_access(instance, access = None):
			if access != None:
				Galist[instance] = access
			else:
				del Galist[instance]
			cat_file(self.AccessFile, str(Galist))
			for conf in Chats.keys():
				for sUser in Chats[conf].get_users():
					if sUser.source and sUser.source == instance:
						if access == None:
							access = Chats[conf].alist.get(instance, None)
						if access != None:
							sUser.access = access
						else:
							sUser.calc_acc()

		if body:
			body = body.split(None, 1)
			if len(body) == 2:
				Nick = body.pop(1)
				if Chats.has_key(source[1]):
					if Chats[source[1]].isHere(Nick):
						instance = get_source(source[1], Nick)
				if not locals().has_key("instance"):
					instance = (Nick.split())[0].lower()
					if not isSource(instance):
						instance = None
				if instance:
					access = body.pop(0)
					if access == chr(33):
						if Galist.has_key(instance):
							set_access(instance)
							answer = AnsBase[4]
						else:
							answer = self.AnsBase[6] % (Nick)
					elif isNumber(access):
						access = int(access)
						if access in xrange(-1, 9):
							set_access(instance, access)
							answer = AnsBase[4]
						else:
							answer = self.AnsBase[7]
					else:
						answer = AnsBase[30]
				else:
					answer = self.AnsBase[10] % (Nick)
			else:
				answer = AnsBase[2]
		else:
			answer = AnsBase[1]
		Answer(answer, stype, source, disp)

	def command_set_local_access(self, stype, source, body, disp):

		def set_access(conf, instance, access = None):
			if access != None:
				Chats[conf].alist[instance] = access
			else:
				del Chats[conf].alist[instance]
			cat_file(chat_file(conf, self.ChatAccessFile), str(Chats[conf].alist))
			for sUser in Chats[conf].get_users():
				if sUser.source and sUser.source == instance:
					if access == None:
						access = Galist.get(instance, None)
					if access != None:
						sUser.access = access
					else:
						sUser.calc_acc()

		if Chats.has_key(source[1]):
			if body:
				body = body.split(None, 1)
				if len(body) == 2:
					Nick = body.pop(1)
					if Chats[source[1]].isHere(Nick):
						instance = get_source(source[1], Nick)
					else:
						instance = (Nick.split())[0].lower()
						if not isSource(instance):
							instance = None
					if instance:
						access = body.pop(0)
						if access == chr(33):
							if Chats[source[1]].alist.has_key(instance):
								set_access(source[1], instance)
								answer = AnsBase[4]
							else:
								answer = self.AnsBase[6] % (Nick)
						elif not Galist.has_key(instance):
							if isNumber(access):
								access = int(access)
								if access in xrange(7):
									set_access(source[1], instance, access)
									answer = AnsBase[4]
								else:
									answer = self.AnsBase[8]
							else:
								answer = AnsBase[30]
						else:
							answer = self.AnsBase[9] % (Nick)
					else:
						answer = self.AnsBase[10] % (Nick)
				else:
					answer = AnsBase[2]
			else:
				answer = AnsBase[1]
		else:
			answer = AnsBase[0]
		Answer(answer, stype, source, disp)

	def load_acclist(self):
		if initialize_file(self.AccessFile):
			Galist.update(eval(get_file(self.AccessFile)))

	def load_local_acclist(self, conf):
		filename = chat_file(conf, self.ChatAccessFile)
		if initialize_file(filename):
			Chats[conf].alist.update(eval(get_file(filename)))

	commands = (
		(command_get_access, "access", 1,),
		(command_get_galist, "acclist", 7,),
		(command_get_lalist, "acclist2", 4,),
		(command_set_access, "gaccess", 8,),
		(command_set_local_access, "laccess", 6,)
					)

	handlers = (
		(load_acclist, "00si"),
		(load_local_acclist, "01si")
					)