Release 1.0.0

This commit is contained in:
2025-06-08 16:16:37 +08:00
parent 0492705128
commit bbc701c686
15 changed files with 1854 additions and 61 deletions
+5 -1
View File
@@ -3,4 +3,8 @@ logs/
node_modules/
.env
session.json
crypto*/
crypto*/
bot.json
bot_crypto
package-lock.json
dist/
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

+1644 -44
View File
File diff suppressed because it is too large Load Diff
+29 -2
View File
@@ -1,24 +1,51 @@
{
"name": "matrix-sob",
"version": "1.0.0",
"main": "index.js",
"main": "src/index.js",
"bin": "src/index.js",
"pkg": {
"scripts": [
"./**/*.js",
"./src/commands/*.js",
"./src/console_commands/*.js",
"./src/util/*.js",
"./src/*.js"
],
"assets": [
"./src/*.json"
],
"__targets": [
"node18-linux-x64",
"node18-win"
],
"__outputPath": "../dist/"
},
"scripts": {
"clean": "rimraf output/",
"test": "echo \"Error: no test specified\" && exit 1",
"clean_plat": "rimraf dist/",
"build": "npm run clean && tsc && copyfiles .env package.json output/",
"build_plat": "npm run clean_plat && mkdirp ./dist && npm run build && npm run platstep2",
"platstep2": "pkg -t node18-win --compress GZip -o ./dist/sob.exe ./output && node output/src/util/setMeta.js",
"quick": "npm run clean && tsc && node ./output/src/index.js"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@matrix-org/matrix-sdk-crypto-nodejs": "^0.3.0-beta.1",
"@matrix-org/olm": "^3.2.15",
"colorts": "^0.1.63",
"dotenv": "^16.5.0",
"matrix-bot-sdk": "^0.7.1",
"node-pager": "^0.3.6",
"rcedit": "^4.0.1",
"rimraf": "^6.0.1",
"tree-kill": "^1.2.2",
"typescript": "^5.8.3",
"winston": "^3.17.0"
},
"devDependencies": {
"mkdirp": "^3.0.1",
"pkg": "^5.8.1"
}
}
+13 -5
View File
@@ -1,10 +1,11 @@
import { AutojoinRoomsMixin, MatrixClient, SimpleFsStorageProvider, RustSdkCryptoStorageProvider } from "matrix-bot-sdk";
import { AutojoinRoomsMixin, MatrixClient, SimpleFsStorageProvider, RustSdkCryptoStorageProvider, RustSdkCryptoStoreType } from "matrix-bot-sdk";
import * as sdk from 'matrix-bot-sdk'
import Logger from "./util/Logger";
import { StrawberryFilling } from "./types/Cheesecake";
const csc = new Logger("Strawberry Cheesecake", 'red')
import { cd, commands, handleCommand } from ".";
import { StoreType } from "@matrix-org/matrix-sdk-crypto-nodejs";
require('dotenv').config()
var homeServer = process.env.homeserver
@@ -18,14 +19,21 @@ var client: MatrixClient = null;
export function BakeStrawberryCheesecake(): StrawberryFilling {
client = null;
csc.log('Baking strawberry cheesecake...')
crypto = new RustSdkCryptoStorageProvider('./crypto1/')
storage = new SimpleFsStorageProvider('session.json')
crypto = new RustSdkCryptoStorageProvider("bot_crypto", RustSdkCryptoStoreType.Sled);
storage = new SimpleFsStorageProvider('bot.json')
cd.quiet('Started Matrix Client.')
client = new MatrixClient(homeServer, accessToken, storage, crypto);
client.start()
//client.start()
csc.log(`Baked strawberry cheesecake. Serving cake.`)
AutojoinRoomsMixin.setupOnClient(client);
client.setPresenceStatus('online', '😭')
client.on("room.message", handleCommand);
return GetStrawberryCheesecake()
}
@@ -45,7 +53,7 @@ export async function RebakeStrawberryCheesecake() {
setTimeout(async () => {
BakeStrawberryCheesecake();
AutojoinRoomsMixin.setupOnClient(client);
await client.start()
//await client.start()
csc.log(`Cinnamon reports a command amount of ${commands.length}`)
csc.log('Connection reset! Cake is served once more with an ID of ' + await client.getUserId())
client.on("room.message", handleCommand);
+1 -1
View File
@@ -1,7 +1,7 @@
import { MatrixClient } from "matrix-bot-sdk";
import { CommandData } from "./types/Command";
import Logger from "./util/Logger";
const c = new Logger("Cinnamon")
const c = new Logger("Cinnamon", 'cyan')
import fs from 'fs';
require('dotenv').config()
+1 -1
View File
@@ -4,7 +4,7 @@ import { CommandData } from "../types/Command";
export const Command: CommandData = {
name: 'delete',
description: 'Deletes/redacts a set amount of messages.',
usage: false,
usage: 'This command currently doesn\'t work.',
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
//await client.replyNotice(roomId, event, "😭");
userInput = userInput.replace(`sob!${Command.name} `, '')
+61
View File
@@ -0,0 +1,61 @@
import { MatrixClient } from "matrix-bot-sdk";
import { CommandData } from "../types/Command";
import fs from 'fs'
import Logger from "../util/Logger";
import { cd } from "..";
const cm = new Logger('Cinnamon/help.js')
export const Command: CommandData = {
name: 'help',
description: 'A list of commands.',
usage: 'sob!help <command name>',
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
userInput = userInput.replace('sob!help ', '')
var args: string[] = userInput.split(' ')
//await client.replyNotice(roomId, event, "😭");
const cmdname = args[0]
const cwd = process.cwd();
cd.quiet(`CmdNm ${cmdname}`)
if (!cmdname || cmdname.endsWith('sob!help'))
try {
//var commands = "\n"
const commandList = fs.readdirSync(cwd + '/output/src/commands')
var output = ''
//var processed_commands: number = 0
output = `${output}Help command usage: ${Command.usage}\nThe following commands are available:\n`
for (let i = 0; i < commandList.length; i++) {
const commandFile = commandList[i];
if (commandFile.includes('.map'))
""
else {
//processed_commands++
const commandMetadata = require(cwd + `/output/src/commands/${commandFile.replace('ts', 'js')}`).Command
const usage = commandMetadata.usage ? commandMetadata.usage : commandFile
output = `${output}${commandFile.replace('.js', '')} : ${commandMetadata.description}\n`
//cm.log(`description: ${commandMetadata.description}`)
//cm.log(`usage: ${usage}`)
}
}
return output;
} catch (err) {
return `An error occured while running this command: ${err}`
}
try {
if (cmdname) {
const metadata: CommandData = require(cwd + `/output/src/commands/${cmdname.replace('ts', 'js')}`).Command
if (Array.isArray(metadata.aliases) && metadata.aliases.length)
cm.log(`Aliases: ${metadata.aliases.join(', ')}`)
return `Command name: ${cmdname}\nDescription: ${metadata.description}\nUsage: ${metadata.usage !== false || metadata.usage ? metadata.usage : 'No particular arguments.'}`
}
} catch (err) {
cd.quiet(`Error during help cmd: ${err}`)
return `The command ${cmdname} was not found.`
}
}
}
export default Command
+2 -2
View File
@@ -5,8 +5,8 @@ import { cd } from "..";
export const Command: CommandData = {
name: 'repeat',
description: 'w...',
usage: false,
description: 'Echoes text.',
usage: 'sob!repeat <text>(;;;@;;;(times to repeat)) [ex. sob!repeat sob;;;@;;;3]',
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
//await client.replyNotice(roomId, event, "😭");
userInput = userInput.replace('sob!repeat ', '')
+1 -1
View File
@@ -4,7 +4,7 @@ import { CommandData } from "../types/Command";
export const Command: CommandData = {
name: 'sob',
description: 'sob...',
usage: false,
usage: 'sob',
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
//await client.replyNotice(roomId, event, "😭");
return "😭"
+4 -3
View File
@@ -22,7 +22,8 @@ export function run(command: string) {
export const Main = async (args: Array<string>) => {
c.log(`Rebuilding project.`)
StrawberryCheesecake.cake.stop()
// assuming you have and use npm already
run('npm run quick')
StrawberryCheesecake.cake.stop();
// assuming you have and use npm already
setTimeout(() => run('npm run quick'), 7000);
return 'Waiting for Strawberry Cheesecake to stop syncing...'
}
+11
View File
@@ -7,6 +7,9 @@ import { Prompt } from "./util/Prompt";
import { Cinnamon, CinnamonInit } from "./Cinnamon";
import { BakeStrawberryCheesecake } from "./Cheesecake";
import { StrawberryFilling } from "./types/Cheesecake";
import { SimpleFsStorageProvider } from "matrix-bot-sdk/lib/storage/SimpleFsStorageProvider";
import { RustSdkCryptoStorageProvider, RustSdkCryptoStoreType } from "matrix-bot-sdk/lib/storage/RustSdkCryptoStorageProvider";
import { MatrixClient } from "matrix-bot-sdk";
dotenv.config()
export const cd = new Logger("DEBUGGER", 'cyan', `${new Date().toLocaleDateString('en-us').replaceAll('/', '-')}-DEBUG`)
@@ -18,6 +21,14 @@ cm.quiet('\n\nNEW CLIENT!')
cm.log("Hi!")
export const StrawberryCheesecake: StrawberryFilling = BakeStrawberryCheesecake()
/*export const StrawberryCheesecake: StrawberryFilling = {
stomach_crypto: storage2,
stomach_session: storage,
cake: client,
accessToken: process.env.token
}*/
// Now that everything is set up, start the bot. This will start the sync loop and run until killed.
StrawberryCheesecake.cake.start().then(async () => {
+1 -1
View File
@@ -18,7 +18,7 @@ type Color = 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white'
import { createLogger, transports, format } from 'winston';
import { dateAsOfInitialization } from '../index.js';
export var defaultLogName = `./logs/${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDay() + 1}.log`
export var defaultLogName = `./logs/${new Date().toLocaleDateString('en-us').replaceAll('/', '-')}.log`
export default class Logger {
public static VERBOSE_LEVEL: VerboseLevel = 3;
+63
View File
@@ -0,0 +1,63 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var rcedit_1 = __importDefault(require("rcedit"));
function SetMetadata() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, rcedit_1.default)("".concat(process.cwd(), "/dist/sob_windows.exe"), {
icon: "".concat(process.cwd(), "/assets/sob.ico"),
"version-string": {
ProductName: 'Sob! Matrix',
FileDescription: 'Sob! Matrix; NodeJS Runtime',
CompanyName: 'sobrooms'
},
'product-version': '1.0.0'
})];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
}
SetMetadata();
+18
View File
@@ -0,0 +1,18 @@
import rcedit from 'rcedit'
const pkg = require('../../config.json')
async function SetMetadata() {
await rcedit(`${process.cwd()}/dist/sob.exe`, {
icon: `${process.cwd()}/assets/sob.ico`,
"version-string": {
ProductName: 'Sob! Matrix',
FileDescription: 'Sob! Matrix; NodeJS Runtime',
CompanyName: 'sobrooms',
OriginalFilename: 'sob.exe'
},
'product-version': pkg.version,
'file-version': pkg.version
})
}
SetMetadata();