mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-23 18:54:05 +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
|
import sys, os
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
import proto
|
import proto
|
||||||
|
import utils
|
||||||
|
|
||||||
@proto.add_cmd
|
@proto.add_cmd
|
||||||
def tell(irc, source, args):
|
def tell(irc, source, args):
|
||||||
try:
|
try:
|
||||||
target, text = args[0], ' '.join(args[1:])
|
target, text = args[0], ' '.join(args[1:])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
proto._sendFromUser(irc, 'PRIVMSG %s :Error: not enough arguments' % source)
|
utils._msg(irc, source, 'Error: not enough arguments.', notice=False)
|
||||||
return
|
return
|
||||||
try:
|
targetuid = proto._nicktoUid(irc, target)
|
||||||
proto._sendFromUser(irc, 'NOTICE %s :%s' % (irc.users[target], text))
|
if targetuid is None:
|
||||||
except KeyError:
|
utils._msg(irc, source, 'Error: unknown user %r' % target, notice=False)
|
||||||
proto._sendFromUser(irc, 'PRIVMSG %s :unknown user %r' % (source, target))
|
return
|
||||||
|
utils._msg(irc, target, text)
|
||||||
|
|
||||||
@proto.add_cmd
|
@proto.add_cmd
|
||||||
def debug(irc, source, args):
|
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.users)
|
||||||
print(irc.servers)
|
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)
|
old_servers = copy(irc.servers)
|
||||||
for sid, data in old_servers.items():
|
for sid, data in old_servers.items():
|
||||||
if data.uplink == split_server:
|
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])
|
handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid])
|
||||||
for user in irc.servers[split_server].users:
|
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.users[user]
|
||||||
del irc.servers[split_server]
|
del irc.servers[split_server]
|
||||||
|
|
||||||
|
5
utils.py
5
utils.py
@ -1,4 +1,5 @@
|
|||||||
import string
|
import string
|
||||||
|
import proto
|
||||||
|
|
||||||
# From http://www.inspircd.org/wiki/Modules/spanningtree/UUIDs.html
|
# From http://www.inspircd.org/wiki/Modules/spanningtree/UUIDs.html
|
||||||
chars = string.digits + string.ascii_uppercase
|
chars = string.digits + string.ascii_uppercase
|
||||||
@ -11,3 +12,7 @@ def next_uid(sid, level=-1):
|
|||||||
return sid + ''.join(a)
|
return sid + ''.join(a)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return UID(level-1)
|
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…
Reference in New Issue
Block a user