예제 #1
0
def addQuote(user_name, quote_user, split, is_mod, is_owner):

    split = split[2:] # split is set to equal everything after the !quote add/remove

    # The user is the first item after !quote add
    if len(split) == 1:	# It's just a username, anything more indicates an incorrect command
        return usage.prepCmd(user_name, "quote", is_mod, is_owner)

    elif len(split) >= 2:
        # The quote is the second item(s) in the list
        quote = " ".join(split[1:]).replace('"', "''")

        command = '''INSERT INTO quotes
                    (name, quote)
                    VALUES ("{}", "{}")'''.format(quote_user, quote)

        if os.path.exists('data/beambot.sqlite'):
            with sqlite3.connect('data/beambot.sqlite') as con:
                cur = con.cursor()
                cur.execute(command)
                return "Quote #" + str(cur.lastrowid) + " added! " + quote + " - " + quote_user
        else:
            return None

    else:
        return usage.prepCmd(user, "quote", is_mod, is_owner)
예제 #2
0
def set(user_name, user_id, cur_item, is_mod, is_owner):

	if not is_owner:	# Don't want anyone other than the owner running this
		return None

	if len(cur_item) > 2:	# SET SETTINGNAME SETTING

		if cur_item[1] == "currencyName":	# Set the currency name
			config['currency_name'] = cur_item[2]
			response = "Currency name is now " + config['currency_name']

		elif cur_item[1] == "commandTimeout":	# Set the command time-out
			try:
				timeout = int(cur_item[2])
			except:		# If that conversion failed, it's not a clean integer
				return "The command timeout must be an integer (Usage: !set commandTimeout [integer])"

			config['cmd_timeout'] == cur_item[2]

			response = "Command timeout is now " + str(config['cmd_timeout'])

		elif cur_item[1] == "announceEnter":	# Announce user entering
			if cur_item[2].lower() == "true":
				config['announce_enter'] = True
				response = "Users joining the stream will now be announced"
			elif cur_item[2].lower() == "false":
				config['announce_enter'] = False
				response = "Users joining the stream will not be announced"
			else:
				response = "Usage: !set announceEnter [true/false]"

		elif cur_item[1] == "announceLeave":	# Announce user leaving
			if cur_item[2].lower() == "true":
				config['announce_leave'] = True
				response = "Users leaving the stream will now be announced"
			elif cur_item[2].lower() == "false":
				config['announce_leave'] = False
				response = "Users leaving the stream will not be announced"
			else:
				response = "Usage: !set announceLeave [true/false]"

		else:
			return usage.prepCmd(user_name, "set", is_mod, is_owner)

		if os.path.exists('data/config.json'):
			with open('data/config.json', 'w') as f:
				json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))

		return response

	else:
		return usage.prepCmd(user_name, "set", is_mod, is_owner)
예제 #3
0
def tackle(user_name, cur_item, is_mod, is_owner):
	cmd = 'tackle'
	if _checkTime(cmd, user_name, is_mod, is_owner):
			return None

	if len(cur_item[1:].split()) >= 2:
		rand = random.randrange(0, 51)
		if rand >= 45:	# Super rare response!
			return "pybot decides to be a momentary pacifist."
		else:			# Normal response
			rand = random.randrange(0, 31)
			if rand <= 5:
				return "pybot {} {}.".format("tackles", cur_item[1:].split()[1])
			elif rand >= 6 and rand <= 10:
				return "pybot {} {}.".format("clobbers", cur_item[1:].split()[1])
			elif rand >= 11 and rand <= 15:
				return "pybot {} {}.".format("creams", cur_item[1:].split()[1])
			elif rand >= 16 and rand <= 20:
				return "pybot {} {}.".format("wallops", cur_item[1:].split()[1])
			elif rand >= 21 and rand <= 25:
				return "pybot {} {}.".format("bashes", cur_item[1:].split()[1])
			elif rand >= 26 and rand <= 31:
				return "pybot {} {}.".format("besets", cur_item[1:].split()[1])
			else:
				return "pybot {} {}.".format("tackles", cur_item[1:].split()[1])

	else:		# Too short, no user supplied
		return usage.prepCmd(user_name, "tackle", is_mod, is_owner)
