Skip to content

Instantly share code, notes, and snippets.

@Kakkoiikun
Last active August 8, 2019 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kakkoiikun/363dbf2ee4ead95ca5982c5c38a01de0 to your computer and use it in GitHub Desktop.
Save Kakkoiikun/363dbf2ee4ead95ca5982c5c38a01de0 to your computer and use it in GitHub Desktop.
Chatango Bot Tutorial
How to make a chatango bot --> Made by Kakkoiikun
-------------------------------------------------------
Updates:
-> Updated the ch.py link and changed 3.6.0 to 3.6.5
------------------------------------------------------------------
Preparations:
1. Download ch.py at https://pastebin.com/81msujvx
2. Install Python 3.6.5 at https://www.python.org/downloads/release/python-365/
3. To open Python 3.6.5 Choose Start > IDLE
4. Place ch.py inside the folder you want
5. Place the following codes inside the folder where the ch.py is
6. Set the indent width of the editor to 2 by Format > New Indent Width
-------------------------------------------------------------------
We need to import the ch.py and other modules to the code
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
---------------------------------------------------------
We also need to make our class. The class can be anything you want but do not forget to add ch.RoomManager. If you are wondering why do we need RoomManager, it is because if you looked at the ch.py itself, there will be a class named RoomManager and the stuffs we need are in there. My class is bot. Replace the one before to this one.
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager)
-------------------------------------------------------
The fun is almost going! We are already on the defines which is fun for me. The first define is the def onInit which is the font styles of the bot. Like html but you will need to remove "#". On the setFontSize (font size), make sure not to add quotation marks
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager):
def onInit(self):
self.setNameColor("000000")
self.setFontColor("000000")
self.setFontFace("Consolas")
self.setFontSize(12)
-------------------------------------------------------------------
Next define is the connections. onConnect is when it is connected. onReconnect is when it reconnected and onDisconnect is when it suddenly disconnected.
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager):
def onInit(self):
self.setNameColor("000000")
self.setFontColor("000000")
self.setFontFace("Consolas")
self.setFontSize(12)
def onConnect(self, room):
print("[INFO]Connected to "+room.name)
def onReconnect(self, room):
print("[INFO]Reconnected to "+room.name)
def onDisconnect(self, room):
print("[INFO]Disconnected to "+room.name)
-------------------------------------------------------------------------------------
Next is the commands. The "!" is the prefix of the bot for commands. We need to add "if self.user == user: return" to disables the bot to respond to itself. Without this define, what will you do with the bot? xD
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager):
def onInit(self):
self.setNameColor("000000")
self.setFontColor("000000")
self.setFontFace("Consolas")
self.setFontSize(12)
def onConnect(self, room):
print("[INFO]Connected to "+room.name)
def onReconnect(self, room):
print("[INFO]Reconnected to "+room.name)
def onDisconnect(self, room):
print("[INFO]Disconnected to "+room.name)
def onMessage(self, room, user, message):
print("[%s] %s: %s" % (room.name, user.name, message.body))
if self.user == user: return
msgd = message.body.split(" ", 1)
if len(msgd) > 1:
cmd, args = msgd[0], msgd[1]
else:
cmd, args = msgd[0], ""
cmd = cmd.lower()
if len(cmd) > 0:
if cmd[0] == "!": ##prefix
used_prefix = True
cmd = cmd[1:]
else:
used_prefix = False
else:
return
---------------------------------------------
Commands will be this section.
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager):
def onInit(self):
self.setNameColor("000000")
self.setFontColor("000000")
self.setFontFace("Consolas")
self.setFontSize(12)
def onConnect(self, room):
print("[INFO]Connected to "+room.name)
def onReconnect(self, room):
print("[INFO]Reconnected to "+room.name)
def onDisconnect(self, room):
print("[INFO]Disconnected to "+room.name)
def onMessage(self, room, user, message):
print("[%s] %s: %s" % (room.name, user.name, message.body))
if self.user == user: return
msgd = message.body.split(" ", 1)
if len(msgd) > 1:
cmd, args = msgd[0], msgd[1]
else:
cmd, args = msgd[0], ""
cmd = cmd.lower()
if len(cmd) > 0:
if cmd[0] == "!": ##prefix
used_prefix = True
cmd = cmd[1:]
else:
used_prefix = False
else:
return
if used_prefix and cmd == "say":
if args:
room.message(args)
else:
room.message("Nothing to say")
elif used_prefix and cmd == "anc" or used_prefix and cmd == "announce":
if args:
if user.name == "yourusernamehere": ##lowercase of your username
for _room in self.rooms:
_room.message(user.name.title()+": "+message.body)
else:
room.message("You do not have permission to use this command.")
else:
room.message("Nothing to announce")
elif used_prefix and cmd == "eval":
if user.name == "yourusernamehere": ##lowercase of your username
if args:
room.message(str(eval(args)))
else:
room.message("Nothing to evaluate")
else:
room.message("You do not have permission to evaluate @"+user.name.title())
elif used_prefix and cmd == "mini":
if args:
try:
args=args.lower()
stuff=str(urlreq.urlopen("http://"+args+".chatango.com").read().decode("utf-8"))
crap,mini=stuff.split("<span class=\"profile_text\"><!-- google_ad_section_start -->",1)
mini,crap=mini.split("<!-- google_ad_section_end --></span>",1)
mini=mini.replace("<img","<!")
room.message(mini, True)
except:
room.message("No data received")
else:
room.message("Invalid")
elif used_prefix and cmd == "end":
if user.name == "yourusernamehere": ##lowercase of your username
time.sleep(1)
self.stop()
else:
room.message("You can't end my life") ##lol
elif used_prefix and cmd == "reconnect":
room.reconnect()
room.message("I have reconnected as you have wished")
elif used_prefix and cmd == "join":
if args:
name = args.lower()
self.joinRoom(name)
room.message("I have joined "+name)
else:
room.message("Invalid")
elif used_prefix and cmd == "leave":
if user.name == "yourusernamehere": ##lowercase of your username
if args:
name = args.lower()
self.leaveRoom(name)
room.message("I have left "+name)
else:
room.message("Invalid")
else:
room.message("No Permission")
elif used_prefix and cmd == "usercount":
room.message("I can see "+str(room.usercount)+" people here :)")
elif used_prefix and cmd == "pm":
name, message = args.split(" ", 1)
name = name.lower()
self.pm.message(ch.User(name), "Message from "+user.name.title()+": "+args)
room.message("Done!")
elif used_prefix and cmd == "cmds":
room.message("My commands: !say, !anc (owner), !eval (owner), !mini, !end (owner), !reconnect, !join, !leave (owner), !usercount, !pm")
---------------------------------------------------------
Wow! We are on the last part! The easy_start will be your class. For example, your class is "example", the code will be "example.easy_start". And on the room, for example, the room link is "http://exampleroom.chatango.com/", the room will be "exampleroom". The other is the bot's info.
Code:
import ch
import time
import sys
import urllib
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
class bot(ch.RoomManager):
def onInit(self):
self.setNameColor("000000")
self.setFontColor("000000")
self.setFontFace("Consolas")
self.setFontSize(12)
def onConnect(self, room):
print("[INFO]Connected to "+room.name)
def onReconnect(self, room):
print("[INFO]Reconnected to "+room.name)
def onDisconnect(self, room):
print("[INFO]Disconnected to "+room.name)
def onMessage(self, room, user, message):
print("[%s] %s: %s" % (room.name, user.name, message.body))
if self.user == user: return
msgd = message.body.split(" ", 1)
if len(msgd) > 1:
cmd, args = msgd[0], msgd[1]
else:
cmd, args = msgd[0], ""
cmd = cmd.lower()
if len(cmd) > 0:
if cmd[0] == "!": ##prefix
used_prefix = True
cmd = cmd[1:]
else:
used_prefix = False
else:
return
if used_prefix and cmd == "say":
if args:
room.message(args)
else:
room.message("Nothing to say")
elif used_prefix and cmd == "anc" or used_prefix and cmd == "announce":
if args:
if user.name == "yourusernamehere": ##lowercase of your username
for _room in self.rooms:
_room.message(user.name.title()+": "+message.body)
else:
room.message("You do not have permission to use this command.")
else:
room.message("Nothing to announce")
elif used_prefix and cmd == "eval":
if user.name == "yourusernamehere": ##lowercase of your username
if args:
room.message(str(eval(args)))
else:
room.message("Nothing to evaluate")
else:
room.message("You do not have permission to evaluate @"+user.name.title())
elif used_prefix and cmd == "mini":
if args:
try:
args=args.lower()
stuff=str(urlreq.urlopen("http://"+args+".chatango.com").read().decode("utf-8"))
crap,mini=stuff.split("<span class=\"profile_text\"><!-- google_ad_section_start -->",1)
mini,crap=mini.split("<!-- google_ad_section_end --></span>",1)
mini=mini.replace("<img","<!")
room.message(mini, True)
except:
room.message("No data received")
else:
room.message("Invalid")
elif used_prefix and cmd == "end":
if user.name == "yourusernamehere": ##lowercase of your username
time.sleep(1)
self.stop()
else:
room.message("You can't end my life") ##lol
elif used_prefix and cmd == "reconnect":
room.reconnect()
room.message("I have reconnected as you have wished")
elif used_prefix and cmd == "join":
if args:
name = args.lower()
self.joinRoom(name)
room.message("I have joined "+name)
else:
room.message("Invalid")
elif used_prefix and cmd == "leave":
if user.name == "yourusernamehere": ##lowercase of your username
if args:
name = args.lower()
self.leaveRoom(name)
room.message("I have left "+name)
else:
room.message("Invalid")
else:
room.message("No Permission")
elif used_prefix and cmd == "usercount":
room.message("I can see "+str(room.usercount)+" people here :)")
elif used_prefix and cmd == "pm":
name, message = args.split(" ", 1)
name = name.lower()
self.pm.message(ch.User(name), "Message from "+user.name.title()+": "+args)
room.message("Done!")
elif used_prefix and cmd == "cmds":
room.message("My commands: !say, !anc (owner), !eval (owner), !mini, !end (owner), !reconnect, !join, !leave (owner), !usercount, !pm")
rooms = ["exampleroom1", "exampleroom2"]
if __name__ == "__main__":
bot.easy_start(rooms, "BotUsername", "BotPassword")
---------------------------------------------------------
You are done! Thank you for reading this one! You can pm me on chatango (Kakkoiikun) if you need help.
You can always add commands and edit them especially the messages and the prefix.
Code --> https://gist.github.com/Kakkoiikun/1c2dfb9ea373b04f6431e7795f91f704
And you need a lot of knowledge and effort to make your bot the python version of b0t
@LeoTheLionSlayer
Copy link

Heh, I know you.

@Kakkoiikun
Copy link
Author

@LeoTheLionSlayer I know you too.

@natineko02
Copy link

hi hi :u I did everything but I have some trouble with the examplebot I'm using windows :u pleasehelp I did text u in chatango :'u

Copy link

ghost commented Apr 18, 2019

How to display messages from a file in chat by timer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment