Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################################################################################################################################## Python V0.3.5
- ### Examplebot
- ### Script Sederhana & dasar untuk pemula
- ### Creator : Hansubaruukun
- ###
- ### Find me at
- ### hanteams.chatango.com
- ### or roombebas.chatango.com
- ###
- ### jika anda butuh bantuan tentang bot jangan segan tanya sama ane .. karna ane juga dulu newbie sama seperti anda xD
- #################################################################################################################
- import ch
- import random
- import sys
- import re
- import json
- import time
- import datetime
- import os
- import urllib
- from xml.etree import cElementTree as ET
- if sys.version_info[0] > 2:
- import urllib.request as urlreq
- else:
- import urllib2 as urlreq
- global bahasa, key
- key = "keysimi" #key api simsimnya
- bahasa = "en"
- def set(x):
- global bahasa
- bahasa = x
- def SimSimi(kalimat):
- g = "sorry im tired ;("
- kata = kalimat.replace(" ","+")
- try:
- data = urllib.request.urlopen("http://sandbox.api.simsimi.com/request.p?key=%s&lc=%s&ft=1.0&text=%s" % (key, bahasa, kata)).read().decode('utf-8')
- jsondata = json.loads(data)
- respon = jsondata["response"]
- if "I HAVE NO RESPONSE" in respon:
- respon = g
- except Exception as e:
- respon = g
- return respon
- botname = 'XXXXX' ##isi id yang mau lu jadikan bot
- password = 'XXXXX' ##isi paswordnya
- ##nick names
- def sntonick(username):
- user = username.lower()
- if user in nicks:
- nick = json.loads(nicks[user])
- return nick
- else:
- return user
- ## DEFINITIONS
- ###Buat text atau notes seperti ini http://prntscr.com/d4ocdq
- ##nicks
- nicks=dict()#empty list
- f=open ("nicks.txt","r")#r=read w=right
- for line in f.readlines():#loop through eachlinimporte and read each line
- try:#try code
- if len(line.strip())>0:#strip the whitespace checkgreater than 0
- user , nick = json.loads(line.strip())
- nicks[user] = json.dumps(nick)
- except:
- print("[Error]Can't load nick %s" % line)
- f.close()
- ##Rooms
- rooms = []
- f = open("rooms.txt", "r") # read-only
- for name in f.readlines():
- if len(name.strip())>0: rooms.append(name.strip())
- f.close()
- ##owners
- owners = []
- try:
- file = open("owners.txt", "r")
- for name in file.readlines():
- if len(name.strip()) > 0:
- owners.append(name.strip())
- print("[INFO]Owners loaded...")
- file.close()
- except:
- print("[ERROR]no file named owners")
- print("2 second to read the error")
- time.sleep(2)
- exit()
- time.sleep(1)
- ###admin
- admin = []
- try:
- file = open("admin.txt", "r")
- for name in file.readlines():
- if len(name.strip()) > 0:
- admin.append(name.strip())
- print("[INFO]Admin loaded...")
- file.close()
- except:
- print("[ERROR]no file named admin")
- print("2 second to read the error")
- time.sleep(2)
- exit()
- time.sleep(1)
- ##archknight
- archknight = []
- try:
- file = open("archknight.txt", "r")
- for name in file.readlines():
- if len(name.strip()) > 0:
- archknight.append(name.strip())
- print("[INFO]archknight loaded...")
- file.close()
- except:
- print("[ERROR]no file named archknight")
- print("2 second to read the error")
- time.sleep(2)
- exit()
- time.sleep(1)
- ##whitelist
- whitelist = []
- try:
- file = open("whitelist.txt", "r")
- for name in file.readlines():
- if len(name.strip()) > 0:
- whitelist.append(name.strip())
- print("[INFO]whitelist loaded...")
- file.close()
- except:
- print("[ERROR]no file named whitelist")
- print("2 second to read the error")
- time.sleep(2)
- exit()
- time.sleep(1)
- #END#
- #Dlist
- dlist = []
- f = open("dlist.txt", "r") # read-onlyimport
- for name in f.readlines():
- if len(name.strip())>0: dlist.append(name.strip())
- f.close()
- #END#
- #SN TRY
- sn = dict()
- try:
- f = open('note.txt','r')
- sn = eval(f.read())
- f.close()
- except:pass
- ## Send Notes
- sasaran = dict()
- f = open ("notes.txt", "r") #read-only
- for line in f.readlines():
- try:
- if len(line.strip())>0:
- to, body, sender = json.loads(line.strip())
- sasaran[to] = json.dumps([body, sender])
- except:
- print("[Error] Notes load fails : %s" % line)
- f.close()
- # SN Notifs
- notif = []
- f = open("notif.txt", "r")
- for name in f.readlines():
- if len(name.strip())>0: notif.append(name.strip())
- f.close
- blacklist = []
- f = open("blacklist.txt", "r")
- for name in f.readlines():
- if len(name.strip())>0: blacklist.append(name.strip())
- f.close()
- ##Buat Module Dasar untuk perintah
- ### Gua kasih contoh (bonus) yaitu : youtube search selebihnya buat sendiri
- def yt(args):
- """
- #In case you don't know how to use this function
- #type this in the python console:
- >>> tube("pokemon dash")
- #and this function would return this thing:
- {'title': 'TAS (DS) Pokémon Dash - Regular Grand Prix', 'descriptions': '1st round Grand Prix but few mistake a first time. Next Hard Grand Prix will know way and few change different Pokémon are more faster and same course Cup.', 'uploader': 'EddieERL', 'link': 'http://www.youtube.com/watch?v=QdvnBmBQiGQ', 'videoid': 'QdvnBmBQiGQ', 'viewcount': '2014-11-04T15:43:15.000Z'}
- """
- search = args.split()
- url = urlreq.urlopen("https://www.googleapis.com/youtube/v3/search?q=%s&part=snippet&key=AIzaSyBSnh-sIjd97_FmQVzlyGbcaYXuSt_oh84" % "+".join(search))
- udict = url.read().decode('utf-8')
- data = json.loads(udict)
- rest = []
- for f in data["items"]:
- rest.append(f)
- d = random.choice(rest)
- link = "http://www.youtube.com/watch?v=" + d["id"]["videoId"]
- videoid = d["id"]["videoId"]
- title = d["snippet"]["title"]
- uploader = d["snippet"]["channelTitle"]
- descript = d["snippet"]['description']
- count = d["snippet"]["publishedAt"]
- return "Result: %s <br/><br/><br/><br/><br/><br/><br/><br/><font color='#ffcc00'><b>%s</b></font><br/><font color='#ff0000'><b>Uploader</b></font>:<b> %s</b><br/><font color='#ff0000'><b>Uploaded on</b></font>: %s<br/><font color='#ff0000'><b>Descriptions</b></font>:<i> %s ...</i><br/> " % (link, title, uploader, count, descript[:200])
- ### Set color untuk bot elu
- class TestBot(ch.RoomManager):
- def onInit(self):
- self.setNameColor("FFFFFF")
- self.setFontColor("FF0000")
- self.setFontFace("1")
- self.setFontSize(11)
- self.enableBg()
- self.enableRecording()
- ##Connecting
- def onConnect(self, room):
- print("Connected")
- def onReconnect(self, room):
- print("Reconnected")
- def onDisconnect(self, room):
- print("Disconnected")
- #################################################################
- ### untuk mengatur level acces bot elu
- #################################################################
- def getAccess(self, user):
- if user.name in owners: return 4 # Owners
- elif user.name in admin: return 3 # Admins
- elif user.name in archknight: return 2 # Arch Knight
- elif user.name in whitelist: return 1
- elif user.name in dlist: return 0
- else: return 0
- ######### Untuk pesan yang ingin dijawab lu
- def onMessage(self, room, user, message):
- try:
- msgdata = message.body.split(" ",1)
- if len(msgdata) > 1:
- cmd, args = msgdata[0], msgdata[1]
- else:
- cmd, args = msgdata[0],""
- cmd=cmd.lower()
- global lockdown
- global newnum
- print(user.name+" - "+message.body)
- if user.name in notif:
- room.message(user.name+", you got ("+str(len(sn[user.name]))+") messages unread. Do irn to read them")
- notif.remove(user.name)
- if user == self.user: return
- if "rere" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["wuts? "]),True)
- if "kacang" == message.body:
- if self.getAccess(user) >= 4:
- room.message (random.choice(["Kacang adalah makanan yang enak, tapi kalo dikacangin beda lagi ceritanya "]),True)
- if "test" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["Kacang Polong"+"@"sntonick(user.name)+ " :D "]),True)
- if "maid" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["Ja?, ada yang bisa dibantu "+sntonick(user.name)+ " ? "]),True)
- if "natsuru" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["Ja?, ada yang bisa dibantu "+sntonick(user.name)+ " ? "]),True)
- if "oyasumi" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message("Oyasumi "+sntonick(user.name)+ " ^o^ ")
- if "ohayou" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message("Ohayou "+sntonick(user.name)+ " ^o^ ")
- if "konnichiwa" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message("Konnichiwa "+sntonick(user.name)+ " ^o^ "),True
- if "konbanwa" == message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message("Konbanwa "+sntonick(user.name)+ " ^o^ ")
- if "afk" in message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["See ya, jangan lama lama "+sntonick(user.name)+" :) ",]),True)
- if "brb" in message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["dada Bos "+sntonick(user.name)+" :) ",]),True)
- if "off" in message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["Bye "+sntonick(user.name)+" :D ",]),True)
- if "fakyu natsuru" in message.body:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0 and not user.name in blacklist:
- room.message (random.choice(["Fakyu "+sntonick(user.name)+" 凸(⊙▂⊙✖ ) !! ",]),True)
- if message.body == "": return
- if message.body[0] in ["ganti sama prefix lu"]:
- data = message.body[1:].split(" ", 1))
- if len(data) > 1:
- cmd, args = data[0], data[1]
- else:
- cmd, args = data[0], ""
- ##untuk mengakses room level dll yang diduduki bot lu
- if self.getAccess(user) == 0: return
- def pars(args):
- args=args.lower()
- for name in room.usernames:
- if args in name:return name
- def roompars(args):
- args = args.lower()
- for name in self.roomnames:
- if args in name:return name
- def roomUsers():
- usrs = []
- gay = []
- prop = 0
- prop = prop + len(room._userlist) - 1
- for i in room._userlist:
- i = str(i)
- usrs.append(i)
- while prop >= 0:
- j = usrs[prop].replace("<User: ", "")
- i = j.replace(">", "")
- gay.append(i)
- prop = prop - 1
- return gay
- def getParticipant(arg):
- rname = self.getRoom(arg)
- usrs = []
- gay = []
- finale = []
- prop = 0
- prop = prop + len(rname._userlist) - 1
- for i in rname._userlist:
- i = str(i)
- usrs.append(i)
- while prop >= 0:
- j = usrs[prop].replace("<User: ", "")
- i = j.replace(">", "")
- gay.append(i)
- prop = prop - 1
- for j in gay:
- if j not in finale:
- finale.append(j)
- return finale
- ##cmds
- if cmd == "cmds":
- if user.name in owners and not user.name in admin and not user.name in archknight and not user.name in whitelist:
- room.message("<br/>"+user.name+" Rank 4 [Owner] "+"<br/>"+"Perintah nothing :<br/> Isi sendiri sesua perintah lu",True)
- if user.name in admin and not user.name in owners and not user.name in archknight and not user.name in whitelist:
- room.message("<br/>"+user.name+" Rank 3 [Admin] "+"<br/>"+" Perintah nothing :<br/>Isi sendiri sesua perintah lu",True)
- if user.name in archknight and not user.name in owners and not user.name in admin and not user.name in whitelist:
- room.message("<br/>"+user.name+" Rank 2 [Archknight] "+"<br/>"+" Perintah nothing:<br/>Isi sendiri sesua perintah lu",True)
- if user.name in whitelist and not user.name in owners and not user.name in admin and not user.name in archknight:
- room.message("<br/>"+user.name+" Rank 1 [Whitelist] "+"<br/>"+" Perintah nothing :<br/>Isi sendiri sesua perintah lu",True)
- ##Setrank
- if cmd == "setrank":
- if self.getAccess(user) < 4:return
- try:
- if len(args) >= 3:
- name = args
- if pars(name) == None:
- name = name
- elif pars(name) != None:
- name = pars(name)
- name, rank = args.lower().split(" ", 1)
- if rank == "4":
- owners.append(name)
- f = open("owners.txt", "w")
- f.write("\n".join(owners))
- f.close()
- room.message("Sukses")
- if name in admin:
- admin.remove(name)
- f = open("admin.txt", "w")
- f.write("\n".join(admin))
- f.close()
- if name in archknight:
- archknight.remove(name)
- f = open("archknight.txt", "w")
- f.write("\n".join(archknight))
- f.close()
- if name in whitelist:
- whitelist.remove(name)
- f = open("whitelist.txt", "w")
- f.write("\n".join(whitelist))
- f.close()
- if rank == "3":
- admin.append(name)
- f = open("admin.txt", "w")
- f.write("\n".join(admin))
- f.close()
- room.message("Sukses")
- if name in owners:
- owners.remove(name)
- f = open("owners.txt", "w")
- f.write("\n".join(owners))
- f.close()
- if name in archknight:
- archknight.remove(name)
- f = open("archknight.txt", "w")
- f.write("\n".join(archknight))
- f.close()
- if name in whitelist:
- whitelist.remove(name)
- f = open("whitelist.txt", "w")
- f.write("\n".join(whitelist))
- f.close()
- if rank == "2":
- archknight.append(name)
- f = open("archknight.txt", "w")
- f.write("\n".join(archknight))
- f.close()
- room.message("Sukses")
- if name in owners:
- owners.remove(name)
- f = open("owners.txt", "w")
- f.write("\n".join(owners))
- f.close()
- if name in admin:
- admin.remove(name)
- f = open("admin.txt", "w")
- f.write("\n".join(admin))
- f.close()
- if name in whitelist:
- whitelist.remove(name)
- f = open("whitelist.txt", "w")
- f.write("\n".join(whitelist))
- f.close()
- if rank == "1":
- whitelist.append(name)
- f = open("whitelist.txt", "w")
- f.write("\n".join(whitelist))
- f.close()
- room.message("Sukses")
- if name in owners:
- owners.remove(name)
- f = open("owners.txt", "w")
- f.write("\n".join(owners))
- f.close()
- if name in admin:
- admin.remove(name)
- f = open("admin.txt", "w")
- f.write("\n".join(admin))
- f.close()
- if name in archknight:
- archknight.remove(name)
- f = open("archknight.txt", "w")
- f.write("\n".join(archknight))
- f.close()
- except:
- room.message("something wrong")
- # clear
- elif cmd == "clear":
- if room.getLevel(self.user) > 0:
- if self.getAccess(user) >= 4 or room.getLevel(user) == 2:
- room.clearall(),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- room.clearUser(ch.User(random.choice(room.usernames))),
- else: room.message("Only rank 4+ or the room owner can do this")
- else:
- room.message("aku bukan mods disini :|")
- ##delete chat
- elif (cmd == "delete" or cmd == "dl" or cmd == "del"):
- if room.getLevel(self.user) > 0:
- if self.getAccess(user) >= 1 or room.getLevel(user) > 0:
- name = args.split()[0].lower()
- room.clearUser(ch.User(name))
- else:room.message("kamu tidak bisa melakukannya!!")
- else:
- room.message("aku bukan mods disini :|")
- ##Eval
- if cmd == "ev" or cmd == "eval" or cmd == "e" and user.name == "rifky102":
- if self.getAccess(user) == 4:
- ret = eval(args)
- if ret == None:
- room.message("Done.")
- return
- room.message(str(ret))
- ###Youtube
- elif cmd == "youtube" or cmd == "yt":
- if args:
- room.message(tube(args),True)
- except Exception as e:
- try:
- et, ev, tb = sys.exc_info()
- lineno = tb.tb_lineno
- fn = tb.tb_frame.f_code.co_filename
- room.message("[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e)))
- return
- except:
- room.message("Undescribeable error detected !!")
- return
- ##Other Crap here, Dont worry about it
- def onFloodWarning(self, room):
- room.reconnect()
- def onJoin(self, room, user):
- print(user.name + " joined the chat!")
- def onLeave(self, room, user):
- print(user.name + " left the chat!")
- def onUserCountChange(self, room):
- print("users: " + str(room.usercount))
- if __name__ == "__main__":
- TestBot.easy_start(rooms, botname, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement