def send_motd(self): if "server_motd" in self.ircd.servconfig and self.ircd.servconfig["server_motd"]: chunks = chunk_message(self.ircd.servconfig["server_motd"], self.ircd.servconfig["server_motd_line_length"]) self.sendMessage(irc.RPL_MOTDSTART, ":- {} Message of the day - ".format(self.ircd.servconfig["server_network_name"])) for chunk in chunks: line = ":- {{:{!s}}} -".format(self.ircd.servconfig["server_motd_line_length"]).format(chunk) # Dynamically inject the line length as a width argument for the line self.sendMessage(irc.RPL_MOTD, line) self.sendMessage(irc.RPL_ENDOFMOTD, ":End of MOTD command") else: self.sendMessage(irc.ERR_NOMOTD, ":MOTD File is missing")
def report_names(self, channel): userlist = [] for user, ranks in channel.users.iteritems(): representation = (self.ircd.prefixes[ranks[0]][0] + user.nickname) if ranks else user.nickname newRepresentation = self.listname(channel, user, representation) if newRepresentation: userlist.append(newRepresentation) # Copy of irc.IRC.names prefixLength = len(self.ircd.name) + len(irc.RPL_NAMREPLY) + len(channel.name) + len(self.nickname) + 10 # 10 characters for CRLF, =, : and spaces namesLength = 512 - prefixLength # May get messed up with unicode lines = chunk_message(" ".join(userlist), namesLength) for l in lines: self.sendMessage(irc.RPL_NAMREPLY, "=", channel.name, ":{}".format(l)) self.sendMessage(irc.RPL_ENDOFNAMES, channel.name, ":End of /NAMES list")
def bidserv_HELP(self, prefix, params): if not params: lines = chunk_message(BIDSERV_HELP_MESSAGE, self.ircd.server_motd_line_length) lines.append("") lines.extend(info['short'] for key, info in self.help_info['bidserv'].items() if key not in ['USAGE', 'HELP']) for l in lines: self.sendMessage("NOTICE", ":{}".format(l), prefix=self.service_prefix("BidServ")) else: info = self.help_info['bidserv'].get(params[0].upper(), None) if not info: # Doesn't exist :( self.sendMessage("NOTICE", ":Unknown command \x02{}\x0F. \"/msg BidServ HELP\" for help.".format(params[0]), prefix=self.service_prefix("BidServ")) else: for l in info['long']: # Print the long message self.sendMessage("NOTICE", ":{}".format(l), prefix=self.service_prefix("BidServ"))
def report_names(self, channel): userlist = [] for user, ranks in channel.users.iteritems(): representation = (self.ircd.prefixes[ranks[0]][0] + user.nickname) if ranks else user.nickname newRepresentation = self.listname(channel, user, representation) if newRepresentation: userlist.append(newRepresentation) # Copy of irc.IRC.names prefixLength = len(self.ircd.name) + len(irc.RPL_NAMREPLY) + len( channel.name) + len( self.nickname) + 10 # 10 characters for CRLF, =, : and spaces namesLength = 512 - prefixLength # May get messed up with unicode lines = chunk_message(" ".join(userlist), namesLength) for l in lines: self.sendMessage(irc.RPL_NAMREPLY, "=", channel.name, ":{}".format(l)) self.sendMessage(irc.RPL_ENDOFNAMES, channel.name, ":End of /NAMES list")
def send_motd(self): if "server_motd" in self.ircd.servconfig and self.ircd.servconfig[ "server_motd"]: chunks = chunk_message( self.ircd.servconfig["server_motd"], self.ircd.servconfig["server_motd_line_length"]) self.sendMessage( irc.RPL_MOTDSTART, ":- {} Message of the day - ".format( self.ircd.servconfig["server_network_name"])) for chunk in chunks: line = ":- {{:{!s}}} -".format( self.ircd.servconfig["server_motd_line_length"] ).format( chunk ) # Dynamically inject the line length as a width argument for the line self.sendMessage(irc.RPL_MOTD, line) self.sendMessage(irc.RPL_ENDOFMOTD, ":End of MOTD command") else: self.sendMessage(irc.ERR_NOMOTD, ":MOTD File is missing")
def onUse(self, user, data): modifier = data["modifier"] if modifier == "+": targetlist = data["targetlist"] discard = [] for target in targetlist: if len(target) > 32 or " " in target: discard.append(target) for target in discard: targetlist.remove(target) if "monitormasks" not in user.cache: user.cache["monitormasks"] = [] if "monitorwatching" not in user.cache: user.cache["monitorwatching"] = [] if self.limit and len(user.cache["monitormasks"]) + len(targetlist) > self.limit: user.sendMessage(irc.ERR_MONLISTFULL, str(self.limit), ",".join(targetlist), ":Monitor list is full") return online = [] offline = [] for target in targetlist: lowerTarget = irc_lower(target) if lowerTarget not in user.cache["monitorwatching"]: user.cache["monitormasks"].append(target) user.cache["monitorwatching"].append(lowerTarget) if lowerTarget not in self.ircd.module_data_cache["monitorwatchedby"]: self.ircd.module_data_cache["monitorwatchedby"][lowerTarget] = [] self.ircd.module_data_cache["monitorwatchedby"][lowerTarget].append(user) if target in self.ircd.users: online.append(target) else: offline.append(target) if online: onLines = chunk_message(" ".join(online), 400) for line in onLines: user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ","))) if offline: offLines = chunk_message(" ".join(offline), 400) for line in offLines: user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ","))) elif modifier == "-": targetlist = data["targetlist"] if "monitormasks" not in user.cache or "monitorwatching" not in user.cache: return for target in targetlist: lowerTarget = irc_lower(target) if lowerTarget in user.cache["monitorwatching"]: user.cache["monitorwatching"].remove(lowerTarget) watchList = user.cache["monitormasks"] for mask in watchList: if irc_lower(mask) == lowerTarget: user.cache["monitormasks"].remove(mask) if lowerTarget in self.ircd.module_data_cache["monitorwatchedby"]: self.ircd.module_data_cache["monitorwatchedby"][lowerTarget].remove(user) elif modifier == "C": if "monitormasks" in user.cache: del user.cache["monitormasks"] if "monitorwatching" in user.cache: for target in user.cache["monitorwatching"]: self.ircd.module_data_cache["monitorwatchedby"][target].remove(user) del user.cache["monitorwatching"] elif modifier == "L": if "monitormasks" in user.cache: userlist = chunk_message(" ".join(user.cache["monitormasks"]), 400) for line in userlist: user.sendMessage(irc.RPL_MONLIST, ":{}".format(line.replace(" ", ","))) user.sendMessage(irc.RPL_ENDOFMONLIST, ":End of MONITOR list") elif modifier == "S": if "monitormasks" in user.cache: online = [] offline = [] for target in user.cache["monitormasks"]: if target in self.ircd.users: online.append(target) else: offline.append(target) if online: onlineLines = chunk_message(" ".join(online), 400) for line in onlineLines: user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ","))) if offline: offlineLines = chunk_message(" ".join(offline), 400) for line in offlineLines: user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ",")))
def onUse(self, user, data): modifier = data["modifier"] if modifier == "+": targetlist = data["targetlist"] discard = [] for target in targetlist: if len(target) > 32 or " " in target: discard.append(target) for target in discard: targetlist.remove(target) if "monitormasks" not in user.cache: user.cache["monitormasks"] = [] if "monitorwatching" not in user.cache: user.cache["monitorwatching"] = [] if self.limit and len( user.cache["monitormasks"]) + len(targetlist) > self.limit: user.sendMessage(irc.ERR_MONLISTFULL, str(self.limit), ",".join(targetlist), ":Monitor list is full") return online = [] offline = [] for target in targetlist: lowerTarget = irc_lower(target) if lowerTarget not in user.cache["monitorwatching"]: user.cache["monitormasks"].append(target) user.cache["monitorwatching"].append(lowerTarget) if lowerTarget not in self.ircd.module_data_cache[ "monitorwatchedby"]: self.ircd.module_data_cache["monitorwatchedby"][ lowerTarget] = [] self.ircd.module_data_cache["monitorwatchedby"][ lowerTarget].append(user) if target in self.ircd.users: online.append(target) else: offline.append(target) if online: onLines = chunk_message(" ".join(online), 400) for line in onLines: user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ","))) if offline: offLines = chunk_message(" ".join(offline), 400) for line in offLines: user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ","))) elif modifier == "-": targetlist = data["targetlist"] if "monitormasks" not in user.cache or "monitorwatching" not in user.cache: return for target in targetlist: lowerTarget = irc_lower(target) if lowerTarget in user.cache["monitorwatching"]: user.cache["monitorwatching"].remove(lowerTarget) watchList = user.cache["monitormasks"] for mask in watchList: if irc_lower(mask) == lowerTarget: user.cache["monitormasks"].remove(mask) if lowerTarget in self.ircd.module_data_cache[ "monitorwatchedby"]: self.ircd.module_data_cache["monitorwatchedby"][ lowerTarget].remove(user) elif modifier == "C": if "monitormasks" in user.cache: del user.cache["monitormasks"] if "monitorwatching" in user.cache: for target in user.cache["monitorwatching"]: self.ircd.module_data_cache["monitorwatchedby"][ target].remove(user) del user.cache["monitorwatching"] elif modifier == "L": if "monitormasks" in user.cache: userlist = chunk_message(" ".join(user.cache["monitormasks"]), 400) for line in userlist: user.sendMessage(irc.RPL_MONLIST, ":{}".format(line.replace(" ", ","))) user.sendMessage(irc.RPL_ENDOFMONLIST, ":End of MONITOR list") elif modifier == "S": if "monitormasks" in user.cache: online = [] offline = [] for target in user.cache["monitormasks"]: if target in self.ircd.users: online.append(target) else: offline.append(target) if online: onlineLines = chunk_message(" ".join(online), 400) for line in onlineLines: user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ","))) if offline: offlineLines = chunk_message(" ".join(offline), 400) for line in offlineLines: user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ",")))