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 8718923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:39:47+00:00 2026-06-13T06:39:47+00:00

So, I’ve been working on an IRC bot lately. It stores the last time

  • 0

So, I’ve been working on an IRC bot lately. It stores the last time someone did something as part of an antispam feature. It used to initialize the lists of users in a WHO reply, which I’ve been moving to use RPL_NAMREPLY.

It almost works. However, I have a very odd-looking problem..

import time

# ...

    def irc_unknown(self, prefix, command, params):
        """Handle packets that aren't handled by the library."""

        # Prefix: asimov.freenode.net
        # Command: RPL_BANLIST
        # Params: ['MCBans_Testing', '#mcbans-test', 'a!*@*', 'gdude2002!g@unaffiliated/gdude2002', '1330592882']

        self.runHook("unknownMessage", {"prefix": prefix, "command": command, "params": params})

        if command == "RPL_BANLIST":
            channel = params[1]
            mask = params[2]
            owner = params[3]
            time = params[4]

            if channel not in self.banlist.keys():
                done = {"done": False, "total": 1}
                banmask = {"owner": owner.split("!")[0], "ownerhost": owner, "time": time, "mask": mask,
                           "channel": channel}
                done[mask] = banmask
                self.banlist[channel] = done

            else:
                if not self.banlist[channel]["done"]:
                    banmask = {"owner": owner.split("!")[0], "ownerhost": owner, "time": time, "mask": mask,
                               "channel": channel}
                    self.banlist[channel][mask] = banmask
                    self.banlist[channel]["total"] += 1

                else:
                    done = {"done": False, "total": 1}
                    banmask = {"owner": owner.split("!")[0], "ownerhost": owner, "time": time, "mask": mask,
                               "channel": channel}
                    done[mask] = banmask
                    self.banlist[channel] = done

        elif command == "RPL_ENDOFBANLIST":
            channel = params[1]

            if channel in self.banlist.keys():
                self.banlist[channel]["done"] = True
            else:
                self.banlist[channel] = {"done": True, "total": 0}

            self.prnt("|= Got %s bans for %s." % (self.banlist[channel]["total"], channel))

            if self.is_op(channel, self.nickname):
                stuff = self.banlist[channel].keys()
                stuff.remove("done")
                stuff.remove("total")

                for element in stuff:
                    if stuff == "*!*@*":
                        self.send_raw("KICK %s %s :Do not set such ambiguous bans!" % (
                        channel, self.banlist[channel][element]["owner"]))
                        self.send_raw("MODE %s -b *!*@*" % channel)
                        self.send_raw(
                            "MODE %s +b *!*@%s" % (channel, self.banlist[channel][element]["ownerhost"].split("@")[1]))
                    else:
                        self.checkban(channel, element, self.banlist[channel][element]["owner"])

        elif command == "RPL_NAMREPLY":
            me, status, channel, names = params
            users = names.split()
            ranks = "+%@&~"

            if not channel in self.chanlist.keys():
                self.chanlist[channel] = {}

            for element in users:
                rank = ""

                for part in ranks:
                    if part in element:
                        rank = rank + part
                    element = element.strip(part)

                done = { 'server': prefix,
                         'status': rank,
                         'last_time': float( time.time() - 0.25 ) }
                self.chanlist[channel][element] = done

            print "Names for %s%s: %s" % (status, channel, names)

        elif command == "RPL_ENDOFNAMES":
            me, channel, message = params
            ops = 0
            voices = 0
            opers = 0
            aways = 0

            for element in self.chanlist[channel].values():
                status = element["status"]
                if "+" in status:
                    voices += 1
                if "@" in status:
                    ops += 1
                if "*" in status:
                    opers += 1
                if "G" in status:
                    aways += 1
            print("|= %s users on %s (%s voices, %s ops, %s opers, %s away)" % (
            len(self.chanlist[channel]), channel, voices, ops, opers, aways))
            print "[%s] (%s) %s" % (prefix, command, params)

        else:
            print "[%s] (%s) %s" % (prefix, command, params)

With it, I get the following error..

  File "C:\Users\Gareth\Documents\GitHub\McBlockit---Helpbot\system\irc.py", line 1422, in irc_unknown
    done = {"server": prefix, "status": rank, "last_time": float(time.time() - 0.25)}
exceptions.UnboundLocalError: local variable 'time' referenced before assignment

As you can see, I’m importing time at the top of the file. And that code works fine in another function. Any ideas?

  • 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-13T06:39:47+00:00Added an answer on June 13, 2026 at 6:39 am

    You have a local variable time defined in an if statement in your function:

            time = params[4]
    

    Because it is inside an if statement nothing is assigned to it, but because of that variable, the imported time module is not available in your function.

    Rename that variable to resolve the conflict.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.