First tilde projects commit

This commit is contained in:
Russell 2015-01-02 16:59:08 +00:00
parent 9bcadfc4a7
commit 726861fae6
40 changed files with 20890 additions and 0 deletions

16
Code/irc/formatter.py Normal file
View File

@ -0,0 +1,16 @@
import time
import re
def format_message(message):
pattern = r'^:.*\!~(.*)@.* (.*) (.*) :(.*)'
now = int(time.time())
matches = re.match(pattern, message)
if not matches:
return ''
nick = matches.group(1).strip()
command = matches.group(2).strip()
channel = matches.group(3).strip()
message = matches.group(4).strip()
return "%s\t%s\t%s\t%s\t%s" % (now, nick, command, channel, message)

BIN
Code/irc/formatter.pyc Normal file

Binary file not shown.

12
Code/irc/get_users.py Normal file
View File

@ -0,0 +1,12 @@
# Return a list of users on this system
def get_users():
# thanks, ~dan!
users = []
with open("/etc/passwd", "r") as f:
for line in f:
if "/bin/bash" in line:
u = line.split(":")[0] # Grab all text before first ':'
users.append(u)
return users

BIN
Code/irc/get_users.pyc Normal file

Binary file not shown.

3130
Code/irc/inflect.py Normal file

File diff suppressed because it is too large Load Diff

BIN
Code/irc/inflect.pyc Normal file

Binary file not shown.

65
Code/irc/int2word.py Normal file
View File

@ -0,0 +1,65 @@
# integer number to english word conversion
# can be used for numbers as large as 999 vigintillion
# (vigintillion --> 10 to the power 60)
# tested with Python24 vegaseat 07dec2006
def int2word(n):
"""
convert an integer number n into a string of english words
"""
# break the number into groups of 3 digits using slicing
# each group representing hundred, thousand, million, billion, ...
n3 = []
r1 = ""
# create numeric string
ns = str(n)
for k in range(3, 33, 3):
r = ns[-k:]
q = len(ns) - k
# break if end of ns has been reached
if q < -2:
break
else:
if q >= 0:
n3.append(int(r[:3]))
elif q >= -1:
n3.append(int(r[:2]))
elif q >= -2:
n3.append(int(r[:1]))
r1 = r
#print n3 # test
# break each group of 3 digits into
# ones, tens/twenties, hundreds
# and form a string
nw = ""
for i, x in enumerate(n3):
b1 = x % 10
b2 = (x % 100)//10
b3 = (x % 1000)//100
#print b1, b2, b3 # test
if x == 0:
continue # skip
else:
t = thousands[i]
if b2 == 0:
nw = ones[b1] + t + nw
elif b2 == 1:
nw = tens[b1] + t + nw
elif b2 > 1:
nw = twenties[b2] + ones[b1] + t + nw
if b3 > 0:
nw = ones[b3] + "hundred " + nw
return nw
############# globals ################
ones = ["", "one ","two ","three ","four ", "five ",
"six ","seven ","eight ","nine "]
tens = ["ten ","eleven ","twelve ","thirteen ", "fourteen ",
"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]
twenties = ["","","twenty ","thirty ","forty ",
"fifty ","sixty ","seventy ","eighty ","ninety "]
thousands = ["","thousand ","million ", "billion ", "trillion ",
"quadrillion ", "quintillion ", "sextillion ", "septillion ","octillion ",
"nonillion ", "decillion ", "undecillion ", "duodecillion ", "tredecillion ",
"quattuordecillion ", "sexdecillion ", "septendecillion ", "octodecillion ",
"novemdecillion ", "vigintillion "]

BIN
Code/irc/int2word.pyc Normal file

Binary file not shown.

0
Code/irc/log Normal file
View File

BIN
Code/irc/mentions.pyc Normal file

Binary file not shown.

42
Code/irc/pretty_date.py Normal file
View File

@ -0,0 +1,42 @@
def pretty_date(time=False):
"""
Get a datetime object or a int() Epoch timestamp and return a
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
'just now', etc
"""
from datetime import datetime
now = datetime.now()
if type(time) is int:
diff = now - datetime.fromtimestamp(time)
elif isinstance(time,datetime):
diff = now - time
elif not time:
diff = now - now
second_diff = diff.seconds
day_diff = diff.days
if day_diff < 0:
return ''
if day_diff == 0:
if second_diff < 10:
return "just now"
if second_diff < 60:
return str(second_diff) + " seconds ago"
if second_diff < 120:
return "a minute ago"
if second_diff < 3600:
return str(second_diff / 60) + " minutes ago"
if second_diff < 7200:
return "an hour ago"
if second_diff < 86400:
return str(second_diff / 3600) + " hours ago"
if day_diff == 1:
return "Yesterday"
if day_diff < 7:
return str(day_diff) + " days ago"
if day_diff < 31:
return str(day_diff / 7) + " weeks ago"
if day_diff < 365:
return str(day_diff / 30) + " months ago"
return str(day_diff / 365) + " years ago"

BIN
Code/irc/pretty_date.pyc Normal file

Binary file not shown.

118
Code/irc/quote_bot.py Executable file
View File

@ -0,0 +1,118 @@
#!/usr/bin/python
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries.
import socket
import os
import sys
from optparse import OptionParser
import get_users
import mentions
import formatter
parser = OptionParser()
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
help="the server to connect to", metavar="SERVER")
parser.add_option("-c", "--channel", dest="channel", default='#tildetown',
help="the channel to join", metavar="CHANNEL")
parser.add_option("-n", "--nick", dest="nick", default='quote_bot',
help="the nick to use", metavar="NICK")
(options, args) = parser.parse_args()
def ping():
ircsock.send("PONG :pingis\n")
def sendmsg(chan , msg):
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
def joinchan(chan):
ircsock.send("JOIN "+ chan +"\n")
def hello():
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
def random_quote(channel):
quote = os.popen("/home/frs/quotes/randquote.py").read()
if len(quote) >= 256:
quote = quote[:253] + '...'
ircsock.send("PRIVMSG "+ channel +" :" + quote + "\n")
def haiku(channel):
h = os.popen("haiku").read().replace("\n", " // ")
ircsock.send("PRIVMSG "+ channel +" :" + h + "\n")
def connect(server, channel, botnick):
ircsock.connect((server, 6667))
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")
joinchan(channel)
def get_user_from_message(msg):
try:
i1 = msg.index(':') + 1
i2 = msg.index('!')
return msg[i1:i2]
except ValueError:
return ""
def say_mentions(user, message):
nick = get_user_from_message(message)
menschns = os.popen("/home/karlen/bin/mensch -u %s -t 24 -z +0" % (user)).read().replace("\t", ": ").split("\n")
for mention in menschns:
if not "" == mention:
toSend = "PRIVMSG "+ nick + " :" + mention + "\n"
if len(toSend) >= 256:
toSend = toSend[:253] + '...'
ircsock.send(toSend)
def say_chatty(channel):
chattyOut = os.popen("/home/karlen/bin/chatty").read().split("\n")
for line in chattyOut:
if line:
ircsock.send("PRIVMSG "+ channel + " :" + line + "\n")
def listen():
while 1:
ircmsg = ircsock.recv(2048)
ircmsg = ircmsg.strip('\n\r')
if ircmsg.find("PING :") != -1:
ping()
formatted = formatter.format_message(ircmsg)
if "" == formatted:
continue
print formatted
split = formatted.split("\t")
time = split[0]
user = split[1]
messageText = split[2]
if ircmsg.find(":!quote") != -1:
random_quote(options.channel)
if ircmsg.find(":!mentions") != -1:
say_mentions(user, ircmsg)
if ircmsg.find(":!chatty") != -1:
say_chatty(options.channel)
if ircmsg.find(":!haiku") != -1:
haiku(options.channel)
if ircmsg.find("PING :") != -1:
ping()
sys.stdout.flush()
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect(options.server, options.channel, options.nick)
listen()

