AntiSpam.check_spam()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 8
rs 10
1
import time
2
3
from django.core.exceptions import ValidationError
4
from django.conf import settings
5
6
7
class AntiSpam(object):
8
9
	def __init__(self):
10
		self.spammed = 0
11
		self.info = {}
12
13
	def check_spam(self, json_message):
14
		message_length = len(json_message)
15
		info_key = int(round(time.time() * 100))
16
		self.info[info_key] = message_length
17
		if message_length > settings.MAX_MESSAGE_SIZE:
18
			self.spammed += 1
19
			raise ValidationError("Message can't exceed %d symbols" % settings.MAX_MESSAGE_SIZE)
20
		self.check_timed_spam()
21
22
	def check_timed_spam(self):
23
		# TODO implement me
24
		pass
25
		# raise ValidationError("You're chatting too much, calm down a bit!")