Skip to content

Commit

Permalink
Add !!/rmblu command
Browse files Browse the repository at this point in the history
This command removes a user from the blacklist.

Syntax:
!!/rmblu userURL
or
!!/rmblu userID site
  • Loading branch information
thomas-daniels committed Feb 14, 2015
1 parent e8d0172 commit 26a6661
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
26 changes: 25 additions & 1 deletion chatcommunicate.py
Expand Up @@ -6,7 +6,7 @@
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
fetch_lines_from_error_log, remove_blacklisted_user
from bayesianfuncs import bayesian_learn_title
from globalvars import GlobalVars
import os
Expand Down Expand Up @@ -147,6 +147,30 @@ def watcher(ev, wrap2):
ev.message.reply("User blacklisted.")
else:
ev.message.reply("Invalid format. Valid format: `!!/addblu profileurl` *or* `!!/addblu userid sitename` where `sitename` is the full site name, such as `stackoverflow.com`, `communitybuilding.stackexchange.com`, `mathoverflow.net`, ...")
if content_lower.startswith("!!/rmblu") \
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_blacklisted_user((uid, site)):
ev.message.reply("User removed from blacklist.")
else:
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("!!/wut"):
ev.message.reply("Whaddya mean, 'wut'? Humans...")
if content_lower.startswith("!!/lick"):
Expand Down
10 changes: 9 additions & 1 deletion datahandling.py
Expand Up @@ -68,7 +68,7 @@ def is_auto_ignored_post(postid_site_tuple):
def is_privileged(room_id_str, user_id_str):
return room_id_str in GlobalVars.privileged_users and user_id_str in GlobalVars.privileged_users[room_id_str]

# methods to add whitelisted/blacklisted users, ignored posts, ...
# methods to add/remove whitelisted/blacklisted users, ignored posts, ...


def add_whitelisted_user(user):
Expand Down Expand Up @@ -111,6 +111,14 @@ def add_ignored_post(postid_site_tuple):
pickle.dump(GlobalVars.ignored_posts, f)


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

# methods that help avoiding reposting alerts:


Expand Down

0 comments on commit 26a6661

Please sign in to comment.