slack/ts/slack.classes.slacklog.ts

30 lines
969 B
TypeScript
Raw Normal View History

2019-09-18 17:37:45 +00:00
import { SlackAccount } from './slack.classes.slackaccount';
import { SlackMessage } from './slack.classes.slackmessage';
2019-09-18 14:47:31 +00:00
export class SlackLog {
public slackAccount: SlackAccount;
public slackMessage: SlackMessage;
public channelName: string;
public completeLog = ``;
2019-09-18 17:37:45 +00:00
constructor(optionsArg: { slackAccount: SlackAccount; channelName: string }) {
2019-09-18 14:47:31 +00:00
this.slackAccount = optionsArg.slackAccount;
this.channelName = optionsArg.channelName;
}
public async sendLogLine(logText: string) {
if (!this.slackMessage) {
this.slackMessage = new SlackMessage(this.slackAccount, {
text: '``` log is loading... ```'
});
await this.slackMessage.sendToRoom(this.channelName);
}
const date = new Date();
2019-09-18 17:37:45 +00:00
this.completeLog +=
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
2019-09-18 14:47:31 +00:00
await this.slackMessage.updateAndSend({
2019-09-18 17:37:45 +00:00
text: '```\n' + this.completeLog + '\n```'
});
2019-09-18 14:47:31 +00:00
}
2019-09-18 17:37:45 +00:00
}