Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:19:18+00:00 2026-06-02T20:19:18+00:00

I am trying to canonize an input from a python bot connected to IRC.

  • 0

I am trying to canonize an input from a python bot connected to IRC.
My python script is as such: http://pastebin.com/St4A1vLf

If someone says “!help“, this appears in the command prompt (When I run the script at the command prompt).

:bot!~botty@112.443.22.5 #fish :!help

What I want to do is take the variable “data” and canonize it so it just shows the user’s nickname, i.e. “bot” so the staring colon ‘:‘ and the rest of the string (from the !~) is also removed.

After this, I want it to send the user who said “!help” a private message/query with “no help settings“. (I will add in the help commands later.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:19:20+00:00Added an answer on June 2, 2026 at 8:19 pm

    First of all: The line you posted makes no sense as the command is missing. What you probably meant is

    :bot!~botty@112.443.22.5 PRIVMSG #fish :!help
    

    But why not use one of the existing irc implementations for python such as twisted-words? They allow you to handle certain commands (such as PRIVMSG in your case) easily.

    If you do not want to do this, you need to parse the incoming message manually and extract whatever information you need.

    Here’s a simple parser. line is one line received from the server.

    def parse_irc(line):
        src = None
        parts = line.split(' ')
        if parts[0][0] == ':':
            srcpart = parts.pop(0)[1:]
            src = {'ident': None, 'host': None}
            if '!' not in srcpart:
                # e.g. a message from a server
                src['nick'] = srcpart
            else:
                # nick!ident@host
                tmp = srcpart.split('!', 1)
                src['nick'] = tmp[0]
                src['ident'], src['host'] = tmp[1].split('@', 1)
        cmd = parts.pop(0)
        args = []
        for i, arg in enumerate(parts):
            if arg[0] == ':':
                args.append(' '.join(parts[i:])[1:])
                break
            args.append(arg)
        return src, cmd, args
    

    Here’s how the parsed lines look like:

    > python ircparser.py 'PING :12345'
    src:  None
    cmd:  'PING'
    args: ['12345']
    > python ircparser.py 'NOTICE AUTH :Welcome to this server'
    src:  None
    cmd:  'NOTICE'
    args: ['AUTH', 'Welcome to this server']
    > python ircparser.py ':me!ident@host PRIVMSG #channel :hi'
    src:  {'nick': 'me', 'host': 'host', 'ident': 'ident'}
    cmd:  'PRIVMSG'
    args: ['#channel', 'hi']
    > python ircparser.py ':me!ident@host PRIVMSG #channel :!help me'
    src:  {'nick': 'me', 'host': 'host', 'ident': 'ident'}
    cmd:  'PRIVMSG'
    args: ['#channel', '!help me']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to save output from this script to a file based on a cell
Trying to transition from urllib in python 2 to python 3. I can output
Trying to pull a value from the sunrise element from [yweather:astronomy] in the Yahoo
Trying to read registry keys remotly (from a host on local intranet)... All the
Trying to do this, but is it wrong? Below is my style and script
Trying to read in some information from the google maps api into my application
I am trying to canonize a XML fragment to avoid printing of self closing
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
Trying to reproduce the problem from this question , I've found I can't plot
Trying to insert data in database from edittext in android but data is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.