Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 815 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chatango Bot Tutorial

#1
Welcome to my wonderfully wonderful tutorial, friends. Before we begin, I'd just like to make it clear that this is EXCLUSIVELY for the chat site, Chatango. Recently there's been an influx of bots there, did you know that? It's pretty obnoxious, honestly. Especially since, well, I HATE them.

So you might be wondering, "But Zeb, if you hate Chatango bots, why are you showing us how to make more of them?" Well, Timmy, I'm showing you because the more there are, the more people will being hating them, and the less widespread they will be in the end. And if it doesn't work out like that? Well, at least it'll help piss plenty of bastards off. And that's more than enough for me.

~~PYTHON and YOU~~

Before creating a Chatango bot, you need a couple of things.
First and foremost, you'll need the

[To see links please register here]

. This can be found on the Python website.
You'll also need a text editor. Python comes with one, as does your OS. But I personally reccomend

[To see links please register here]

.
And now for the bot itself, you'll need the

[To see links please register here]

library. You can thank the all-around genius Lumirayz for this lovely piece of work.

... I'm assuming that if you've read this far, you've got all the bits and bobs needed to build a bot. If not, STOP RIGHT NOW. Learning by doing is the only real way to learn. Get your shit together and hit up all the downloads...

Got them? Good. You can continue along now...

~~BABY STEPS~~
*Skip this if you already know how Python works*

First things first, you're gonna want to make a basic Python file.
Make a new folder labeled "Chat Bot", open up your text editor of choice and create a new file.

To confirm it's working, paste the following into the file and save it as bot.py.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Be sure to save it in the proper location, if only for the sake of organization.

Run the program by double-clicking your new file. A command prompt should pop up, saying "Hello, Chatango!". If it doesn't, you've either saved it wrong or you've downloaded the wrong version of Python... For shame. It takes skills to screw that up. Go back to the beginning and try again. READ IT MORE CLOSELY, THIS TIME, BUB.

Well, assuming you've gotten it all working, we'll move on to the actual bot...

~~BOTTA BING, BOTTA BOOM~~

Remember that file I had you download at the start? That ch.py thing? thing?
If you haven't already moved it to our project folder, do it now. I'll wait...

Open up our bot file again.
We'll start by importing out new library. Clear what you've already entered, if there's anything there. You can import other Python files with


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


In this case, we've imported our own library. Usually you'll be importing core Python libraries, but it can be used to import any .pyfiles, so long as it's in the same folder, or Python's lib folder.

Now that we've got that out of the way, we can use any of the functions, classes, and variables located within the file. That's obviously important, since we can't interface with the Chatango servers without it.

Well, not unless you're familiar with how it works. But as I like to say, why go an extra mile when you've got the same place right next door?

To being using the bot, we need to tell it to connect to Chatango. To do this, we need to create a new class.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Boom. That easy.
Class tells Python that we're creating a class, bot is the name of the class, and ch.RoomManager telling it what we need to include within this class, which is the RoomManager class from ch.py in this case.

So now that we have a new class, we need to activate it. As it stands, our bot will just sit there, doing nothing. That's no fun. Unless you're a weirdo. Are you a weirdo?

... Actually, forget that I asked...

To call this class, we just need to write it's name. But we don't just need the class, we need a specific function within it. Do do this, we write the class name, a period, and then the name of the function. We'll also need to include the variables the function requires, like so:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Of course, you'll need to replace the information with your own...

And the rooms variable MUST be a list, otherwise it WILL NOT WORK.

A list is exactly what it sounds like. It's just a list of strings, intergers, floats, or what have you. You can add more things to the list by seperating them with a comma, as shown above. The only limit is how many you can connect to at once. If you only intend to connect to your PMs, you can just leave the list blank.

A small note, any missing variables will be filled in when the bot is run. It will ask you for the details within the command window.


~~DANCE, SLAVE~~

"But Zeb," I hear you cry, "I tried running it, and nothing happened!"
Well, Timmy, that's because WE'RE FUCKING NOT DONE YET. And who the HELL told you to run it yet? ... Now sit down and shut up while I speak, or I'll have to get the Whippin' Stick out.

