Advertisement
Thelorgoreng

simplebot

Sep 12th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.61 KB | None | 0 0
  1. import ch
  2. import random
  3. import sys
  4. import re
  5. if sys.version_info[0] > 2:
  6.   import urllib.request as urlreq
  7. else:
  8.   import urllib2 as urlreq
  9.  
  10.  
  11. ##Dance moves!
  12. #kinda useless
  13.  
  14. dancemoves = [
  15.   "(>^.^)>",
  16.   "(v^.^)v",
  17.   "v(^.^v)",
  18.   "<(^.^<)"
  19. ]
  20.  
  21. ##Setting Pretty Colors
  22. #Font setting for your bot
  23.  
  24. class TestBot(ch.RoomManager):
  25.   def onInit(self):
  26.     self.setNameColor("F9F")
  27.     self.setFontColor("F33")
  28.     self.setFontFace("1")
  29.     self.setFontSize(10)
  30.     self.enableBg()
  31.     self.enableRecording()
  32.  
  33. ##Connecting Crap
  34. #This is what will be printed on your python console when event called
  35.  
  36.   def onConnect(self, room):
  37.     print("Connected")
  38.  
  39.   def onReconnect(self, room):
  40.     print("Reconnected")
  41.  
  42.   def onDisconnect(self, room):
  43.     print("Disconnected")
  44.  
  45.  
  46. ##Ignore this, you dont need to worry about this
  47. #Well, you can actually take a little time to look at it and learn something
  48.  
  49.   def onMessage(self, room, user, message):
  50.    try:
  51.     if room.getLevel(self.user) > 0:
  52.       print(user.name, message.body)
  53.     else:
  54.       print(user.name, message.body)
  55.     if self.user == user: return
  56.     if message.body[0] == "/":   ##Here is the Prefix part
  57.       data = message.body[1:].split(" ", 1)
  58.       if len(data) > 1:
  59.         cmd, args = data[0], data[1]
  60.       else:
  61.         cmd, args = data[0], ""
  62.  
  63. ##COMMANDS!
  64. #Setting up commands for yer bot
  65.  
  66. ##Eval
  67. ##You may want/need to evaluate something about your bot.
  68.       if cmd == "ev" or cmd == "eval" or cmd == "e":
  69.           ret = eval(args)
  70.           if ret == None:
  71.             room.message("Done.")
  72.             return
  73.           room.message(str(ret))
  74.  
  75.         ##Say
  76.         #Make your bot say what you want
  77.       if cmd == "say":
  78.         room.message(args)
  79.  
  80.         ##Random User
  81.         #What's this for ? this one cmd will make your boy say the name of a random user in a room
  82.       if cmd == "randomuser":
  83.         room.message(random.choice(room.usernames))
  84.  
  85.         ##Check Level
  86.         #This one cmd is tho make your bot say your mod level in the current room you're in
  87.       elif cmd == "mylvl":
  88.         room.message("Your mod level: %i" %(room.getLevel(user)))
  89.  
  90.         ##List Mods
  91.         #List of Mods and Owner name in the current room you're in
  92.       elif cmd == "mods":
  93.         room.message(", ".join(room.modnames + [room.ownername]))
  94.  
  95.         ##DANCE!!!!
  96.         #Dance ? Of Course !!! ^_^
  97.       elif cmd == "dance":
  98.         for i, msg in enumerate(dancemoves):
  99.           self.setTimeout(i / 2, room.message, msg)
  100.          
  101.         ##Check if Mod
  102.         #not really important
  103.       elif cmd == "ismod":
  104.         user = ch.User(args)
  105.         if room.getLevel(user) > 0:
  106.           room.message("yesh")
  107.         else:
  108.           room.message("nope")
  109.    except Exception as e:
  110.       try:
  111.         et, ev, tb = sys.exc_info()
  112.         lineno = tb.tb_lineno
  113.         fn = tb.tb_frame.f_code.co_filename
  114.         room.message("[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e)))
  115.         return
  116.       except:
  117.         room.message("Undescribeable error detected !!")
  118.         return
  119.  
  120.   ##Other Crap here, Dont worry about it
  121.  
  122.   def onFloodWarning(self, room):
  123.     room.reconnect()
  124.  
  125.   def onJoin(self, room, user):
  126.    print(user.name + " joined the chat!")
  127.  
  128.   def onLeave(self, room, user):
  129.    print(user.name + " left the chat!")
  130.  
  131.   def onUserCountChange(self, room):
  132.     print("users: " + str(room.usercount))
  133.  
  134.   def onMessageDelete(self, room, user, msg):
  135.     print("MESSAGE DELETED: " + user.name + ": " + msg.body)
  136.  
  137.  
  138. if __name__ == "__main__": TestBot.easy_start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement