def register(self, irc, msg, args, otherIrc, password, email): """[<network>] <password> [<email>] Uses the experimental REGISTER command to create an account for the bot on the <network>, using the <password> and the <email> if provided. Some networks may require the email. You may need to use the 'services verify' command afterward to confirm your email address.""" # Using this early draft specification: # https://gist.github.com/edk0/bf3b50fc219fd1bed1aa15d98bfb6495 self._checkCanRegister(irc, otherIrc) cap_values = ( otherIrc.state.capabilities_ls["draft/account-registration"] or "").split(",") if "email-required" in cap_values and email is None: irc.error(_("This network requires an email address to register."), Raise=True) label = ircutils.makeLabel() self._register[label] = (irc, msg.nick) otherIrc.queueMsg( ircmsgs.IrcMsg( server_tags={"label": label}, command="REGISTER", args=["*", email or "*", password], ))
def verify(self, irc, msg, args, otherIrc, account, code): """[<network>] <account> <code> If the <network> requires a verification code, you need to call this command with the code the server gave you to finish the registration.""" self._checkCanRegister(irc, otherIrc) label = ircutils.makeLabel() self._register[label] = (irc, msg.nick) otherIrc.queueMsg( ircmsgs.IrcMsg(server_tags={"label": label}, command="VERIFY", args=[account, code]))
def nunban(self, irc, msg, args, nick): """<nick> If found, will unban mask/account associated with <nick> """ label = ircutils.makeLabel() if nick not in self.db: irc.error(f'There are no bans associated with {nick}') else: if self.db[nick] == 'suspended': irc.queueMsg(msg=ircmsgs.IrcMsg(command='NS', args=('UNSUSPEND', nick), server_tags={"label": label})) irc.reply(f'Enabling suspended account {nick}') self.db.pop(nick) else: irc.queueMsg(msg=ircmsgs.IrcMsg(command='UNKLINE', args=('', self.db[nick]), server_tags={"label": label})) irc.reply(f'Removing KLINE for {self.db[nick]}') self.db.pop(nick)
def outFilter(self, irc, msg): # Mark/remember outgoing relayed messages, so we can rewrite them if # rewriteRelayed is True. if msg.command in ('PRIVMSG', 'NOTICE'): rewriteRelayed = self.registryValue('rewriteRelayed', msg.channel, irc.network) if rewriteRelayed and 'echo-message' in irc.state.capabilities_ack: assert 'labeled-response' in irc.state.capabilities_ack, \ 'echo-message was negotiated without labeled-response.' # If we negotiated the echo-message cap, we have to remember # this message was relayed when the server sends it back to us. if 'label' not in msg.server_tags: msg.server_tags['label'] = ircutils.makeLabel() if msg.tagged('relayedMsg'): # Remember this was a relayed message, in case # rewriteRelayed is True. self._emitted_relayed_msgs[msg.server_tags['label']] = True else: # Else, we can simply rely on internal tags, because echos are # simulated. if msg.tagged('relayedMsg'): msg.tag('ChannelLogger__relayed') return msg
def nban(self, irc, msg, args, opts, nick, reason): """[--duration <duration>] <nick> [<reason>] will add a KLINE for the host associated with <nick> and also KILL the connection. If <nick> is registered it will suspend the respective account <duration> is of the format '1y 12mo 31d 10h 8m 13s' not adding a <duration> will add a permanent KLINE <reason> is optional as well. """ opts = dict(opts) label = ircutils.makeLabel() try: hostmask = irc.state.nickToHostmask(nick) host = hostmask.split("@")[1] bannable_host = f'*!*@{host}' ih = hostmask.split("!")[1] bannable_ih = f'*!{ih}' except KeyError: irc.error( "No such nick", Raise=True, ) # Registered Nicks # Implement do330 and RPL_WHOISOPERATOR instead if host == 'irc.liberta.casa': irc.queueMsg(msg=ircmsgs.IrcMsg(command='NS', args=('SUSPEND', nick), server_tags={"label": label})) irc.reply( f'Suspending account for {nick} Note: <duration> and' ' <reason> are currently not applicable here and will be ignored' ) self.db[nick] = 'suspended' # Discord Nicks # Workaround for hardcoded host values. elif host == '4b4hvj35u73k4.liberta.casa' or host == 'gfvnhk5qj5qaq.liberta.casa' or host == 'fescuzdjai52n.liberta.casa': arg = ['ANDKILL'] if 'duration' in opts: arg.append(opts['duration']) arg.append(bannable_ih) if reason: arg.append(reason) irc.queueMsg(msg=ircmsgs.IrcMsg( command='KLINE', args=arg, server_tags={"label": label})) irc.reply(f'Adding a KLINE for discord user: {bannable_ih}') self.db[nick] = bannable_ih # Unregistered Nicks else: arg = ['ANDKILL'] if 'duration' in opts: arg.append(opts['duration']) arg.append(bannable_host) if reason: arg.append(reason) irc.queueMsg(msg=ircmsgs.IrcMsg( command='KLINE', args=arg, server_tags={"label": label})) irc.reply(f'Adding a KLINE for unregistered user: {bannable_host}') self.db[nick] = bannable_host