Right now, what we have is a bot shell. All it does it connect to the Chatango servers. Now we need to make it do stuff, don't we?

To do this, we've got to call a few of the functions from our library.

To start, go back to the class line. This is where all the action happens -- within our bot class. Begin a new line, just below it. Python is very picky about indentation, so enter a few spaces or hit tab once to tell it that our new line is part of the class.

We'll being by telling it to log any messages from the rooms it's in.
We do this by creating a new function, onMessage:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


See those things in the parenthesis? Those are VERY important. They store all the information we need from Chatango. Due to their importance, I'll give a brief rundown of what they do:

self- This isn't actually from Chatango. This is a Python thing. It allows you to use anything located within the class, even if it was written after the function it's used with. Normally this can't be done, because function and variable scopes only extends to things written BEFORE they're called. Which makes sense, right? You can't use something before it exists...

room - This stores what you need from the room the message is sent from, such as the name, the owner, the mods, or the connected users, as well as allows you to send messages and delete messages.

user - This stores information about the user sending the message. This includes their name and their styles (font color, name color, font size, and font style).

message - This stores information about the message being sent. This includes the actual message, the date, and the users IP(if the bots account is a mod).

Now these are obviously gonna be useful to log the message. We'll need need to get a few things for the logs to be useful, though. The name of the person speaking, the room their located in, and of course, what they're saying.

Once more, start a new line below out onMessage function and indent once more. Since we're just logging, we'll want to use the print function. We'll also be mixing variables and strings. There are a few ways to do this, but the preferred way is with format().


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


What we've done is told the program to take the string "[{0}] {1}: {2}", replace the curly brackets ({0},{1},{2}) with their respective variables(room.name, user.name.title(), message.body).

A small note, title() is NOT needed. What it does is capitalize the first letter, which makes logs more attractive.

~~YOU'RE STILL NOT DANCING~~

I'm assuming you want a little more than a stenographer, right? In this section, I'll cover a few of the other events that you might find useful.

onInit(self) - Called on init.
onMessage(self, room, user, message)- Called when a message gets received.
onJoin(self, room, user) - Called when a user joins. Anonymous users get ignored here.
onLeave(self, room, user) - Called when a user leaves. Anonymous users get ignored here.
onPMMessage(self, pm, user, body) - Called when a PM is recieved.

There are a large number more, which I'll list below, but you're most likely going to use these a lot more than the rest.

There are a few things we want our bot to have, right?
Bots will use the default(not room default) settings. That is, black font and name color, no background, Calibri, and 12 font size.
The should be changed at the start. To do this, we add the onInit function to our current bot.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Now we need to add the settings to alter the styles:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


The first two can be any valid hex color code. Font face needs to be a valid font, which can be found on the Chatango site itself. Font size is an integer. Pleaes note that integers must NOT have quotes around them, unlike strings. Putting quotes around a number will tell Python you want to treat it as a string, which have different properties than integers do.

Now that you've got a sexy font, we want to make use of that, right? We'll add a basic command to do this.
In the onMessage section, we'll add a few things...


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Wow. That's a lot more than what we've added so far, yeah? I'll bet you're wonder just what the fuck that all does. At least if you're new to Python, you will be.
If you're familiar with the language, you'll be scolding me...

Anyhow, you deserve an explanation. So calm your tits, and zip it.

I'll start with this try-except "nonsense"...

In Python, try-except is just basic error catching. Try to do this, if it doesn't work do this. We need it, because we're trying to split the message we've just recieved.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


is setting two variables at once, cmd and args. That is to say, the command and the arguments. It's splitting the message apart based on spaces. But what if there are NO spaces? Well, Python won't like that. So if it tries to split it, Python will throw an error like toddler throws a tantrum. Because Python is a big baby...

But I digress. So how do we deal with this? We give it some guidance. We tell Python exactly what to do, since it has no idea. And that's what the except part does. If it can't seperate the message, it skips ahead to the next area and sets the command to the whole message. We add the arguments anyway, however, just to make sure we don't screw something up later on... Remember, you can't use something that doesn't exist.

