Advertisement
Thelorgoreng

Thelordorenk Bot module

Aug 27th, 2015
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.15 KB | None | 0 0
  1. ############################################################################
  2. ############################################################################
  3. ####    Getting Started Bot                                     ############
  4. ####    File            = Kana's bot.py                         ############    
  5. ####    Originaly by    = Wildanchuan                           ############
  6. ####    Edited by       = Thelorgorenk                          ############
  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://khususme.chatango.com                    ############
  11. ####    Last update:                                            ############
  12. ####            09.00 PM August, 27 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. def tube(args):
  56.   try:
  57.     search = args.split()
  58.     url = urlreq.urlopen("https://www.googleapis.com/youtube/v3/search?q=%s&part=snippet&key=AIzaSyBSnh-sIjd97_FmQVzlyGbcaYXuSt_oh84" % "+".join(search))
  59.     udict = url.read().decode('utf-8')
  60.     data = json.loads(udict)
  61.     rest = []
  62.     for f in data["items"]:
  63.       rest.append(f)
  64.  
  65.     d = random.choice(rest)
  66.     link = "http://www.youtube.com/watch?v=" + d["id"]["videoId"]
  67.     videoid = d["id"]["videoId"]
  68.     title = d["snippet"]["title"]
  69.     uploader = d["snippet"]["channelTitle"]
  70.     descript = d["snippet"]['description']
  71.     count    = d["snippet"]["publishedAt"]
  72.     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])
  73.   except Exception as e:
  74.     return str(e)
  75. # implied command? 
  76. # call bot name with command after
  77. # call bot name with command after
  78. #Setting Pretty Colors
  79. #Font setting for your bot
  80.  
  81. class TestBot(ch.RoomManager):
  82.   def onInit(self):
  83.     self.setNameColor("FF0000")
  84.     self.setFontColor("FF00")
  85.     self.setFontFace("Gorgia")
  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.  
  96. ##gugel image
  97.   def gsimg(self, search):
  98.     encoded = urllib.parse.quote(search)
  99.     rawData = urllib.request.urlopen('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='+encoded).read().decode('utf-8')
  100.     jsonData = json.loads(rawData)
  101.     searchResults = jsonData["responseData"]["results"]
  102.     for data in searchResults:
  103.       title = data["title"]
  104.       print(title)
  105.       link = data["url"]
  106.       if link:
  107.         full = link
  108.         return('I found: %s <br> %s' % (title, full))
  109.       break
  110.  
  111.  
  112.  
  113. ##Connecting Crap
  114. #This is what will be printed on your python console when event called
  115. #ini pesan yg keluar ketika BOT nya aktif
  116.  
  117.   def onConnect(self, room):
  118.     print ("[INFO] Reconnected to : "+room.name)
  119.     room.setSilent(False)#new code for flood ban
  120.     self.setNameColor("FF0000")
  121.     self.setFontColor("FF0000")
  122.     self.setFontFace("Georgia")
  123.     self.setFontSize(12)
  124.     self.enableBg()
  125.     self.enableRecording()
  126.     room.message("|| MAZE NOW ON-LINE || a BOT by |wildanchuan|")
  127.   def onReconnect(self, room):
  128.     print("Reconnected")
  129.     room.message("|AMACCHI NOW RECONNECT||ムmムくくサェ れ㊤メ ㊤れしェれも| *waves*")
  130.  
  131.   def onDisconnect(self, room):
  132.     print("Disconnected")
  133.     room.message("|AMACCHI NOW DISCONECTED||ムmムくくサェ れ㊤メ ㊤れしェれも| *waves*")
  134.   ##Ignore this, you dont need to worry about this
  135. #Well, you can actually take a little time to look at it and learn something
  136.   def onMessage(self, room, user, message):
  137.   #### Comenzi fara prefix
  138.  
  139. ## ini perintah yang ga pake tanda " / " bisa di edit
  140.  
  141.    if message.body.startswith("@"+"wildanchuan"):
  142.     if user.name == "wildanchuan": ##user name ini bisa di ganti sesuai nick kamu
  143.      room.message("papa Mavok ya")
  144.     else:
  145.      room.message("Jika tidak di jawab mohon maaf. karena papa sering sibuk."+" @"+user.name)
  146.    if message.body.startswith("edo tensei"):
  147.      room.message("@AkenoIO @animeh4ckerIO @rokibkyujuroku @tsutsukaakushi @PutraDaiki @OtakuGamers04 @cranel1 @HCSama2012 @Shiokage @Kyosuke003 @DutaKun @Yukki111 @HasegawaRyuga @budhydarmaone @YukisunaYokagami @ToyotomiHedoyoshi @Akamx @clonerxyz @FiveFa @Koinyan @ketela35 @WildanChuan @coeg95 @Thelorgorenk @ShamanTheBeater @ArthuroDragnell @shintarou99")
  148.    if message.body.startswith("@"+"mazechuan"):
  149.      if user.name == "wildanchuan":
  150.       room.message("toustano, masta ? @"+"wildanchuan")
  151.      else:
  152.       room.message("nani..? " +" @"+user.name)
  153.    if message.body.startswith("maze"):
  154.      if user.name == "wildanchuan":
  155.       room.message("Tousta no masta..")
  156.      else:
  157.       room.message("tousta no, aniki..?" +" @"+user.name)
  158.    if message.body.startswith("kerja bagus"):
  159.      if user.name == "wildanchuan":
  160.       room.message("arigato gozaimasu papa~")
  161.      else:
  162.        room.message("sankyu nee~")
  163.    if message.body.startswith("test"):
  164.      if user.name == "wildanchuan":
  165.       room.message("Maze TEST SUCCES")
  166.      else:
  167.       room.message("SUCCES Coeg" +" @"+user.name)
  168.    if message.body.startswith("gua "):
  169.      jawab = ["nggak","bisa jadi","tentu","siapa ya?","jones ya ?"]
  170.      room.message(random.choice(jawab)+" @"+user.name)
  171.    if message.body.startswith("gue "):
  172.      jawab = ["nggak","bisa jadi","tentu","siapa ya?","jones ya ?"]
  173.      room.message(random.choice(jawab)+" @"+user.name)
  174.    if message.body.startswith("woi"):
  175.      room.message("awas IMPOTEN ntar" +" @"+user.name)
  176.    if message.body.startswith("credit"):
  177.      room.message("Editor : wildanchuan")
  178.      room.message("script : pak shaman")
  179.      room.message("moder : pak thelor")
  180.      room.message("special thanks : pak cloner" +" @"+user.name)            
  181.    if message.body.startswith("sepi"):
  182.      room.message("Slow,Maze here" +" @"+user.name)
  183.    if message.body.startswith("pagi"):
  184.      room.message("selamat pagi :)" +" @"+user.name)
  185.    if message.body.startswith("siang"):
  186.      room.message("selamat siang :)" +" @"+user.name)
  187.    if message.body.startswith("malam"):
  188.      room.message("selamat malam :)" +" @"+user.name)
  189.    if message.body.startswith("ohayo"):
  190.      room.message("hai, ohayo" +" @"+user.name)
  191.    if message.body.startswith("konbanwa"):
  192.      room.message("hai, konbawa :v" +" @"+user.name)
  193.    if message.body.startswith("oyasumi"):
  194.      room.message("hai, oyasumi :v" +" @"+user.name)
  195.    if message.body.startswith("konichiwa"):
  196.      room.message("hai, konichiwa :)" +" @"+user.name)
  197.    if message.body.startswith("link"):
  198.      room.message("kore.. http://ust.chatango.com/um/w/i/wildanchuan/img/l_41.jpg")
  199.    if message.body.startswith("jam"):
  200.      if user.name == "wildanchuan":
  201.       room.message(strftime("%H:%M:%S", localtime()))
  202.      else:
  203.       room.message("Ga punya JAM ya..?" +" @"+user.name)
  204.    if message.body.startswith("tanggal"):
  205.      if user.name == "wildanchuan":
  206.       room.message(strftime ("Sekarang: %a,%d-%b-%Y ", localtime()))
  207.      else:
  208.       room.message("Ga punya Kalender ya ya..?" +" @"+user.name)
  209.    if message.body.startswith("siapa yang "):
  210.      room.message(random.choice(room.usernames) +" @"+user.name)
  211.    if message.body.startswith("afk"):
  212.      if user.name == "wildanchuan":
  213.       room.message("hati hati papa sayank, salam buat mama")
  214.      else:
  215.       room.message("AFK..?, emang gua pikirin, AFK sono.." +" @"+user.name)
  216.    if message.body.startswith("back"):
  217.      if user.name == "wildanchuan":
  218.       room.message("okairi, papa~sama")
  219.      else:
  220.       room.message("okairi coeg" +" @"+user.name)
  221.    try:
  222.     if room.getLevel(self.user) > 0:
  223.       print(user.name, message.body)
  224.     else:
  225.       print(user.name, message.body)
  226.     if self.user == user: return
  227.     if message.body[0] == "." :   ## << yg tanda " - " bisa di ganti sesuka hati
  228.       data = message.body[1:].split(" ", 1)
  229.       if len(data) > 1:
  230.         cmd, args = data[0], data[1]
  231.       else:
  232.         cmd, args = data[0], ""
  233.  
  234.    
  235.  
  236.  
  237.  
  238. ##COMMANDS!
  239. #Setting up commands for yer bot
  240.  #commands section
  241. #### Invite
  242.       if cmd == "invite" or cmd == "Invite":
  243.         if len (args) > 0:
  244.             self.pm.message(ch.RoomManager(args),"%s You have a group invite by ! http://%s.chatango.com ." %(owners[0],room.name))
  245.             room.message("Invite on progress %s in Access group. :)" % args)
  246.         else:
  247.             room.message("Sry have problem. :3")
  248.    
  249.  
  250.          
  251.      
  252.         ##Say
  253.         #Make your bot say what you want
  254.         #ini perintah yg pake " / "
  255.       if cmd == "ev" or cmd == "eval" or cmd == "e":
  256.           ret = eval(args)
  257.           if ret == None:
  258.             room.message("Done.")
  259.             return
  260.           room.message(str(ret))
  261.       elif cmd == "bot":
  262.         jawab = ["BOT v10.1 amacchi version"]
  263.         room.message(random.choice(jawab)+" @"+user.name)
  264.       elif cmd == "help":
  265.         jawab = ["perintah PREFIX amacchi With [.] [rm] [on] [say] [yt] [prof] [img]"]
  266.         room.message(random.choice(jawab)+" @"+user.name)
  267.  
  268.        
  269.         ##Check Level
  270.         #This one cmd is tho make your bot say your mod level in the current room you're in
  271.  
  272.       elif cmd == "mylvl":
  273.         room.message("Your mod level: %i" %(room.getLevel(user)))
  274.  
  275.         ##shutdon
  276.       elif cmd == "off":
  277.         if user.name == "wildanchuan":
  278.           room.message("Shutting down ...")
  279.           time.sleep(1)
  280.           self.stop()
  281.         else:
  282.             room.message("Only the owner can use this command. mew *h* ")
  283.  
  284.         ### username list
  285.       elif cmd =="on":
  286.         room.message("User ON-LINE: " + str(room.usercount) + str(room.getUserlist(1))+" .")
  287.  
  288.         ##lock
  289.       elif cmd == "kunci":
  290.         if user.name == "wildanchuan":
  291.          room.message("maze succes lock")
  292.          room.setSilent(True)
  293.         else:
  294.             room.message("don't have permission *h* ")
  295.  
  296.         ##unlock
  297.       elif cmd == "buka":
  298.         if user.name == "wildanchuan":
  299.          room.setSilent(False)
  300.          room.message("SUCCES UNLOCK")
  301.         else:
  302.            room.message("MALES ah ah ah..*h*")
  303.  
  304.         ##bc
  305.       elif cmd == "broadcast":
  306.         if user.name =="wildanchuan":
  307.  
  308.           for room in self.rooms:
  309.             if args == "": return
  310.             else:
  311.               room.message("Broadcast from - "+user.name + ": "+args, True)
  312.           else:
  313.                 room.message("[<b>%s</b>] Only Councill Members are allowed" % "ERROR", False)
  314.       ## Join and Leave Rooms
  315.                 if cmd == "join" and len(args) > 1:
  316.                   if self.getAccess(user) >= 0 or user.name in room.ownername and self.getAccess(user) < 0 or user.name in room.ownername:
  317.                     if args not in self.roomnames:
  318.                       room.message("*Joins <b>%s</b>*" % args, True)
  319.                       self.joinRoom(args)
  320.                     else:
  321.                         room.message("I'm there already :|")
  322.                   else:
  323.                         room.message("You mere mortals can never do that !!")
  324.          
  325.      ## leave
  326.                 if cmd == "leave":
  327.                    if self.getAccess(user) > 0 or room.getLevel(user) == 0:
  328.                      if args:
  329.                        if self.getAccess(user) > 0:
  330.                          room.message("i've left <b>%s</b>" % args, True)
  331.                          self.leaveRoom(args)
  332.                 else: return
  333.                 if not args:
  334.                   room.message("Okay, I'm leaving this place")
  335.                   self.leaveRoom(room.name)
  336.                 else:
  337.                              room.message("You mere mortals can never do that !!")                
  338.  
  339.        
  340.  
  341.  
  342.  
  343.         #nama Room
  344.       elif cmd == "rm":
  345.         room.message("<b>%s</b> You ON-line In The <b>%s</b>" % (user.name.title(), room.name) + " the owner is <b>%s</b> " % str(room.ownername), True)
  346.  
  347.  
  348.         #yutub
  349.       if cmd == "yt" or cmd == "ytb":
  350.           room.message(tube(args),True)
  351.         #gogel
  352.       elif cmd == "gis" and len(args) > 0:
  353.           if room.name == "khususmeme":
  354.             room.message("showing Google images here :|")
  355.           else:
  356.             try:
  357.                 search = args.split()
  358.                 import urllib.request
  359.                 with urllib.request.urlopen("http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=%s" % "+".join(search)) as url:
  360.                     udict = url.read().decode()
  361.                 a = re.finditer('"unescapedUrl":"(.+?)","url":"', udict)
  362.                 matches = []
  363.                 for match in a:
  364.                     match = str(match.group(1))
  365.                     matches.append(match)
  366.                
  367.                 link = random.choice(matches)
  368.                 try:
  369.                     link = link.replace("https", "http")
  370.                 except:
  371.                     print("Random choice isn't SSL.")
  372.                 if args: room.message("%s I found: %s" % (user.name), link), True
  373.             except Exception as e:
  374.                 room.message("%s I'm sorry, I was unable to find anything for search term: %s :|" % (user.name), args), True
  375.                 print(e)
  376.  
  377.  
  378.         #say a~
  379.       elif cmd == "say":
  380.         if args:
  381.           room.message(args+"")
  382.         else:
  383.             room.message("Baka yaroo :v")
  384.  
  385.  
  386.      
  387.  
  388.         ##List Mods
  389.         #List of Mods and Owner name in the current room you're in
  390.  
  391.       elif cmd == "mods":
  392.         room.message(", ".join(room.modnames + [room.ownername]))
  393.         #### Seen
  394.       elif cmd == "invitegroup" or cmd == "ig":
  395.         if len (args) > 0:
  396.          self.pm.message(ch.RoomManager(args),"%s You have group invite! check this Chatango Group http://%s.chatango.com ." %(room.ownername[0],room.name))
  397.          room.message("Youre invite %s now is in Accest Group. :)" % args)
  398.         else:
  399.           room.message("MALES")
  400.       ##DANCE!!!!
  401.         #Dance ? Of Course !!! ^_^
  402.       elif cmd == "dance":
  403.         for i, msg in enumerate(dancemoves):
  404.           self.setTimeout(i / 2, room.message, msg)
  405.                #### Pm
  406.       elif cmd == "pm" or cmd == "Pm" or cmd == "PM" or cmd == "Private Message":
  407.         data = args.split(" ", 1)
  408.         if len(data) > 1:
  409.           name , args = data[0], data[1]
  410.           self.pm.message(ch.User(name), "[Pesan Penting] By - "+ user.name +" : "+args+" ")
  411.           room.message("SUCCES SEND MESSAGE")
  412.         #### Invite
  413.       elif cmd == "invite" or cmd == "Invite":
  414.         if len (args) > 0:
  415.             self.pm.message(ch.RoomManager(args),"%s You have a group invite by ! http://%s.chatango.com ." %(owners[0],room.name))
  416.             room.message("Invite on progress %s in Access group. :)" % args)
  417.         else:
  418.             room.message("Sry have problem. :3")
  419.         #### Profile
  420.       elif cmd == "prof" or cmd == "profile" or cmd == "Prof" or cmd == "Profile":
  421.         try:
  422.           args=args.lower()
  423.           stuff=str(urlreq.urlopen("http://"+args+".chatango.com").read().decode("utf-8"))
  424.           crap, age = stuff.split('<span class="profile_text"><strong>Age:</strong></span></td><td><span class="profile_text">', 1)
  425.           age, crap = age.split('<br /></span>', 1)
  426.           crap, gender = stuff.split('<span class="profile_text"><strong>Gender:</strong></span></td><td><span class="profile_text">', 1)
  427.           gender, crap = gender.split(' <br /></span>', 1)
  428.           if gender == 'M':
  429.               gender = 'Male'
  430.           elif gender == 'F':
  431.               gender = 'Female'
  432.           else:
  433.               gender = '?'
  434.           crap, location = stuff.split('<span class="profile_text"><strong>Location:</strong></span></td><td><span class="profile_text">', 1)
  435.           location, crap = location.split(' <br /></span>', 1)
  436.           crap,mini=stuff.split("<span class=\"profile_text\"><!-- google_ad_section_start -->",1)
  437.           mini,crap=mini.split("<!-- google_ad_section_end --></span>",1)
  438.           mini=mini.replace("<img","<!")
  439.           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>'
  440.           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
  441.           room.message(prodata,True)
  442.         except:
  443.           room.message(""+args+" doesn't exist o.o ")
  444.         #
  445.         if cmd =="wordtoday" or cmd=="wt":
  446.             if user.name in owners:
  447.               if user.name in wordtodaytime:
  448.                 w = json.loads(wordtodaytime[user.name])
  449.                 if time.time() < w:
  450.                   w = int(w) - int(time.time())
  451.                   minute = 60
  452.                   hour = minute * 60
  453.                   day = hour * 24
  454.                   days =  int(w / day)
  455.                   hours = int((w % day) / hour)
  456.                   minutes = int((w % hour) / minute)
  457.                   seconds = int(w % minute)
  458.                   string = ""
  459.                   if days > 0:
  460.                     string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  461.                   if len(string) > 0 or hours > 0:
  462.                     string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  463.                   if len(string) > 0 or minutes > 0:
  464.                     string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  465.                   string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  466.                   room.message("You can use wordtoday after <font color='#9999FF'>%s</font>  (~^o^)~ "% string,True)
  467.                   return
  468.               if urank(user.name) >= 1:
  469.                 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"]))
  470.                 room.message("Dear "+sntonick(user.name)+" Your word today is : <b><font color='#FF9966'>"+str(x)+"</font></b>",True)
  471.                 wordtodaytime[user.name] = json.dumps(time.time()+1200)
  472.  
  473.         ##Check if Mod
  474.         #not really important
  475.       elif cmd == "ismod":
  476.         user = ch.User(args)
  477.         if room.getLevel(user) > 0:
  478.           room.message("yesh")
  479.         else:
  480.           room.message("nope")
  481.    except Exception as e:
  482.       try:
  483.         et, ev, tb = sys.exc_info()
  484.         lineno = tb.tb_lineno
  485.         fn = tb.tb_frame.f_code.co_filename
  486.         room.message("[Expectation Failed]kesalahan di sekitar Line %i"(fn, lineno, str(e)))
  487.         return
  488.       except:
  489.         room.message("Undescribeable error detected !!")
  490.         return
  491.  
  492.  
  493.   def onFloodWarning(self, room):
  494.     room.reconnect()
  495.  
  496.   def onJoin(self, room, user):
  497.    print(user.name + " joined the chat!")
  498.    if user.name =="wildanchuan":
  499.      room.message("Masta Wildan now ON-LINE")
  500.    else :
  501.      room.message("@" + user.name + " Telah memasuki room chat")
  502.      
  503.  
  504.   def onLeave(self, room, user):
  505.    print(user.name + " leave the chat!")
  506.    room.message("@" + user.name + " Telah keluar dari room chat.!")
  507.  
  508.   def onUserCountChange(self, room):
  509.    print("jumlah user berubah")
  510.    room.message("jadi,sekarang jumlah user: " + str(room.usercount))
  511.  
  512.   def onMessageDelete(self, room, user, msg):
  513.     print("MESSAGE DELETED: " + user.name + ": " + msg.body)
  514.  
  515.  
  516. if __name__ == "__main__": TestBot.easy_start()
  517.  
  518.     #The End!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement