Exemple #1
0
def receiveData():
    global TIME
    global allCommands
    global allRegex
    global bot_mod
    global KEEP_RUNNING
    TIME = datetime.now()
    readbuffer = ""

    # allCommands['hello'] = [hello, [], "", False]
    allCommands["soultran"] = [soultran, bot_mod, "", False]
    allCommands["uptime"] = [uptime, [], "", False]
    allCommands["set"] = [setAccount, bot_mod, "", False]
    allCommands["runes"] = [runes, [], "", False]
    allCommands["masteries"] = [masteries, [], "", False]
    allCommands["mastery"] = [masteries, [], "", False]
    allCommands["profile"] = [profile, [], "", False]
    allCommands["rank"] = [rank, [], "", False]
    allCommands["roll"] = [roll, [], "", False]
    allCommands["quote"] = [quote, [], "", False]
    allCommands["fact"] = [fact, [], "", False]
    allCommands["activity"] = [activity, [], "", False]
    allCommands["song"] = [getMusic, [], "", False]
    allCommands["add"] = [addCommand, bot_mod, "", False]
    allCommands["start"] = [start, bot_mod, "", False]
    allCommands["enter"] = [enterGiveaway, [], False]
    # allCommands['winner'] = [winner, bot_mod, False]
    allCommands["commands"] = [commandList, [], False]

    loadCustomCommands()
    loadRegex()
    # reg = re.compile("^(?=.*?regex).*$")

    while KEEP_RUNNING:
        data = s.recv(1024)

        if len(data) == 0:
            print("Connection was closed.")

        somebytes = data.decode("UTF-8")
        readbuffer += readbuffer + somebytes
        temp = str.split(readbuffer, "\r\n")
        readbuffer = temp.pop()

        for line in temp:
            line = str.rstrip(line)
            line = str.split(line)

            if len(line) > 3:
                if line[1] == "PRIVMSG":
                    name = parseName(line[0])
                    print("Message by {} in channel {}".format(name, line[2]))

                    if line[2][1:] == CHANNEL:
                        updateUserDataBase(name)

                    currentCommand = getCommand(line[3])
                    currentMessage = line[3]

                    if currentCommand in allCommands and allowed(name, allCommands[currentCommand][1]):
                        allCommands[currentCommand][0](name, line[2], line[4:], allCommands[currentCommand][2])
                    else:
                        for exp in range(0, len(allRegex)):
                            flagString = allRegex[exp][2]["flags"]
                            flags = None
                            for f in range(0, len(flagString)):
                                print(flagString[f])
                                if flagString[f] == "m":
                                    if flags == None:
                                        flags = re.MULTILINE
                                    else:
                                        flags = flags | re.MULTILINE
                                if flagString[f] == "i":
                                    if flags == None:
                                        flags = re.IGNORECASE
                                    else:
                                        flags = flags | re.IGNORECASE
                                if flagString[f] == "s":
                                    if flags == None:
                                        flags = re.DOTALL
                                    else:
                                        flags = flags | re.DOTALL
                                if flagString[f] == "u":
                                    if flags == None:
                                        flags = re.UNICODE
                                    else:
                                        flags = flags | re.UNICODE
                            if flags != None:
                                regToTest = re.compile(allRegex[exp][2]["command"], flags)
                            else:
                                regToTest = re.compile(allRegex[exp][2]["command"])
                            answer = allRegex[exp][2]["answer"]
                            if regToTest.match(currentMessage):
                                writeMessage(answer, line[2])
                    try:
                        print(line)
                    except:
                        print("-----------------------------------")
                        print("---Failed to print user message.---")
                        print("-----------------------------------")
                elif line[3] == "+o":
                    bot_mod.append(line[4])
                    print(line)
                    print("Added " + line[4] + " as a mod!")
                elif line[3] == "-o":
                    # It removes Mods now. Not so hard.
                    bot_mod.remove(line[4])
                    print(line)
                    print("Removed a mod!")
                else:
                    print(line)
            if line[0] == "PING":
                print("Got PING PONG", (datetime.now() - TIME))
                s.send(bytes("PONG {}\r\n".format(line[1]), "UTF-8"))
    print("Done thread.")
Exemple #2
0
    if userInput == "quit":
        saveDatabase()

        try:
            KEEP_RUNNING = False
            s.shutdown(socket.SHUT_WR)
            s.close()
            # t.close()
        except:
            print("Could not end the connection.")
        break
    elif userInput == "save":
        saveDatabase()
    elif userInput == "load":
        loadCustomCommands()
    elif userInput == "uptime":
        uptime("", "", "")
    elif userInput == "add":
        print("Mod to add?")
        userInput = input()
        bot_mod.append(userInput)
        print("Done adding that mod manually!")
    elif userInput == "join":
        userInput = input()
        s.send(bytes("JOIN #{}\r\n".format(userInput), "UTF-8"))
    elif userInput[0] == "\\":
        s.send(bytes("{}\r\n".format(userInput[1:-1]), "UTF-8"))
    else:
        s.send(bytes("PRIVMSG #{} :{}\r\n".format(CHANNEL, userInput), "UTF-8"))
print("Ended")
Exemple #3
0
def receiveData():
    global TIME
    global allCommands
    global allRegex
    global bot_mod
    TIME = datetime.now()
    readbuffer = ""

    # allCommands['hello'] = [hello, [], "", False]
    allCommands['soultran'] = [soultran, bot_mod, "", False]
    allCommands['uptime'] = [uptime, [], "", False]
    allCommands['set'] = [setAccount, bot_mod, "", False]
    allCommands['runes'] = [runes, [], "", False]
    allCommands['masteries'] = [masteries, [], "", False]
    allCommands['mastery'] = [masteries, [], "", False]
    allCommands['profile'] = [profile, [], "", False]
    allCommands['rank'] = [rank, [], "", False]
    allCommands['roll'] = [roll, [], "", False]
    allCommands['quote'] = [quote, [], "", False]
    allCommands['fact'] = [fact, [], "", False]
    allCommands['activity'] = [activity, [], "", False]
    allCommands['song'] = [getMusic, [], "", False]
    allCommands['add'] = [addCommand, bot_mod, "", False]
    allCommands['start'] = [start, bot_mod, "", False]
    allCommands['enter'] = [enterGiveaway, [], False]
    allCommands['winner'] = [winner, bot_mod, False]
    allCommands['commands'] = [commandList, [], False]

    loadCustomCommands()
    loadRegex()
    # reg = re.compile("^(?=.*?regex).*$")

    while 1:
        somebytes = s.recv(1024).decode('UTF-8')
        readbuffer += readbuffer + somebytes
        temp = str.split(readbuffer, '\r\n')
        readbuffer = temp.pop()

        for line in temp:
            line = str.rstrip(line)
            line = str.split(line)

            if len(line) > 3:
                if line[1] == 'PRIVMSG':
                    name = parseName(line[0])
                    print("Message by {} in channel {}".format(name, line[2]))

                    if line[2][1:] == CHANNEL:
                        updateUserDataBase(name)

                    currentCommand = getCommand(line[3])
                    currentMessage = line[3]

                    if currentCommand in allCommands and allowed(
                            name, allCommands[currentCommand][1]):
                        allCommands[currentCommand][0](
                            name, line[2], line[4:],
                            allCommands[currentCommand][2])
                    else:
                        for exp in range(0, len(allRegex)):
                            flagString = allRegex[exp][2]['flags']
                            flags = None
                            for f in range(0, len(flagString)):
                                print(flagString[f])
                                if flagString[f] == "m":
                                    if flags == None:
                                        flags = re.MULTILINE
                                    else:
                                        flags = flags | re.MULTILINE
                                if flagString[f] == "i":
                                    if flags == None:
                                        flags = re.IGNORECASE
                                    else:
                                        flags = flags | re.IGNORECASE
                                if flagString[f] == "s":
                                    if flags == None:
                                        flags = re.DOTALL
                                    else:
                                        flags = flags | re.DOTALL
                                if flagString[f] == "u":
                                    if flags == None:
                                        flags = re.UNICODE
                                    else:
                                        flags = flags | re.UNICODE
                            if flags != None:
                                regToTest = re.compile(
                                    allRegex[exp][2]['command'], flags)
                            else:
                                regToTest = re.compile(
                                    allRegex[exp][2]['command'])
                            answer = allRegex[exp][2]['answer']
                            if regToTest.match(currentMessage):
                                writeMessage(answer, line[2])
                    try:
                        print(line)
                    except:
                        print("-----------------------------------")
                        print("---Failed to print user message.---")
                        print("-----------------------------------")
                elif line[3] == '+o':
                    bot_mod.append(line[4])
                    print(line)
                    print("Added " + line[4] + " as a mod!")
                elif line[3] == '-o':
                    # It removes Mods now. Not so hard.
                    bot_mod.remove(line[4])
                    print(line)
                    print("Removed a mod!")
                else:
                    print(line)
            if (line[0] == "PING"):
                s.send(bytes("PONG {}\r\n".format(line[1]), 'UTF-8'))