예제 #4
0
def give(user_name, cur_item, is_mod, is_owner):

    split = cur_item[1:].split()

    if len(split) >= 3:
        user_recv = split[1]    # User recieving dimes
        if user_recv[0] == '@':
            user_recv = user_recv[1:]           # Remove the @ character
            try:    # Try to convert argument to int type
                num_send = int(split[2])    # Number of dimes being transferred
            except: # Oops! User didn't provide an integer
                return usage.prepCmd(user_name, "give", is_mod, is_owner)

        con = _returnCon()
        if con != False:
            results = _returnCurrency(user_recv)

            if len(results) >= 1:   # Check if the user recieving exists in the database
                recv_currency_original = results[0][0]  # The recieving user's current # of currency

                results = _returnCurrency(user_name)

                if len(results) >= 1:   # Check if the user sending exists in database
                    send_currency_original = results[0][0]  # The sending user's current # of currency

                    if num_send <= send_currency_original and num_send > 0: # Make sure the sending user has enough dimes & it's not 0 or negative

                        user_recv_dimes = int(recv_currency_original) + int(num_send)
                        user_send_dimes = int(send_currency_original) - int(num_send)

                        _updateCurrency(user_recv, user_recv_dimes)
                        _updateCurrency(user_name, user_send_dimes)

                        return "@ {} now has {} {} !".format(user_recv, str(user_recv_dimes), config['currency_name'])

                    else:
                        return None         # Sending user lacks enough currency to send

                else:       # User not in dimes database
                    _addName(user_recv)

                    return "@ {} now has {} {} !".format(user_recv, str(num_send), config['currency_name'])
        else:
            return None
    else:
        return usage.prepCmd(user_name, "give", is_mod, is_owner)
예제 #5
0
def schedule(user_name, cur_item, is_mod, is_owner, websocket):
	cmd = "schedule"

	if not is_mod or not is_owner:
		return None 	# Mod/owner only

	if len(cur_item) < 3:
		return usage.prepCmd(user_name, "schedule", is_mod, is_owner)

	cmd_cmd = cur_item[1]

	if cmd_cmd.lower() == "add":
		if len(cur_item) >= 3:
			text = cur_item[2:]
			response = schedule_mod.register(text, websocket)
		else:
			 return "Usage: !schedule add MESSAGEHERE"

	elif cmd_cmd.lower() == "remove":
		try:
			schedule_id = int(cur_item[2])
		except:
			return "Usage: !schedule remove MESSAGEIDHERE"

		response = schedule_mod.msg_rm(schedule_id, websocket)

	elif cmd_cmd.lower() == "update":
		try:
			schedule_id = int(cur_item[2])
		except:
			return "Usage: !schedule update MESSAGEIDHERE MESSAGETEXTHERE"

		if len(cur_item) >= 3:
			text = cur_item[3:]
			response = schedule_mod.edit_msg(text, schedule_id, websocket)
		else:
			return "Usage: !schedule update MESSAGEIDHERE MESSAGETEXTHERE"
	else:
		return usage.prepCmd(user_name, "schedule", is_mod, is_owner)

	return response
예제 #6
0
def ban(user_name, cur_item, is_mod, is_owner):
	if is_mod or is_owner:		# Only want mods/owners to have ban control
		if len(cur_item[1:].split()) >= 2:	# Make sure we have username to ban
			ban_user = cur_item[1:].split()[1]
			if ban_user[0] == "@":
				ban_user = ban_user[1:]	# Remove the @ character
			return ban_user + " has been chatbanned!", ban_user

		else:	# Wrong # of args
			ban_user = ""
			return usage.prepCmd(user_name, "ban", is_mod, is_owner), ban_user
	else:			# Not mod/owner
		return None
