Ejemplo n.º 1
0
def info(text="", exactMatch=True):
    global rooms
    global roomName
    text = text.strip().lower()
    results = []
    if text:
        results.extend([name for name in rooms if text in name])
    elif roomName and roomName in rooms:
        text = roomName
        results.append(text)
    else:
        return TinTin.echo("Error!  Room undefined.", "mume")
    if not results:
        TinTin.echo(
            "There aren't any rooms named '%s' in the database." % text,
            "mume")
    else:
        for result in sorted(results):
            exits = []
            for door, direction in rooms[result]:
                if direction:
                    exits.append("%s (%s)" % (direction, door))
                else:
                    exits.append("(%s)" % door)
            TinTin.echo("%s: %s" % (result, ", ".join(exits)), "mume")
Ejemplo n.º 2
0
def add(newDoor="", newDirection=""):
    global rooms
    global roomName
    global validDirections
    currentRoom = roomName
    newDoor = newDoor.strip().lower()
    newDirection = newDirection.strip().lower()
    newDirection = "".join([
        dir for dir in validDirections
        if newDirection and dir.startswith(newDirection)
    ])
    if not currentRoom:
        return TinTin.echo("Error!  Current room undefined.", "mume")
    elif not newDoor or not newDirection:
        return TinTin.echo(
            "Syntax: dadd [door] [%s]" % "|".join(validDirections), "mume")
    elif currentRoom not in rooms:
        rooms[currentRoom] = []
    TinTin.echo(
        "adding the door '%s' located '%s' to '%s'." %
        (newDoor, newDirection, currentRoom), "mume")
    rooms[currentRoom].append([newDoor, newDirection])
    rooms[currentRoom] = list(
        uniq(
            sorted(rooms[currentRoom],
                   key=lambda
                   (door, direction): validDirections.index(direction)
                   if direction in validDirections else 0)))
    save()
Ejemplo n.º 3
0
def mute():
    global muted
    if not mixer:
        return
    muted = muted == False
    if muted:
        stop()
    TinTin.echo("sound %s." % "muted" if muted else "unmuted", "mume")
Ejemplo n.º 4
0
def mute():
	global muted
	if not mixer:
		return
	muted = muted==False
	if muted:
		stop()
	TinTin.echo("sound %s." % "muted" if muted else "unmuted", "mume")
Ejemplo n.º 5
0
def stop(filename=""):
	global sounds
	if not mixer:
		return
	filename = filename.strip()
	if filename:
		if filename in sounds:
			sounds[filename].stop()
			del sounds[filename]
		else:
			TinTin.echo("that sound has not been loaded!", "mume")
	else:
		for sound in sounds:
			sounds[sound].stop()
		sounds.clear()
Ejemplo n.º 6
0
def stop(filename=""):
    global sounds
    if not mixer:
        return
    filename = filename.strip()
    if filename:
        if filename in sounds:
            sounds[filename].stop()
            del sounds[filename]
        else:
            TinTin.echo("that sound has not been loaded!", "mume")
    else:
        for sound in sounds:
            sounds[sound].stop()
        sounds.clear()
Ejemplo n.º 7
0
def add(newDoor="", newDirection=""):
	global rooms
	global roomName
	global validDirections
	currentRoom = roomName
	newDoor = newDoor.strip().lower()
	newDirection = newDirection.strip().lower()
	newDirection = "".join([dir for dir in validDirections if newDirection and dir.startswith(newDirection)])
	if not currentRoom:
		return TinTin.echo("Error!  Current room undefined.", "mume")
	elif not newDoor or not newDirection:
		return TinTin.echo("Syntax: dadd [door] [%s]" % "|".join(validDirections), "mume")
	elif currentRoom not in rooms:
		rooms[currentRoom] = []
	TinTin.echo("adding the door '%s' located '%s' to '%s'." % (newDoor, newDirection, currentRoom), "mume")
	rooms[currentRoom].append([newDoor, newDirection])
	rooms[currentRoom] = list(uniq(sorted(rooms[currentRoom], key=lambda (door, direction): validDirections.index(direction) if direction in validDirections else 0)))
	save()