217
Code/irc/randomtopics.txt Normal file
View File

@ -0,0 +1,217 @@
What was the last picture you took with your phone?
Do you know any big gossipers?
Have you been pulled over by a cop?
Do you know your heritage?
What have you always wanted? Did you ever get it?
What kind of sickness have you lied about so you wouldn't go to work?
What was the last lie you told?
Have you ever danced in the rain?
What is your blood type?
Have you ever been in a car accident?
What was the weirdest prank call that you have made?
Best compliment you have received?
Do you trust anyone with your life?
What is your greatest strength or weakness?
What is your perfect pizza?
What was your first thought when you woke up this morning
Do you get along with your family? Why or why not?
Ugly and live forever, or attractive and die in a year?
You discover that your wonderful one year old child is because of a mix up at the hospital and not yours. Would you want to exchange the child to correct the mistake?
Would you be willing to lie to a court for a close friend if it meant saving your friend from going to jail for life?
Would you be willing to eat a bowl of crickets for 0,000?
If you could have anyone locked in a room so that you could torment them for a day, whom would you choose ad how would you torment them?
Do you feel that children should be sheltered from unhappiness?
If you could have personally witnessed anything, what would you want to have seen?
If you could wake up tomorrow in the body of someone else, who would you pick and what would you do?
If you could be any age for a week, what age would that be?
What question do you hate to answer?
If you could only have one meal for the rest of your life, what would it be?
Where do you go to get on a computer?
How do you start a conversation?
What keys on a keyboard do you not use?
If you had a brainwashing machine, who would you use it on?
You are walking home in the dark, you see something move. What/Who is it(guess)? What do you do?
What is the strangest name someone has introduced themselves as to you? What is their real name?
Where were you 3 hours ago? Do you think someone was stalking you?
Have you ever eating a crayon, or glue? Or what strange thing have you eaten?
What type of music do you listen to? (Genre, artists, songs?)
What cheers you up?
What do you constantly think about that, either makes you sad or just anything?
Is there something you constantly lose at your hours or anywhere?
Do you have a favorite book or read much? Why or why not?
What is the longest you have gone without sleep?
Do you have anyone you go to for advice? In person or online?
What is the habit you are proudest of breaking or want to break?
Is there anything I should know?
What do you order or not order at a restaurant you have been to or never been to?
What is your favorite word? Least favorite?
Describe something that's happened to you for which had no explanation.
What did you do for your latest birthday?
What holidays do you celebrate? Are you a religious person or not?
If you had to be named after a city, state, or country (etc), which would you want it to be?
Who is your hero?
Which do you use more often, the dictionary or the thesaurus?
Have you ever been stung by a bee?
Have you ever tipped a cow?
What's the sickest you have ever been?
Are you still learning who you are?
Are you afraid of heights? Or what are you afraid of?
Have you ever taken dance lessons? Who would you want to dance with?
What is the most memorable class you have ever taken?
Why?
What's your favorite knock-knock joke?
What is your favorite commercial?
If you could spend the day with any celebrity, who would it be?
What is your favorite breakfast food?
Do you like guacamole? Have you ever been in a food fight?
What is your favorite thing to spend money on?
What is the weirdest thing about you? Are you proud of it?
Ever been in love with 2 people at the same time? Do you think that's wrong?
Ever had any relatives in jail?
Glass half full or half empty? Or is the glass just malformed?
Mountains or the beach? View, or the tv?
Plain, train, or car? Boat, subway, or teleportation device?
If you could retire tomorrow, what would you do?
Ever sold/donated your blood? If you haven't do you want to?
Crowds, small groups, or &#8220;Go away, I'm a loner&#8221;?
Name the most terrifying moment of your life so far. Have you recovered from it?
What famous person do people tell you that you most resemble?
What is the strangest thing you have ever eaten?
If you could bring any person back to life, who would it be?
Do you believe honesty is the best policy?
What dead person would you least want to be haunted by?
Who would you most like to be stuck in an elevator with?
Who would you least like to be .?
What do you think Victoria's secret is?
Which cartoon character do you resemble the most?
Would you rather go a week without bathing, but be able to change your clothes? Or a week without changing your clothes but be able to bathe.
Which of the four seasons do you most love? Or Hate?
If you could choose your method of dying or where, what would they be?
If you had to be trapped in a tv show for a month, which would you choose?
List someone you know, and describe them in 5 words.
You can select one person from history and have them truthfully answer one question, who would you select and what is the question?
If you join the circus, what would you perform?
Is there anything purple within 10 feet of you? What is it?
When was the last time you bought something? What was it?
Are you wearing socks right now?
Have you been to the movies in the last 5 days?
When was the last time you ran/went for a jog?
Your dream vacation? Worst vacation? Best vacation?
Worst injury you have had?
Grab the book nearest to you, turn to page 18, and find line 4.
Stretch your left arm out as far as you can, What can you touch?
Before you started this survey, what were you doing?
What is the last thing you watched on TV?
Without looking, guess what time it is
Now look at the clock. What is the actual time?
With the exception of the computer, what can you hear?
When did you last step outside? What were you doing?
Did you dream last night?
Do you remember your dreams?
When did you last laugh?
Do you remember why / at what?
What is on the walls of the room you are in?
Seen anything weird lately?
What is the last film you saw?
If you could live anywhere in the world, where would you live?
If you became a multi-millionaire overnight, what would you buy?
Tell me something about you that most people don't know.
If you could change one thing about the world, regardless of guilt or politics, what would you do?
Do you like to dance?
Would you ever consider living abroad?
Does your name make any interesting anagrams?
Who made the last incoming call on your phone?
What is the last thing you downloaded onto your computer?
Last time you swam in a pool?
Type of music you like most?
Type of music you dislike most?
Are you listening to music right now?
What color is your bedroom carpet?
If you could change something about your home, without worry about expense or mess, what would you do?
What was the last thing you bought?
Have you ever ridden on a motorbike?
Would you go bungee jumping or sky diving?
Do you have a garden?
Do you really know all the words to your national anthem?
What is the first thing you think of when you wake up in the morning?
If you could eat lunch with one famous person, who would it be?
Who sent the last text message you received?
Which store would you choose to max out your credit card?
What time is bed time?
Have you ever been in a beauty pageant?
How many tattoos do you have?
If you don't have any, have you ever thought of getting one?
What did you do for your last birthday?
Do you carry a donor card?
Who was the last person you ate dinner with?
Is the glass half empty or half full?
What's the farthest-away place you've been?
When's the last time you ate a homegrown tomato?
Have you ever won a trophy?
Are you a good cook?
Do you know how to pump your own gas?
If you could meet any one person (from history or currently alive), who would it be?
Have you ever had to wear a uniform to school?
Do you touch-type?
What's under your bed?
Do you believe in love at first sight?
Think fast, what do you like right now?
Where were you on Valentine's day?
What time do you get up?
What was the name of your first pet?
Who is the second to last person to call you?
Is there anything going on this weekend?
How are you feeling right now?
What do you think about the most?
What time do you get up in the morning?
If you had A Big Win in the Lottery, how long would you wait to tell people?
Who would you tell first?
What is the last movie that you saw at the cinema?
Do you sing in the shower?
Which store would you choose to max out your credit card?
What do you do most when you are bored?
What do you do for a living?
Do you love your job?
What did you want to be when you grew up?
If you could have any job, what would you want to do/be?
Which came first the chicken or the egg?
How many keys on your key ring?
Where would you retire to?
What kind of car do you drive?
What are your best physical features?
What are your best characteristics?
If you could go anywhere in the world on vacation where would you go?
What kind of books do you like to read?
Where would you want to retire to?
What is your favorite time of the day?
Where did you grow up?
How far away from your birthplace do you live now?
What are you reading now?
Are you a morning person or a night owl?
Can you touch your nose with your tongue?
Can you close your eyes and raise your eyebrows?
Do you have pets?
How many rings before you answer the phone?
What is your best childhood memory?
What are some of the different jobs that you have had in your life?
Any new and exciting things that you would like to share?
What is most important in life?
What Inspires You?
How lucky are you and why?
If you were a pizza deliveryman how would you benefit from scissors?
If you could sing one song on American Idol, what would it be?
Are you more of a hunter or a gatherer?
If you were on an island and could only bring 3 things, what would you bring?
If you were a box of cereal, what would you be and why?
Do you believe in Big Foot?
Why is a tennis ball fuzzy?
What is your least favorite thing about humanity?
How honest are you?
If you were 80 years old, what would you tell your children?
You're a new addition to the crayon box, what color would you be and why?
How does the internet work?
If there was a movie produced about your life, who would play you, and why?
What's the color of money?
What was the last gift you gave someone?
What is the funniest thing that has happened to you recently?
Have you ever been on a boat?

