mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-04 00:47:21 +01:00 
			
		
		
		
	utils.py: Make _msg a shared function (Closes #3)
This commit is contained in:
		
							parent
							
								
									4ead81a66f
								
							
						
					
					
						commit
						0fcf5ead04
					
				@ -2,21 +2,23 @@
 | 
			
		||||
import sys, os
 | 
			
		||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 | 
			
		||||
import proto
 | 
			
		||||
import utils
 | 
			
		||||
 | 
			
		||||
@proto.add_cmd
 | 
			
		||||
def tell(irc, source, args):
 | 
			
		||||
    try:
 | 
			
		||||
        target, text = args[0], ' '.join(args[1:])
 | 
			
		||||
    except IndexError:
 | 
			
		||||
        proto._sendFromUser(irc, 'PRIVMSG %s :Error: not enough arguments' % source)
 | 
			
		||||
        utils._msg(irc, source, 'Error: not enough arguments.', notice=False)
 | 
			
		||||
        return
 | 
			
		||||
    try:
 | 
			
		||||
        proto._sendFromUser(irc, 'NOTICE %s :%s' % (irc.users[target], text))
 | 
			
		||||
    except KeyError:
 | 
			
		||||
        proto._sendFromUser(irc, 'PRIVMSG %s :unknown user %r' % (source, target))
 | 
			
		||||
    targetuid = proto._nicktoUid(irc, target)
 | 
			
		||||
    if targetuid is None:
 | 
			
		||||
        utils._msg(irc, source, 'Error: unknown user %r' % target, notice=False)
 | 
			
		||||
        return
 | 
			
		||||
    utils._msg(irc, target, text)
 | 
			
		||||
 | 
			
		||||
@proto.add_cmd
 | 
			
		||||
def debug(irc, source, args):
 | 
			
		||||
    proto._sendFromUser(irc, 'NOTICE %s :Debug info printed to console.' % (source))
 | 
			
		||||
    utils._msg(irc, source, 'Debug info printed to console.')
 | 
			
		||||
    print(irc.users)
 | 
			
		||||
    print(irc.servers)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								proto.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								proto.py
									
									
									
									
									
								
							@ -159,10 +159,10 @@ def handle_squit(irc, numeric, command, args):
 | 
			
		||||
    old_servers = copy(irc.servers)
 | 
			
		||||
    for sid, data in old_servers.items():
 | 
			
		||||
        if data.uplink == split_server:
 | 
			
		||||
            print('Server %s also hosts server %s, splitting that too?!' % (split_server, sid))
 | 
			
		||||
            print('Server %s also hosts server %s, splitting that too...' % (split_server, sid))
 | 
			
		||||
            handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid])
 | 
			
		||||
    for user in irc.servers[split_server].users:
 | 
			
		||||
        print("Removing user %s from server %s" % (user, split_server))
 | 
			
		||||
        print("Removing user %s (%s) from server %s" % (user, user.nick, split_server))
 | 
			
		||||
        del irc.users[user]
 | 
			
		||||
    del irc.servers[split_server]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								utils.py
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								utils.py
									
									
									
									
									
								
							@ -1,4 +1,5 @@
 | 
			
		||||
import string
 | 
			
		||||
import proto
 | 
			
		||||
 | 
			
		||||
# From http://www.inspircd.org/wiki/Modules/spanningtree/UUIDs.html
 | 
			
		||||
chars = string.digits + string.ascii_uppercase
 | 
			
		||||
@ -11,3 +12,7 @@ def next_uid(sid, level=-1):
 | 
			
		||||
        return sid + ''.join(a)
 | 
			
		||||
    except StopIteration:
 | 
			
		||||
        return UID(level-1)
 | 
			
		||||
 | 
			
		||||
def _msg(irc, target, text, notice=True):
 | 
			
		||||
    command = 'NOTICE' if notice else 'PRIVMSG'
 | 
			
		||||
    proto._sendFromUser(irc, '%s %s :%s' % (command, target, text))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user