Fix irc bot auth
This commit is contained in:
@@ -27,6 +27,6 @@ import { IrcbotService } from './ircbot/ircbot.service';
|
||||
IrcbotModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, IrcbotService],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
@@ -9,5 +9,6 @@ export default () => ({
|
||||
tls: process.env.IRC_TLS === 'true',
|
||||
port: parseInt(process.env.IRC_PORT ?? '6697'),
|
||||
channel: process.env.IRC_CHANNEL ?? '#usdev',
|
||||
password: process.env.IRC_PASSWORD ?? '',
|
||||
},
|
||||
});
|
||||
|
@@ -4,6 +4,5 @@ import { DomainrproxyService } from 'src/domainrproxy/domainrproxy.service';
|
||||
|
||||
@Module({
|
||||
providers: [IrcbotService, DomainrproxyService],
|
||||
exports: [IrcbotService],
|
||||
})
|
||||
export class IrcbotModule {}
|
||||
|
@@ -18,14 +18,19 @@ export class IrcbotService {
|
||||
public readonly domainrProxy: DomainrproxyService,
|
||||
) {
|
||||
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({
|
||||
port: this.configService.get<number>('irc.port'),
|
||||
host: this.configService.get<string>('irc.server'),
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
this.client = irc(this.socket);
|
||||
this.client.nick(process.env.NODE_ENV === 'production' ? 'usbot' : 'usdev');
|
||||
this.client.user('usbot', 'usbot');
|
||||
if (ircPassword) this.client.pass(ircPassword);
|
||||
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>(
|
||||
'irc.channel',
|
||||
) as string;
|
||||
@@ -34,28 +39,27 @@ export class IrcbotService {
|
||||
this.logger.verbose(`${channel} contains ${JSON.stringify(names)}`);
|
||||
});
|
||||
|
||||
this.client.on('errors', this.logger.error);
|
||||
|
||||
this.client.on('message', async (message) => {
|
||||
console.log(message);
|
||||
if (message.to !== channel) return;
|
||||
if (message.message[0] !== this.prefix) return;
|
||||
|
||||
const [command, ...args] = message.message.substring(1).split(' ');
|
||||
|
||||
switch (command) {
|
||||
case 'domain':
|
||||
const domain = args[0];
|
||||
const queryResult = await this.domainrProxy.queryForDomain(domain);
|
||||
this.client.send(
|
||||
channel,
|
||||
`${queryResult[0].domain} ${queryResult[0].status}`,
|
||||
);
|
||||
return;
|
||||
default:
|
||||
this.client.send(channel, `Dunno what ${command} means`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
switch (command) {
|
||||
case 'domain':
|
||||
const domain = args[0];
|
||||
const queryResult = await this.domainrProxy.queryForDomain(domain);
|
||||
this.client.send(
|
||||
channel,
|
||||
`${queryResult[0].domain} ${queryResult[0].status}`,
|
||||
);
|
||||
return;
|
||||
default:
|
||||
this.client.send(channel, `Dunno what ${command} means`);
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user