Guest User

Untitled

a guest
Nov 25th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.37 KB | None | 0 0
  1. import sys, socket, threading, urllib, os, random, time, random, md5, json
  2. readbuffer = ''
  3. step = 0
  4. channel = '#adventure'
  5. username = 'AdventureGame'
  6.  
  7.  
  8.  
  9.  
  10. colours = ['red','orange','yellow','green','blue','indigo','violet']
  11. materials = ['wooden','steel','stone']
  12.  
  13. motions = ['walks','runs','skips','dances','rolls']
  14.  
  15. heights = ['tall','average','short']
  16. builds = ['stocky','fat','medium']
  17. skins = ['dark','fair','light']
  18. sexs = ['male','female','guy','man','shiela','bloke','dude','girl','woman']
  19. eyes = ['hazel','blue','green','red','black']
  20. hairs = ['blond','black','brunet','ginga']
  21.  
  22. entrances = ['door','tunnle','hole']
  23. locations = ['cave','hall','room','forest','store']
  24.  
  25. adjectives = ['small','huge','massive','cold','dark','scary','empty','empty','stone']
  26.  
  27. weapons = ['hammer','rusty knife','blunt sword','axe']
  28. objects = ['spoon','key','map','compas','torch','pick']
  29.  
  30.  
  31.  
  32. def encrypt(string):
  33.     return md5.new(string).digest()
  34.  
  35. def IRCUser(line):
  36.     '''splits a list to give just a user'''
  37.     return line[0].split(':')[1].split('!')[0]
  38.  
  39. s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
  40.  
  41. def randArray(array):
  42.     length = (len(array))-1
  43.     randInt = random.randint(0, length)
  44.     return array[randInt]
  45.  
  46. def generateScenario():
  47.     location = randArray(locations)
  48.     adjective = randArray(adjectives)
  49.     weapon = randArray(weapons)
  50.     object_ = randArray(objects)
  51.     character = generateCharacter()
  52.     exit = randArray(entrances)
  53.     motion = randArray(motions)
  54.     return 'You are in a '+adjective+' ' +location+'. You have a '+weapon+' and a '+object_ +'. A '+character+' '+motion+' towards you... You see a '+exit +' to your left.'
  55.  
  56. def generateCharacter():
  57.     height = randArray(heights)
  58.     skin = randArray(skins)
  59.     hair = randArray(hairs)
  60.     eye = randArray(eyes)
  61.     build = randArray(builds)
  62.     return '{"hair":"'+hair+'","eyes":"'+eye+'","skin":"'+skin+'","height":"'+height+'","build":"'+build+'"}'
  63.  
  64. def sendToChannel(message):
  65.     s.send('PRIVMSG '+channel+' '+message+'\r\n')
  66. def checkExistingUser(username):
  67.     return False
  68. print('Attempting to connect...')
  69. try:
  70.     s.connect( ('irc.minecraft.co.nz',6667) )
  71.     s.send('NICK '+username+'\r\n')
  72.     s.send('USER '+username+' '+username+' '+username+' :TTOBOT\r\n' )
  73.  
  74. except:
  75.     print('Failed to connect.', sys.exc_info() )
  76.  
  77. class user():
  78.     def create(blank):
  79.     username = IRCUser(line)
  80.     password = encrypt(line[4])
  81.     filename = "users/"+IRCUser(line)+".dat"
  82.     character = generateCharacter()
  83.     FILE = open(filename,"w")
  84.     FILE.write("username="+username+'\r\n')
  85.     FILE.write('password='+password+'\r\n')
  86.     FILE.write('character='+character+'\r\n')
  87.     FILE.close()
  88.     def getCharacter(blank):
  89.     username = IRCUser(line)
  90.     filename = "users/"+username+".dat"
  91.     FILE = open(filename,"r")
  92.     while FILE:
  93.             fline = FILE.readline()
  94.         key = fline.split("=")[0]
  95.         value = fline.split("=")[1]
  96.         if(key == "character"):return value
  97.        
  98.  
  99. user = user()
  100. while 1:
  101.     readbuffer = readbuffer + s.recv(1024)
  102.     tmp = readbuffer.split('\n')
  103.     readbuffer = tmp.pop()
  104.  
  105.     for line in tmp:
  106.    
  107.         line = line.rstrip().split()
  108.         if 'PING' in line : s.send('PONG\r\n')
  109.         if '/MOTD' in line:
  110.             s.send('JOIN '+channel+'\r\n')
  111.         s.send('PRIVMSG isabelle Hello isabelle!\r\n')
  112.         s.send('PRIVMSG '+channel+'belle1: Hello isabelle!\r\n')
  113.         print("Connected!")
  114.     if ':!kill' in line:
  115.             if(IRCUser(line) == "ttocskcaj"):
  116.             print('Exiting.')
  117.             s.send('PRIVMSG '+channel+' Goodbye :(\r\n')
  118.             sys.exit()
  119.         else:
  120.         s.send('PRIVMSG '+channel+' I\'ll bite your face cunt!\r\n')
  121.  
  122.    
  123.     if ':!scenario' in line:
  124.         scenario = generateScenario()
  125.         s.send('PRIVMSG '+channel +' '+scenario+'\r\n')
  126.     if ':!register' in line:
  127.         if (len(line) <5 ):
  128.         sendToChannel("Useage: !register <password>")
  129.         else:
  130.             if(checkExistingUser(IRCUser(line))):
  131.             sendToChannel("You are already registered!")
  132.             else:
  133.             user.create()
  134.             print(IRCUser(line) + " just registered")
  135.             sendToChannel("Thankyou for registering, "+IRCUser(line))
  136.             sendToChannel("Here's a little bit about your character: ")
  137.             char = json.loads(user.getCharacter())
  138.             sendToChannel('You have '+char['hair'] +' hair, '+char['eyes'] +' eyes, '+char['height'] +' and '+char['build'] +'.')
  139.             print(char)
  140. f.close()
  141.  
  142. s.close()
Add Comment
Please, Sign In to add comment