3
Code/irc/run.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
nohup ./tilde_bot.py -s 127.0.0.1 -n tilde_bot -c \#bot_test >> log 2>> log &

5
Code/irc/run_topic.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#tildetown >> log 2>> log &
#nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#bot_test >> log 2>> log &
#./topic_bot.py -s 127.0.0.1 -n topic_bot -c \#bot_test

89
Code/irc/tilde_bot.py Executable file
View File

@ -0,0 +1,89 @@
#!/usr/bin/python
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries.
import socket
import os
import sys
from optparse import OptionParser
import get_users
import mentions
import formatter
parser = OptionParser()
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
help="the server to connect to", metavar="SERVER")
parser.add_option("-c", "--channel", dest="channel", default='#bot_test',
help="the channel to join", metavar="CHANNEL")
parser.add_option("-n", "--nick", dest="nick", default='tilde_bot',
help="the nick to use", metavar="NICK")
(options, args) = parser.parse_args()
def ping():
ircsock.send("PONG :pingis\n")
def sendmsg(chan , msg):
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
def joinchan(chan):
ircsock.send("JOIN "+ chan +"\n")
def hello():
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
def tilde(channel, user, time):
#h = os.popen("haiku").read().replace("\n", " // ")
msg = time + ":" + user
print msg
ircsock.send("PRIVMSG "+ channel +" :" + msg + "\n")
def connect(server, channel, botnick):
ircsock.connect((server, 6667))
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")
joinchan(channel)
def get_user_from_message(msg):
try:
i1 = msg.index(':') + 1
i2 = msg.index('!')
return msg[i1:i2]
except ValueError:
return ""
def listen():
while 1:
ircmsg = ircsock.recv(2048)
ircmsg = ircmsg.strip('\n\r')
if ircmsg.find("PING :") != -1:
ping()
formatted = formatter.format_message(ircmsg)
if "" == formatted:
continue
print formatted
split = formatted.split("\t")
time = split[0]
user = split[1]
messageText = split[2]
if ircmsg.find(":!tilde") != -1:
tilde(options.channel, user, time)
if ircmsg.find("PING :") != -1:
ping()
sys.stdout.flush()
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect(options.server, options.channel, options.nick)
listen()

187
Code/irc/topicbot.py Executable file
View File

