def setprefix(message, args): if len(args) > 1: message.message.reply("One argument (prefix) needed!") return None if len(args) == 0: PREFS.set("global", "reply_delimiter", "%") WolfUtils.REPLY_DELIM = "%" message.message.reply("Prefix reset to default of `%`.") for room in SESSION_STORAGE.get("in_rooms"): if room.id != message.data['room_id']: room.send_message("The reply prefix has been set to `%` by " + WolfUtils.getName(message.data['user_id']) + ".") else: PREFS.set("global", "reply_delimiter", args[0]) WolfUtils.REPLY_DELIM = args[0] message.message.reply("Prefix set to `" + args[0] + "`.") for room in SESSION_STORAGE.get("in_rooms"): if room.id != message.data['room_id']: room.send_message("The reply prefix has been set to `" + args[0] + "` by " + WolfUtils.getName(message.data['user_id']) + ".")
def setprefix(message, args): if len(args) > 1: message.message.reply("One argument (prefix) needed!") return None if len(args) == 0: PREFS.set("global", "command_delimiter", "!!/") WolfUtils.CMD_DELIM = "!!/" message.message.reply("Prefix globally reset to default of `!!/`.") for room in SESSION_STORAGE.get("in_rooms"): if room != message.data['room_id']: room.send_message("The bot prefix has been set to `!!/` by " + WolfUtils.getName(message.data['user_id']) + ".") else: PREFS.set("global", "command_delimiter", args[0]) WolfUtils.CMD_DELIM = args[0] message.message.reply("Prefix globally set to `" + args[0] + "`.") for room in SESSION_STORAGE.get("in_rooms"): if room != message.data['room_id']: room.send_message("The bot prefix has been set to `" + args[0] + "` by " + WolfUtils.getName(message.data['user_id']) + ".")
def addfilter(message, args): if len(args) != 1: message.message.reply("One argument (url) needed!") return None FILTER_URL = args[0] PREFS.set(message.data['room_id'], "word_filter_source", FILTER_URL) message.message.reply("Filter Source URL set to " + args[0])
def remfilter(message, args): if len(args) < 2: message.message.reply("Two arguments [bl|wl] (words) needed!") return None if args[0] == "bl": WORD_LIST = PREFS.get(message.data['room_id'], "word_filter_blacklist", []) LIST_NAME = "blacklist" elif args[0] == "wl": WORD_LIST = PREFS.get(message.data['room_id'], "word_filter_whitelist", []) LIST_NAME = "whitelist" else: message.message.reply( "First argument must be either `bl` (modify blacklist) or `wl` (modify whitelist)!" ) return None if len(args) == 2: word = args[1] if word in WORD_LIST: WORD_LIST.remove(word) PREFS.set(message.data['room_id'], "word_filter_" + LIST_NAME, WORD_LIST) message.message.reply("`" + word + "` has been removed from the filter " + LIST_NAME + ".") else: message.message.reply("`" + word + "` is not in the filter " + LIST_NAME + "!") return None else: merge_fail = [] for word in args: if word in WORD_LIST: WORD_LIST.remove(word) else: merge_fail.append(word) PREFS.set(message.data['room_id'], "word_filter_" + LIST_NAME, WORD_LIST) if len(merge_fail) == 0: message.message.reply("All words were removed from the " + LIST_NAME + "successfully.") elif len(merge_fail) == len(args): message.message.reply("No words could be removed from the " + LIST_NAME + " (not there?).") else: message.message.reply( str(len(merge_fail)) + " words could not be removed from the the " + LIST_NAME + " (not there?):\n" + " ".join(merge_fail))
def setprefix(message, args): if len(args) > 1: message.message.reply("One argument (prefix) needed!") return None if len(args) == 0: PREFS.set("reply_delimiter", "%") WolfUtils.REPLY_DELIM = "%" message.message.reply("Prefix reset to default of `%`.") else: PREFS.set("reply_delimiter", args[0]) WolfUtils.REPLY_DELIM = args[0] message.message.reply("Prefix set to `" + args[0] + "`.")
def setprefix(message, args): if len(args) > 1: message.message.reply("One argument (prefix) needed!") return None if len(args) == 0: PREFS.set("command_delimiter", "!!/") WolfUtils.CMD_DELIM = "!!/" message.message.reply("Prefix reset to default of `!!/`.") else: PREFS.set("command_delimiter", args[0]) WolfUtils.CMD_DELIM = args[0] message.message.reply("Prefix set to `" + args[0] + "`.")
def addfilter(message, args): if len(args) < 2: message.message.reply("Two arguments [bl|wl] (words) needed!") return None if args[0] == "bl": WORD_LIST = PREFS.get(message.data['room_id'], "word_filter_blacklist", []) LIST_NAME = "blacklist" elif args[0] == "wl": WORD_LIST = PREFS.get(message.data['room_id'], "word_filter_whitelist", []) LIST_NAME = "whitelist" else: message.message.reply("First argument must be either bl or wl!") return None if len(args) == 2: word = args[1] if word not in WORD_LIST: WORD_LIST.append(word) PREFS.set(message.data['room_id'], "word_filter_" + LIST_NAME, WORD_LIST) message.message.reply("`" + word + "` has been added to the filter " + LIST_NAME + ".") else: message.message.reply("`" + word + "` is already in the filter" + LIST_NAME + "!") return None else: merge_fail = [] for word in args[1:]: if word not in WORD_LIST: WORD_LIST.append(word) else: merge_fail.append(word) PREFS.set(message.data['room_id'], "word_filter_" + LIST_NAME, WORD_LIST) if len(merge_fail) == 0: message.message.reply("All words were added to " + LIST_NAME + " successfully.") elif len(merge_fail) == len(args): message.message.reply("No words could be added to the " + LIST_NAME + " (already there?).") else: message.message.reply( str(len(merge_fail)) + " words could not be added to the " + LIST_NAME + " (already there?):\n" + " ".join(merge_fail))
def lockdown(message, args): room = message.data['room_id'] lockdownState = PREFS.get(room, "lockdown", False) if len(args) == 1: if args(0) == "false" or args(0) == "off": if not lockdownState: message.message.reply("Lockdown mode is already disabled.") else: PREFS.set(room, "lockdown", False) message.message.reply( "Room no longer lockdown. Commands may be freely given, and tasks will run once again." ) elif args(0) == "true" or args(0) == "on": if lockdownState: message.message.reply("Lockdown mode is already enabled.") else: PREFS.set(room, "lockdown", True) message.message.reply( "Room under lockdown. Only admins may give commands to the bot, and tasks will not run." ) return if not lockdownState: PREFS.set(room, "lockdown", True) message.message.reply( "Room under lockdown. Only admins may give commands to the bot, and tasks will not run." ) else: PREFS.set(room, "lockdown", False) message.message.reply( "Room no longer under lockdown. Commands may be freely given, and tasks will run once again." )
def joinRoom(message, args): if (len(args) == 0): message.message.reply("Needs one argument: room_id") return rid = args[0] if PREFS.get(rid, "banned", False) == True: message.message.reply( "The bot has been banned from joining that room!") return PREFS.set(rid, "active", True) message.message.reply("The bot has joined the given room.") restart("1", "1")
def addadmin(message, args): if len(args) == 0 or len(args) > 1: message.message.reply("One argument (user_id) needed!") return None currentAdmins = PREFS.get("admins", []) if args[0] not in currentAdmins: currentAdmins.append(args[0]) PREFS.set("admins", currentAdmins) message.message.reply( WolfUtils.getName(args[0]) + " (ID " + args[0] + ") added as bot admin.") return None else: message.message.reply("User is already a declared admin!") return None
def unblacklistUser(message, args): if len(args) != 1: message.message.reply("Needs one argument (user_id)") return None user_to_unbl = args[0] current_blacklist = PREFS.get("blacklist", []) if user_to_unbl in current_blacklist: current_blacklist.remove(user_to_unbl) PREFS.set("blacklist", current_blacklist) message.message.reply( WolfUtils.getName(user_to_unbl) + " (ID " + user_to_unbl + ") is now permitted to use WolfBot commands.") else: message.message.reply("User is already blacklisted!")
def addadmin(message, args): if len(args) == 0 or len(args) > 1: message.message.reply("One argument (user_id) needed!") return None currentAdmins = PREFS.get("admins", []) if args[0] in currentAdmins: currentAdmins.remove(args[0]) PREFS.set("admins", currentAdmins) message.message.reply( WolfUtils.getName(args[0]) + " removed from bot admin.") return None else: message.message.reply( "User is not a declared admin! (This command may not be used to remove inherited rights)" ) return None
def addshortcut(message, args): if len(args) != 2: message.message.reply("Two arguments (name, url) needed!") return None currentShortcuts = PREFS.get("post-shortcuts", {}) if args[0] in currentShortcuts: message.message.reply(args[0] + " is already a shortcut! Can't add.") return None args[1] = args[1].decode('ascii', 'ignore') currentShortcuts[args[0]] = args[1] PREFS.set("post-shortcuts", currentShortcuts) message.message.reply("From now on, the shortcut `" + args[0] + "` will return [this link](" + args[1] + ").")
def setroom(message, args): if len(args) != 1: message.message.reply("Needs one argument (room_id)") return None newRoom = str(args[0]) PREFS.set("chat_id", args[0]) newRoomName = json.load( urllib2.urlopen("https://chat.stackexchange.com/rooms/thumbs/" + newRoom))["name"] message.message.reply( "The bot will reload soon, and will use the new room upon restart. The bot will be moved to [" + newRoomName + "](https://chat.stackexchange.com/rooms/" + newRoom + ").") time.sleep(3) os.execl(sys.executable, sys.executable, *sys.argv)
def blacklistUser(message, args): if len(args) != 1: message.message.reply("Needs one argument (user_id)") return None user_to_bl = args[0] current_blacklist = PREFS.get("blacklist", []) if user_to_bl not in current_blacklist: if not WolfUtils.isAdmin(user_to_bl): current_blacklist.append(user_to_bl) PREFS.set("blacklist", current_blacklist) message.message.reply( WolfUtils.getName(user_to_bl) + " (ID " + user_to_bl + ") is no longer permitted to use WolfBot commands.") else: message.message.reply( "Admins and Superusers may not be blacklisted.") else: message.message.reply("User is already blacklisted!")
def takeRoot(message, args): if len(args) != 1: message.message.reply("Needs one argument (captain_key)") return None currentDevs = PREFS.get("devs", []) if currentDevs == []: if args[0].lower() == PREFS.get("captain_key").lower(): currentDevs.append(str(message.data['user_id'])) PREFS.set("devs", currentDevs) message.message.reply("https://i.imgur.com/2oNMYD3.jpg") PREFS.delete("captain_key") PREFS.save() else: message.message.reply( "You are by far the worst captain I've ever heard of.") else: message.message.reply( "You are by far the worst captain I've ever heard of.")
def leaveRoom(message, args): if len(args) == 0: mode = "normal" else: mode = args[0] if mode == "purge": PREFS.purgeChat(message.data['room_id']) restart("1", "1") elif mode == "ban": PREFS.purgeChat(message.data['room_id']) PREFS.set(message.data['room_id'], "banned", True) restart("1", "1") elif mode == "normal": PREFS.set(message.data['room_id'], "active", False) restart("1", "1") else: message.message.reply( "Command expects a mode: normal, purge, ban (No argument implies normal)" )
message.message.reply("Uh oh! I ran into a problem :(. See the console for more details.") print("WolfBot loading... please wait.") try: input = raw_input except NameError: pass # Handle setup first. __USER__ = PREFS.get("global", "username", None) __PASS__ = PREFS.get("global", "password", None) if __USER__ is None: __USER__ = input("Please enter the e-mail to use: ") PREFS.set("global", "username", __USER__) __PASS__ = getpass.getpass("Please enter the password to use: ") PREFS.set("global", "password", __PASS__) PREFS.save() if PREFS.get("global", "devs", []) == []: ckey = "%06x" % random.randint(0, 0xFFFFFF) PREFS.set("global", "captain_key", ckey) print("Please run this command to gain superuser privileges (single-use!):\n\n " + WolfUtils.CMD_DELIM + "iamthecaptainnow " + ckey.upper() + "\n\n") # Register the Client to be used client = chatexchange6.Client('stackexchange.com') client.login(__USER__, __PASS__) # Get the Bot itself
def clearfilter(message, args): PREFS.set(message.data['room_id'], "word_filter_blacklist", []) PREFS.set(message.data['room_id'], "word_filter_whitelist", []) message.message.reply("The filter list has been cleared.")
def clearfilter(message, args): WORD_BLACKLIST = {} WORD_WHITELIST = {} PREFS.set("word_filter_blacklist", {}) PREFS.set("word_filter_whitelist", {}) message.message.reply("The filter list has been cleared.")
print("WolfBot loading... please wait.") try: input = raw_input except NameError: pass # Handle setup first. __USER__ = PREFS.get("username", None) __PASS__ = PREFS.get("password", None) __CHATID__ = PREFS.get("chat_id", None) if __USER__ is None: __USER__ = input("Please enter the e-mail to use: ") PREFS.set("username", __USER__) __PASS__ = getpass.getpass("Please enter the password to use: ") PREFS.set("password", __PASS__) PREFS.save() if __CHATID__ is None: __CHATID__ = input("Please enter the Chat to join: ") PREFS.set("chat_id", __CHATID__) PREFS.save() if PREFS.get("devs", []) == []: ckey = "%06x" % random.randint(0, 0xFFFFFF) PREFS.set("captain_key", ckey) print( "Please run this command to gain superuser privileges (single-use!):\n\n /iamthecaptainnow " + ckey.upper() + "\n\n")