63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { MatrixClient } from "matrix-js-sdk";
|
|
import type { ICallbackStore } from "../types.js";
|
|
import { config } from "../../config.js";
|
|
|
|
let client: MatrixClient;
|
|
|
|
const registerModuleTest = (
|
|
matrixClient: MatrixClient,
|
|
callbackStore: ICallbackStore,
|
|
) => {
|
|
client = matrixClient;
|
|
|
|
callbackStore.messageCallbacks.push({
|
|
startCondition: `${config.app.triggerPrefix}ping`,
|
|
callbackFunc: onPing,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startCondition: `${config.app.triggerPrefix}say `,
|
|
callbackFunc: onSay,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startCondition: `${config.app.triggerPrefix}help`,
|
|
callbackFunc: onHelp,
|
|
});
|
|
};
|
|
|
|
const onPing = (_text: string, roomId: string) => {
|
|
client.sendTextMessage(roomId, "Pong!");
|
|
};
|
|
|
|
const onSay = (text: string, roomId: string) => {
|
|
const trigger = `${config.app.triggerPrefix}say `;
|
|
|
|
client.sendTextMessage(roomId, text.replace(trigger, ""));
|
|
};
|
|
|
|
const onHelp = (_text: string, roomId: string) => {
|
|
client.sendHtmlMessage(
|
|
roomId,
|
|
"",
|
|
`<h3>Role: User</h3>
|
|
<ul>
|
|
<li><b>!ping</b> - Pong!</li>
|
|
<li><b>!say {text}</b> - Repeats your message</li>
|
|
<li><b>!help</b> - Prints this help message</li>
|
|
<li><b>!rank</b> - Prints your rank and experience</li>
|
|
<li><b>!leaderboard</b> - Prints total user ranking</li>
|
|
</ul>
|
|
<hr/>
|
|
<h3>Role: Moderator</h3>
|
|
<ul>
|
|
<li><b>!loaddata</b> - Load bot data</li>
|
|
<li><b>!savedata</b> - Save bot data</li>
|
|
</ul>
|
|
<hr/>
|
|
<h3>Role: Admin</h3>
|
|
<ul>
|
|
<li><b>!shutdown</b> - Shutdown bot</li>
|
|
</ul>`,
|
|
);
|
|
};
|
|
|
|
export { registerModuleTest };
|