@ -0,0 +1,187 @@
#!/usr/bin/python
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries.
import socket
import os
import sys
from optparse import OptionParser
import fileinput
import random
import formatter
import get_users
import mentions
import pretty_date
import inflect
parser = OptionParser()
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
help="the server to connect to", metavar="SERVER")
parser.add_option("-c", "--channel", dest="channel", default='#bot_test',
help="the channel to join", metavar="CHANNEL")
parser.add_option("-n", "--nick", dest="nick", default='topicbot',
help="the nick to use", metavar="NICK")
(options, args) = parser.parse_args()
p = inflect.engine()
def ping():
ircsock.send("PONG :pingis\n")
def sendmsg(chan , msg):
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
def joinchan(chan):
ircsock.send("JOIN "+ chan +"\n")
def hello():
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
def get_topic(channel, user, time):
#topic scores are saved as <USER>&^%<GETS SCORE>&^%<SETS SCORE>
with open("topicscores.txt", "r") as scorefile:
scores = scorefile.readlines()
userscore = 1
found = False
with open("topicscores.txt", "w") as scorefile:
for idx,score in enumerate(scores):
data = score.strip("\n").split("&^%")
if(data[0] == user):
found = True
userscore = int(data[1])+1
scores[idx] = data[0] + "&^%" + str(userscore) + "&^%" + data[2] + "\n"
scorefile.writelines(scores)
if(not found):
scorefile.write(user + "&^%1&^%0")
with open("topics_" + channel + ".txt", "r") as topics:
topic = topics.readlines()[-1].strip("\n").split("&^%", 3)
ircsock.send("PRIVMSG "+ channel +" :I've told you " + p.number_to_words(userscore) + " times! It's \"" + topic[2] + "\" (Set by " + topic[1] + " " + pretty_date.pretty_date(int(topic[0])) + ")\n")
def count_topic(channel, user, time, msg):
with open("topics_" + channel + ".txt", "a") as topics:
topics.write(time + "&^%" + user + "&^%" + msg + "\n")
with open("topicscores.txt", "r") as scorefile:
scores = scorefile.readlines()
userscore = 1
found = False
with open("topicscores.txt", "w") as scorefile:
for idx,score in enumerate(scores):
data = score.strip("\n").split("&^%")
if(data[0] == user):
found = True
userscore = int(data[2])+1
scores[idx] = data[0] + "&^%" + data[1] + "&^%" + str(userscore) + "\n"
scorefile.writelines(scores)
if(not found):
scorefile.write(user + "&^%0&^%1")
ircsock.send("PRIVMSG "+ channel +" :" + user + " has changed the topic " + p.number_to_words(userscore) + " times!\n")
def set_topic(channel, user, time, msg):
ircsock.send("TOPIC "+ channel +" :" + msg + "\n")
count_topic(channel, user, time, msg)
def random_topic(channel, user, time):
with open("randomtopics.txt") as rtopics:
msg = random.choice(rtopics.readlines()).strip("\n")
set_topic(channel, user, time, msg)
def rollcall(channel):
ircsock.send("PRIVMSG "+ channel +" :topicbot reporting! I respond to !topic !settopic !randomtopic !thistory\n")
def topic_score():
ircsock.send("PRIVMSG "+ channel +" :Not implemented yet")
def topic_scores():
ircsock.send("PRIVMSG "+ channel +" :Not implemented yet")
def topic_history(channel, user, count):
try:
iCount = int(count.split()[1])
except ValueError:
iCount = 3
if(iCount > 10):
iCount = 10
if(iCount < 1):
iCount = 3
with open("topics_" + channel + ".txt", "r") as topicsfile:
#topics = topicsfile.readlines()[-iCount:].reverse()
ircsock.send("PRIVMSG "+ channel +" :Ok, here were the last " + p.number_to_words(iCount) + " topics\n")
for idx,topic in enumerate(reversed(topicsfile.readlines()[-iCount:])):
topic = topic.strip("\n").split("&^%", 3)
ircsock.send("PRIVMSG "+ channel +" :" + str(idx+1) + ": \"" + topic[2] + "\" (Set by " + topic[1] + " " + pretty_date.pretty_date(int(topic[0])) + ")\n")
def connect(server, channel, botnick):
ircsock.connect((server, 6667))
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")
joinchan(channel)
def get_user_from_message(msg):
try:
i1 = msg.index(':') + 1
i2 = msg.index('!')
return msg[i1:i2]
except ValueError:
return ""
def listen():
while 1:
ircmsg = ircsock.recv(2048)
ircmsg = ircmsg.strip('\n\r')
if ircmsg.find("PING :") != -1:
ping()
formatted = formatter.format_message(ircmsg)
if "" == formatted:
continue
# print formatted
split = formatted.split("\t")
time = split[0]
user = split[1]
command = split[2]
channel = split[3]
messageText = split[4]
if(command == "TOPIC" and user != options.nick):
count_topic(channel,user, time, messageText)
if ircmsg.find(":!topic") != -1:
get_topic(channel, user, time)
if ircmsg.find(":!settopic") != -1:
set_topic(channel, user, time, messageText[10:])
if ircmsg.find(":!tscores") != -1:
topic_scores()
elif ircmsg.find(":!tscores") != -1:
topic_score()
if ircmsg.find(":!randomtopic") != -1:
random_topic(channel, user, time)
if ircmsg.find(":!thistory") != -1:
topic_history(channel, user, messageText)
if ircmsg.find(":!rollcall") != -1:
rollcall(channel)
if ircmsg.find("PING :") != -1:
ping()
sys.stdout.flush()
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect(options.server, options.channel, options.nick)
listen()

0
Code/irc/topics.txt Normal file
View File

5
Code/irc/topicscores.txt Normal file
View File

@ -0,0 +1,5 @@
krowbar&^%20&^%13
um&^%11&^%8
kc&^%0&^%10
marcus&^%3&^%0
khoi&^%1&^%0

1
Code/ruby/.gem Normal file
View File

@ -0,0 +1 @@
gem 'opal'

1
Code/ruby/Grimoire Submodule

@ -0,0 +1 @@
Subproject commit bd995fa5d7a64c179e7c562bb05f75cac67d8036

7
ideas.txt Normal file
View File

@ -0,0 +1,7 @@
TopicBot
- !settopic - sets the current topic
- !topic - prints the current topic
- Saves all topics set from !settopic to a text file along with a timestamp
and who set the topic
- On load, sets the last topic in the topics file as the current topic
- Current topic will time out after X hours (or just display the time)

15
public_html/df/index.html Normal file
View File

@ -0,0 +1,15 @@
<head>
<title>tilde.town ~dorf fortress!!</title>
<style>body{color:white;}</style>
</head>
<body bgcolor="#000" font-color="#fff">
<center>
<img src="http://40.media.tumblr.com/fe7375a3f9a3c169aa70b46791f23251/tumblr_mmni19vFVn1rkg8q5o1_r1_500.png" />
</center>
<p>it's the tilde.town dwarf fortress succession game!</p>
<h2>sign up!!!!</h2>
<p>drop ~jumblesale an email</p>
<p><em>strike the earth!</em></p>
</body>

12
public_html/index.html Normal file
View File

@ -0,0 +1,12 @@
<html>
<head>
<title>WIP</title>
</head>
<body>
<h2>I just clobbered my index.html file</h2>
<h3>New site some time soon</h3>
<ul>
<li><a href="twine2/">Twine 2.0</a></li>
<li><a href="mission/">Mission name generator</a></li>
</ul>
</body>

View File

