Example #1
0
def receive_sms():
    try:
        msg = {
            "src": sanitize_number(request.values.get('From', None)),
            "dst": sanitize_number(request.values.get('To', None)),
            "text": request.values.get('Text', None)
        }

    except InvalidNumber:
        return make_response("invalid", 406)

    if not (msg["src"] and msg["dst"] and msg["text"]):
        return make_response("missing parameter", 406)

    msg["text"] = msg["text"].strip()

    if not msg["text"]:
        print("\nIgnoring empty text")
        return make_response("empty", 406)

    db = get_db()

    user_type = UserType.from_number(msg["src"],
                                     subscribers=get_subscribers(),
                                     banned=get_banned(),
                                     vetoers=settings.vetoers)
    print("\nReceived SMS from {} ({}) to {}: {}".format(
        msg["src"], user_type.name.lower(), msg["dst"], msg["text"]))

    if user_type is UserType.BANNED:
        print("\nIgnoring banned user {}".format(msg["src"]))
        return responses.queued(msg["src"], msg["dst"])

    if msg["text"].lower() == "unstop":
        if user_type is UserType.UNSUBSCRIBED:
            subscribe(msg["src"])
            return responses.subscribed(msg["src"], msg["dst"])
        return responses.already_subscribed(msg["src"], msg["dst"])

    if msg["text"].lower() in commands.unsubscribe:
        if user_type is UserType.UNSUBSCRIBED:
            return responses.not_subscribed(msg["src"], msg["dst"])
        unsubscribe(msg["src"])
        return responses.unsubscribed(msg["src"], msg["dst"])

    if user_type is not UserType.UNSUBSCRIBED and msg["text"].lower(
    ) in commands.subscribe:
        return responses.already_subscribed(msg["src"], msg["dst"])

    if user_type is UserType.UNSUBSCRIBED and commands.has_subscribe_phrase(
            msg["text"]):
        subscribe(msg["src"])
        return responses.subscribed(msg["src"], msg["dst"])

    if user_type is not UserType.VETOER:
        msgid = enqueue(msg)
        inform(msgid, msg)
        return responses.queued(msg["src"], msg["dst"])

    # VETOER COMMANDS BELOW

    cmd = msg["text"].strip('"').split()
    try:
        if cmd[0].lower() in ("ok", "veto", "ban", "info"):
            msg_requested = db.execute(
                "select src, dst, text from queue where id = ?",
                [cmd[1]]).fetchone()
            if msg_requested is None:
                return responses.nomsg(cmd[1], msg["src"], msg["dst"])

            if cmd[0].lower() == "info":
                return responses.inform(cmd[1], msg_requested["text"],
                                        msg["src"], msg["dst"])

            if cmd[0].lower() == "ok":
                if send_immediately(cmd[1]):
                    return responses.approved(cmd[1], msg["src"], msg["dst"])
                return responses.nomsg(cmd[1], msg["src"], msg["dst"])

            if dequeue(cmd[1]):
                if cmd[0].lower() == "ban":
                    ban(msg_requested["src"])
                    return responses.ban(cmd[1], msg_requested["src"],
                                         msg["src"], msg["dst"])
                return responses.vetoed(cmd[1], msg["src"], msg["dst"])
            return responses.nomsg(cmd[1], msg["src"], msg["dst"])

        if msg["text"].lower() in ("subscribers", "subscribed", "signups",
                                   "sign-ups", "signed up", "signed-up",
                                   "users"):
            return responses.subscribers(msg["src"], len(get_subscribers()),
                                         msg["dst"])

        if msg["text"].lower() == "investigators":
            return responses.vetoers(msg["src"], msg["dst"])

        if cmd[0].lower() == "investigators":
            wallops(" ".join(cmd[1:]), msg["src"], msg["dst"])
            return responses.wallops_ok(msg["src"], msg["dst"])

        if msg["text"].lower() == "queue":
            return responses.queue_status(msg["src"], get_queue(), msg["dst"])

        if msg["text"].lower() in ("banned", "bans"):
            return responses.banned(msg["src"], len(get_banned()), msg["dst"])

        if msg["text"].lower() == "ping":
            return responses.pong(msg["src"], msg["dst"])

    except IndexError:
        return responses.nomsgid(msg["src"], msg["dst"])

    # direct blast message
    blast(msg, from_vetoer=True)
    return responses.thank_you(msg["src"], msg["dst"])
Example #2
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
Example #3
0
def getResp(curItem, userName=None, msgLocalID=None):

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

	if cmd[0] == "hey":				# Say hey
		response = responses.hey(userName)

	elif cmd[0] == "ping":				# Ping Pong Command
		response = responses.ping(userName)

	elif cmd[0] == "dimes" or cmd[0] == "currency":			# Get user balance
		response = responses.dimes(userName, curItem)

	elif cmd[0] == "give":	# Give dimes to a user
		response = responses.give(userName, curItem)

	elif cmd[0] == "ban":	# Ban a user from chatting
		response, banUser = responses.ban(userName, curItem)
		bannedUsers.append(banUser)

		pickle.dump(bannedUsers, open('data/bannedUsers.p', "wb"))

	elif cmd[0] == "unban":	# Unban a user
		response, uBanUser = responses.unban(userName, curItem)
		bannedUsers.remove(uBanUser)

		pickle.dump(bannedUsers, open('data/bannedUsers.p', "wb"))

	elif cmd[0] == "quote": # Get random quote from DB
		response = responses.quote(userName, curItem)

	elif cmd[0] == "tackle":# Tackle a user!
		response = responses.tackle(userName, curItem)

	elif cmd[0] == "slap":	# Slap someone
		response = responses.slap(userName)

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

	elif cmd[0] == "hug":	# Give hugs!
		response = responses.hug(userName, curItem)

	elif cmd[0] == "raid":	# Go raid peoples
		response = responses.raid(userName, curItem)

	elif cmd[0] == "raided":	# You done got raided son!
		response = responses.raided(userName, curItem)

	elif cmd[0] == "twitch":	# Go raid peoples on Twitch.tv!
		response = responses.twitch(userName, curItem)

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

	elif cmd[0] == "command":	# Add command for any users
		response = responses.command(userName, curItem)

	elif cmd[0] == "command+":	# Add mod-only command
		response = responses.commandMod(userName, curItem)

	elif cmd[0] == "command-":	# Remove a command
		response = responses.commandRM(userName, curItem)

	elif cmd[0] == "whitelist":	# Whitelist a user
		if len(cmd) >= 3:	# True means it has something like `add` or `remove`
			if cmd[1] == 'add':
				response = responses.whitelist(userName, curItem)
			elif cmd[1] == 'remove':
				response = responses.whitelistRM(userName, curItem)
			else: 	# Not add or remove
				response = None
		else:		# Just get the whitelist
			response = responses.whitelistLS(userName, curItem)

	elif cmd[0] == "goodbye":	# Turn off the bot correctly
		if is_owner or userName == 'ParadigmShift3d':
			packet = {
				"type":"method",
				"method":"msg",
				"arguments":['See you later my dear sir, wot wot!'],
				"id":msgLocalID
			}

			return packet, True	# Return the Goodbye message packet &
		else:		# Don't want anyone but owner killing the bot
			return None, False
	else:					# Unknown or custom command
		response = responses.custom(userName, curItem)

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

	return response, False 		# Return the response to calling statement