Fix irc bot auth

This commit is contained in:
2023-09-19 21:42:34 -06:00
parent d34ff00dac
commit 09596b77d8
4 changed files with 24 additions and 20 deletions

View File

@@ -27,6 +27,6 @@ import { IrcbotService } from './ircbot/ircbot.service';
IrcbotModule, IrcbotModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [AppService, IrcbotService], providers: [AppService],
}) })
export class AppModule {} export class AppModule {}

View File

@@ -9,5 +9,6 @@ export default () => ({
tls: process.env.IRC_TLS === 'true', tls: process.env.IRC_TLS === 'true',
port: parseInt(process.env.IRC_PORT ?? '6697'), port: parseInt(process.env.IRC_PORT ?? '6697'),
channel: process.env.IRC_CHANNEL ?? '#usdev', channel: process.env.IRC_CHANNEL ?? '#usdev',
password: process.env.IRC_PASSWORD ?? '',
}, },
}); });

View File

@@ -4,6 +4,5 @@ import { DomainrproxyService } from 'src/domainrproxy/domainrproxy.service';
@Module({ @Module({
providers: [IrcbotService, DomainrproxyService], providers: [IrcbotService, DomainrproxyService],
exports: [IrcbotService],
}) })
export class IrcbotModule {} export class IrcbotModule {}

View File

@@ -18,14 +18,19 @@ export class IrcbotService {
public readonly domainrProxy: DomainrproxyService, public readonly domainrProxy: DomainrproxyService,
) { ) {
if (!this.configService.get<boolean>('irc.enabled')) return; if (!this.configService.get<boolean>('irc.enabled')) return;
const nick = process.env.NODE_ENV === 'production' ? 'usbot' : 'usdev';
const ircPassword = this.configService.get<string>('irc.password');
this.socket = connect({ this.socket = connect({
port: this.configService.get<number>('irc.port'), port: this.configService.get<number>('irc.port'),
host: this.configService.get<string>('irc.server'), host: this.configService.get<string>('irc.server'),
rejectUnauthorized: false, rejectUnauthorized: false,
}); });
this.client = irc(this.socket); this.client = irc(this.socket);
this.client.nick(process.env.NODE_ENV === 'production' ? 'usbot' : 'usdev'); if (ircPassword) this.client.pass(ircPassword);
this.client.user('usbot', 'usbot'); this.client.user(nick + 'login', `us.dev bot ${process.env.NODE_ENV}`);
this.client.nick(nick + 'login');
this.client.send('nickserv', `identify ${nick} ${ircPassword}`);
console.log(nick);
const channel: string = this.configService.get<string>( const channel: string = this.configService.get<string>(
'irc.channel', 'irc.channel',
) as string; ) as string;
@@ -34,28 +39,27 @@ export class IrcbotService {
this.logger.verbose(`${channel} contains ${JSON.stringify(names)}`); this.logger.verbose(`${channel} contains ${JSON.stringify(names)}`);
}); });
this.client.on('errors', this.logger.error);
this.client.on('message', async (message) => { this.client.on('message', async (message) => {
console.log(message);
if (message.to !== channel) return; if (message.to !== channel) return;
if (message.message[0] !== this.prefix) return; if (message.message[0] !== this.prefix) return;
const [command, ...args] = message.message.substring(1).split(' '); const [command, ...args] = message.message.substring(1).split(' ');
switch (command) { try {
case 'domain': switch (command) {
const domain = args[0]; case 'domain':
const queryResult = await this.domainrProxy.queryForDomain(domain); const domain = args[0];
this.client.send( const queryResult = await this.domainrProxy.queryForDomain(domain);
channel, this.client.send(
`${queryResult[0].domain} ${queryResult[0].status}`, channel,
); `${queryResult[0].domain} ${queryResult[0].status}`,
return; );
default: return;
this.client.send(channel, `Dunno what ${command} means`); default:
return; this.client.send(channel, `Dunno what ${command} means`);
} return;
}
} catch {}
}); });
} }
} }