Ejemplo n.º 1
0
def run():
	s = openSocket()
	userListFile = open("userlist.txt", "w")
	joinRoom(s)
	readbuffer = ""

	while True:
		readbuffer = readbuffer + s.recv(1024).decode()
		temp = readbuffer.split("\n")
		readbuffer = temp.pop()
		
		for line in temp:
			print(line)
			if "PING" in line:
				s.send((line.replace("PING", "PONG")+ "\r\n").encode("utf-8"))
				break

			user = getUser(line)
			message = getMessage(line)
			print (user + " typed :" + message)

			#Greet New User
			if isUserNew(user):
				welcomeNewUser(s,user)
				users.append(user)
				userListFile.write(user + " ")
				print(users)
Ejemplo n.º 2
0
Archivo: Run.py Proyecto: kc0zhq/rxbot3
def main():
    global nowplaying, paused
    s = openSocket()
    joinRoom(s)
    readbuffer = ""
    while True:
        try:
            inc = s.recv(1024)
            readbuffer = readbuffer + inc.decode("utf-8")
            temp = readbuffer.split("\n")
            readbuffer = temp.pop()
            for line in temp:
                if "PING" in line:
                    s.send(bytes("PONG :tmi.twitch.tv\r\n".encode("utf-8")))
                else:
                    # All these things break apart the given chat message to make things easier to work with.
                    user = getUser(line)
                    message = str(getMessage(line))
                    command = ((message.split(' ', 1)[0]).lower()).replace("\r", "")
                    cmdarguments = message.replace(command or "\r" or "\n", "")
                    getint(cmdarguments)
                    print(("(" + formatted_time() + ")>> " + user + ": " + message))
                    # Run the commands function
                    runcommand(command, cmdarguments, user)
        except socket.error:
            print("Socket died")
            reconnect()
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.overrideredirect(True)
        self['background'] = 'black'
        self.geometry("+0+20")
        self.attributes("-alpha", 1)

        self.s = openSocket()
        joinRoom(self.s)
        self.readbuffer = ""

        self.questionLabel = tk.Label(self,
                                      text="",
                                      bg="black",
                                      fg="white",
                                      font="HouseSlant-Regular 15",
                                      anchor="w")
        self.questionLabel.pack()

        self.voteA = tk.Label(self,
                              text="",
                              bg="black",
                              fg="white",
                              font="HouseSlant-Regular 30",
                              anchor="w")
        self.voteA.pack()
        self.voteB = tk.Label(self,
                              text="",
                              bg="black",
                              fg="white",
                              font="HouseSlant-Regular 30",
                              anchor="w")
        self.voteB.pack()
        self.voteC = tk.Label(self,
                              text="",
                              bg="black",
                              fg="white",
                              font="HouseSlant-Regular 30",
                              anchor="w")
        self.voteC.pack()

        self.update_tekst()
        self.get_votes()
Ejemplo n.º 4
0
def main():
    s = openSocket()
    joinRoom(s)
    channel = getChannel()
    p = re.compile("!([a-zA-Z]+)") #Setting up pattern to match commands
    cd = getDict() #Dictionary of Commands
    td = {c: 0 for c in cd} #Initializing dictionary of most recent commands
    ld = getLims() #Dictionary of time limits for commands
    followtime = time.time()

    readBuffer, user, message = "", "", "" #Initializing needed variables
    try:
        while True:
            readBuffer = readBuffer + s.recv(1024).decode("UTF-8")
            temp = readBuffer.split("\n")
            readBuffer = temp.pop()
            followtime = checkFollow(s, followtime)

            for line in temp:
                if "PING :tmi.twitch.tv" in line:
                    if "PING :tmi.twitch.tv" == line[:19]:
                        print(line)
                        sysMessage(s, (line.replace("PING", "PONG")))
                    else:
                        sendMessage(s, "Nice try.") #Preventing shennanigans
                else:
                    user = getUser(line)
                    message = getMessage(line)
                    print(user + " typed :" + message)
                    m = p.match(message) #Pattern matching for commands
                    if m:
                        td = recognize(s, m.group(1), cd, td, ld)
                    #Checking if the broadcaster called for the bot to quit
                    if "!quit" in message and user == channel:
                        return
    finally:
        closeSocket(s)
        return
from Socket import openSocket, sendMessage
from Initialize import joinRoom
from Settings import OWNER
import time
from User import users, games
from Time_functions import stopWatch, checkUptime
from Info_functions import getMessage, getUser, Console, checkUser
from Bad_words import timeOut, bad_words
from Commands import checkCommand, commands

s = openSocket()
joinRoom(s)
start = time.time()
readbuffer = ""

while True:

    try:
        readbuffer = s.recv(1024)
        readbuffer = readbuffer.decode()
        temp = readbuffer.split("\n")
        readbuffer = readbuffer.encode()
        readbuffer = temp.pop()
    except:
        temp = ""
    for line in temp:
        if line == "":
            break
        # So twitch doesn't timeout the bot.
        if "PING" in line and Console(line):
            msg = "PONG tmi.twitch.tv\r\n".encode()
