Advertisement
Thelorgoreng

ExampleBot

Aug 27th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.86 KB | None | 0 0
  1. ############################################################################
  2. ############################################################################
  3. ####    Getting Started Bot                                     ############
  4. ####    File            = ExampleBot.py                         ############    
  5. ####    Originaly by    = clonerxyz                             ############
  6. ####    Edited by       = Thelorgorenk                          ############
  7. ####    you can PM for info about making a chatango             ############
  8. ####    bot in http://thelorgorenk.chatango.com, and you can    ############
  9. ####    and you can also chat in :                              ############
  10. ####            http://khususme.chatango.com                    ############
  11. ####    Last update:                                            ############
  12. ####            3.21 AM August, 1 2015 by Thelorgorenk          ############
  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 json
  22. import time
  23. import re
  24. if sys.version_info[0] > 2:
  25.   import urllib.request as urlreq
  26. else:
  27.   import urllib2 as urlreq
  28. from time import localtime, strftime
  29. wordtodaytime = dict()
  30. ##Dance moves!
  31. #kinda useless
  32.  
  33. dancemoves = [
  34.   "(>^.^)>",
  35.   "(v^.^)v",
  36. ]
  37. song = [
  38.   "Dirimu, dirimulah! Orang yang beriku senyum ini",
  39. "Jika kita bisa membuat air mata yang bersinar, itu 'kan 'jadi bintang jatuh",
  40. "Tanganmu t'lah terluka, tapi jangan pernah lepaskannya lagi",
  41. "Dari langit yang terpenuhi keinginan, hari esok 'kan segera datang",
  42.  
  43. "Cahya yang membimbingku adalah dirimu",
  44. "Dan aku pun ditarik karenanya",
  45. "Sebelum kusadarim kita mulai sebrangi jalan itu",
  46. "Sekaranglah saatnya! Jikalau kita hanya bisa bersinar di sini",
  47. ]
  48.  
  49. bete = [
  50. "kunci",
  51. ]
  52. pagi = [
  53. "ohayou oni-chan",
  54. ]
  55.  
  56. # implied command?    
  57. # call bot name with command after
  58. # call bot name with command after
  59. #Setting Pretty Colors
  60. #Font setting for your bot
  61. def tube(args):
  62.   try:
  63.     search = args.split()
  64.     url = urlreq.urlopen("https://www.googleapis.com/youtube/v3/search?q=%s&part=snippet&key=AIzaSyBSnh-sIjd97_FmQVzlyGbcaYXuSt_oh84" % "+".join(search))
  65.     udict = url.read().decode('utf-8')
  66.     data = json.loads(udict)
  67.     rest = []
  68.     for f in data["items"]:
  69.       rest.append(f)
  70.  
  71.     d = random.choice(rest)
  72.     link = "http://www.youtube.com/watch?v=" + d["id"]["videoId"]
  73.     videoid = d["id"]["videoId"]
  74.     title = d["snippet"]["title"]
  75.     uploader = d["snippet"]["channelTitle"]
  76.     descript = d["snippet"]['description']
  77.     count    = d["snippet"]["publishedAt"]
  78.     return "<f x1233FF33='1'>Ha<f x1200F='1'>sil:<f x12F00='1'> %s <br/><br/><br/><br/><br/><br/><br/><br/><font color='#ffcc00'><b>%s</b></font><br/><font color='#ff0000'><b>Yang ngeupload</b></font>:<b> %s</b><br/><font color='#ff0000'><b>Di publikasikan pada</b></font>: %s<br/><font color='#ff0000'><b>Rincian</b></font>:<i> %s ...</i><br/> " % (link, title, uploader, count, descript[:200])
  79.   except Exception as e:
  80.     return str(e)
  81. class TestBot(ch.RoomManager):
  82.   def onInit(self):
  83.     self.setNameColor("F9F")
  84.     self.setFontColor("F33")
  85.     self.setFontFace("1")
  86.     self.setFontSize(13)
  87.     self.enableBg()
  88.     self.enableRecording()
  89. ##### Pars Def
  90.   def pars(args):
  91.           args=args.lower()
  92.           userlist = roomUsers()
  93.           for name in userlist:
  94.             if args in name:return name  
  95. ##Connecting Crap
  96. #This is what will be printed on your python console when event called
  97.  
  98.   def onConnect(self, room):
  99.     print("Connected")
  100.  
  101.   def onReconnect(self, room):
  102.     print("Reconnected")
  103.  
  104.   def onDisconnect(self, room):
  105.     print("Disconnected")
  106.  
  107.  
  108. ##Ignore this, you dont need to worry about this
  109. #Well, you can actually take a little time to look at it and learn something
  110.   def onMessage(self, room, user, message):
  111.   #### Comenzi fara prefix
  112.    if message.body.startswith("test"):
  113.      room.message("Test request granted :v")
  114.    if message.body.startswith("woi"):
  115.      room.message("Apa njay? :v :)")
  116.    if message.body.startswith("sepi"):
  117.      room.message("I'am here. :)")
  118.    if message.body.startswith("siang"):
  119.      room.message("Hello, siang :)")
  120.    if message.body.startswith("malam"):
  121.      room.message("Hello, malam :)")
  122.    if message.body.startswith("konbanwa"):
  123.      room.message("Hello, konbanwa")
  124.    if message.body.startswith("oyasumi"):
  125.      room.message("Hello, oyasumi :v")
  126.    if message.body.startswith("konichiwa"):
  127.      room.message("Hello, konichiwa :)")
  128.    if message.body.startswith("jam"):
  129.       room.message(strftime("%H:%M:%S", localtime()))      
  130.    if message.body.startswith("tanggal"):
  131.      room.message(strftime ("HARI: %a,%d-%b-%Y ", localtime()))
  132.    if message.body.startswith("siapa yang "):
  133.      room.message(random.choice(room.usernames))
  134.    if message.body.startswith("lol"):
  135.      room.message("Yea lol  @"+user.name+".")
  136.      room.message(random.choice(jawab)+" @"+user.name)
  137. ##COMMANDS!
  138. #Setting up commands for yer bot
  139.  #commands section
  140. #### Invite
  141.      if message.body[0] == "/":
  142.       data = message.body[1:].split(" ", 1)
  143.       if len(data) > 1:
  144.         cmd, args = data[0], data[1]
  145.       else:
  146.         cmd, args = data[0], ""
  147.       if cmd == "yt":
  148.         room.message(tube(args),True)
  149.       if cmd == "invite" or cmd == "Invite":
  150.         if len (args) > 0:
  151.             self.pm.message(ch.RoomManager(args),"%s You have a group invite by ! http://%s.chatango.com ." %(owners[0],room.name))
  152.             room.message("Invite on progress %s in Access group. :)" % args)
  153.         else:
  154.             room.message("Sry have problem. :3")
  155. ##You may want/need to evaluate something about your bot.
  156.      
  157.       if cmd == "ev" or cmd == "eval" or cmd == "e":
  158.           ret = eval(args)
  159.           if ret == None:
  160.             room.message("Done.")
  161.             return
  162.           room.message(str(ret))
  163.      
  164.         ##Say
  165.         #Make your bot say what you want
  166.  
  167.       elif cmd == "afk":
  168.         jawab = ["See u"]
  169.         room.message(random.choice(jawab)+" @"+user.name)
  170.       elif cmd == "crunch":
  171.         jawab = ["https://31.media.tumblr.com/50dcec4f797eb86ea483558695c874f1/tumblr_nqru66BNYc1u8lwqgo1_500.gif"]
  172.         room.message(random.choice(jawab)+" @"+user.name)
  173.       elif cmd == "nja":
  174.         jawab = ["Njaa ne ^^"]
  175.         room.message(random.choice(jawab)+" @"+user.name)
  176.       elif cmd == "coeghd":
  177.         jawab = ["anda kenapa?"]
  178.         room.message(random.choice(jawab)+" @"+user.name)
  179.       elif cmd == ":v":
  180.         jawab = ["emoticon dewa"]
  181.         room.message(random.choice(jawab)+" @"+user.name)
  182.       elif cmd == "lebaran":
  183.         jawab = ["minal aidzin wal faizin kk"]
  184.         room.message(random.choice(jawab)+" @"+user.name)
  185.       elif cmd == "gue tamvan gak ?":
  186.         jawab = ["kaga","tamvan","jelek","biasa aja"]
  187.         room.message(random.choice(jawab)+" @"+user.name)
  188.       elif cmd == "hmm":
  189.         jawab = ["maho detcted"]
  190.         room.message(random.choice(jawab)+" @"+user.name)
  191.       elif cmd == "konbanwa":
  192.         jawab = ["tidur sana jangan ngalong :v"]
  193.         room.message(random.choice(jawab)+" @"+user.name)
  194.       elif cmd == "naruto":
  195.         jawab = ["adalah anime yang selalu flash back"]
  196.         room.message(random.choice(jawab)+" @"+user.name)
  197.       elif cmd == "bnp":
  198.         jawab = ["erorr forbidden access denied"]
  199.         room.message(random.choice(jawab)+" @"+user.name)
  200.         ##Random User
  201.         #What's this for ? this one cmd will make your boy say the name of a random user in a room
  202.       if cmd == "randomuser":
  203.         room.message(random.choice(room.usernames))
  204.  
  205.         ##Check Level
  206.         #This one cmd is tho make your bot say your mod level in the current room you're in
  207.       elif cmd == "mylvl":
  208.         room.message("Your mod level: %i" %(room.getLevel(user)))
  209.  
  210.         ##List Mods
  211.         #List of Mods and Owner name in the current room you're in
  212.       elif cmd == "mods":
  213.         room.message(", ".join(room.modnames + [room.ownername]))
  214.         #### Seen
  215.       elif cmd == "invitegroup" or cmd == "ig":
  216.         if len (args) > 0:
  217.          self.pm.message(ch.RoomManager(args),"%s You have group invite! check this Chatango Group http://%s.chatango.com ." %(room.ownername[0],room.name))
  218.          room.message("Youre invite %s now is in Accest Group. :)" % args)
  219.         else:
  220.           room.message("gak mau ah nginvite dia")
  221.         ##DANCE!!!!
  222.         #Dance ? Of Course !!! ^_^
  223.       elif cmd == "dance":
  224.         for i, msg in enumerate(dancemoves):
  225.           self.setTimeout(i / 2, room.message, msg)
  226.                #### Pm
  227.       elif cmd == "pm" or cmd == "Pm" or cmd == "PM" or cmd == "Private Message":
  228.         data = args.split(" ", 1)
  229.         if len(data) > 1:
  230.           name , args = data[0], data[1]
  231.           self.pm.message(ch.User(name), "[Private.Message] By - "+user.name+" : "+args+" ")
  232.           room.message("Has been sent to "+name+"")
  233.         #### Invite
  234.       elif cmd == "invite" or cmd == "Invite":
  235.         if len (args) > 0:
  236.             self.pm.message(ch.RoomManager(args),"%s You have a group invite by ! http://%s.chatango.com ." %(owners[0],room.name))
  237.             room.message("Invite on progress %s in Access group. :)" % args)
  238.         else:
  239.             room.message("Sry have problem. :3")
  240.         #### Profile
  241.       elif cmd == "prof" or cmd == "profile" or cmd == "Prof" or cmd == "Profile":
  242.         try:
  243.           args=args.lower()
  244.           stuff=str(urlreq.urlopen("http://"+args+".chatango.com").read().decode("utf-8"))
  245.           crap, age = stuff.split('<span class="profile_text"><strong>Age:</strong></span></td><td><span class="profile_text">', 1)
  246.           age, crap = age.split('<br /></span>', 1)
  247.           crap, gender = stuff.split('<span class="profile_text"><strong>Gender:</strong></span></td><td><span class="profile_text">', 1)
  248.           gender, crap = gender.split(' <br /></span>', 1)
  249.           if gender == 'M':
  250.               gender = 'Male'
  251.           elif gender == 'F':
  252.               gender = 'Female'
  253.           else:
  254.               gender = '?'
  255.           crap, location = stuff.split('<span class="profile_text"><strong>Location:</strong></span></td><td><span class="profile_text">', 1)
  256.           location, crap = location.split(' <br /></span>', 1)
  257.           crap,mini=stuff.split("<span class=\"profile_text\"><!-- google_ad_section_start -->",1)
  258.           mini,crap=mini.split("<!-- google_ad_section_end --></span>",1)
  259.           mini=mini.replace("<img","<!")
  260.           picture = '<a href="http://fp.chatango.com/profileimg/' + args[0] + '/' + args[1] + '/' + args + '/full.jpg" style="z-index:59" target="_blank">http://fp.chatango.com/profileimg/' + args[0] + '/' + args[1] + '/' + args + '/full.jpg</a>'
  261.           prodata = '<br/> <a href="http://chatango.com/fullpix?' + args + '" target="_blank">' + picture + '<br/><br/> Age: '+ age + ' <br/> Gender: ' + gender +  ' <br/> Location: ' +  location + '' '<br/> <a href="http://' + args + '.chatango.com" target="_blank"><u>Chat With User</u></a> ' "<br/><br/> "+ mini
  262.           room.message(prodata,True)
  263.         except:
  264.           room.message(""+args+" doesn't exist o.o ")
  265.         #
  266.         if cmd =="wordtoday" or cmd=="wt":
  267.             if user.name in owners:
  268.               if user.name in wordtodaytime:
  269.                 w = json.loads(wordtodaytime[user.name])
  270.                 if time.time() < w:
  271.                   w = int(w) - int(time.time())
  272.                   minute = 60
  273.                   hour = minute * 60
  274.                   day = hour * 24
  275.                   days =  int(w / day)
  276.                   hours = int((w % day) / hour)
  277.                   minutes = int((w % hour) / minute)
  278.                   seconds = int(w % minute)
  279.                   string = ""
  280.                   if days > 0:
  281.                     string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  282.                   if len(string) > 0 or hours > 0:
  283.                     string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  284.                   if len(string) > 0 or minutes > 0:
  285.                     string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  286.                   string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  287.                   room.message("You can use wordtoday after <font color='#9999FF'>%s</font>  (~^o^)~ "% string,True)
  288.                   return
  289.               if urank(user.name) >= 1:
  290.                 x=(random.choice(["sadness","happines","yaoi","yuri","horny","nice","bad","bastard","young","lazy","poor","rich","ugly","handshome","beautiful","good","gay","keep calm","arrogant","naughty","special","sweet","tits","areola","pupy","ass","sunny","dizzy","nude","old","lifeless","dying",'death',"impotent","cancer"]))
  291.                 room.message("Dear "+sntonick(user.name)+" Your word today is : <b><font color='#FF9966'>"+str(x)+"</font></b>",True)
  292.                 wordtodaytime[user.name] = json.dumps(time.time()+1200)
  293.  
  294.         ##Check if Mod
  295.         #not really important
  296.       elif cmd == "ismod":
  297.         user = ch.User(args)
  298.         if room.getLevel(user) > 0:
  299.           room.message("yesh")
  300.         else:
  301.           room.message("nope")
  302.         return
  303.  
  304.   ##Other Crap here, Dont worry about it
  305.  
  306.   def onFloodWarning(self, room):
  307.     room.reconnect()
  308.  
  309.   def onJoin(self, room, user):
  310.    print(user.name + " joined the chat!")
  311.  
  312.   def onLeave(self, room, user):
  313.    print(user.name + " left the chat!")
  314.  
  315.   def onUserCountChange(self, room):
  316.     print("users: " + str(room.usercount))
  317.  
  318.   def onMessageDelete(self, room, user, msg):
  319.     print("MESSAGE DELETED: " + user.name + ": " + msg.body)
  320.  
  321.  
  322. if __name__ == "__main__": TestBot.easy_start()
  323.  
  324.     #The End!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement