96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { MatrixClient } from "matrix-js-sdk";
|
|
import type { ICallbackStore } from "../types.js";
|
|
import { config, packageConfig } from "../../config.js";
|
|
import { platform } from "os";
|
|
|
|
let client: MatrixClient;
|
|
|
|
const registerModuleBase = (
|
|
matrixClient: MatrixClient,
|
|
callbackStore: ICallbackStore,
|
|
) => {
|
|
client = matrixClient;
|
|
|
|
callbackStore.messageCallbacks.push({
|
|
startConditions: [`${config.app.triggerPrefix}ping`],
|
|
callbackFunc: onPing,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startConditions: [`${config.app.triggerPrefix}info`],
|
|
callbackFunc: onInfo,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startConditions: [`${config.app.triggerPrefix}say `],
|
|
callbackFunc: onSay,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startConditions: [`${config.app.triggerPrefix}bowling `],
|
|
callbackFunc: onBowling,
|
|
});
|
|
callbackStore.messageCallbacks.push({
|
|
startConditions: [`${config.app.triggerPrefix}help`],
|
|
callbackFunc: onHelp,
|
|
});
|
|
};
|
|
|
|
const onPing = (_text: string, roomId: string) => {
|
|
client.sendTextMessage(roomId, "Pong!");
|
|
};
|
|
|
|
const onInfo = (_text: string, roomId: string) => {
|
|
client.sendHtmlMessage(
|
|
roomId,
|
|
"",
|
|
`<p>AsloBot version <b>${packageConfig.version}</b> running on <b>${platform()}</b></p>`,
|
|
);
|
|
};
|
|
|
|
const onSay = (text: string, roomId: string) => {
|
|
const trigger = `${config.app.triggerPrefix}say `;
|
|
|
|
client.sendTextMessage(roomId, text.replace(trigger, ""));
|
|
};
|
|
|
|
const onBowling = (text: string, _roomId: string) => {
|
|
const trigger = `${config.app.triggerPrefix}bowling `;
|
|
|
|
client.sendTextMessage(config.app.bowlingRoomId, text.replace(trigger, ""));
|
|
};
|
|
|
|
const onHelp = (_text: string, roomId: string) => {
|
|
client.sendHtmlMessage(
|
|
roomId,
|
|
"",
|
|
`<h3>Role: Any</h3>
|
|
<ul>
|
|
<li><b>!ping</b> - Pong!</li>
|
|
<li><b>!info</b> - Prints information about this bot</li>
|
|
<li><b>!say {text}</b> - Repeats your message</li>
|
|
<li><b>!bowling {text}</b> - Repeats your message in bowling</li>
|
|
<li><b>!help</b> - Prints this help message</li>
|
|
<li><b>!me / !me {mention}</b> - Prints your role, level, experience, money and ai cost</li>
|
|
<li><b>!leaderboard</b> - Prints total user ranking</li>
|
|
<li><b>!aileaderboard</b> - Prints total user ai cost</li>
|
|
</ul>
|
|
<h3>Role: User</h3>
|
|
<ul>
|
|
<li><b>!ai {text}</b> - Say something to Gemini 3</li>
|
|
<li><b>!img {text}</b> - Generate an image</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>!setrole {user} {role}</b> - Set role for a user</li>
|
|
<li><b>!shutdown</b> - Shutdown bot</li>
|
|
</ul>
|
|
<h4>AsloBot version ${packageConfig.version}</h4>`,
|
|
);
|
|
};
|
|
|
|
export { registerModuleBase };
|