예제 #1
0
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']) +
                                  ".")
예제 #2
0
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']) +
                                  ".")
예제 #3
0
def taskRunFilter(room):
    global LAST_PULL_TIME

    FILTER_URL = PREFS.get(room.id, "word_filter_source")
    WORD_BLACKLIST = PREFS.get(room.id, "word_filter_blacklist", [])
    WORD_WHITELIST = PREFS.get(room.data, "word_filter_whitelist", [])

    if FILTER_URL is None:
        print("[E] Unable to run task! Filter URL is empty.")
        return None

    results = []
    post_timestamps = []

    data = feedparser.parse(FILTER_URL).entries

    for entry in data:
        post_timestamps.append(seTimeToUnixTime(entry['published']))
        if seTimeToUnixTime(entry['published']) > LAST_PULL_TIME:
            for word in WORD_BLACKLIST:
                if word.lower() in entry['summary'].lower() and not any(
                        oword.lower() in entry['summary'].lower()
                        for oword in WORD_WHITELIST):
                    results.append({
                        "trigger": word,
                        "title": entry['title'],
                        "url": entry['id']
                    })

    try:
        LAST_PULL_TIME = max(post_timestamps)
    except ValueError:
        LAST_PULL_TIME = LAST_PULL_TIME

    if len(results) == 1:
        room.send_message("[**" + SESSION_STORAGE.get("bot_username") + "**] Found filtered post, matches word `" + results[0]["trigger"] + \
        "`: [" + results[0]["title"] + "](" + results[0]["url"] + ")")
    elif len(results) > 1:
        s = ""
        for result in results:
            s += "[" + result["title"] + "](" + result[
                "url"] + "), matches word `" + result["trigger"] + "`\n"
        room.send_message("[**" + SESSION_STORAGE.get("bot_username") +
                          "**] Found multiple filtered posts:\n" + s)
예제 #4
0
def listenerDeleteMessage(message):
    if message.data["content"] == "@" + SESSION_STORAGE.get(
            "bot_username") + " " + WolfUtils.REPLY_DELIM + "d":
        if WolfUtils.isAdmin(message.data["user_id"]):
            chatexchange6.messages.Message(message.data["parent_id"],
                                           message.client).delete()
예제 #5
0
def start(message, args):
    message.message.reply("Hi there! Welcome to " + SESSION_STORAGE.get("bot_username") + "!")
예제 #6
0
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")

# Register the Client to be used
client = chatexchange6.Client('stackexchange.com')
client.login(__USER__, __PASS__)

# Get the Bot itself
me = client.get_me()

SESSION_STORAGE.set("bot_username", me.name.replace(" ", ""))
SESSION_STORAGE.set("bot_id", client._br.user_id)

# Bind the user to the chat room
room = client.get_room(__CHATID__)
room.join()

roomWatcher = room.watch(on_message)
print("WolfBot online.")

while True:
    time.sleep(1)
    TASKS.runTasks(room)

PREFS.save()
client.logout()
예제 #7
0
    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
me = client.get_me()

SESSION_STORAGE.set("bot_username", me.name.replace(" ", ""))
SESSION_STORAGE.set("bot_id", client._br.user_id)

allRooms = PREFS.all()

if len(allRooms) == 1:
    PREFS.set("1", "active", True)

for room in allRooms:
    if room == "global":
        continue

    if PREFS.get(room, "active", True):
        PREFS.set(room, "active", True)
        print("Updated room ID " + str(room) + " to new prefs format. It is now Active.")
    else: