forked from nortxort/tinybot-rtc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_user.py
More file actions
117 lines (88 loc) · 3.37 KB
/
check_user.py
File metadata and controls
117 lines (88 loc) · 3.37 KB
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
class CheckUser:
"""
A class to perform various ban checks on a User object.
The checks will be done, against the different ban lists
and other ban rules in the config file.
If a test is True, then the user will be banned.
"""
def __init__(self, tinybot, user, conf):
"""
Initialize the CheckUser class.
:param tinybot: An instance of TinychatBot.
:type tinybot: TinychatBot
:param user: The User object to check.
:type user: User
:param conf: The config file.
:type conf: config
"""
self.tinybot = tinybot
self.user = user
self.config = conf
def check_account(self):
"""
Check if the user account is in the account bans list.
:return: True, if the user was banned.
:rtype: bool
"""
if self.user.account in self.config.B_ACCOUNT_BANS:
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_kick_msg(self.user.id)
else:
self.tinybot.send_ban_msg(self.user.id)
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_chat_msg('Auto-Kicked: (bad account)')
else:
self.tinybot.send_chat_msg('Auto-Banned: (bad account)')
return True
return False
def guest_entry(self):
"""
Check if the user is a guest, and allowed to join.
:return: True, if the user was banned.
:rtype: bool
"""
if self.user.account == '' and not self.config.B_ALLOW_GUESTS:
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_kick_msg(self.user.id)
else:
self.tinybot.send_ban_msg(self.user.id)
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_chat_msg('Auto-Kicked: (guests not allowed)')
else:
self.tinybot.send_chat_msg('Auto-Banned: (guests not allowed)')
return True
return False
def check_nick(self):
"""
Check if the user's nick is in the nick bans list.
:return: True, if the user was banned.
:rtype: bool
"""
if self.user.nick in self.config.B_NICK_BANS:
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_kick_msg(self.user.id)
else:
self.tinybot.send_ban_msg(self.user.id)
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_chat_msg('Auto-Kicked: (bad nick)')
else:
self.tinybot.send_chat_msg('Auto-Banned: (bad nick)')
return True
return False
def check_lurker(self):
"""
Check if the user is a lurker, and allowed to join.
:return: True, if the user was banned.
:rtype: bool
"""
if self.user.is_lurker and not self.config.B_ALLOW_LURKERS:
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_kick_msg(self.user.id)
else:
self.tinybot.send_ban_msg(self.user.id)
if self.config.B_USE_KICK_AS_AUTOBAN:
self.tinybot.send_chat_msg('Auto-Kicked: (lurkers not allowed)')
else:
self.tinybot.send_chat_msg('Auto-Banned: (lurkers not allowed)')
return True
return False