forked from WiiLink24/room-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
315 lines (239 loc) · 9.16 KB
/
models.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import enum
from flask_sqlalchemy import BaseQuery, SQLAlchemy
from sqlalchemy import func
from sqlalchemy.event import listens_for
from sqlalchemy.types import TypeDecorator
from sqlalchemy_searchable import SearchQueryMixin
from sqlalchemy_utils import TSVectorType
from flask_login import LoginManager, UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
import sqlalchemy
import json
db = SQLAlchemy()
login = LoginManager()
@login.user_loader
def load_user(id):
return User.query.get(int(id))
class DictType(TypeDecorator):
impl = sqlalchemy.Text()
def process_bind_param(self, value, dialect):
if value is not None:
value = json.dumps(value)
return value
def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
class RoomMenu(db.Model):
id = db.Column(db.Integer, primary_key=True, unique=True)
room_id = db.Column(db.Integer)
data = db.Column(DictType) # This is a dict with keys in it for that type.
# TODO: Figure out a suitable UI, maybe even using Javascript?
class User(db.Model, UserMixin):
# Used to login to the Admin Panel
id = db.Column(db.Integer, primary_key=True, default=1)
username = db.Column(db.String(100))
password_hash = db.Column(db.String)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
@listens_for(User.__table__, "after_create")
def create_default_user(target, connection, **kw):
"""Adds a default user to The Underground.
By default, we assume admin:admin."""
table = User.__table__
connection.execute(
table.insert().values(
username="admin",
password_hash=generate_password_hash("admin"),
)
)
class Posters(db.Model):
poster_id = db.Column(db.Integer, primary_key=True, unique=True)
msg = db.Column(db.String(15), nullable=False)
movie_id = db.Column(db.Integer, nullable=False)
# While a maximum of 47 characters seems arbitrary, it is what it is.
# It appears they mandate the last byte in their char array is null (and sprintf),
# so perhaps the internal type is char[48]?
title = db.Column(db.String(47), nullable=False)
class News(db.Model):
id = db.Column(db.Integer, primary_key=True, unique=True)
msg = db.Column(db.String, nullable=False)
class PayPosters(db.Model):
poster_id = db.Column(db.Integer, primary_key=True, unique=True)
msg = db.Column(db.String(15), nullable=False)
movie_id = db.Column(db.Integer, nullable=False)
title = db.Column(db.String(47), nullable=False)
type = db.Column(db.Integer, nullable=False)
aspect = db.Column(db.Boolean, nullable=False)
class ConciergeMiis(db.Model):
mii_id = db.Column(
db.Integer, db.ForeignKey("mii_data.mii_id"), primary_key=True, unique=True
)
clothes = db.Column(db.Integer, nullable=False)
action = db.Column(db.Integer, nullable=False)
prof = db.Column(db.String(129), nullable=False)
movie_id = db.Column(db.Integer, nullable=False)
voice = db.Column(db.Boolean, default=False, nullable=False)
# MiiData provides the genuine Mii alongside other common information.
class MiiData(db.Model):
mii_id = db.Column(db.Integer, primary_key=True)
data = db.Column(db.LargeBinary(74), nullable=False)
name = db.Column(db.String(10), nullable=False)
color1 = db.Column(db.String(6), nullable=False)
color2 = db.Column(db.String(6), nullable=False)
class MiiMsgInfo(db.Model):
# We make both the Mii's ID and message type unique, as to allow row
# identification for SQLAlchemy.
mii_id = db.Column(
db.Integer, db.ForeignKey("mii_data.mii_id"), primary_key=True, nullable=False
)
type = db.Column(db.Integer, primary_key=True, nullable=False)
seq = db.Column(db.Integer, primary_key=True, nullable=False)
msg = db.Column(db.String, nullable=False)
face = db.Column(db.Integer, nullable=False)
class FullTextSearchable(BaseQuery, SearchQueryMixin):
pass
class Movies(db.Model):
query_class = FullTextSearchable
movie_id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
category_id = db.Column(
db.Integer,
db.ForeignKey("categories.category_id"),
primary_key=True,
nullable=False,
)
title = db.Column(db.String(48), nullable=False)
length = db.Column(db.String(8), nullable=False)
aspect = db.Column(db.Boolean, nullable=False)
genre = db.Column(db.Integer, nullable=False)
sp_page_id = db.Column(db.Integer, nullable=False)
ds_mov_id = db.Column(db.Integer, nullable=True)
staff = db.Column(db.Boolean, nullable=False)
date_added = db.Column(db.DateTime, nullable=False, server_default=func.now())
search_vector = db.Column(TSVectorType("title"))
class PayMovies(db.Model):
query_class = FullTextSearchable
movie_id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
title = db.Column(db.String, nullable=False)
length = db.Column(db.String(), nullable=False)
note = db.Column(db.String(76), nullable=False)
price = db.Column(db.Integer, nullable=False)
released = db.Column(db.String(10), nullable=False)
category_id = db.Column(
db.Integer,
db.ForeignKey("pay_categories.category_id"),
primary_key=True,
nullable=False,
)
date_added = db.Column(db.DateTime, nullable=False, server_default=func.now())
search_vector = db.Column(TSVectorType("title", "note"))
class PayCategories(db.Model):
category_id = db.Column(db.Integer, primary_key=True, unique=True)
name = db.Column(db.String)
# Starts at 10, goes up by 1 each time
genre_id = db.Column(db.Integer)
class PayCategoryHeaders(db.Model):
title = db.Column(db.String, primary_key=True, unique=True)
class Categories(db.Model):
category_id = db.Column(db.Integer, primary_key=True, unique=True)
name = db.Column(db.String)
class RoomBGMTypes(enum.Enum):
SOFT_GUITAR = 1
NORMAL = 2
FOLK = 3
JAZZY = 4
TRUMPET = 5
CHIMES = 6
WESTERN = 7
HARP = 8
@classmethod
def choices(cls):
return [(choice, choice.name) for choice in cls]
@classmethod
def coerce(cls, item):
return cls(int(item)) if not isinstance(item, cls) else item
def __str__(self):
return str(self.value)
class RoomContentBGMTypes(enum.Enum):
Sadness = 1
Upbeat = 2
Relaxing = 3
Classical = 4
Playful = 5
Chill = 6
Adventurous = 7
Jolly = 8
Happiness = 9
Casino = 10
Parade = 11
Excitement = 12
idk = 13
@classmethod
def choices(cls):
return [(choice, choice.name) for choice in cls]
@classmethod
def coerce(cls, item):
return cls(int(item)) if not isinstance(item, cls) else item
def __str__(self):
return str(self.value)
class Rooms(db.Model):
room_id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
bgm = db.Column(db.Enum(RoomBGMTypes))
mascot = db.Column(db.Boolean)
contact = db.Column(db.Boolean)
intro_msg = db.Column(db.String)
contact_data = db.Column(db.String)
news = db.Column(db.String)
level = db.Column(db.Integer, default=1)
class RoomMiis(db.Model):
room_id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True)
mii_id = db.Column(db.Integer, db.ForeignKey("mii_data.mii_id"), nullable=False)
mii_msg = db.Column(db.String)
class EvaluateData(db.Model):
id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
movie_id = db.Column(db.Integer, index=True)
gender = db.Column(db.Integer)
blood = db.Column(db.Integer)
age = db.Column(db.Integer)
vote = db.Column(db.Integer)
class PollData(db.Model):
id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
poll_id = db.Column(db.Integer, index=True)
wii_num = db.Column(db.BigInteger)
choice = db.Column(db.Integer)
age = db.Column(db.Integer)
gender = db.Column(db.Integer)
class ContentTypes(enum.Enum):
Video = 0
Image = 1
@classmethod
def choices(cls):
return [(choice, choice.name) for choice in cls]
@classmethod
def coerce(cls, item):
return cls(int(item)) if not isinstance(item, cls) else item
def __str__(self):
return str(self.value)
class LinkTypes(enum.Enum):
Regular = 0
TheatreMovie = 1
TheatreCategory = 2
Shop = 3
Room = 4
Category = 5
@classmethod
def choices(cls):
return [(choice, choice.name) for choice in cls]
@classmethod
def coerce(cls, item):
return cls(int(item)) if not isinstance(item, cls) else item
def __str__(self):
return str(self.value)
class IntroInfo(db.Model):
cnt_id = db.Column(db.Integer, autoincrement=True, primary_key=True, unique=True)
cnt_type = db.Column(db.Enum(ContentTypes))
cat_name = db.Column(db.String)
link_type = db.Column(db.Enum(LinkTypes))
link_id = db.Column(db.Integer)