Ejemplo n.º 8
0
def review(channel, text=""):
	try:
		with open("communication/%s.txt"%channel, "rb") as f:
			data = f.readlines()
	except IOError as e:
		TinTin.echo("%s: '%s'" % (e.strerror, e.filename), "mume")
	text = text.strip()
	if not data:
		output = ["%s log is empty!" % channel.capitalize()]
	elif text.isdigit() and int(text)>=1:
		output = data[-int(text):]
	elif not text.isdigit() and text!="":
		output = [line for line in data if text in line.lower()]
	else:
		output = data[-20:]
	if not output:
		output = ["Nothing found!"]
	for line in output[-100:]:
		TinTin.echo(line.strip(), "mume")
Ejemplo n.º 9
0
def play(filename="", volume="100"):
	global sounds
	filename = filename.strip()
	if muted or not filename or not mixer:
		return
	if not volume.isdigit():
		return TinTin.echo("Invalid volume: only numbers 1-100 are allowed.", "mume")
	volume = int(volume) / 100.0
	path = os.path.join(SOUNDS_DIR, filename)
	if os.path.isdir(path):
		filename = random.choice(os.listdir(path))
		path = os.path.join(path, filename)
	if not filename in sounds:
		if os.path.exists(path):
			sounds[filename] = mixer.Sound(path)
		else:
			return TinTin.echo("No such sound", "mume")
	sounds[filename].set_volume(volume)
	sounds[filename].play()
Ejemplo n.º 10
0
def play(filename="", volume="100"):
    global sounds
    filename = filename.strip()
    if muted or not filename or not mixer:
        return
    if not volume.isdigit():
        return TinTin.echo("Invalid volume: only numbers 1-100 are allowed.",
                           "mume")
    volume = int(volume) / 100.0
    path = os.path.join(SOUNDS_DIR, filename)
    if os.path.isdir(path):
        filename = random.choice(os.listdir(path))
        path = os.path.join(path, filename)
    if not filename in sounds:
        if os.path.exists(path):
            sounds[filename] = mixer.Sound(path)
        else:
            return TinTin.echo("No such sound", "mume")
    sounds[filename].set_volume(volume)
    sounds[filename].play()
Ejemplo n.º 11
0
def info(text="", exactMatch=True):
	global rooms
	global roomName
	text = text.strip().lower()
	results = []
	if text:
		results.extend([name for name in rooms if text in name])
	elif roomName and roomName in rooms:
		text = roomName
		results.append(text)
	else:
		return TinTin.echo("Error!  Room undefined.", "mume")
	if not results:
		TinTin.echo("There aren't any rooms named '%s' in the database." % text, "mume")
	else:
		for result in sorted(results):
			exits = []
			for door, direction in rooms[result]:
				if direction:
					exits.append("%s (%s)" % (direction, door))
				else:
					exits.append("(%s)" % door)
			TinTin.echo("%s: %s" % (result, ", ".join(exits)), "mume")
Ejemplo n.º 12
0
def actionAll(action=""):
	global rooms
	global roomName
	currentRoom = roomName
	if not currentRoom:
		return TinTin.echo("Error!  Current room undefined.", "mume")
	elif currentRoom not in rooms:
		return TinTin.echo("There aren't any rooms named '%s' in the database." % currentRoom, "mume")
	elif not action:
		return TinTin.echo("Error! You must specify an action to perform.", "mume")
	for door, direction in rooms[currentRoom]:
		if direction:
			TinTin.send("%s %s %s" % (action, door, direction), "mume")
		else:
			TinTin.send("%s %s" % (action, door), "mume")
Ejemplo n.º 13
0
def actionAll(action=""):
    global rooms
    global roomName
    currentRoom = roomName
    if not currentRoom:
        return TinTin.echo("Error!  Current room undefined.", "mume")
    elif currentRoom not in rooms:
        return TinTin.echo(
            "There aren't any rooms named '%s' in the database." % currentRoom,
            "mume")
    elif not action:
        return TinTin.echo("Error! You must specify an action to perform.",
                           "mume")
    for door, direction in rooms[currentRoom]:
        if direction:
            TinTin.send("%s %s %s" % (action, door, direction), "mume")
        else:
            TinTin.send("%s %s" % (action, door), "mume")
