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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:54:46+00:00 2026-06-16T08:54:46+00:00

I’d like to ask how can I make my python irc bot run commands

  • 0

I’d like to ask how can I make my python irc bot run commands only given by specified nick ?

My bot has Skybot – Python IRC bot core, it’s based on it.

That’s the module that imports in every command

import inspect
import re


def _hook_add(func, add, name=''):
if not hasattr(func, '_hook'):
    func._hook = []
func._hook.append(add)

if not hasattr(func, '_filename'):
    func._filename = func.func_code.co_filename

if not hasattr(func, '_args'):
    argspec = inspect.getargspec(func)
    if name:
        n_args = len(argspec.args)
        if argspec.defaults:
            n_args -= len(argspec.defaults)
        if argspec.keywords:
            n_args -= 1
        if argspec.varargs:
            n_args -= 1
        if n_args != 1:
            err = '%ss must take 1 non-keyword argument (%s)' % (name,
                        func.__name__)
            raise ValueError(err)

    args = []
    if argspec.defaults:
        end = bool(argspec.keywords) + bool(argspec.varargs)
        args.extend(argspec.args[-len(argspec.defaults):
                    end if end else None])
    if argspec.keywords:
        args.append(0)  # means kwargs present
    func._args = args

if not hasattr(func, '_thread'):  # does function run in its own thread?
    func._thread = False


def sieve(func):
    if func.func_code.co_argcount != 5:
        raise ValueError(
                'sieves must take 5 arguments: (bot, input, func, type, args)')
    _hook_add(func, ['sieve', (func,)])
    return func

def command(arg=None, **kwargs):
    args = {}

def command_wrapper(func):
    args.setdefault('name', func.func_name)
    _hook_add(func, ['command', (func, args)], 'command')
    return func

if kwargs or not inspect.isfunction(arg):
    if arg is not None:
        args['name'] = arg
    args.update(kwargs)
    return command_wrapper
else:
    return command_wrapper(arg)


def event(arg=None, **kwargs):
    args = kwargs

def event_wrapper(func):
    args['name'] = func.func_name
    args.setdefault('events', ['*'])
    _hook_add(func, ['event', (func, args)], 'event')
    return func

if inspect.isfunction(arg):
    return event_wrapper(arg, kwargs)
else:
    if arg is not None:
        args['events'] = arg.split()
    return event_wrapper


def singlethread(func):
    func._thread = True
    return func


def regex(regex, flags=0, **kwargs):
    args = kwargs

def regex_wrapper(func):
    args['name'] = func.func_name
    args['regex'] = regex
    args['re'] = re.compile(regex, flags)
    _hook_add(func, ['regex', (func, args)], 'regex')
    return func

if inspect.isfunction(regex):
    raise ValueError("regex decorators require a regex to match against")
else:
    return regex_wrapper

and that’s how a simple command works:

from util import hook, http

@hook.command
def calc(inp):
    '''.calc <term> google calc result'''

    h = http.get_html('http://www.google.com/search', q=inp)

    m = h.xpath('//h2[@class="r"]/text()')

    if not m:
        return "Could not calculate " + inp

    res = ' '.join(m[0].split())

    return res

Also, I’d like to make it to have 2 admins, like only 2 people will be able to command it.I’d have done that myself, but looking at code I have no idea what to do 😕

Thank you!

  • 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-16T08:54:47+00:00Added an answer on June 16, 2026 at 8:54 am

    Add a nick keyword argument to your function, then check that against a list of nicks allowed to execute administrator commands:

    administrators = ('nick1', 'nick2')
    
    @hook.command
    def someadmincommand(inp, nick=''):
        if nick not in administratiors:
            return 'I don't think so, {0}'.format(nick)
    
        # `nick` is an administrator, do your worst
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.