Making a Chatango Bot With Python

Hello There guys ,

In these past few years I've been visitting some of Anime Fansub sites and blogs  to check on some anime and to stream of course, and I pretty much enjoys it, well, because Anime has always been A work of art that I love .
      While I'm streaming online in some Anime site I'd always see a "Chat Box" hanging next to the video streaming (It is a Chatgroup provided by Chatango ), And yup, I always join the chat and posting some random topics or any certain topics while I wait the stream buffering . But there was one time that I saw an anime streaming site that got a different feel . The time I tried to chat, there's a person who posted a certain message to use a chat bot . I was curious . Of course, it's kinda new for me to see a chat bot outside of IRC Chat Bots or automated chat bot app in smartphones . But not that much, it took my interest and so I played with the bot too . I've played it for some months and I got the idea to make my own bot, so I searched in webs and asked some of programmer friends many questions, and then found out that we can make a chat bot with Python Programming language . "It's difficult to learn programming !!", Yes of course, it took me 4 months only to learn a few basics of python and here I am making my own bot .
As you can see in this blog, we got one of chat group too . If you're wondering about what is a chatango bot, you can ask some people inside the "Hell Grounds Chat" on the right side of the blog, and you can also play the bot inside it \(^ω^)/ .

      Now let's skip the unimportant part and get started with the main topic .
I'm about to tell you how to make your own chatango bot using python, if you're wondering about "Can I use anything else besides python ?", Yes you can use PHP, C++, Java, etc., but I can't help you with anything besides python, because I just learned python programming myself and that's the only thing I understand for now.

And so, you need to install Python 3.3.2 on your PC (THIS METHOD WON'T WORK WITH OLDER VERSION OF PYTHON). You can download Python 3.3.2 HERE .
If you're using Ubuntu Linux, you can see some tutorials on how to install python HERE .

Next, after you've installed Python 3.3.2 you need to download a chatango library ( ch.py ) and you can download it from HERE . This is what you need to make your bot access the Chatango .
Next thing is you can download this ExampleBot Script to get started .

And remember to check this out chatango-bot-inner-guide-part-1   a starter short guide on making commands variations.

After you're done installing python and downloading those CH.py and ExampleBot.py , You're set to make your own bot.
You need to put CH.py and ExampleBot.py in the same folder .
If you're using windows, you can start the bot just by opening ExampleBot.py with your Python console or run it with Python Iddle .
If you're using Ubuntu Linux, you may need to download Python Iddle for convenience use, and you can see the tutorial for downloading Python-Iddle3 HERE .
The time you open your ExampleBot script on python console or running it with iddle python console, you're in for connecting part, and you will see in the console "Room names separated by semicolons: " , that means you need to type the chatango room name / chatgroup name (E.g. :  remaire) and you hit Enter, and you'll see "User Name: " in the console
to put a Chatango User Name in there, you hit Enter again and type your password .
when you're done with connecting the bot to a room, Check the chatgroup which name you put when the connecting part started (in the example I gave you "http://remaire.chatango.com") . If you see your bot name in the room's user list, that means you're done with Connecting your bot . Check the command list in your ExampleBot script and try commanding your bot with [!] as prefix (E.g. !mylvl) and it will respond you with the very same thing you programmed the bot in the script .

"Tadaaa !!" ,  You've made your own bot .
So that's the end of this short and simple tutorial .
See you soon ! ^ω^)/

