############################################################################ ############################################################################ #### Getting Started Bot ############ #### File = ExampleBot.py ############ #### Originaly by = TryHardHusky ############ #### Edited by = 0rX ############ #### you can PM for info about making a chatango ############ #### bot in http://0rx.chatango.com, and you can ############ #### and you can also chat in : ############ #### http://monosekai.chatango.com ############ #### Last update: ############ #### 3.21 AM July, 5 2015 by 0rx ############ ############################################################################ ############################################################################ ##Importing Random Crap xD #here you can see that you're importing ch library import ch import random import sys import re if sys.version_info[0] > 2: import urllib.request as urlreq else: import urllib2 as urlreq ##Dance moves! #kinda useless dancemoves = [ "(>^.^)>", "(v^.^)v", ] # implied command? # call bot name with command after # call bot name with command after #Setting Pretty Colors #Font setting for your bot class TestBot(ch.RoomManager): def onInit(self): self.setNameColor("FE8A14") self.setFontColor("FE8A14") self.setFontFace("1") self.setFontSize(10) self.enableBg() self.enableRecording() ##Connecting Crap #This is what will be printed on your python console when event called def onConnect(self, room): print("Connected") def onReconnect(self, room): print("Reconnected") def onDisconnect(self, room): print("Disconnected") ##Ignore this, you dont need to worry about this #Well, you can actually take a little time to look at it and learn something def onMessage(self, room, user, message): try: if room.getLevel(self.user) > 0: print(user.name, message.body) else: print(user.name, message.body) if self.user == user: return if message.body[0] == "-" : data = message.body[1:].split(" ", 1) if len(data) > 1: cmd, args = data[0], data[1] else: cmd, args = data[0], "" ##COMMANDS! #Setting up commands for yer bot #commands section ##You may want/need to evaluate something about your bot. if cmd == "ev" or cmd == "eval" or cmd == "e": ret = eval(args) if ret == None: room.message("Done.") return room.message(str(ret)) ##Say #Make your bot say what you want elif cmd == "say": room.message("im just an robots") elif cmd == "ohayou": jawab = ["ohayou","ohayou"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "oha": jawab = ["ohayou","ohayou"] room.message(random.choice(jawab)+" @"+user.name) if cmd == "ko sepi" or cmd == "sevi" or cmd == "sepi ya" or cmd == "sepi": jawab = ["aku akan menghibur mu",""] room.message(random.choice(jawab)+" @"+user.name) for i, msg in enumerate(dancemoves): self.setTimeout(i / 2, room.message, msg) elif cmd == "++++": jawab = ["bot system kaneki v1.0 siap membantu"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "fight": jawab = ["http://data2.whicdn.com/images/156069110/large.gif"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "help": jawab = ["i can't helping you :v #RIPENGLISH :v"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "afk": jawab = ["terimakasih untuk chat nya hari ini"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "crunch": jawab = ["https://31.media.tumblr.com/50dcec4f797eb86ea483558695c874f1/tumblr_nqru66BNYc1u8lwqgo1_500.gif"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "nja": jawab = ["bye2"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "coeghd": jawab = ["anda kenapa?"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == ":v": jawab = ["emoticon dewa"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "lebaran": jawab = ["minal aidzin wal faizin kk"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "gue tamvan gak ?": jawab = ["kaga","tamvan","jelek","biasa aja"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "hmm": jawab = ["maho detcted"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "konbanwa": jawab = ["tidur sana jangan ngalong :v"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "naruto": jawab = ["adalah anime yang selalu flash back"] room.message(random.choice(jawab)+" @"+user.name) elif cmd == "bnp": jawab = ["erorr forbidden access denied"] room.message(random.choice(jawab)+" @"+user.name) ##Random User #What's this for ? this one cmd will make your boy say the name of a random user in a room if cmd == "randomuser": room.message(random.choice(room.usernames)) ##Check Level #This one cmd is tho make your bot say your mod level in the current room you're in elif cmd == "mylvl": room.message("Your mod level: %i" %(room.getLevel(user))) ##List Mods #List of Mods and Owner name in the current room you're in elif cmd == "mods": room.message(", ".join(room.modnames + [room.ownername])) ##DANCE!!!! #Dance ? Of Course !!! ^_^ elif cmd == "dance": for i, msg in enumerate(dancemoves): self.setTimeout(i / 2, room.message, msg) ##Check if Mod #not really important elif cmd == "ismod": user = ch.User(args) if room.getLevel(user) > 0: room.message("yesh") else: room.message("nope") 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)) def onMessageDelete(self, room, user, msg): print("MESSAGE DELETED: " + user.name + ": " + msg.body) if __name__ == "__main__": TestBot.easy_start() #The End!!
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question