本文整理汇总了Python中Core.chanusertracker.CUT类的典型用法代码示例。如果您正苦于以下问题:Python CUT类的具体用法?Python CUT怎么用?Python CUT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CUT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notice
def notice(self, text, target=None, priority=0):
# If we're opped in a channel in common with the user, we can reply with
# CNOTICE instead of NOTICE which doesn't count towards the flood limit.
if hasattr(self, "_channel") and CUT.opped(self.get_chan()) and CUT.nick_in_chan(target or self.get_nick(), self.get_chan()):
self.write("CNOTICE %s %s :%s" % (target or self.get_nick(), self.get_chan(), text), priority=priority)
else:
self.write("NOTICE %s :%s" % (target or self.get_nick(), text), priority=priority)
示例2: robocop
def robocop(self, message, request_id, mode):
request = Request.load(request_id, active=False)
if request is None:
return
if mode == "cancel":
reply = "Cancelled scan request %s" % (request.id,)
message.privmsg(reply, self.scanchan())
nicks = CUT.get_user_nicks(request.user.name)
for nick in nicks:
message.privmsg(reply, nick)
return
if mode == "block":
reply = "Updated request %s dists to %s" % (request.id, request.dists,)
message.privmsg(reply, self.scanchan())
nicks = CUT.get_user_nicks(request.user.name)
for nick in nicks:
message.privmsg(reply, nick)
return
user = request.user
planet = request.target
requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
dists_intel = planet.intel.dists if planet.intel else 0
message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s%s) " % (request.id, requester, request.type, planet.x,planet.y,planet.z,
dists_intel, "/r:%s" % request.dists if request.dists > 0 else "") + request.link, self.scanchan())
示例3: pnick
def pnick(message):
# Part of a WHOIS result
if message.get_msg() == "is logged in as":
nick = message.line.split()[3]
pnick = message.line.split()[4]
# Set the user's pnick
CUT.get_user(nick, pnick=pnick)
示例4: execute
def execute(self, message, user, params):
username = params.group(1)
member = User.load(name=username, active=False)
if member is None:
message.alert("No such user '%s'" % (username,))
return
if member.access > user.access:
message.reply(
"You may not remove %s, his or her access (%s) exceeds your own (%s)"
% (member.name, member.access, user.access)
)
return
mbraxx = Config.getint("Access", "member")
home = Config.get("Channels", "home")
coraxx = Config.getint("Access", "core")
core = Config.get("Channels", "core")
if member.active and member.access >= mbraxx:
message.privmsg("remuser %s %s" % (home, member.name), "P")
if member.active and member.access >= coraxx:
message.privmsg("remuser %s %s" % (core, member.name), "P")
session.delete(member)
session.commit()
message.reply("Removed user %s" % (member.name,))
CUT.untrack_user(member.name)
示例5: privmsg
def privmsg(self, text, target=None, priority=0):
if os.path.isfile("/tmp/meetingmode"):
return
# Privmsg someone. Target defaults to the person who triggered this line
# Should we send colours?
if (
Config.has_option("Connection", "color")
and not Config.has_option("NoColor", target)
and not (target[0] in ["#", "&"] and Config.has_option("NoColorChan", target[1:]))
):
text = "\x03" + Config.get("Connection", "color") + text + "\x0F"
color = True
else:
color = False
# If we're opped in a channel in common with the user, we can reply with
# CPRIVMSG instead of PRIVMSG which doesn't count towards the flood limit.
if (
(not target or target[0] not in "#&")
and hasattr(self, "_channel")
and CUT.opped(self.get_chan())
and CUT.nick_in_chan(target or self.get_nick(), self.get_chan())
):
self.write("CPRIVMSG %s %s :%s" % (target or self.get_nick(), self.get_chan(), text), color, priority)
else:
self.write("PRIVMSG %s :%s" % (target or self.get_nick(), text), color, priority)
示例6: part
def part(message):
# Someone is leaving a channel
if message.get_nick() == Merlin.nick:
# Bot is leaving the channel
CUT.del_chan(message.get_chan())
else:
# Someone is leaving a channel we're in
CUT.part(message.get_chan(), message.get_nick())
示例7: channels
def channels(message):
# Part of a WHOIS result
if message.get_chan() == Merlin.nick:
# Cycle through the list of channels
for chan in message.get_msg().split():
if chan[0] in ("@","+"): chan = chan[1:]
# Reset the channel and get a list of nicks
CUT.new_chan(chan)
message.write("NAMES %s\nTOPIC %s" % (chan,chan,))
示例8: pnick
def pnick(message):
# Part of a WHOIS result
hostmask = message.line.split()[5]
m = pnickre.match(hostmask)
if m:
nick = message.line.split()[3]
pnick = m.group(1)
# Set the user's pnick
CUT.get_user(nick, None, pnick=pnick)
示例9: kick
def kick(message):
# Someone is kicked
kname = message.line.split()[3]
if Merlin.nick == kname:
# Bot is kicked from the channel
CUT.del_chan(message.get_chan())
else:
# Someone is kicked from a channel we're in
CUT.part(message.get_chan(), kname)
示例10: names
def names(message):
# List of users in a channel
for nick in message.get_msg().split():
if nick == "@"+Merlin.nick:
CUT.opped(message.get_chan(), True)
if nick[0] in ("@","+"): nick = nick[1:]
CUT.join(message.get_chan(), nick)
if Config.get("Misc","usercache") == "join":
# Use whois to get the user's pnick
message.write("WHOIS %s" % (nick,))
示例11: execute
def execute(self, message, user, params):
username = params.group(1)
access = params.group(2).lower()
if access.isdigit():
access = int(access)
elif access in self.true:
access = True
elif access in self.false:
access = False
else:
try:
access = Config.getint("Access",access)
except Exception:
message.reply("Invalid access level '%s'" % (access,))
return
member = User.load(name=username, active=False)
if member is None:
message.alert("No such user '%s'" % (username,))
return
if type(access) is int and not member.active:
message.reply("You should first re-activate user %s" %(member.name,))
return
if access > user.access or member.access > user.access:
message.reply("You may not change access higher than your own")
return
mbraxx = Config.getint("Access","member")
home = Config.get("Channels","home")
if type(access) == int:
if member.active == True and member.access < mbraxx and access >= mbraxx:
message.privmsg("adduser %s %s 399" %(home, member.name,), Config.get("Services", "nick"))
message.reply("%s has been added to %s"%(member.name, home,))
if member.active == True and member.access >= mbraxx and access < mbraxx:
message.privmsg("remuser %s %s"%(home, member.name,), Config.get("Services", "nick"))
message.privmsg("ban %s *!*@%s.%s GTFO, EAAD"%(home, member.name, Config.get("Services", "usermask"),), Config.get("Services", "nick"))
member.access = access
else:
if member.active != access and access == True and member.access >= mbraxx:
message.privmsg("adduser %s %s 399" %(home, member.name,), Config.get("Services", "nick"))
message.reply("%s has been added to %s"%(member.name, home,))
if member.active != access and access == False and member.access >= mbraxx:
message.privmsg("remuser %s %s"%(home, member.name,), Config.get("Services", "nick"))
message.privmsg("ban %s *!*@%s.%s GTFO, EAAD"%(home, member.name, Config.get("Services", "usermask"),), Config.get("Services", "nick"))
member.active = access
session.commit()
message.reply("Editted user %s access: %s" % (member.name, access,))
if not member.active:
CUT.untrack_user(member.name)
示例12: channels
def channels(message):
# Part of a WHOIS result
if message.get_chan() == Merlin.nick:
# Cycle through the list of channels
for chan in message.get_msg().split():
modes, chan = chanre.match(chan).groups()
opped = "@" in modes
# Reset the channel and get a list of nicks
CUT.new_chan(chan)
CUT.opped(chan, opped)
if CUT.mode_is("rapid", "join"):
message.write("NAMES %s\nTOPIC %s" % (chan,chan,))
示例13: run
def run(self):
# Import elements of Core we need
# These will be refreshed each time the Loader reloads
from Core.loader import Loader
from Core.exceptions_ import Quit, Reboot, Reload, Call999
from Core.connection import Connection
from Core.chanusertracker import CUT
from Core.robocop import RoboCop
from Core.router import Router
from Core.actions import Action
# Collect any garbage remnants that might have been left behind
# from an old loader or backup that wasn't properly dereferenced
gc.collect()
try:
# Attach the IRC connection and configure
self.irc = Connection.attach(*self.irc)
# Attach the RoboCop/clients sockets and configure
self.robocop = RoboCop.attach(*self.robocop)
# Attach the CUT state
self.cut = CUT.attach(*self.cut)
# Operation loop
Router.run()
except Call999 as exc:
# RoboCop server failed, restart it
self.robocop = RoboCop.disconnect(str(exc))
return
except Reboot as exc:
# Reset the connection first
self.irc = Connection.disconnect(str(exc) or "Rebooting")
print "%s Reloading..." % (time.asctime(),)
# Reimport all the modules
Loader.reload()
return
except Reload:
# Detach the current CUT state
self.cut = CUT.detach()
print "%s Reloading..." % (time.asctime(),)
# Reimport all the modules
Loader.reload()
return
except (Quit, KeyboardInterrupt, SystemExit) as exc:
self.irc = Connection.disconnect(str(exc) or "Bye!")
self.robocop = RoboCop.disconnect(str(exc) or "Bye!")
sys.exit("Bye!")
示例14: blocks
def blocks(self, message, user, params):
id = params.group(1)
dists = int(params.group(2)) + 1
request = Request.load(id)
if request is None:
message.reply("No open request number %s exists (idiot)." % (id,))
return
if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()):
message.reply("Scan request %s isn't yours and you're not a scanner!" % (id,))
return
# Update Intel
planet = request.target
if planet.intel is None:
planet.intel = Intel()
planet.intel.dists = max(planet.intel.dists, dists)
request.dists = max(request.dists, dists)
session.commit()
reply = "Updated request %s dists to %s" % (id, request.dists)
message.reply(reply)
if message.get_chan() != self.scanchan():
message.privmsg(reply, self.scanchan())
nicks = CUT.get_user_nicks(request.user.name)
if message.get_nick() not in nicks:
for nick in nicks:
message.privmsg(reply, nick)
示例15: router
def router(self, message, command):
for name, regex, access in self.routes:
params = regex.match(command)
if params is None:
continue
else:
break
else:
raise ParseError
route = getattr(self, name)
user = self.check_access(message, access)
if user is None:
raise UserError
if getattr(route, "_USER", False) is True:
if self.is_user(user) is False:
message.get_pnick()
raise UserError
if getattr(route, "_PLANET", False) is True:
if self.user_has_planet(user) is False:
raise PrefError
if getattr(route, "_CHANNEL", None) is not None:
if self.is_chan(message, route._CHANNEL) is False:
raise ChanParseError(route._CHANNEL)
if getattr(route, "_USER_IN", None) is not None:
if CUT.nick_in_chan(message.get_nick(), route._USER_IN) is not True:
raise ChanParseError(route._USER_IN)
return route, name, user, params