예제 #7
0
def removeQuote(user, split, is_mod, is_owner):

    if len(split) == 1:	# It's just a username, anything more indicates an incorrect command
        return usage.prepCmd(user, "quote", is_mod, is_owner)

    elif len(split) >= 2:
        quote_id = split[2]

        command = """DELETE FROM quotes
                        WHERE id LIKE {}""".format(quote_id)

        if os.path.exists('data/beambot.sqlite'):
            with sqlite3.connect('data/beambot.sqlite') as con:
                cur = con.cursor()
                cur.execute(command)

                if cur.rowcount >= 1:
                    return "Quote #" + str(quote_id) + " removed."
        else:
            return None

    else:
        return usage.prepCmd(user, "quote", is_mod, is_owner)
예제 #8
0
def store(user_name, cur_item, is_mod, is_owner):
	cmd = "store"

	if _checkTime(cmd, user_name, is_mod, is_owner):
		return None

	if is_mod or is_owner:
		if len(cur_item) >= 2:
			if cur_item[1] == "add" or cur_item[1] == "remove" or cur_item[1] == "edit":
				return store_mod.storeEdit(user_name, cur_item, is_mod, is_owner)
			else:
				return usage.prepCmd(user_name, "store", is_mod, is_owner)

	return store_mod.storeList(user_name, is_mod, is_owner)
예제 #9
0
def hug(user_name, cur_item, is_mod, is_owner):
	cmd = 'hug'

	if _checkTime(cmd, user_name, is_mod, is_owner):		# if _checkTime() returns True then the command is on timeout, return nothing
		return None

	if len(cur_item[1:].split()) >= 2:

		hugUser = cur_item[1:].split()[1]

		return "{} gives a great big hug to {}! <3".format(user_name, hugUser)

	else:	# Wrong # of args
		return usage.prepCmd(user_name, "hug", is_mod, is_owner)
예제 #10
0
def unban(user_name, cur_item, is_mod, is_owner):
	if is_mod or is_owner:		# Only want mods/owners to have ban control

		if len(cur_item[1:].split()) >= 2:
			uban_user = cur_item[1:].split()[1]
			if uban_user[0] == "@":
				uban_user = ban_user[1:]	# Remove the @ character

			return uban_user + " has been un-banned!", uban_user

		else:	# Wrong # of args
			uban_user = ""
			return usage.prepCmd(user_name, "unban", is_mod, is_owner), uban_user
	else:			# Not owner/mod
		return None
예제 #11
0
def raid(user_name, cur_item, is_mod, is_owner):
	cmd = 'raid'

	if is_mod or is_owner:	# Check if mod or owner
		split = cur_item[1:].split()
		if len(split) >= 2:
			raid = split[1]
			if raid[0] == "@":
				raid = raid[1:]	# Remove the @ character
			return "Stream's over everyone!"\
					" Thanks for stopping by, let's go raid @{} at beam.pro/{}!".format(raid, raid)

		else:		# Wrong # of args
			return usage.prepCmd(user_name, "raid", is_mod, is_owner)

	else:
		return None
예제 #12
0
def raided(user_name, cur_item, is_mod, is_owner):
	cmd = 'raided'

	if not is_mod or not is_owner:	# Check if user is owner/mod
		return None

	split = cur_item[1:].split()
	print ("responses637:\t",split)
	if len(split) >= 2:
		raid = split[1]
		if raid[0] == "@":
			return "Thank you so much {} for the raid!"\
				" Everyone go give them some love at beam.pro/{}!".format(raid, raid)
		else:
			return "Thank you so much @{} for the raid!"\
				" Everyone go give them some love at beam.pro/{}!".format(raid, raid)

	else:		# Wrong # of args
		return usage.prepCmd(user_name, "raided", is_mod, is_owner)
예제 #13
0
def blame(user_name, cur_item, is_mod, is_owner):
	cmd = "blame"

	if _checkTime(cmd, user_name, is_mod, is_owner):
		return None
	else:
		print ('cur_item:\t',cur_item[1:])
		if len(cur_item[1:]) > 5:
			if cur_item[1:][5] == " ":		# Is it a space?

				if cur_item[1:][6] == "@":	# Is it an @USERNAME?
					return cur_item[7:] + " has been duly blamed! " + cur_item[7:] + \
							" you have been blamed!"
				else:			# Nope, add the @ symbol
					return cur_item[6:] + " has been duly blamed! @" + cur_item[7:] + \
							" you have been blamed!"
			else:				# Nope, take the 6th character onward
				return cur_item[6:] + " has been duly blamed! @" + cur_item[6:] + \
						" you have been blamed!"

		else:	# It's too short to include anyone to blame, so return usage
			return usage.prepCmd(user_name, cmd, is_mod, is_owner)