Now let's move on to the next part.

If you have any experience in programming, or even "advanced" math, you'll know exactly what an if-else statement is.
"If these conditions are true, do this. Else, do this." It's a lot like a try-except, but it has conditions and can't be used to detect core errors.

So what does this if-else do, exactly? It checks to see if the first character in cmd is our prefix, which in this case is an exclamation point.
We need to have this, to avoid spamming every time someone starts their sentence with one of our commands.

We do this check NOW so that we don't have to do it for EVERY command. We can just use the variable created here, which is set to True or False based on whether the condition is true or not.

Assuming it is true, it will remove the prefix from the command with:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Now on to the last new snippet.

We start out with looks like another if-else statement, but look closer... There's no else here. That's because Python doesn't need to have it unless you need it. And since we don't need to it do anything if you don't use the correct command, we don't need it.

There are two other weird things about this if statement. First is the use of lower() here. Much like our use of title() above, this automatically controls the string for us. However, this time is converts the entire command into lowercase. We do this to simplify string comparison.

The second is that we just use the prfx variable on its own. That's a weird condition, right? Well, in Python, using a variable on it's own as a condition is the same as checking to see if it's set to True.
In simpler terms, if our prefix was used, it will work. If not, it won't.

So now that we've check if the command matches, and the prefix was used, we can tell it to do something. For this, I've simply told the bot to repeat your arguments. That is, repeat anything after the first space.

For example, when you run the bot and go to the room that the bot is in, type "!say HELLO!" and the bot will say "HELLO!".

Please note that this will NOT work if you say it on the same account as the bot.

~~LIGHT AT THE END~~

Wow... It took me a lot to explain so little... Well, I tried to be through, didn't I?

...

Well, that's all you need to know to use the bot. The same ideas apply to EVERYTHING else. All of these ideas can be reused and altered to create an PM or chat spammer, a PM or chat autoresponder, a fully function chatbot like Botteh or Whaze, and even more. All that's left is for you to learn more about Python itself... Well, that and learn the other functions of ch.py...

I suppose I could make a reference sheet...

~~ REFERENCE SHEET~~

There. A reference sheet. Happy? This can all be found in the library, but YOU'RE too LAZY to look at it yourself... :l

Events:

Remember, these are used within out bot class...

onInit(self) - Called on init.
onConnect(self, room) - Called when connected to the room.
onReconnect(self, room) - Called when reconnected to the room.
onConnectFail(self, room) - Called when the connection failed.
onDisconnect(self, room) - Called when the client gets disconnected.
onLoginFail(self, room) - Called on login failure, disconnects after.
onFloodBan(self, room) - Called when either flood banned or flagged.
onFloodBanRepeat(self, room) - Called when trying to send something when floodbanned.
onFloodWarning(self, room) - Called when an overflow warning gets received.
onMessageDelete(self, room, user, message) - Called when a message gets deleted.
onModChange(self, room) - Called when the moderator list changes.
onModAdd(self, room, user) - Called when a moderator gets added.
onModRemove(self, room, user) - Called when a moderator gets removed.
onMessage(self, room, user, message) - Called when a message gets received.
onHistoryMessage(self, room, user, message) - Called when a message gets received from history.
onJoin(self, room, user) - Called when a user joins. Anonymous users get ignored here.
onLeave(self, room, user) - Called when a user leaves. Anonymous users get ignored here.
onRaw(self, room, raw) - Called before any command parsing occurs.
onPing(self, room) - Called when a ping gets sent.
onUserCountChange(self, room) - Called when the user count changes.
onBan(self, room, user, target) - Called when a user gets banned.
onUnban(self, room, user, target) - Called when a user gets unbanned.
onBanlistUpdate(self, room) - Called when a banlist gets updated.
onPMConnect(self, pm)
onPMDisconnect(self, pm)
onPMPing(self, pm)
onPMMessage(self, pm, user, body)
onPMOfflineMessage(self, pm, user, body)
onPMContactlistReceive(self, pm)
onPMBlocklistReceive(self, pm)
onPMContactAdd(self, pm, user)
onPMContactRemove(self, pm, user)
onPMBlock(self, pm, user)
onPMUnblock(self, pm, user)
onPMContactOnline(self, pm, user)
onPMContactOffline(self, pm, user)
onEventCalled(self, room, evt, *args, **kw) - Called on every room-based event.

