1 Replies - 1219 Views - Last Post: 15 May 2011 - 03:30 AM Rate Topic: -----

#1 IRCfreak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-May 11

python error IRC bot

Posted 15 May 2011 - 01:39 AM

import sys
import socket
import string
import os

host = "irc.freenode.net" # the irc server
port = 6667 # port number
nick = "aussiebot" # nickname
ident = "aussiebot" # identity
realname = "aussiebot" # the name of the bot
owner = "Guardian-PFD" # who made it
channel = "##aussiepowder"
server_msg = "" # messages from the server and client
 
s = socket.socket() # open socket
s.connect((host, port)) # connect to server
s.send("Nick: "+nick+"\n") # we send the nickname to the server
s.send("User: "+ident+" "+host+" Name: "+realname+"\n")
 

while 1:
    line = s.recv(500) # recieve the server messages
    print(line)
    if line.find("Welcome to the aussie powder IRC network!!!") != -1: # join #c0dingf0x
        s.send("JOIN "+channel+"\n")
        if line.find("PRIVMSG") != -1:
            parsemsg(line)
            line = line.rstrip()
            line = line.split()
            if(line[0] == "PING"):
                s.send("PONG "+line[1]+"\n")
                 
def parsemsg(msg):
    complete = msg[1: ].split(":", 1) # Parse the message into useful data
    info = complete[0].split(" ")
    msgpart = complete[1]
    sender = info[0].split("!")
    if msgpart[0] == "$" and sender[0] == owner: # treat messge starting with $ as a command
        cmd = msgpart[1: ].split(" ")
        if cmd[0] == "op":
            s.send("MODE "+info[2]+" +o "+cmd[1]+"\n")
        if cmd[0] == "deop":
            s.send("MODE "+info[2]+" -o "+cmd[1]+"\n")
        if cmd[0] == "voice":
            s.send("MODE "+info[2]+" +v "+cmd[1]+"\n")
        if cmd[0] == "devoice":
            s.send("MODE "+info[2]+" -v "+cmd[1]+"\n")
        if cmd[0] == "sys":
            syscmd(msgpart[1: ], info[2])
             
    if msgpart[0] == "_" and sender[0] == owner: # treat messages with _ as explict command sent to the server
        cmd = msgpart[1: ]
        s.send(cmd+"\n")
        print("cmd = "+cmd)
 
def syscmd(commandline, channel):
    cmd = commandline.replace("sys ", "")
    cmd = cmd.rstrip()
    os.system(cmd+" >temp.txt")
    a = open("temp.txt")
    ot = a.read()
    ot.replace("\n", "|")
    a.close()
    s.send("PRIVMSG "+channel+" :"+ot+"\n")




i have this error:

Traceback (most recent call last):
  File "C:\Python32\aussiebot", line 17, in <module>
    s.send("Nick: "+nick+"\n") # we send the nickname to the server
TypeError: 'str' does not support the buffer interface


Is This A Good Question/Topic? 0
  • +

Replies To: python error IRC bot

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: python error IRC bot

Posted 15 May 2011 - 03:30 AM

Python 3? I think you need to convert the string to bytes before presenting it to send. For further reading.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1