SHARE
TWEET

bot

a guest Jul 13th, 2019 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import random
  3.  
  4. import zope.interface, logging
  5. from twisted.internet import reactor
  6.  
  7. from Houdini.Plugins import Plugin
  8. from Houdini.Handlers import Handlers
  9.  
  10. class Bot(object):
  11.     zope.interface.implements(Plugin)
  12.  
  13.     author = "Houdini Team"
  14.     version = 0.1
  15.     description = "A bot plugin"
  16.  
  17.     id = 0
  18.     name = None
  19.     x, y = (0, 0)
  20.     frame = 1
  21.     membershipDays = 750
  22.     nameglow = ''
  23.     namecolor = ''
  24.     bubblecolor = ''
  25.     bubbletext = ''
  26.     speed = 4
  27.     mood = ''
  28.     bubbleglow = ''
  29.     moodglow = ''
  30.     moodcolor = ''
  31.     walls = 1
  32.     size = 100
  33.  
  34.     # Set the attribute to None for random clothing
  35.     clothing = None
  36.  
  37.     # If you set this to False, the bot will not automatically spawn in the room.
  38.     # Instead, he will show up and disappear whenever he's needed.
  39.     isStationary = True
  40.  
  41.     botString = None
  42.  
  43.     namesFile = "names.txt" # Path relative to this plugin
  44.     namesFileUrl = "https://www.cs.cmu.edu/Groups/AI/areas/nlp/corpora/names/other/names.txt"
  45.     namesList = None
  46.  
  47.     def __init__(self, server):
  48.         self.logger = logging.getLogger("Houdini")
  49.  
  50.         self.server = server
  51.  
  52.         self.namesFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), self.namesFile)
  53.  
  54.         if self.name is None: # Ooh~
  55.             self.randomizeName()
  56.  
  57.         allItems = self.server.items.schemaObjects.keys()
  58.  
  59.         """
  60.        This is intentionally placed outside of the if statement to allow randomization (via the command)
  61.        even if the bot wasn't initially created randomly.
  62.        """
  63.         # TODO: Exclude bait items probably (LAZY)
  64.         self.headIds = [itemId for itemId in allItems if self.server.items.isItemHead(itemId)]
  65.         self.faceIds = [itemId for itemId in allItems if self.server.items.isItemFace(itemId)]
  66.         self.neckIds = [itemId for itemId in allItems if self.server.items.isItemNeck(itemId)]
  67.         self.bodyIds = [itemId for itemId in allItems if self.server.items.isItemBody(itemId)]
  68.         self.handIds = [itemId for itemId in allItems if self.server.items.isItemHand(itemId)]
  69.         self.feetIds = [itemId for itemId in allItems if self.server.items.isItemFeet(itemId)]
  70.         self.flagIds = [itemId for itemId in allItems if self.server.items.isItemPin(itemId)]
  71.         self.photoIds = [itemId for itemId in allItems if self.server.items.isItemPhoto(itemId)]
  72.  
  73.         if self.clothing is None: # Lewd~! o//o
  74.             self.randomizeClothing()
  75.  
  76.         self.updateString()
  77.  
  78.         Handlers.GetInventory += self.handleJoinRoom # For the initial room join
  79.         Handlers.JoinRoom += self.handleJoinRoom
  80.         Handlers.JoinPlayerIgloo += self.handleJoinRoom
  81.  
  82.     def addToRoom(self, player):
  83.         player.sendXt("ap", self.botString)
  84.  
  85.     def removeFromRoom(self, player):
  86.         player.sendXt("rp", self.id)
  87.  
  88.     # TODO: Don't join game rooms (?)
  89.     def handleJoinRoom(self, player, data):
  90.         if self.isStationary:
  91.             self.addToRoom(player)
  92.  
  93.     def sendMessage(self, player, message):
  94.         if not self.isStationary:
  95.             reactor.callFromThread(self.addToRoom, player)
  96.  
  97.         reactor.callFromThread(player.sendXt, "sm", self.id, message)
  98.  
  99.         if not self.isStationary:
  100.             # May need to proxy this call through callFromThread
  101.             reactor.callLater(2, self.removeFromRoom, player)
  102.  
  103.     def ready(self):
  104.         self.logger.info("Bot plugin has been loaded")
  105.  
  106.     def randomizeName(self):
  107.         if not os.path.isfile(self.namesFile):
  108.             self.downloadNames()
  109.  
  110.         if self.namesList is None:
  111.             with open(self.namesFile, "r") as namesFile:
  112.                 self.namesList = namesFile.readlines()
  113.  
  114.         self.name = random.choice(self.namesList).strip()
  115.  
  116.     def randomizeClothing(self):
  117.         self.clothing = {
  118.             "Color": random.randrange(1, 14),
  119.             "Head": random.choice(self.headIds),
  120.             "Face": random.choice(self.faceIds),
  121.             "Neck": random.choice(self.neckIds),
  122.             "Body": random.choice(self.bodyIds),
  123.             "Hand": random.choice(self.handIds),
  124.             "Feet": random.choice(self.feetIds),
  125.             "Flag": random.choice(self.flagIds),
  126.             "Photo": random.choice(self.photoIds)
  127.         }
  128.  
  129.     def updateString(self):
  130.         self.botString = ("{bot.id}|"
  131.                           "{bot.name}|"
  132.                           "1|"
  133.                           "{Color}|"
  134.                           "{Head}|"
  135.                           "{Face}|"
  136.                           "{Neck}|"
  137.                           "{Body}|"
  138.                           "{Hand}|"
  139.                           "{Feet}|"
  140.                           "{Flag}|"
  141.                           "{Photo}|"
  142.                           "{bot.x}|"
  143.                           "{bot.y}|"
  144.                           "{bot.frame}|"
  145.                           "1|"
  146.                           "{bot.membershipDays}|"
  147.                           "{bot.nameglow}|"
  148.                           "{bot.namecolor}|"
  149.                           "{bot.bubblecolor}|"
  150.                           "{bot.bubbletext}|"
  151.                           "{bot.speed}|"  
  152.                           "{bot.mood}|"
  153.                           "{bot.bubbleglow}|"
  154.                           "{bot.moodglow}|"
  155.                           "{bot.moodcolor}|"
  156.                           "{bot.walls}|"
  157.                           "{bot.size}".format(bot=self, **self.clothing))
  158.  
  159.     def downloadNames(self):
  160.         import urllib2
  161.         namesResponse = urllib2.urlopen(self.namesFileUrl)
  162.  
  163.         with open(self.namesFile, "w") as namesFile:
  164.             namesFile.write(namesResponse.read())
  165.  
  166.         namesResponse.close()
  167.  
  168.         self.logger.info("[Bot] Names file has been downloaded.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top