Skip to content

Commit

Permalink
!!/addwlu and !!/rmwlu commands
Browse files Browse the repository at this point in the history
Using the !!/addwlu and !!/rmwlu commands, you can manually add/remove
users to SmokeDetector's whitelist.

Syntax:
!!/addwlu userURL
or
!!/addwlu userID site
!!/rmwlu has the same syntax
  • Loading branch information
thomas-daniels committed Feb 14, 2015
1 parent 61b0225 commit ac1dc70
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
50 changes: 47 additions & 3 deletions chatcommunicate.py
Expand Up @@ -4,9 +4,7 @@
from parsing import fetch_post_id_and_site_from_msg_content,\
get_user_from_url, fetch_owner_url_from_msg_content,\
fetch_title_from_msg_content
from datahandling import add_false_positive, is_privileged,\
add_whitelisted_user, add_blacklisted_user, add_ignored_post,\
fetch_lines_from_error_log, remove_blacklisted_user
from datahandling import *
from bayesianfuncs import bayesian_learn_title
from globalvars import GlobalVars
import os
Expand Down Expand Up @@ -171,6 +169,52 @@ def watcher(ev, wrap2):
ev.message.reply("User is not blacklisted.")
else:
ev.message.reply("Invalid format. Valid format: `!!/rmblu profileurl` *or* `!!/rmblu userid sitename` where `sitename` is the full site name, such as `stackoverflow.com`, `communitybuilding.stackexchange.com`, `mathoverflow.net`, ...")
if content_lower.startswith("!!/addwlu") \
and is_privileged(ev_room, ev_user_id):
uid = -1
site = ""
if len(message_parts) == 2:
uid_site = get_user_from_url(message_parts[1])
if uid_site is not None:
uid = uid_site[0]
site = uid_site[1]
elif len(message_parts) == 3:
uid = message_parts[1]
site = message_parts[2]
digit_re = re.compile("^[0-9]+$")
site_re = re.compile(r"^(\w+\.stackexchange\.com|\w+\.(com|net))$")
if not (digit_re.match(uid) and site_re.match(site)):
uid = -1
site = ""
if uid != -1 and site != "":
add_whitelisted_user((uid, site))
ev.message.reply("User whitelisted.")
else:
ev.message.reply("Invalid format. Valid format: `!!/addwlu profileurl` *or* `!!/addwlu userid sitename` where `sitename` is the full site name, such as `stackoverflow.com`, `communitybuilding.stackexchange.com`, `mathoverflow.net`, ...")
if content_lower.startswith("!!/rmwlu") \
and is_privileged(ev_room, ev_user_id):
uid = -1
site = ""
if len(message_parts) == 2:
uid_site = get_user_from_url(message_parts[1])
if uid_site is not None:
uid = uid_site[0]
site = uid_site[1]
elif len(message_parts) == 3:
uid = message_parts[1]
site = message_parts[2]
digit_re = re.compile("^[0-9]+$")
site_re = re.compile(r"^(\w+\.stackexchange\.com|\w+\.(com|net))$")
if not (digit_re.match(uid) and site_re.match(site)):
uid = -1
site = ""
if uid != -1 and site != "":
if remove_whitelisted_user((uid, site)):
ev.message.reply("User removed from whitelist.")
else:
ev.message.reply("User is not whitelisted.")
else:
ev.message.reply("Invalid format. Valid format: `!!/rmwlu profileurl` *or* `!!/rmwlu userid sitename` where `sitename` is the full site name, such as `stackoverflow.com`, `communitybuilding.stackexchange.com`, `mathoverflow.net`, ...")
if content_lower.startswith("!!/wut"):
ev.message.reply("Whaddya mean, 'wut'? Humans...")
if content_lower.startswith("!!/lick"):
Expand Down
9 changes: 9 additions & 0 deletions datahandling.py
Expand Up @@ -119,6 +119,15 @@ def remove_blacklisted_user(user):
pickle.dump(GlobalVars.blacklisted_users, f)
return True


def remove_whitelisted_user(user):
if user not in GlobalVars.whitelisted_users:
return False
GlobalVars.whitelisted_users.remove(user)
with open("whitelistedUsers.txt", "w") as f:
pickle.dump(GlobalVars.whitelisted_users, f)
return True

# methods that help avoiding reposting alerts:


Expand Down

0 comments on commit ac1dc70

Please sign in to comment.