mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-03 16:37:22 +01:00 
			
		
		
		
	WIP admin commands
This commit is contained in:
		
							parent
							
								
									36a93320d7
								
							
						
					
					
						commit
						86c7fd0db1
					
				
							
								
								
									
										67
									
								
								plugins/admin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								plugins/admin.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
# admin.py: PyLink administrative commands
 | 
			
		||||
import sys, os
 | 
			
		||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 | 
			
		||||
import proto
 | 
			
		||||
import utils
 | 
			
		||||
 | 
			
		||||
class NotAuthenticatedError(Exception):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
def checkauthenticated(irc, source):
 | 
			
		||||
    if not irc.users[source].identified:
 | 
			
		||||
        raise NotAuthenticatedError("You are not authenticated!")
 | 
			
		||||
 | 
			
		||||
@utils.add_cmd
 | 
			
		||||
def eval(irc, source, args):
 | 
			
		||||
    checkauthenticated(irc, source)
 | 
			
		||||
    args = ' '.join(args)
 | 
			
		||||
    if not args.strip():
 | 
			
		||||
        utils.msg(irc, source, 'No code entered!')
 | 
			
		||||
        return
 | 
			
		||||
    exec(args)
 | 
			
		||||
 | 
			
		||||
@utils.add_cmd
 | 
			
		||||
def spawnclient(irc, source, args):
 | 
			
		||||
    checkauthenticated(irc, source)
 | 
			
		||||
    try:
 | 
			
		||||
        nick, ident, host = args[:3]
 | 
			
		||||
    except ValueError:
 | 
			
		||||
        utils.msg(irc, source, "Error: not enough arguments. Needs 3: nick, user, host.")
 | 
			
		||||
        return
 | 
			
		||||
    proto.spawnClient(irc, nick, ident, host)
 | 
			
		||||
 | 
			
		||||
@utils.add_cmd
 | 
			
		||||
def removeclient(irc, source, args):
 | 
			
		||||
    checkauthenticated(irc, source)
 | 
			
		||||
    try:
 | 
			
		||||
        nick = args[0].lower()
 | 
			
		||||
    except IndexError:
 | 
			
		||||
        utils.msg(irc, source, "Error: not enough arguments. Needs 1: nick.")
 | 
			
		||||
        return
 | 
			
		||||
    u = _nicktoUid(nick)
 | 
			
		||||
    if u is None or u not in irc.server[irc.sid].users:
 | 
			
		||||
        utils.msg(irc, source, "Error: user %r not found." % nick)
 | 
			
		||||
        return
 | 
			
		||||
    _sendFromUser(irc, u, "QUIT :Client Quit")
 | 
			
		||||
    proto.removeClient(irc, nick, ident, host)
 | 
			
		||||
 | 
			
		||||
@utils.add_cmd
 | 
			
		||||
def joinclient(irc, source, args):
 | 
			
		||||
    checkauthenticated(irc, source)
 | 
			
		||||
    try:
 | 
			
		||||
        nick = args[0]
 | 
			
		||||
        clist = args[1].split(',')
 | 
			
		||||
        if not clist:
 | 
			
		||||
            raise IndexError
 | 
			
		||||
    except IndexError:
 | 
			
		||||
        utils.msg(irc, source, "Error: not enough arguments. Needs 2: nick, comma separated list of channels.")
 | 
			
		||||
        return
 | 
			
		||||
    u = _nicktoUid(nick)
 | 
			
		||||
    if u is None or u not in irc.server[irc.sid].users:
 | 
			
		||||
        utils.msg(irc, source, "Error: user %r not found." % nick)
 | 
			
		||||
        return
 | 
			
		||||
    for channel in clist:
 | 
			
		||||
        if not channel.startswith('#'):
 | 
			
		||||
            utils.msg(irc, source, "Error: channel names must start with #.")
 | 
			
		||||
            return
 | 
			
		||||
    joinClient(irc, ','.join(clist))
 | 
			
		||||
@ -55,14 +55,3 @@ def listcommands(irc, source, args):
 | 
			
		||||
    cmds.sort()
 | 
			
		||||
    utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds))
 | 
			
		||||
utils.add_cmd(listcommands, 'list')
 | 
			
		||||
 | 
			
		||||
@utils.add_cmd
 | 
			
		||||
def eval(irc, source, args):
 | 
			
		||||
    if not irc.users[source].identified:
 | 
			
		||||
        utils.msg(irc, source, 'You are not authenticated!')
 | 
			
		||||
        return
 | 
			
		||||
    args = ' '.join(args)
 | 
			
		||||
    if not args.strip():
 | 
			
		||||
        utils.msg(irc, source, 'No code entered!')
 | 
			
		||||
        return
 | 
			
		||||
    exec(args)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user