Comments

  1. I did everything and wrote my rooms name,bots username and password but it won't connect to the room.

    ReplyDelete
    Replies
    1. What's the problem ?
      Have you typed a correct room name and correct chatango account for the bot in the python shell ?

      Delete
  2. can you help me make a bot 0rx?

    ReplyDelete
    Replies
    1. No, I don't make bots for people.
      From this article, I don't actually tell you to make it, You're copying the script and develop it.
      Just use the basic script I shared in this article and develop it yourself.
      If you have any question about making commands, you can always ask someone from the chatterbox above. Some of them have learned to make their own bots

      Delete
  3. Great bot/tut, just configured mine ^^. Can You please help me on adding 2-3 features of: -posting every 30 mins a message like "read rules"
    -warning a user by posting: (username) "don't flood" if one writes 5 messages in a row.
    -ban user if message content matches xxx (for autobanning spambots)
    Thx a lot in advance, great work! Unfortunately, I am a newbie to Python :/

    ReplyDelete
    Replies
    1. Well, if you are SUCH a newbie, why even bothering with making one?
      Ugh, fine, let me help you a bit...
      1.To post a message every 30 mins you don't need a bot, chatango can do it on it's own.
      2.The username of the person that writes something is stored in the variable user.name. I believe that you can refer to it just as "name" but I am not sure on how to do that now, so just use it as user.name. Now you need a second variable to store the times this user has made a message, and the old user.
      So, for what you want to do, you need one variable that stores the current user messaging(let's call it "oldmsg") and one to store the times he has posted a message(let's call it "msgtimes").
      Now go to "def onMessage(self, room, user, message):" and there is the function that answers to the commands. Now, I've never tried to do that, so I don't quite know how to do it, but I can give you a hint :) (I guess I am a newbie to python after all :/ ) In every message the bot receives, WITHOUT the prefix, so that piece of code should not be under the if statement with the prefix, the bot should store the user that said that in the variable oldmsg, and se the variable msgtimes to msgtimes + 1. While I was typing this I actually tested it, so here is a piece of code, ending right before the prefix part ^^
      def onMessage(self, room, user, message):
      global msgtimes
      global olduser

      try:
      if room.getLevel(self.user) > 0:
      print(user.name, message.body)
      else:
      print(user.name, message.body)
      if self.user == user: return
      if olduser == user.name:
      msgtimes = msgtimes + 1
      if msgtimes > 3:
      room.message(user.name + " is spamming the group")
      msgtimes = 0
      else:
      olduser = user.name
      msgtimes = 0
      You need to assign oldmsg and msgtimes in the start of the program, where you import stuff, like so:
      oldmsg = ""
      msgtimes = 0
      It doesn't work that properly actually, as I said, I am a newbie my self, but oh well...
      3.Well, I have no idea how to ban users, take a look at ch.py, it's long, but read it, it's there somewhere, let's say for example that you ban users like "banuser(user.name)" that is not how it;s done, but if it was, you would just say
      if user.message == "xxx"
      banuser(user.message)
      Ok, that's it, if you have further questions, please ask me :D

      Delete
    2. As I see, the indentation is kinda shit here, so u need to know some python to get this code to work, because if you copy paste it like that, it would never work... If you can't figure it out, I can post it in github or something, let me know

      Delete
    3. I don't know how people add flood warning system but I can help you with the auto-banning. The bot needs to be a moderator/admin to ban. So here is the code:
      if message.body == "xxx":
      room.banUser(user.name)

      And for the unban, I hope you know how to use it:
      room.unban(user.name)

      And you might also want the read rules thing (place it under def onMessage):
      self.setInterval(int(1800), room.message, "read rules")

      Delete
  4. elif cmd == "rules":
    self.setInterval(1800, room.message, "read rules")

    ReplyDelete
  5. Are you allowed to use lumirayz code?

    ReplyDelete
  6. @anon To be honest, Lumi doesn't seem pleased with this bot thing we're doing. But you can see the credits and license part of ch.py which doesn't prohibit us from using it with cautions. Just remember to credit lumi as long as you use his ch.py .
    Best regards
    0rx

    ReplyDelete
  7. Hmm actually you told us the all the file to download but you didnt gave use how to operate or put shits on it how helpful! thats why people keep stealing peoples other bot codes because of your cruelity that you even teach people how to code it and your right you shouldnt help us making bot but you need to teach us the platform how to make it!

    and if your offence with this I apologize for that but seeing this people's post I felt pain because Im llike them but sooner I found someone have the gratitude to help me

    they are ( Chatango User : Why, Lumirayz and Onii )
    well people who can read this you can ask them freely but dont push them to teach you shits just ask how do you do the basic platform to lunch bots in chat and the other commands!

    ReplyDelete
    Replies
    1. Learn python please, if you use ch.py making a bot is just too easy, if you can't do it, u need to practice more, their job is not to make the bot for you, even ch.py isn't supposed to be used, it's just there to help you learn :) But still, if you have any questions, go ahead, ask me, I am not an expert, but I might be able to help

      Delete
  8. Was typing it all correctly and it connected but the problem when i type a command the bot won't show up.. and give me this problem http://puu.sh/iUAdi/cfccdb7c52.png.. on both ch.py and bot.py on this chatroom only.. it work wonder in other chat room.. except this one www.animeshowtv.chatango.com

    ReplyDelete
  9. I'm having an issue. i want to get the chatbot to disconnect from a chat on command, but I can't figure it out.

    ReplyDelete
    Replies
    1. Oh, of course you can do it, just sit and read all the ch.py library and you'll figure it out. Woah, why am I replying to everyone in here?

      Delete
    2. self.leaveRoom("chatroom name goes here") You are welcome

      Delete
  10. Chill out guys, I'm sorry for not replying on your comments and questions, And thanks for some people who would take care of those in need, I regret making this post, as there are many ppl who don't actually understand the reason I make this article. If you ever feel the need to copy some codes regarding chatango bot, You may check my pastebin page at http://pastebin.com/u/0rx I often shared some random codes which might be usefull for you guys who just started coding your own bots.
    And again, I'm sorry that I will never be of much help, since I've stopped developing my own bot project.
    All I can say is do your best to start from scratch

    ReplyDelete
  11. So, I made a bot too (thanks 0rX, your code and tutorial was really helpfull) but I added something more! It doesn't just listen to commands, it can have a nice conversation with you (cool huh?) It can also PM, but you'll need to download RiveScript for python to make that part work, and it's kinda tricky sometimes. Anyways, here's the code for anyone wondering, have fun! http://pastebin.com/gftEasiS

    ReplyDelete
  12. Is there a command for the bot to send chat message between two chat channels that the bot is lurking?

    ReplyDelete
    Replies
    1. Explain further, and give example pls

      Delete
    2. I have the bot joined two channels. Whatever message was received from one channel will be posted on the other channel and vice versa. Of course filtering the bot message is there to prevent infinite looping

      Delete
    3. Well, you could change the "room" variable, or make two onMessage functions, run some tests, I am not sure, but changing the room variable could make the bot post the message somewhere else, but it could also raise quite some errors :/

      Delete
  13. Replies
    1. You won't get an answer faster if you type it 3 times, lel. And, I don't think that it will work on phone, I mean, you can't just download a compiler on your phone and run it, cause you need quite some libraries, but you can search on google or ask stackoverflow to get a more precise answer

      Delete
    2. Lol, I tried to run it on android using qPython3 and it runs fine, tho some sys cmds aren't working.

      Delete
  14. Hey hey hey! I am new to Python, coding in general. I wanna make a bot for my chatroom, for RP things, and logging into chatango accounts (like some of my OG accounts, to reset timers, so i don't forget.) I am not asking for someone to make the code for me, but more of material to learn how to make it for myself.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for a life time."

    Thanks for any references/links that may be posted, and if you wanna talk super indepth, message me at this long list of accounts
    Loke
    Negative
    Waker
    Vindicator
    JellalFernandes
    ChipSkylark

    ReplyDelete
    Replies
    1. Okay, just learn the basic python from youtube, ANY basic knowledge (JUST THE BASIC should be enough) of python is very usefull for you to make a decent bot.
      You can always find something in my pastebin for referrences (here-> http://pastebin.com/u/0rx). Anyway, good luck on your bot and have a nice day.


      Best regards
      0rx

      Delete
  15. LUMIRAYZ IS A KUNT LEL

    ReplyDelete
  16. I'm getting a syntax error in the ch.py file provided and I don't know enough about python to fix it myself. Just thought you guys should know.

    ReplyDelete
    Replies
    1. What kinda syntax error from inside ch.py ?
      Give me the details about the error and I might be able to help (just copy and paste the error code in the comment)

      Delete
  17. All this is commands to bot? http: //pastebin.com/u/0rx ? Makes a tutorial for each command? you let people download the codes. and not teach, how one by and use. Do you have a bot, perfect, could help newcomers, the as per the commands.
    All commands, only give the code will not help, if the person does not know how to use. You could do more tutorials, teaching as per the commands on the bot, step by step., the simplest commands. and more complicated commands. would help a lot. but thank you all.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. I would like to say that this blog really convinced me to do it! Thanks, very good post. Nike shoe bot

    ReplyDelete

Post a Comment

Popular Posts