@ -0,0 +1,5 @@
{
"data1": "foo",
"data2": "bar",
"data3": ["foo","bar","baz"]
};

View File

@ -0,0 +1,15 @@
<html>
<head>
<title>Secret Mission Name Generator</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="./js/lodash.js"></script>
<script src="./js/mission.js"></script>
</head>
<body ng-app="MissionApp">
<div ng-controller="MissionController as m">
<label>Click for a super secret mission name:</label>
<input type="button" ng-click="name = m.getMissionName();" ng-init="name=''" value="Get Mission Name"/>
<div><h3><em>{{name}}</em><h3></div>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
(function(angular) {
'use strict';
angular.module('MissionApp',[]);
function MissionController() {
var self = this;
var adjectives = Array('Bold','Breaking','Brilliant','Crescent','Dark|Darkness','Desert|Desert','Evening|Darkness','Final','First','July','Last','Libery|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Roaring|Roar|Scream','Rolling','Sand','Screaming','Soaring','Standing|Stand','Star|Star','Urgent','Utopian','Valiant');
var nouns = Array('Action','Alert','Beauty','Claw','Darkness','Dawn','Day','Desert','Envy','Fall','Fist','Flight','Fury','Guard','Hammer','Hand','Honor','Hope','Hurricane','Liberty','Light','Lightning','Magic','Morning','October','Power','Rain','Repose','Roar','Scream','Skull','Shield','Stand','Star','Storm','Streak','Sun','Thunder','Wind','Wrath');
var colors = Array('Black','Blue','Brown','Gray','Green','Indego','Orange','Purple','Rainbow','Red','Scarlet','Violet','White','Yellow');
var actors = Array('Condor','Eagle','Guardian','Hawk','Hydra','Lady','Lion','Scorpion','Spartan','Titan','Victor','Viking','Warrior');
var mission_grammars = Array(
{chance:30, grammar: 'adj1 + " " + noun1'},
{chance:10, grammar: 'color + " " + noun1'},
{chance:10, grammar: 'color + " " + actor'},
{chance:10, grammar: 'actor +"\'s " + noun1'},
{chance:10, grammar: 'noun1 + " of the " + noun2'},
{chance:10, grammar: 'noun1 + " of " + noun2'},
{chance:10, grammar: 'adj1 + " " + noun1 + " and " + adj2 + " " + noun2'},
{chance:3, grammar: '"Attack of the " + actors + "s"'}
);
this.getNoun = function(badNouns) {
return _.chain(nouns)
.difference(badNouns)
.sample()
.value();
};
this.getMissionName = function() {
var adj1 = _.sample(adjectives);
var adj2 = _.sample(adjectives);
while(adj1 == adj2)
adj2 = _.sample(adjectives);
var badWords = _.uniq(adj1.split('|').slice(1).concat(adj2.split('|').slice(1)));
var noun1 = self.getNoun(badWords);
var noun2 = self.getNoun(badWords);
while(noun1 == noun2)
noun2 = self.getNoun(badWords);
adj1 = adj1.split('|')[0];
adj2 = adj2.split('|')[0];
var color = _.sample(colors);
var actor = _.sample(actors);
var mission = '';
var rand = Math.floor(Math.random() * 100 + 1);
if(rand <= 25)
mission += 'Operation ';
else if(rand <= 50)
mission += 'Project ';
else if(rand <= 75)
mission += 'Code: ';
var sumChance = _.chain(mission_grammars).pluck('chance').reduce(function(sum, c) { return sum + c;}).value();
rand = Math.floor(Math.random() * sumChance + 1);
for(var gi in mission_grammars) {
var g = mission_grammars[gi];
if(rand > g.chance) {
rand -= g.chance;
}
else {
mission += eval(g.grammar);
return mission;
}
}
return '';
};
};
angular.module('MissionApp').controller('MissionController', [MissionController]);
}(window.angular));

View File

@ -0,0 +1,48 @@
module Mission
@adjectives = []
@nouns = []
@colors = []
@animals = []
@mission_grammars = []
def Mission.get_name()
adj, bad_nouns = get_adj();
noun = get_noun(bad_nouns)
adj2 = adj
noun2 = noun
while adj2[0] == adj[0] || noun2 == noun
adj2, bad_nouns = get_adj();
noun2 = get_noun(bad_nouns)
end
color = get_color()
animal = get_animal()
name = ""
case rand(1..100)
when 1..10
name += "Project "
when 11..20
name += "Operation "
end
total_prob = 0
@mission_grammars.each{|grammar|
grammar[0] = grammar[0].to_i
total_prob += grammar[0]
}
chance = rand(1..total_prob)
@mission_grammars.each{|grammar|
if chance < grammar[0]
name += eval(grammar[1])
break
end
chance -= grammar[0]
}
return name
end
end

3065
public_html/twine/index.html Normal file

File diff suppressed because one or more lines are too long

3065
public_html/twine/test2.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

43
ttitt/krowbar.twee Normal file
View File

@ -0,0 +1,43 @@
:: krowbar-start [start inv]
<<Init>>
<<if visited("krowbar-start") is 1>>Welcome to the adventure!<<endif>>
There is a sealed door on the wall.
<<if not visited("Get McGuffin")>>You see a McGuffin<br><<endif>>\
<<if not visited("Get Coins")>>You see a few coins on the floor<br><<endif>>\
<<actions "Get McGuffin" "Get Coins">>\
<<if $items['McGuffin'] is true>><<actions "Use McGuffin on door">><<endif>>\
<<if visited("Use McGuffin on door")>>[[Go through door|Room2]]<<endif>>
[[PlayerProfile]]
[[Return to Hub|Start]]
:: Get McGuffin
You pick up the McGuffin.
<<set $items['McGuffin'] to true>>
[[Return|previous()]]
:: Get Coins
You find <<$items['gold'] += random(2,5)>> coins
[[Return|previous()]]
:: Use McGuffin on door
You use the McGuffin on the door.
The McGuffin crumbles and the door opens.
<<set $items['McGuffin'] to false>>
[[Return|previous()]]
:: Room2 [inv]
This is room2. There is a cake on the ground.
The door ahead is blocked.
<<actions "Eat cake">>
<<if $stats['strength'] gte 3>>[[Break through the door|Room3]]
<<else>>You are not strong enough to break this door.<<endif>>
::Eat cake
You feel incredibly stronger!
Strength increased to <<$stats['strength'] += 3>>
[[Return|previous()]]
:: Room3 [inv]
Seriously, nothing here.
Return to [[the start|Start]]

168
ttitt/macros.twee Normal file
View File

