Skip to content

Commit

Permalink
add loggers to spica
Browse files Browse the repository at this point in the history
  • Loading branch information
ender-null committed May 22, 2024
1 parent 4156aed commit b1c656e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/plugins/spica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WebSocket } from 'ws';
import { Bot } from '../bot';
import { PluginBase } from '../plugin';
import { Message } from '../types';
import { getInput, isCommand, isOwner, isTrusted } from '../utils';
import { getInput, isCommand, isOwner, isTrusted, logger } from '../utils';

export class SpicaPlugin extends PluginBase {
constructor(bot: Bot) {
Expand Down Expand Up @@ -39,8 +39,11 @@ export class SpicaPlugin extends PluginBase {
return this.bot.replyMessage(msg, this.bot.errors.permissionRequired);
}
const input = getInput(msg);
logger.info('before websocket');
const ws: WebSocket = new WebSocket('wss://spica.end.works/wired');
logger.info('after websocket');
ws.on('ready', () => {
logger.info('spica ready');
if (isCommand(this, 1, msg.content)) {
ws.send('status');
} else if (isCommand(this, 2, msg.content)) {
Expand All @@ -51,6 +54,7 @@ export class SpicaPlugin extends PluginBase {
});

ws.on('message', (data: string) => {
logger.info('spica message');
let text = this.bot.errors.noResults;
if (isCommand(this, 1, msg.content)) {
const result = JSON.parse(data.slice(7));
Expand All @@ -64,7 +68,7 @@ export class SpicaPlugin extends PluginBase {
const result = JSON.parse(data.slice(9));
text = '';
for (const key in result) {
text += `${key} ${result[key] ? '✅' : '🆘'}`;
text += `${result[key] ? '✅' : '🆘'} ${key}`;
}
} else {
text = `<code class="language-shell">$ ${input}\n\n${data.toString()}</code>`;
Expand Down

0 comments on commit b1c656e

Please sign in to comment.