예제 #14
0
def storeBuy(user_name, cur_item, is_mod, is_owner):
    from responses import give

    if len(cur_item) >= 2:
        cur_item = cur_item[1:]     # Make it just the arguments, remove the command string
    else:
        return usage.prepCmd(user_name, "buy", is_mod, is_owner)

    store_items = _updateStore()
    config = _updateConfig()

    for item in store_items:
        if cur_item[0].lower() == item["title"]:    # It matches an item in the store
            with sqlite3.connect('data/beambot.sqlite') as con:
                cur = con.cursor()

                command = '''SELECT gears
                            FROM gears
                            WHERE name LIKE \"%''' + user_name + '%\"'''

                cur.execute(command)

                results = cur.fetchall()

                if len(results) >= 1:
                    user_currency = int(results[0][0])
                    if user_currency >= item["cost"]:  # Does the user have enough currency?
                        new_currency = user_currency - item["cost"]

                        command = '''UPDATE gears
                                    SET gears={}
                                    WHERE name="{}"'''.format(new_currency, user_name)

                        cur.execute(command)

                        return item["description"]

                return "Not enough " + config["currency_name"]
예제 #15
0
def commandMod(user_name, cur_item, is_mod, is_owner):		# Command available to mods only

	global cust_commands

	if is_mod or is_owner:	# Make sure the user is a mod or streamer
		split = cur_item[1:].split()
		if len(split) >= 2:
			command = split[2]
			response = " ".join(split[3:])

			print ('response:\t',response)

			newCMD = {
				'cmd':command,
				'op':'True',
				'response':response
			}

			# Check for duplicates
			for cmd in cust_commands:
				if cmd["cmd"] == newCMD["cmd"]:
					return None

			cust_commands.append(newCMD)

			print ('cust_commands:\t',json.dumps(cust_commands))

			with open('data/commands{}.json'.format(config['CHANNEL']), 'w') as f:
				f.write(json.dumps(cust_commands))		# Update the stored JSON file

			return 'Command \'' + newCMD['cmd'] + '\' created! ' + newCMD['response']

		response = usage.prepCmd(user, "command+", is_mod, is_owner) # Return None because the command lacks a response
		return response

	else:
		return None		# Not mod or owner