Variables and Functions:

This isn't a complete list... But here are a few. Remember, if the variable isn't listed in the parenthesis after your event, you can't use it!

Also, don't forget to replace the things inside of the arrows brackets.

room -
  • room.message(<STRING>) - Sends a message to the chat
  • room.delete(message) - Deletes the message. *Don't change this one. It won't work.
  • room.name - Returns the rooms name as a string.


message -
  • message.body - Returns the message text itself.
  • message.ip - Returns the IP of the person that posted. Only works if account is modded.
  • message.time - Returns the time the message was sent as a UNIX timestamp.


user -
  • user.name - Returns the name of the user that sent the message. Note, it's ALWAYS lowercase.
If you have any more questions about things that you want to do with the bot, and are really too lazy (or dumb) to look through the library, post them here... I guess. Whatever. Noob.

~~Samples~~

[To see links please register here]


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

wlist is the trigger word list, ulist is the trigger name list, and msg is the generic response message.


[To see links please register here]

Requires this

[To see links please register here]

interpreter and my

[To see links please register here]

interpreter.


Both of these require the username and password to be filled in, at the bottom.
Disclaimer, none of these files are particularly... well done. They're what you get when you haven't slept in days and decided it's a good idea to make something. :l
You should really code for ZorkBot, any Pythonista would cry.

~~CONCLUSION~~

Welp, there you have it. That's how to make a Chatango bot.
If I've missed anything, please, tell me.

And remember, this is NOT a general Python tutorial. It's specific to Chatango bots. That said, the length is due in part to it being partially intended for those unfamiliar with Python.

Err... Zeb out, I guess?
Reply

#2
Good work God.

I love how you use Python, Python is shit, Batch is like better!
Reply

#3
My gawd! Now that's what I call a detailed and thorough tutorial! Really nice work. Maybe I'll make one and piss off some people...
Reply

#4
Nice detailed tutorial, reminds me of my electronics class :#
Reply

#5
Had some code error. All good now.

I try to make tutorials nice and informative. And funny.
Hate boring tuts.
Reply

#6
yayaya stfu
:l

Also, I intend to write that text adventure tutorial eventually.
That'd be a basic Python tutorial, that would help with creating a more advanced bot with this.

Of course, I doubt any of you use Chatango like I do.
I have about 10 chats open at all hours of the day...
Reply

#7
This is a nice, detailed tutorial. Nice work!
Reply

#8
Very good work God, Really in-depth I can tell you took your time on this.
Reply

#9
Not sure if you're going to read this, but to change the encoding in Notepad++, there's an option at the top saying "Encoding". It's the fifth menu option. Set it to UTF-8 to display these characters. However you may experience issues when getting the bot to show them. The easiest way to resolve this is with

[To see links please register here]

.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


is a very simple way to do this.


As for the Youtube Search API, the URL is

Quote:

[To see links please register here]


Naturally you'll have to replace "SEARCH_TERM_HERE" with the word or phrase you're searching for.

I'm not going to teach how to handle JSON in Python, nor will I build anything for you, so I recommend doing some reading if you don't know what to do with that.


[size=15pt]For anyone else:[/size] You can contact me on Chatango by the username Anizeb. I don't long on that account often, but I won't be coming back here to maintain this thread either, so it's your best bet for asking for help.

God, out.

Also screw the asshole that took my name. :l

Edit:
Also the weights in ch.py were out of date, should be working now.
Reply

#10
Quote:(07-22-2013, 06:08 PM)God_mybb_import2018 Wrote:

[To see links please register here]

Err... Zeb out, I guess?[/align]

I'm assuming you have a chatango acc, add me. " Duubz "
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through