@ -0,0 +1,168 @@
:: Inventory
<br>
<strong>Inventory:</strong>
<<Inventory>>
:: ShowInventory [script]
try {
version.extensions['Inventory'] = {
major:0, minor:1, revision:0
};
macros['Inventory'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var items = state.history[0].variables.items;
if (items == undefined) {
new Wikifier(place, "nothing");
return;
}
for(var name in items) {
if(!isNaN(parseFloat(items[name])) && isFinite(items[name])) {
msg += name + "(" + items[name] + "), ";
}
else if(items[name] != false) {
msg += name + ", ";
}
};
new Wikifier(place, msg.slice(0,-2));
},
init: function() { },
};
} catch(e) {
throwError(place,"Inventory Setup Error: " + e.message);
}
:: PlayerStats
<br>
<strong>Player Stats:</strong>
<<PlayerStats>>
:: ShowPlayerStats [script]
try {
version.extensions['PlayerStats'] = {
major:0, minor:1, revision:0
};
macros['PlayerStats'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.stats;
if (stats == undefined) {
new Wikifier(place, "no stats");
return;
}
for(var stat in stats) {
if(stat.slice(-4) == "_max") {
continue;
}
msg += stat + ": " + stats[stat];
if(stats[stat+"_max"] != undefined) {
msg += " / " + stats[stat+"_max"];
}
msg += "<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerStats Setup Error: " + e.message);
}
:: PlayerSkills
<br>
<strong>Player Skills:</strong>
<<PlayerSkills>>
:: ShowPlayerSkills [script]
try {
version.extensions['PlayerSkills'] = {
major:0, minor:1, revision:0
};
macros['PlayerSkills'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.skills;
if (stats == undefined) {
new Wikifier(place, "no skills");
return;
}
for(var stat in stats) {
msg += stat + ": " + stats[stat]+"<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerSkills Setup Error: " + e.message);
}
:: PlayerProfile
[[Return|previous()]]
-~-~-~-~-~-
<<display PlayerStats>>
<<display PlayerSkills>>
<<display Inventory>>
:: postrender [script]
postrender.tagInventory = function(place) {
var inv = tale.get("Inventory");
if (inv.id !== undefined && ~this.tags.indexOf("inv")) {
new Wikifier(place, inv.processText());
};
var stats = tale.get("PlayerStats");
if(stats.id !== undefined && ~this.tags.indexOf("stats")) {
new Wikifier(place, stats.processText());
};
var skills = tale.get("PlayerSkills");
if(skills.id !== undefined && ~this.tags.indexOf("skills")) {
new Wikifier(place, skills.processText());
};
}
:: core-init
<<nobr>>
<<set $items = {} >>
<<set $events = {} >>
<<set $stats = {} >>
<<set $stats['health'] to 10 >>
<<set $stats['health_max'] to 10 >>
<<set $stats['mana'] to 5 >>
<<set $stats['mana_max'] to 5 >>
<<set $stats['intelligence'] to 3 >>
<<set $stats['strength'] to 1 >>
<<set $skills = {} >>
<<set $skills['adventuring'] = 2 >>
<<set $items['gold'] to 0 >>
<<endnobr>>
:: GetInit [script]
try {
version.extensions['GetInit'] = {
major:0, minor:1, revision:0
};
macros['Init'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "<<nobr>><<if visited(passage()) eq 1>>";
for(var p in tale.passages) {
/%if(~tale.passages[p].tags.indexOf("init")) {%/
if(p.slice(-5) == "-init") {
msg += "<<display \"" + p + "\">>";
}
}
msg += "<<endif>><<endnobr>>";
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"GetInit Setup Error: " + e.message);
}

185
twine/global.twee Normal file
View File

@ -0,0 +1,185 @@
:: Start
[[Start Adventure|krowbar-start]]
Visited <<print visited("Start")>> times.
<<set $items = {} >>
<<set $events = {} >>
<<set $stats = {} >>
<<set $stats['health'] to 10 >>
<<set $stats['health_max'] to 10 >>
<<set $stats['mana'] to 5 >>
<<set $stats['mana_max'] to 5 >>
<<set $stats['intelligence'] to 3 >>
<<set $stats['strength'] to 1 >>
<<set $skills = {} >>
<<set $skills['adventuring'] = 2 >>
<<set $items['gold'] to 0 >>
:: krowbar-start [start inv]
<<if visited("krowbar-start") is 1>>Welcome to the adventure!<<endif>>
There is a door on the wall.
<<if not visited("Get McGuffin")>>You see a McGuffin<<endif>>
<<if not visited("Get Coins")>>You see a few coins on the floor<<endif>>
<<actions "Get McGuffin" "Get Coins">>\
<<if $items['McGuffin'] is true>><<actions "Use McGuffin on door">><<endif>>\
<<if visited("Use McGuffin on door")>>[[Go through door|Room2]]<<endif>>
[[PlayerProfile]]
<<display "INVALID">>
:: Get McGuffin
You pick up the McGuffin.
<<set $items['McGuffin'] to true>>
[[Return|previous()]]
:: Get Coins
You pick up the coins.
<<set $items['gold'] += 3>>
[[Return|previous()]]
:: Use McGuffin on door
You use the McGuffin on the door.
The McGuffin crumbles and the door opens.
<<set $items['McGuffin'] to false>>
[[Return|previous()]]
:: Room2 [inv]
This is room2. There is a cake on the ground.
The door ahead is blocked.
<<actions "Eat cake">>
<<if $stats['strength'] gte 3>>[[Break through the door|Room3]]
<<else>>You are not strong enough to break this door.<<endif>>
::Eat cake
You feel incredibly stronger!
Strength increased to <<$stats['strength'] += 3>>
[[Return|previous()]]
:: Room3 [inv]
Seriously, nothing here.
:: Inventory
<br>
<strong>Inventory:</strong>
<<Inventory>>
:: ShowInventory [script]
try {
version.extensions['Inventory'] = {
major:0, minor:1, revision:0
};
macros['Inventory'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var items = state.history[0].variables.items;
if (items == undefined) {
new Wikifier(place, "nothing");
return;
}
for(var name in items) {
if(!isNaN(parseFloat(items[name])) && isFinite(items[name])) {
msg += name + "(" + items[name] + "), ";
}
else if(items[name] != false) {
msg += name + ", ";
}
};
new Wikifier(place, msg.slice(0,-2));
},
init: function() { },
};
} catch(e) {
throwError(place,"Inventory Setup Error: " + e.message);
}
:: PlayerStats
<br>
<strong>Player Stats:</strong>
<<PlayerStats>>
:: ShowPlayerStats [script]
try {
version.extensions['PlayerStats'] = {
major:0, minor:1, revision:0
};
macros['PlayerStats'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.stats;
if (stats == undefined) {
new Wikifier(place, "no stats");
return;
}
for(var stat in stats) {
if(stat.slice(-4) == "_max") {
continue;
}
msg += stat + ": " + stats[stat];
if(stats[stat+"_max"] != undefined) {
msg += " / " + stats[stat+"_max"];
}
msg += "<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerStats Setup Error: " + e.message);
}
:: PlayerSkills
<br>
<strong>Player Skills:</strong>
<<PlayerSkills>>
:: ShowPlayerSkills [script]
try {
version.extensions['PlayerSkills'] = {
major:0, minor:1, revision:0
};
macros['PlayerSkills'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.skills;
if (stats == undefined) {
new Wikifier(place, "no skills");
return;
}
for(var stat in stats) {
msg += stat + ": " + stats[stat]+"<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerSkills Setup Error: " + e.message);
}
:: PlayerProfile
[[Return|previous()]]
-~-~-~-~-~-
<<display PlayerStats>>
<<display PlayerSkills>>
<<display Inventory>>
:: postrender [script]
postrender.tagInventory = function(place) {
var inv = tale.get("Inventory");
if (inv.id !== undefined && ~this.tags.indexOf("inv")) {
new Wikifier(place, inv.processText());
};
var stats = tale.get("PlayerStats");
if(stats.id !== undefined && ~this.tags.indexOf("stats")) {
new Wikifier(place, stats.processText());
};
var skills = tale.get("PlayerSkills");
if(skills.id !== undefined && ~this.tags.indexOf("skills")) {
new Wikifier(place, skills.processText());
};
}

174
twine/global.twee.bak Normal file
View File

@ -0,0 +1,174 @@
:: Start
[[Start Adventure|krowbar-start]]
<<set $items = {} >>
<<set $events = {} >>
<<set $stats = {} >>
<<set $stats['health'] to 10 >>
<<set $stats['health_max'] to 10 >>
<<set $stats['mana'] to 5 >>
<<set $stats['mana_max'] to 5 >>
<<set $stats['intelligence'] to 3 >>
<<set $skills = {} >>
<<set $skills['adventuring'] = 2 >>
<<set $items['gold'] to 0 >>
:: krowbar-start [start inv stats skills]
<<if visited("krowbar-start") is 1>>Welcome to the adventure!<<endif>>
There is a door on the wall.
<<if not visited("Get McGuffin")>>You see a McGuffin<<endif>>
<<if not visited("Get Coins")>>You see a few coins on the floor<<endif>>
<<actions "Get McGuffin" "Get Coins">>\
<<if $items['McGuffin'] is true>><<actions "Use McGuffin on door">><<endif>>\
<<if visited("Use McGuffin on door")>>[[Go through door|Room2]]<<endif>>
[[PlayerProfile]]
:: Get McGuffin
You pick up the McGuffin.
<<set $items['McGuffin'] to true>>
[[Return|previous()]]
:: Get Coins
You pick up the coins.
<<set $items['gold'] += 3>>
[[Return|previous()]]
:: Use McGuffin on door
You use the McGuffin on the door.
The McGuffin crumbles and the door opens.
<<set $items['McGuffin'] to false>>
[[Return|previous()]]
:: Room2 [inv]
This is room2. There is nothing here.
[[Go to room3|Room3]]
:: Room3 [inv]
Seriously, nothing here.
:: Inventory
<br>
<strong>Inventory:</strong>
<<Inventory>>
:: ShowInventory [script]
try {
version.extensions['Inventory'] = {
major:0, minor:1, revision:0
};
macros['Inventory'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var items = state.history[0].variables.items;
if (items == undefined) {
new Wikifier(place, "nothing");
return;
}
for(var name in items) {
if(!isNaN(parseFloat(items[name])) && isFinite(items[name])) {
msg += name + "(" + items[name] + "), ";
}
else if(items[name] != false) {
msg += name + ", ";
}
};
new Wikifier(place, msg.slice(0,-2));
},
init: function() { },
};
} catch(e) {
throwError(place,"Inventory Setup Error: " + e.message);
}
:: PlayerStats
<br>
<strong>Player Stats:</strong>
<<PlayerStats>>
:: ShowPlayerStats [script]
try {
version.extensions['PlayerStats'] = {
major:0, minor:1, revision:0
};
macros['PlayerStats'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.stats;
if (stats == undefined) {
new Wikifier(place, "no stats");
return;
}
for(var stat in stats) {
if(stat.slice(-4) == "_max") {
continue;
}
msg += stat + ": " + stats[stat];
if(stats[stat+"_max"] != undefined) {
msg += " / " + stats[stat+"_max"];
}
msg += "<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerStats Setup Error: " + e.message);
}
:: PlayerSkills
<br>
<strong>Player Skills:</strong>
<<PlayerSkills>>
:: ShowPlayerSkills [script]
try {
version.extensions['PlayerSkills'] = {
major:0, minor:1, revision:0
};
macros['PlayerSkills'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.skills;
if (stats == undefined) {
new Wikifier(place, "no skills");
return;
}
for(var stat in stats) {
msg += stat + ": " + stats[stat]+"<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerSkills Setup Error: " + e.message);
}
:: PlayerProfile
[[Return|previous()]]
-~-~-~-~-~-
<<display PlayerStats>>
<<display PlayerSkills>>
<<display Inventory>>
:: postrender [script]
postrender.tagInventory = function(place) {
var inv = tale.get("Inventory");
if (inv.id !== undefined && ~this.tags.indexOf("inv")) {
new Wikifier(place, inv.processText());
};
var stats = tale.get("PlayerStats");
if(stats.id !== undefined && ~this.tags.indexOf("stats")) {
new Wikifier(place, stats.processText());
};
var skills = tale.get("PlayerSkills");
if(skills.id !== undefined && ~this.tags.indexOf("skills")) {
new Wikifier(place, skills.processText());
};
}

194
twine/krowbar.twee Normal file
View File

@ -0,0 +1,194 @@
:: Start
[[krowbar-start]]
:: Set Globals [script]
try {
macros['SetGlobals'] =
{
handler: function(place, macroName, params, parser)
{
},
var gVars = state.history[0].variables;
gVars.items = {};
gVars.items['gold'] = 0;
gVars.events = {};
gVars.stats = {};
gVars.stats['health'] = 10;
gVars.stats['health_max'] = 10;
gVars.stats['strength'] = 1;
gVars.skills = {};
gVars.skills['adventuring'] = 2;
} catch(e) {
console.log("Error during Globals setup: " + e.message);
}
:: krowbar-start [start inv]
<<if visited("krowbar-start") is 1>>Welcome to the adventure!<<endif>>
There is a door on the wall.
<<if not visited("Get McGuffin")>>You see a McGuffin<<endif>>
<<if not visited("Get Coins")>>You see a few coins on the floor<<endif>>
<<actions "Get McGuffin" "Get Coins">>\
<<if $items['McGuffin'] is true>><<actions "Use McGuffin on door">><<endif>>\
<<if visited("Use McGuffin on door")>>[[Go through door|Room2]]<<endif>>
[[PlayerProfile]]
:: Get McGuffin
You pick up the McGuffin.
<<set $items['McGuffin'] to true>>
[[Return|previous()]]
:: Get Coins
You pick up the coins.
<<set $items['gold'] += 3>>
[[Return|previous()]]
:: Use McGuffin on door
You use the McGuffin on the door.
The McGuffin crumbles and the door opens.
<<set $items['McGuffin'] to false>>
[[Return|previous()]]
:: Room2 [inv]
This is room2. There is a cake on the ground.
The door ahead is blocked.
<<actions "Eat cake">>
<<if $stats['strength'] gte 3>>[[Break through the door|Room3]]
<<else>>You are not strong enough to break this door.<<endif>>
::Eat cake
You feel incredibly stronger!
Strength increased to <<$stats['strength'] += 3>>
[[Return|previous()]]
:: Room3 [inv]
Seriously, nothing here.
Return to [[the start|Start]]
:: Inventory
<br>
<strong>Inventory:</strong>
<<Inventory>>
:: ShowInventory [script]
try {
version.extensions['Inventory'] = {
major:0, minor:1, revision:0
};
macros['Inventory'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var items = state.history[0].variables.items;
if (items == undefined) {
new Wikifier(place, "nothing");
return;
}
for(var name in items) {
if(!isNaN(parseFloat(items[name])) && isFinite(items[name])) {
msg += name + "(" + items[name] + "), ";
}
else if(items[name] != false) {
msg += name + ", ";
}
};
new Wikifier(place, msg.slice(0,-2));
},
init: function() { },
};
} catch(e) {
throwError(place,"Inventory Setup Error: " + e.message);
}
:: PlayerStats
<br>
<strong>Player Stats:</strong>
<<PlayerStats>>
:: ShowPlayerStats [script]
try {
version.extensions['PlayerStats'] = {
major:0, minor:1, revision:0
};
macros['PlayerStats'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.stats;
if (stats == undefined) {
new Wikifier(place, "no stats");
return;
}
for(var stat in stats) {
if(stat.slice(-4) == "_max") {
continue;
}
msg += stat + ": " + stats[stat];
if(stats[stat+"_max"] != undefined) {
msg += " / " + stats[stat+"_max"];
}
msg += "<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerStats Setup Error: " + e.message);
}
:: PlayerSkills
<br>
<strong>Player Skills:</strong>
<<PlayerSkills>>
:: ShowPlayerSkills [script]
try {
version.extensions['PlayerSkills'] = {
major:0, minor:1, revision:0
};
macros['PlayerSkills'] =
{
handler: function(place, macroName, params, parser)
{
var msg = "";
var stats = state.history[0].variables.skills;
if (stats == undefined) {
new Wikifier(place, "no skills");
return;
}
for(var stat in stats) {
msg += stat + ": " + stats[stat]+"<br>";
}
new Wikifier(place, msg);
},
init: function() { },
};
} catch(e) {
throwError(place,"PlayerSkills Setup Error: " + e.message);
}
:: PlayerProfile
[[Return|previous()]]
-~-~-~-~-~-
<<display PlayerStats>>
<<display PlayerSkills>>
<<display Inventory>>
:: postrender [script]
postrender.tagInventory = function(place) {
var inv = tale.get("Inventory");
if (inv.id !== undefined && ~this.tags.indexOf("inv")) {
new Wikifier(place, inv.processText());
};
var stats = tale.get("PlayerStats");
if(stats.id !== undefined && ~this.tags.indexOf("stats")) {
new Wikifier(place, stats.processText());
};
var skills = tale.get("PlayerSkills");
if(skills.id !== undefined && ~this.tags.indexOf("skills")) {
new Wikifier(place, skills.processText());
};
}

45
twine/test_visited.twee Normal file
View File

@ -0,0 +1,45 @@
:: Start
<<display "krowbar-start">>
:: krowbar-start [start]
<<set $items = {} >>
<<set $items['gold'] to 5 >>
Here is the start page.
There is a door on the wall.
<<display "item_mcguffin">>
<<if visited("Get McGuffin") and $state_startDoor_isOpen neq true>>
<<actions "Use McGuffin on door">>
<<endif>>
<<if $state_startDoor_isOpen is true>>
[[Go through door|Room2]]
<<endif>>
<<display "Inventory">>
:: item_mcguffin
<<if not visited("Get McGuffin") >>
You see a McGuffin.
<<actions "Get McGuffin">>
<<endif>>
:: Get McGuffin
You pick up the McGuffin.
[[Return|previous()]]
:: Use McGuffin on door
You use the McGuffin on the door.
The McGuffin crumbles and the door opens.
<<set $state_startDoor_isOpen to true>>
[[Return|Start]]
[[Go through door|Room2]]
:: Room2
This is room2. There is nothing here.
[[Go back to the start|Start]]
:: Inventory
Inventory:
<<print $items['gold'] + " gold">>
<<if visited("Get McGuffin")>>
<<print "McGuffin">>
<<endif>>

36
twine/twineGuidelines.txt Normal file
View File

@ -0,0 +1,36 @@
Here are some of my thoughts on our Twine story guidelines
## The Player ##
* Should have global objects for $items, $events, $stats, and $skills that any
story could modify
## Player Inventory ##
* Global inventory items should be of the form
* Per-story inventory items should be of the form
* To pick up an item, use the <<action "Get {item}">>
* To check if a player has already retrieved an item, either check the
* $items['NAME'] value or check "visited("Get NAME")"
* An item can be added to the global items hash with the following
$items['NAME'] = VALUE
* A unique item, like "gearbox" or "sword", will have VALUE of true
* When a unique items is used up or destroyed, set its value to false
* Generic items that the player can have many of, like "gold" or "smallKey",
will have a numerical value
## Player Stats and Skills ##
* Are persistant between stories
* Are stored as
$stat.{name} = {value}
$skill.{name} = {value}
## The Hub ##
* Should heal the player
* Should be able to tell the player their stats/skills
## Rules for all stories ##
* All stories should have a path that leads back to the hub
* Stories can NOT kill the player
** Alternately, we could allow player death to 'port them to the Hub
* Stories should not cause the player to lose or use up global objects
** An exception to this could be gold or money
* Should not decrease a stat or skill