Chatango BOT commands 11-24-2013, 05:09 PM
#1
This tutorial is a follow-up of Zeb's original [TUTORIAL] CHATANGO BOT TUTORIAL. This is also not endorsed by Zeb himself.
Let's begin before I grow wrinckles.
We need a prefix for commands. Without this we won't have any working commands aside from the non-prefixed ones.
For all commands in this tutorial to work import a bit more than just ch.py. Just copy and paste the following into the imports section of your BOT.
My bot prefix is a backslash for easy use. That's just me.
We will also need a way to split commands, and arguments. So let's add those materials.
We also should add a way to determine when to ignore commands. Say if you do /say /say, the bot will do /say twice until it can't say anything else. This being said we can't have that. Infinite loops are bad unless useful. You're going to be adding all of this under your onMessage, unless another specified location is given.
You're going to have to add if self.user == user: return.
And print if a user says something.
Let's move on to a youtube command. Which was mention in Zeb's tutorial as a reply. However, I am doing this to help clear up any misconception.
What this is telling the bot to do is go to a url, open it up, read it's code, and report back in a chat message if the video does not exist, show the video itself, or show an error.
Next is the profile command.
This does the same as the youtube command, but instead it searches profiles. Same concept though, so you should be able to grasp it easily.
We're going to do a die command so that you can easily stop the bot.
The command basically tells the bot to stop ONLY on the command of the specified user. If a user that is not specified tries the command it will say "[INFO][CMD]KILL COMMAND FAILED." and return to it's normal state.
Announce commands are VERY useful. They are used to send a message to all chatrooms the bot is in. Useful for bots such as botteh.
And we can't forget the all time famous say command.
Once more this tutorial is a follow-up of Zeb's [TUTORIAL] CHATANGO BOT TUTORIAL. And again this is also not endorsed by Zeb himself. If you have any questions for a command, or comments, peanuts, popcorn, anything slap it down below. I might be able to help you.
If you want to see my bot in action go to http://intellectchat.chatango.com/
Let's begin before I grow wrinckles.
We need a prefix for commands. Without this we won't have any working commands aside from the non-prefixed ones.
For all commands in this tutorial to work import a bit more than just ch.py. Just copy and paste the following into the imports section of your BOT.
Code:
import sys
import os
import cgi
import traceback
import time
import urllib
import datetime
import binascii
import json
import threading
import random
from xml.etree import cElementTree as ET
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
onConnect(self, room):
room.message("Connected.")
Print("Connected")
onReronnect(self, room):
print("Reconnected")
onDisconnect(self, room):
Print("Disconnected")
onMessage(self, room, user, message):
prefix = "/"My bot prefix is a backslash for easy use. That's just me.
We will also need a way to split commands, and arguments. So let's add those materials.
Code:
onMessage(self, room, user, message):
prefix = "/"
msgdata = message.body.split(" ",1)
if len(msgdata) > 1:
cmd, args = msgdata[0], msgdata[1]
else:
cmd, args = msgdata[0],""
cmd=cmd.lower()
if len(cmd) >0:
if cmd[0]==prefix:
used_prefix = True
cmd = cmd[1:]
else:
used_prefix= False
else:
returnWe also should add a way to determine when to ignore commands. Say if you do /say /say, the bot will do /say twice until it can't say anything else. This being said we can't have that. Infinite loops are bad unless useful. You're going to be adding all of this under your onMessage, unless another specified location is given.
You're going to have to add if self.user == user: return.
Code:
onMessage(self, room, user, message):
prefix = "/"
if self.user == user: return
msgdata = message.body.split(" ",1)
if len(msgdata) > 1:
cmd, args = msgdata[0], msgdata[1]
else:
cmd, args = msgdata[0],""
cmd=cmd.lower()
if len(cmd) >0:
if cmd[0]==prefix:
used_prefix = True
cmd = cmd[1:]
else:
used_prefix= False
else:
returnAnd print if a user says something.
Code:
onMessage(self, room, user, message):
print(user.name+": "+message.body)
prefix = "/"
if self.user == user: return
msgdata = message.body.split(" ",1)
if len(msgdata) > 1:
cmd, args = msgdata[0], msgdata[1]
else:
cmd, args = msgdata[0],""
cmd=cmd.lower()
if len(cmd) >0:
if cmd[0]==prefix:
used_prefix = True
cmd = cmd[1:]
else:
used_prefix= False
else:
returnLet's move on to a youtube command. Which was mention in Zeb's tutorial as a reply. However, I am doing this to help clear up any misconception.
Code:
elif used_prefix and cmd=="youtube" and len(args) > 0:
try:
yword=args.replace(" ","_")
ydata= urlreq.urlopen("http://gdata.youtube.com/feeds/api/videos?vq="+yword+"&racy=include&orderby=relevance&max-results=1")
yread= str(ydata.read())
if "<openSearch:totalResults>0</openSearch:totalResults>" in yread:
room.message("No results found for "+args)
else:
trash , yclean=yread.split("<media:player url='http://www.youtube.com/watch?v=",1)
yclean , trash=yclean.split("&",1)
room.message("http://http://www.youtube.com/watch?v="+yclean,True)
except:
room.message("Error.")What this is telling the bot to do is go to a url, open it up, read it's code, and report back in a chat message if the video does not exist, show the video itself, or show an error.
Next is the profile command.
Code:
elif used_prefix and cmd=="profile" and len(args) > 0:
try:
name=args
pdata= urlreq.urlopen("http://st.chatango.com/profileimg/"+args[:1]+"/"+args[1:2]+"/"+args+"/mod1.xml")
pread= str(pdata.read())
if "<img style" in pread:
room.message(args+" is not (yet) a chatango username.")
else:
trash , pclean=pread.split("<body>",1)
pclean , trash=pclean.split("</body>",1)
room.message(urllib.parse.unquote(''+pclean+''"<br>"), True)
except:
room.message(args+" is not (yet) a chatango username.")This does the same as the youtube command, but instead it searches profiles. Same concept though, so you should be able to grasp it easily.
We're going to do a die command so that you can easily stop the bot.
Code:
elif used_prefix and cmd=="die":
if user.name.lower() == "yourusernamehere":
room.message("Saved data.")
print("[INFO][DATA][CMD]Saved data.")
f.close
room.message("[INFO][CMD]KILL COMMAND IN PROGRESS.")
time.sleep(1)
self.stop()
else:
room.message("[INFO][CMD]KILL COMMAND FAILED.")The command basically tells the bot to stop ONLY on the command of the specified user. If a user that is not specified tries the command it will say "[INFO][CMD]KILL COMMAND FAILED." and return to it's normal state.
Announce commands are VERY useful. They are used to send a message to all chatrooms the bot is in. Useful for bots such as botteh.
Code:
elif used_prefix and cmd == "anc" and len(args) > 0:
if user.name.lower() == "yourusernamehere":
for _room in self.rooms:
_room.message("Announcement from "+user.name.title()+": "+args)
else:
room.message("Owners only, BUB")And we can't forget the all time famous say command.
Code:
elif used_prefix and cmd == "say":
if args:
room.message(args)
else:
room.message("Nothing to say.")Once more this tutorial is a follow-up of Zeb's [TUTORIAL] CHATANGO BOT TUTORIAL. And again this is also not endorsed by Zeb himself. If you have any questions for a command, or comments, peanuts, popcorn, anything slap it down below. I might be able to help you.
If you want to see my bot in action go to http://intellectchat.chatango.com/
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)








![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)