Exemple #4
0
def receiveData():
    global TIME
    global allCommands
    global bot_mod
    TIME = datetime.now()
    readbuffer = ""

    # allCommands['hello'] = [hello, [], "", False]
    allCommands["soultran"] = [soultran, bot_mod, "", False]
    allCommands["uptime"] = [uptime, [], "", False]
    allCommands["set"] = [setAccount, bot_mod, "", False]
    allCommands["runes"] = [runes, [], "", False]
    allCommands["masteries"] = [masteries, [], "", False]
    allCommands["mastery"] = [masteries, [], "", False]
    allCommands["profile"] = [profile, [], "", False]
    allCommands["rank"] = [rank, [], "", False]
    allCommands["roll"] = [roll, [], "", False]
    allCommands["quote"] = [quote, [], "", False]
    allCommands["fact"] = [fact, [], "", False]
    allCommands["activity"] = [activity, [], "", False]
    allCommands["song"] = [getMusic, [], "", False]
    allCommands["add"] = [addCommand, bot_mod, "", False]
    allCommands["start"] = [start, bot_mod, "", False]
    allCommands["enter"] = [enterGiveaway, [], False]
    allCommands["winner"] = [winner, bot_mod, False]
    allCommands["commands"] = [commandList, [], False]

    loadCustomCommands()

    while 1:
        somebytes = s.recv(1024).decode("UTF-8")
        readbuffer += readbuffer + somebytes
        temp = str.split(readbuffer, "\r\n")
        readbuffer = temp.pop()

        for line in temp:
            line = str.rstrip(line)
            line = str.split(line)

            if len(line) > 3:
                if line[1] == "PRIVMSG":
                    name = parseName(line[0])
                    print("Message by {} in channel {}".format(name, line[2]))

                    if line[2][1:] == CHANNEL:
                        updateUserDataBase(name)

                    currentCommand = getCommand(line[3])

                    if currentCommand in allCommands and allowed(name, allCommands[currentCommand][1]):
                        allCommands[currentCommand][0](name, line[2], line[4:], allCommands[currentCommand][2])

                    try:
                        print(line)
                    except:
                        print("-----------------------------------")
                        print("---Failed to print user message.---")
                        print("-----------------------------------")
                elif line[3] == "+o":
                    bot_mod.append(line[4])
                    print(line)
                    print("Added " + line[4] + " as a mod!")
                elif line[3] == "-o":
                    # It removes Mods now. Not so hard.
                    bot_mod.remove(line[4])
                    print(line)
                    print("Removed a mod!")
                else:
                    print(line)
            if line[0] == "PING":
                s.send(bytes("PONG {}\r\n".format(line[1]), "UTF-8"))
Exemple #5
0
        try:
            s.close()
            t.close()
        except:
            print("Could not end the connection.")
        break
    elif userInput == "save":
        try:
            print(database['names'])
            with open(CHATDATABASE, 'w') as fp:
                json.dump(database, fp)
        except:
            print("Could not save. \n{}".format(sys.exc_info()))
    elif userInput == "load":
        loadCustomCommands()
    elif userInput == "uptime":
        uptime("", "", "")
    elif userInput == "add":
        print("Mod to add?")
        userInput = input()
        bot_mod.append(userInput)
        print("Done adding that mod manually!")
    elif userInput == "join":
        userInput = input()
        s.send(bytes("JOIN #{}\r\n".format(userInput), 'UTF-8'))
    elif userInput[0] == '\\':
        s.send(bytes("{}\r\n".format(userInput[1:-1]), 'UTF-8'))
    else:
        s.send(bytes("PRIVMSG #{} :{}\r\n".format(CHANNEL, userInput),
                     'UTF-8'))