-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
192 lines (141 loc) · 6.45 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
import random
import string
from datetime import datetime
from sqlalchemy import BigInteger
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_json import NestedMutableJson
Base = declarative_base()
def randomword():
return "".join(random.choice(string.ascii_letters + string.digits) for i in range(32))
class Users(Base):
"""Storing user data"""
__tablename__ = "users"
user_id = Column(Integer(), primary_key=True, nullable=False, index=True)
channel = Column(Integer(), primary_key=True, nullable=False, index=True)
user = Column(String(64))
time_in_channel = Column(Integer(), default=0)
message_count = Column(Integer(), default=0)
cheers = Column(Integer(), default=0)
last_update = Column(DateTime(), onupdate=datetime.now)
last_message = Column(DateTime())
subs_gifted = Column(Integer(), default=0)
class Subscriptions(Base):
"""Store subscription info"""
__tablename__ = "subscriptions"
user_id = Column(Integer(), ForeignKey("users.user_id"), primary_key=True, nullable=False, index=True)
channel = Column(Integer(), ForeignKey("users.channel"), primary_key=True, nullable=False, index=True)
subscription_level = Column(String(64))
cumulative_months = Column(Integer(), default=0)
streak_months = Column(Integer(), default=0)
class Announcements(Base):
"""Storing data for the announcements command"""
__tablename__ = "announcements"
id = Column(Integer(), primary_key=True, nullable=False)
text = Column(String(1024), nullable=False)
created_date = Column(DateTime(), default=datetime.now)
last_sent = Column(DateTime(), default=datetime.now)
times_sent = Column(Integer(), default=0)
enabled = Column(Boolean(), default=True)
groups = Column(String(1024), nullable=True)
category = Column(Integer(), ForeignKey("announcements_categories.id", name="announcement_id"), default=1)
class AnnouncementCategories(Base):
"""Announcement Categories"""
__tablename__ = "announcements_categories"
id = Column(Integer(), primary_key=True, nullable=False)
name = Column(String(1024), nullable=False)
class Settings(Base):
"""Used for storing random bot settings"""
__tablename__ = "settings"
id = Column(Integer(), primary_key=True)
key = Column(String(128), nullable=False, unique=True)
value = Column(String(1024), nullable=False)
class Wigs(Base):
"""We have to keep our wigs somewhere..."""
__tablename__ = "wigs"
id = Column(Integer(), primary_key=True)
wig_name = Column(String(128), nullable=False, unique=True)
enabled = Column(Boolean())
class LinksToDiscordIgnoreList(Base):
"""List of twitch users to ignore for sending links to discord."""
__tablename__ = "linkstodiscordignorelist"
id = Column(Integer(), primary_key=True)
username = Column(String(128), nullable=False, unique=True)
class IgnoreList(Base):
"""Table of regex patterns to ignore all commands from."""
__tablename__ = "ignorelist"
id = Column(Integer(), primary_key=True)
pattern = Column(String(128), nullable=False, unique=True)
enabled = Column(Boolean(), default=True)
class TriviaQuestions(Base):
"""Table for Trivia"""
__tablename__ = "trivia_questions"
id = Column(Integer(), primary_key=True)
text = Column(String(1024), nullable=False)
answers = Column(String(2048), nullable=False, default={})
explain = Column(String(1024))
last_used_date = Column(DateTime(), default=datetime.now)
last_update_date = Column(DateTime(), default=datetime.now)
created_date = Column(DateTime(), default=datetime.now)
created_by = Column(String(128))
reference = Column(String(1024))
sound = Column(String(32), default=None)
image = Column(String(32), default=None)
# priority = Column(Boolean(), default=False)
order = Column(Integer(), default=99999)
enabled = Column(Boolean(), default=True)
class TriviaResults(Base):
"""Table for storing user data for trivia"""
__tablename__ = "trivia_results"
user_id = Column(Integer(), ForeignKey("users.user_id"), primary_key=True, nullable=False, index=True)
channel = Column(Integer(), ForeignKey("users.channel"), primary_key=True, nullable=False, index=True)
total_wins = Column(Integer(), nullable=False, default=0)
trivia_points = Column(Integer(), nullable=False, default=0)
questions_answered_correctly = Column(NestedMutableJson)
class WebAuth(Base):
"""Table for storing discord user ids for web authentication"""
__tablename__ = "web_auth"
id = Column(BigInteger(), primary_key=True, nullable=False, index=True)
name = Column(String(128), nullable=False)
enabled = Column(Boolean(), default=True)
admin = Column(Boolean(), default=False)
mod = Column(Boolean(), default=False)
user = Column(Boolean(), default=False)
api_key = Column(String(32), default=randomword)
class Clips(Base):
"""Table for storing twitch clips"""
__tablename__ = "clips"
id = Column(Integer(), primary_key=True)
name = Column(String(32), nullable=False, unique=True)
title = Column(String(1024))
url = Column(String(256), nullable=False)
enabled = Column(Boolean, default=True)
added_by = Column(String(128), default="")
class RaidLog(Base):
"""Table for logging raids"""
__tablename__ = "raidlog"
id = Column(Integer(), primary_key=True)
raider = Column(String(26), nullable=False)
viewers = Column(Integer())
timestamp = Column(DateTime(), onupdate=datetime.now)
class KnownBots(Base):
"""Table to store known bots for auto banning"""
__tablename__ = "knownbots"
id = Column(Integer(), primary_key=True)
botname = Column(String(26), nullable=False, unique=True)
enableblock = Column(
Boolean(), default=True, doc="Setting to False will prevent the bot from banning this user automagically"
)
added_timestamp = Column(DateTime(), onupdate=datetime.now)
banned = Column(Boolean(), default=False, doc="True when the bot has auto banned the user")
class BotRegex(Base):
"""Table to store regex patterns for auto banning bots"""
__tablename__ = "botsregex"
id = Column(Integer(), primary_key=True)
pattern = Column(String(128), nullable=False, unique=True)
enabled = Column(Boolean(), default=True)