Skip to content

Commit

Permalink
stop private message spamming
Browse files Browse the repository at this point in the history
  • Loading branch information
Justine Tunney committed Sep 28, 2011
1 parent 0ef6293 commit 4936e38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion occupywallst/api.py
Expand Up @@ -33,7 +33,7 @@
"""

import re
from datetime import datetime
from datetime import datetime, timedelta

from django.conf import settings
from django.contrib import auth
Expand Down Expand Up @@ -425,6 +425,14 @@ def message_send(user, to_username, content, **kwargs):
if last:
if (datetime.now() - last[0].published).seconds < 30:
raise APIException("hey slow down a little!")
if not user.is_staff:
hours24 = datetime.now() - timedelta(hours=24)
rec = db.Message.objects.filter(from_user=user, published__gt=hours24)
sentusers = set(m.to_user.username for m in rec)
max_ = settings.OWS_MAX_PRIVMSG_USER_DAY
if len(sentusers) > max_:
raise APIException("you can't private message more than %d users "
"in one day" % (max_))
msg = db.Message.objects.create(from_user=user,
to_user=to_user,
content=content)
Expand Down
1 change: 1 addition & 0 deletions occupywallst/settings.py
Expand Up @@ -23,6 +23,7 @@

OWS_POST_LIMIT_THREAD = 60 * 5 # five minutes
OWS_POST_LIMIT_COMMENT = 30 # 30 seconds
OWS_MAX_PRIVMSG_USER_DAY = 7
OWS_CANONICAL_URL = 'https://occupywallst.org' # no path or trailing slash
OWS_NOTIFY_PUB_ADDR = ('127.0.0.1', 9010)

Expand Down

0 comments on commit 4936e38

Please sign in to comment.