Jump to content

Recommended Posts

Posted

Create your own SkypeBOT

 

What is Skype4Py

 

Skype4Py is a Python wrapper for the Skype API. It is platform independent, written completely in Python and reimplements the Skype4COM's API in a pythonic way.

This specific tutorial is written for Python 2, however it can easily be translated for Python 3. Even though this does have a lot of stuff, I will be going over what I personally use.

By the way, it says PHP code. That's because I want syntax highlighting. All this is in python. Not php.

Also, This will be a shitty bot. I feel the need to say this, because I'm covering the VERY BASICS. Learning python will help you a lot more.

 

Download Links

 

I assume you already have python when reading this, if not Download Here  Also, you will need to download Skype4Py  Anyways, that should be everything you need.

 

Get the bot attached to skype

 

 

First you will want your bot to attach to skype. This can be easily done with the code below.

 

PHP Code:
import Skype4Py

# Create an instance of the Skype class.
skype = Skype4Py.Skype()

# Connect the Skype object to the Skype client.
skype.Attach() 

 

After that, you should get something like this

 

hCaja.png

 

Starting with the bot

 

Here's a few things you should know. These are the main things I use in my bot.

I still recommend you learn the other stuff too.

 

PHP Code:
#Here's a short example on what you could do.

if Message.Body == '!test':
    Message.Chat.SendMessage('Appears to work!')

#This makes it so whenever a message is "!test", it sends "Appears to work!"

#You could always do something along the lines of

if msg.startswith('!test'):
    Message.Chat.SendMessage('Appears to work!')

#This makes it so if someone's message starts with !test, it will send. Even if it has random characters after it. 

 

#This is extremely useful. This allows the bot to send messages.
#If you need an example, view it above. 

 

This is also very useful. Let's say you want admin controls, that only you can do. My bot has a simple leave feature, and it's set up like

 

if Status == 'SENT' or Message.FromHandle == 'MySkypeName': #If sent by the bot, or if it's sent by me.
    if Message.Body == '!leave': #If the command activates
    Message.Chat.SendMessage('Buh-bye!')
    Message.Chat.SendMessage('/leave') #Sends /leave, which happens to be a skype command 

 

Putting together the bot

 

Now, I don't think you want to know everything in depth. If you do, you can check the links below.

 

First of all, you should import Skype4Py

 

import Skype4Py[php]

[color=white]Then you want skype4py to attach to your skype. Heres something you should add.[/color]
[php]
skype = Skype4Py.Skype();
skype.OnMessageStatus = command
if skype.Client.IsRunning == False:
    skype.Client.Start()
skype.Attach(); 

 

Then you want to set up a command, and set it up so it reads it. You then need to set up a test command, which you can see below.

 

def command(Message, Status):
    if Status == 'SENT' or (Status == 'RECEIVED'):
  if Message.Body == '!test':
    Message.Chat.SendMessage('Appears to work!') 

 

And then an endless loop (There are many ways to do this).

 

while True:
    raw_input('') 

 

And then, you're all set! (I think)

 

Useful Links

 

http://python.org/

http://skype4py.sourceforge.net/doc/html/

http://sourceforge.net/projects/skype4py/

 

Download to my thinned-down bot (not an achievement at all):

 

http://db.tt/ZHBlcT3M

 

import Skype4Py 

def command(Message, Status): 
    if Status == 'SENT' or (Status == 'RECEIVED'): 
  if Message.Body == '!test': 
    Message.Chat.SendMessage('Appears to work!') 

skype = Skype4Py.Skype(); 
skype.OnMessageStatus = command 
if skype.Client.IsRunning == False: 
    skype.Client.Start() 
skype.Attach();  
while True: 
    raw_input('')

 

Have Fun!  8)

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...