Advertisement
0rx

ExampleBot (Updated July, 5 2015)

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