Ejemplo n.º 14
0
def delete(delDoor="", delDirection=""):
	global rooms
	global roomName
	global validDirections
	currentRoom = roomName
	delDoor = delDoor.strip().lower()
	delDirection = delDirection.strip().lower()
	delDirection = "".join([dir for dir in validDirections+["all"] if delDirection and dir.startswith(delDirection)])
	if not currentRoom:
		return TinTin.echo("Error!  Room is undefined.", "mume")
	elif currentRoom not in rooms:
		return TinTin.echo("Error! The current room isn't in the database.", "mume")
	elif not delDoor or not delDirection:
		return TinTin.echo("Syntax: ddel [door|all] [%s|all]" % "|".join(validDirections), "mume")
	elif delDoor!="all" and delDirection!="all":
		if [delDoor, delDirection] in rooms[currentRoom]:
			TinTin.echo("Deleting '%s' located '%s' from '%s'." % (delDoor, delDirection, currentRoom), "mume")
			rooms[currentRoom].remove([delDoor, delDirection])
		else:
			return TinTin.echo("'%s' does not have any exits to the '%s' with the name '%s'." % (currentRoom, delDirection, delDoor), "mume")
	elif delDirection != "all":
		# Check to see if the current room has any secrets in the given direction.
		if [[door, direction] for door, direction in rooms[currentRoom] if direction == delDirection]:
			TinTin.echo("Deleting all exits '%s' from '%s'." % (delDirection, currentRoom), "mume")
			rooms[currentRoom] = [[door, direction] for door, direction in rooms[currentRoom] if direction != delDirection]
		else:
			return TinTin.echo("'%s' does not have any exits to the '%s'." % (currentRoom, delDirection), "mume")
	elif delDoor != "all":
		# Check to see if the current room has any secret doors with the given name.
		if [[door, direction] for door, direction in rooms[currentRoom] if door == delDoor]:
			TinTin.echo("Deleting all secret doors with the name '%s' from '%s'." % (delDoor, currentRoom), "mume")
			rooms[currentRoom] = [[door, direction] for door, direction in rooms[currentRoom] if door != delDoor]
		else:
			return TinTin.echo("'%s' does not have any secret doors called '%s'." % (currentRoom, delDoor), "mume")
	if delDoor=="all" and delDirection=="all" or not rooms[currentRoom]:
		TinTin.echo("Deleting the room '%s' from the database." % currentRoom, "mume")
		del rooms[currentRoom]
	save()
Ejemplo n.º 15
0
import os.path
import json
from tintin import TinTin

DATABASE_FILE = "data/secret_exits.json"
SAMPLE_DATABASE_FILE = "data/secret_exits.json.sample"

if os.path.exists(DATABASE_FILE):
	if not os.path.isdir(DATABASE_FILE):
		path = DATABASE_FILE
	else:
		TinTin.echo("Error: '%s' is a directory, not a file." % DATABASE_FILE, "python")
elif os.path.exists(SAMPLE_DATABASE_FILE):
	if not os.path.isdir(SAMPLE_DATABASE_FILE):
		path = SAMPLE_DATABASE_FILE
	else:
		TinTin.echo("Error: '%s' is a directory, not a file." % SAMPLE_DATABASE_FILE, "python")
else:
	path = None
	TinTin.echo("Error: neither '%s' nor '%s' can be found." % (DATABASE_FILE, SAMPLE_DATABASE_FILE), "mume")

if not path:
	rooms = {}
else:
	try:
		with open(path, "rb") as data:
			rooms = json.load(data, encoding="UTF-8")
	except IOError as e:
		rooms = {}
		TinTin.echo("%s: '%s'" % (e.strerror, e.filename), "mume")
	except ValueError as e:
Ejemplo n.º 16
0
import os.path
import json
from tintin import TinTin

DATABASE_FILE = "data/secret_exits.json"
SAMPLE_DATABASE_FILE = "data/secret_exits.json.sample"

if os.path.exists(DATABASE_FILE):
    if not os.path.isdir(DATABASE_FILE):
        path = DATABASE_FILE
    else:
        TinTin.echo("Error: '%s' is a directory, not a file." % DATABASE_FILE,
                    "python")
elif os.path.exists(SAMPLE_DATABASE_FILE):
    if not os.path.isdir(SAMPLE_DATABASE_FILE):
        path = SAMPLE_DATABASE_FILE
    else:
        TinTin.echo(
            "Error: '%s' is a directory, not a file." % SAMPLE_DATABASE_FILE,
            "python")
else:
    path = None
    TinTin.echo(
        "Error: neither '%s' nor '%s' can be found." %
        (DATABASE_FILE, SAMPLE_DATABASE_FILE), "mume")