예제 #16
0
def getResp(cur_item, user_name=None, user_id=None, msg_local_id=None, is_mod=False, is_owner=False, websocket=None):

	goodbye = False

	config = _updateConfig()

	# ----------------------------------------------------------
	# Commands
	# ----------------------------------------------------------
	cmd = cur_item[1:].split()

	if len(cmd) < 1:
		return None, False	# It's a single "!" character, so return None (not a command)

	if cmd[0][0:5] == "blame":	# Blame a user
		response = responses.blame(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "commands":		# Get list of commands
		response = responses.cmdList(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "hey":				# Say hey
		response = responses.hey(user_name, is_mod, is_owner)

	elif cmd[0] == "ping":				# Ping Pong Command
		response = responses.ping(user_name, is_mod, is_owner)

	elif (cmd[0] == config["currency_name"] or
		cmd[0] == config["currency_cmd"] or
	 	cmd[0] == "currency"):			# Get user balance
		currency_ret, user = responses.dimes(user_name, cur_item, is_mod, is_owner)

		if currency_ret != False or currency_ret != None:
			response = "@" + user + " has " + currency_ret + " " + config['currency_name'] + "!"
		else:
			response = "@" + user + " has no " + config['currency_name'] + "! :o"

	elif cmd[0] == "give":	# Give dimes to a user
		response = responses.give(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "ban":	# Ban a user from chatting
		response, banUser = responses.ban(user_name, cur_item, is_mod, is_owner)
		if banUser != "":
			bannedUsers.append(banUser)

		print ("bannedUsers",bannedUsers)

		pickle.dump(bannedUsers, open('data/bannedUsers{}.p'.format(config['CHANNEL']), "wb"))

	elif cmd[0] == "unban":	# Unban a user
		response, uBanUser = responses.unban(user_name, cur_item, is_mod, is_owner)
		if uBanUser != "":
			bannedUsers.remove(uBanUser)

		print ("bannedUsers",bannedUsers)

		pickle.dump(bannedUsers, open('data/bannedUsers{}.p'.format(config['CHANNEL']), "wb"))

	elif cmd[0] == "quote":	# Get random quote from DB
		response = responses.quote(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "tackle":# Tackle a user!
		response = responses.tackle(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "slap":	# Slap someone
		response = responses.slap(user_name, is_mod, is_owner)

	elif cmd[0] == "set":	# Bot configuration - Uses cmd instead of cur_item
		response = responses.set(user_name, user_id, cmd, is_mod, is_owner)

	elif cmd[0] == "schedule":	# Run commands at set intervals
		response = responses.schedule(user_name, cmd, is_mod, is_owner, websocket)

	elif cmd[0] == "store":		# List the items for sale
		response = responses.store(user_name, cmd, is_mod, is_owner)

	elif cmd[0] == "buy":		# Buy something from store using currency
		response = responses.store_buy(user_name, cmd, is_mod, is_owner)

	elif cmd[0] == "uptime":# Bot uptime
		response = responses.uptime(user_name, initTime, is_mod, is_owner)

	elif cmd[0] == "hug":	# Give hugs!
		response = responses.hug(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "raid":	# Go raid peoples
		response = responses.raid(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "raided":	# You done got raided son!
		response = responses.raided(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "twitch":	# Go raid peoples on Twitch.tv!
		response = responses.twitch(user_name, cur_item, is_mod, is_owner)

	elif cmd[0] == "whoami":	# Who am I? I'M A GOAT. DUH.
		response = responses.whoami(user_name, is_mod, is_owner)

	elif cmd[0] == "command":	# Add command for any users
		if len(cmd) <= 2:	# It's not long enough to have a response
			return usage.prepCmd(user_name, "command", is_mod, is_owner), False

		if cmd[1] == "add":
			response = responses.command(user_name, cur_item, is_mod, is_owner)
		elif cmd[1] == "remove":
			response = responses.commandRM(user_name, cur_item, is_mod, is_owner)
		elif cmd[1] == "update":
			response = responses.editCommand(user_name, cur_item, is_mod, is_owner, is_mod_only=False)
		else:					# Not add or remove, return usage
			response = usage.prepCmd(user_name, "command", is_mod, is_owner)

	elif cmd[0] == "command+":	# Add mod-only command
		if len(cmd) <= 2:	# It's not long enough to have a response
			return usage.prepCmd(user_name, "command", is_mod, is_owner), False

		if cmd[1] == "add":
			response = responses.commandMod(user_name, cur_item, is_mod, is_owner)
		elif cmd[1] == "remove":
			response = responses.commandRM(user_name, cur_item, is_mod, is_owner)
		elif cmd[1] == "update":
			response = responses.editCommand(user_name, cur_item, is_mod, is_owner, is_mod_only=True)
		else:					# Not add or remove, return usage
			response = usage.prepCmd(user_name, "command+", is_mod, is_owner)

	elif cmd[0] == "goodbye":	# Turn off the bot correctly
		return control.goodbye(user_name, is_owner, msg_local_id)

	else:					# Unknown or custom command
		response = responses.custom(user_name, cur_item, is_mod, is_owner)

	print ('command:\t',cmd,'\n',
		'response:\t',response,'\n')	# Console logging

	return response, False 		# Return the response to calling statement
예제 #17
0
def quote(user_name, cur_item, is_mod, is_owner):
	cmd = 'quote'

	"""
	If _checkTime() returns True then the command is on timeout, return nothing
	also, if the user is mod or streamer then just let them run it as much as
	they want.
	"""
	if _checkTime(cmd, user_name, is_mod, is_owner):
			return None

	split = cur_item[1:].split()

	if len(split) == 1:		# It's just 1 string, get random quote
		command = '''SELECT name
					FROM quotes'''

		with sqlite3.connect('data/beambot.sqlite') as con:
			cur = con.cursor()

			cur.execute(command)

			results = cur.fetchall()

			if len(results) < 1:
				return None
			else:
				rand = random.randrange(len(results))

			user = results[rand][0]

	elif len(split) == 2:		# If it's just 2 strings, get quote for user
		user = split[1]		# Set the user to be the second string

		if user[0] == "@":	# The first character is the @ character - remove that
			user = user[1:]

		# This code checks if it's someone failing at the !quote command
		elif user == "add" or user == "remove" or user == "update":
			return usage.prepCmd(user_name, "quote", is_mod, is_owner)

	elif len(split) >= 3:		# It's add/remove quote
		if is_mod or is_owner:

			cmd_cmd = split[1]

			if cmd_cmd == "add" or cmd_cmd == "remove":

				quote_user = split[2]

				if quote_user[0] == '@':
					quote_user = quote_user[1:]	# Remove the @ sign, we work without them

				if cmd_cmd == "add":
					response = quotes.addQuote(user_name, quote_user, split, is_mod, is_owner)
					return response

				elif cmd_cmd == "remove":
					response = quotes.removeQuote(user_name, split, is_mod, is_owner)
					return response

		else:
			return None

	else:
		return usage.prepCmd(user_name, "quote", is_mod, is_owner)

	with sqlite3.connect('data/beambot.sqlite') as con:
		cur = con.cursor()

		command = '''SELECT quote, id
					FROM quotes
					WHERE name LIKE \"%''' + user + '%\"'''

		cur.execute(command)

		results = cur.fetchall()

		print ("results:\t\t",results)

	if len(results) >= 1:	# Make sure there's at least 1 quote
		rand = random.randrange(len(results))

		quote = results[rand][0]
		quote_id = results[rand][1]

		response = quote + " - " + user

		return response

	else:		# No quotes in the database for user!
		return "Oh noes! There are no quotes :( Try adding some via !quote add!"
예제 #18
0
def storeEdit(user_name, cur_item, is_mod, is_owner):
    store_items = _updateStore()

    if cur_item[1] == "add":
        if len(cur_item[1:]) >= 4:  # Requires item title + cost + description
            title = cur_item[2]
            try:
                cost = int(cur_item[3])
            except:
                return usage.prepCmd(user_name, "store", is_mod, is_owner)

            description = " ".join(cur_item[4:])
            item_add = {
                "title":title,
                "cost":cost,
                "description":description
                }

            store_items.append(item_add)

            if _dumpStore(store_items):
                return "Store item " + title + " added. It will cost " + str(cost) + " " + config["currency_name"]
            else:
                print ("Store item addition failed, store JSON file missing!")
                return None
        else:
            return usage.prepCmd(user_name, "store", is_mod, is_owner)

    elif cur_item[1] == "remove":
        if len(cur_item[1:]) >= 2:
            store_items[:] = [item for item in store_items if item["title"] != cur_item[2].lower()]
            if _dumpStore(store_items):
                return "Store item {} removed".format(cur_item[2])
            else:
                print ("Store item removal failed, store JSON file missing!")
                return None
        else:
            return usage.prepCmd(user_name, "store", is_mod, is_owner)

    elif cur_item[1] == "edit":
        if len(cur_item[1:]) >= 4:  # Requires item title + cost + description
            for item in store_items:
                if item["title"] == cur_item[2].lower():
                    try:
                        item["cost"] = int(cur_item[3])
                    except:
                        return usage.prepCmd(user_name, "store", is_mod, is_owner)

                    item["description"] = " ".join(cur_item[4:])
                    break

            if _dumpStore(store_items):
                return "Store item {} updated! Cost: {}".format(cur_item[2], cur_item[3])
            else:
                print ("Store item editing failed, store JSON file is missing!")
                return None

        else:
            return usage.prepCmd(user_name, "store", is_mod, is_owner)

    else:
        return usage.prepCmd(user_name, "store", is_mod, is_owner)