Ejemplo n.º 6
0
def chatBot(chan, newjoin):
    lasttip = datetime.datetime.now()
    s = openSocket(chan)
    joinRoom(s, chan, newjoin)
    readbuffer = ""
    close = False

    while close != True:
        lastping = datetime.datetime.now()
        readbuffer = readbuffer + s.recv(1024).decode("UTF-8")
        temp = str.split(readbuffer, "\n")
        readbuffer = temp.pop()
        js = open('users.txt')
        users = json.load(js)
        js.close()

        # User Settings Go Here
        caps = users[chan][0]

        if lasttip < datetime.datetime.now() - datetime.timedelta(hours=1):
            lasttip = datetime.datetime.now()
            commandFROGTip(s, chan, caps)

        for line in temp:
            print(line)
            # reply to IRC PING's so we dont get disconnected
            if "PING" in line:
                s.sendall(bytes("PONG :tmi.twitch.tv\r\n", "UTF-8"))
                lastping = datetime.datetime.now()
                break
            user = getUser(line)
            message = getMessage(line)
            print(user + " typed :" + message)
            #Listen for !frogtip command
            if re.search(r'^!frogtip', message, re.IGNORECASE):
                if lasttip < datetime.datetime.now() - datetime.timedelta(
                        seconds=15):
                    commandFROGTip(s, chan, caps)
                    lasttip = datetime.datetime.now()
                    break
            if re.search(r'^!join', message, re.IGNORECASE):
                print(chan)
                if chan == IDENT.lower():
                    if user not in users:
                        newjoin = True
                        users[user] = [0]
                        sendMessage(
                            s, chan, "Joining " + user +
                            "'s channel. If you would like FROGTips to hop off, type !leave in your channel while FROG is nearby."
                        )
                        joinChannel(user, newjoin)
                        with open('users.txt', 'w') as file:
                            file.write(json.dumps(users))
                            file.close
                    else:
                        sendMessage(
                            s, chan,
                            "FROGTips is already in this channel. Please do not hog FROG"
                        )
                    break
                else:
                    sendMessage(
                        s, chan,
                        "To have FROGTips join your channel, say !join in the chat at https://twitch.tv/frogtips"
                    )
                    break
                break
            if re.search(r'^!leave', message, re.IGNORECASE):
                if chan == user:
                    sendMessage(s, chan, "Leaving " + user + "'s channel. D:")
                    del users[user]
                    print(users)
                    with open('users.txt', 'w') as file:
                        file.write(json.dumps(users))
                        file.close
                    close = True
                else:
                    sendMessage(s, chan,
                                "Hop off, you aren't the channel owner.")
                break
            if re.search(r'^!caps', message, re.IGNORECASE):
                if chan == IDENT.lower():
                    sendMessage(s, chan,
                                "Toggling CAPS in " + user + "'s channel.")
                    print(users[user][0])
                    if users[user][0] == 1:
                        users[user][0] = 0
                        with open('users.txt', 'w') as file:
                            file.write(json.dumps(users))
                            file.close
                    else:
                        users[user][0] = 1
                        with open('users.txt', 'w') as file:
                            file.write(json.dumps(users))
                            file.close
                    break
                break
        time.sleep(0.2)
        if lastping < datetime.datetime.now() - datetime.timedelta(minutes=7):
            chatBot(chan, newjoin)
            close = True
        pass
Ejemplo n.º 7
0
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.'''
import string
import time
from Read import getUser, getMessage
from Socket import openSocket, sendMessage
from Initialize import joinRoom
from Chat_Commands import chatCommands, fileRead
from sys import argv

s = openSocket()
joinRoom(s)
readbuffer = ""

greeting = "hey, hi, hello, greetings"
person = "haylee, chat, friends, guys, all, everyone"
greeting = greeting.split(",")
person = person.split(",")
greeted = []
mods = []
trusted = []
wgreeted = open('Files/Greeted.txt', 'a')
tempWhitelist = []


while True:
	readbuffer = readbuffer + s.recv(1024)
Ejemplo n.º 8
0
from Socket import openSocket,sendMessage
from Initialize import joinRoom
from Funcs import getUserAndMessage, getTime, getDate, getCommands
from datetime import datetime

sock = openSocket()
joinRoom(sock)

readBuffer = ""
while True:
    readBuffer = readBuffer + sock.recv(2048).decode('utf-8')
    temp = readBuffer.split('\n')
    readBuffer = temp.pop()

    for line in temp:
        user, message = getUserAndMessage(line)
        commands = {"!hello\r" : "HeyGuys, @" + user + "! Я - twitchKMBot!",
                    "!clear\r" : "/clear",
                    "!date\r" : getDate(),
                    "!time\r" : getTime(),
                    "!commands\r" : ""}
        commands["!commands\r"] = getCommands(commands)

        print(user + " typed :" + message)

        if message in commands:
            sendMessage(sock, commands[message])

        # отвечает на сообщение Twitch'a 'PING :tmi.twitch.tv', показывая, что бот не АФК
        if line.startswith('PING'):
            sendMessage(sock, "Hey, Twitch! I'm not AFK! SMOrc SMOrc SMOrc")
Ejemplo n.º 9
0
 def __init__(self):
     self.s = openSocket()
     joinRoom(self.s)
Ejemplo n.º 10
0
def reconnect():
    while True:
        if lastping < datetime.datetime.now() - datetime.timedelta(minutes=6):
            joinRoom(s)