if not path:
    rooms = {}
else:
    try:
        with open(path, "rb") as data:
Ejemplo n.º 17
0
import os
import random

from tintin import TinTin

try:
	from pygame import mixer
except ImportError:
	TinTin.echo("Unable to import pyGame: please make sure it is installed.", "gts")
	mixer = None


SOUNDS_DIR = "sounds"

sounds = {}
muted = False


def play(filename="", volume="100"):
	global sounds
	filename = filename.strip()
	if muted or not filename or not mixer:
		return
	if not volume.isdigit():
		return TinTin.echo("Invalid volume: only numbers 1-100 are allowed.", "mume")
	volume = int(volume) / 100.0
	path = os.path.join(SOUNDS_DIR, filename)
	if os.path.isdir(path):
		filename = random.choice(os.listdir(path))
		path = os.path.join(path, filename)
	if not filename in sounds:
Ejemplo n.º 18
0
import os
import random

from tintin import TinTin

try:
    from pygame import mixer
except ImportError:
    TinTin.echo("Unable to import pyGame: please make sure it is installed.",
                "gts")
    mixer = None

SOUNDS_DIR = "sounds"

sounds = {}
muted = False


def play(filename="", volume="100"):
    global sounds
    filename = filename.strip()
    if muted or not filename or not mixer:
        return
    if not volume.isdigit():
        return TinTin.echo("Invalid volume: only numbers 1-100 are allowed.",
                           "mume")
    volume = int(volume) / 100.0
    path = os.path.join(SOUNDS_DIR, filename)
    if os.path.isdir(path):
        filename = random.choice(os.listdir(path))
        path = os.path.join(path, filename)
Ejemplo n.º 19
0
def delete(delDoor="", delDirection=""):
    global rooms
    global roomName
    global validDirections
    currentRoom = roomName
    delDoor = delDoor.strip().lower()
    delDirection = delDirection.strip().lower()
    delDirection = "".join([
        dir for dir in validDirections + ["all"]
        if delDirection and dir.startswith(delDirection)
    ])
    if not currentRoom:
        return TinTin.echo("Error!  Room is undefined.", "mume")
    elif currentRoom not in rooms:
        return TinTin.echo("Error! The current room isn't in the database.",
                           "mume")
    elif not delDoor or not delDirection:
        return TinTin.echo(
            "Syntax: ddel [door|all] [%s|all]" % "|".join(validDirections),
            "mume")
    elif delDoor != "all" and delDirection != "all":
        if [delDoor, delDirection] in rooms[currentRoom]:
            TinTin.echo(
                "Deleting '%s' located '%s' from '%s'." %
                (delDoor, delDirection, currentRoom), "mume")
            rooms[currentRoom].remove([delDoor, delDirection])
        else:
            return TinTin.echo(
                "'%s' does not have any exits to the '%s' with the name '%s'."
                % (currentRoom, delDirection, delDoor), "mume")
    elif delDirection != "all":
        # Check to see if the current room has any secrets in the given direction.
        if [[door, direction] for door, direction in rooms[currentRoom]
                if direction == delDirection]:
            TinTin.echo(
                "Deleting all exits '%s' from '%s'." %
                (delDirection, currentRoom), "mume")
            rooms[currentRoom] = [[door, direction]
                                  for door, direction in rooms[currentRoom]
                                  if direction != delDirection]
        else:
            return TinTin.echo(
                "'%s' does not have any exits to the '%s'." %
                (currentRoom, delDirection), "mume")
    elif delDoor != "all":
        # Check to see if the current room has any secret doors with the given name.
        if [[door, direction] for door, direction in rooms[currentRoom]
                if door == delDoor]:
            TinTin.echo(
                "Deleting all secret doors with the name '%s' from '%s'." %
                (delDoor, currentRoom), "mume")
            rooms[currentRoom] = [[door, direction]
                                  for door, direction in rooms[currentRoom]
                                  if door != delDoor]
        else:
            return TinTin.echo(
                "'%s' does not have any secret doors called '%s'." %
                (currentRoom, delDoor), "mume")
    if delDoor == "all" and delDirection == "all" or not rooms[currentRoom]:
        TinTin.echo("Deleting the room '%s' from the database." % currentRoom,
                    "mume")
        del rooms[currentRoom]
    save()