Init
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { CommandData } from "../types/Command";
|
||||
import { commands, StrawberryCheesecake } from "..";
|
||||
import Logger from "../util/Logger";
|
||||
import { cd } from "..";
|
||||
import { EatStrawberryCheesecake, RebakeStrawberryCheesecake } from "../Cheesecake";
|
||||
import { run } from "../console_commands/update";
|
||||
|
||||
export var dbg = {
|
||||
sessionIsForDebugging: true,
|
||||
targetEvent: 'none',
|
||||
roomId: 'none'
|
||||
};
|
||||
|
||||
export const Command: CommandData = {
|
||||
name: 'dbg',
|
||||
description: 'Debug command.',
|
||||
usage: false,
|
||||
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
|
||||
userInput = userInput.replace('sob!dbg ', '')
|
||||
cd.quiet(`Tt ${userInput}`)
|
||||
var args: string[] = userInput.split(' ')
|
||||
if (args[0] && event.sender === "@maki:chat.sob.moe") {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case 'cinnamon':
|
||||
var out = `Cinnamon found:\n\n`
|
||||
for (let i = 0; i < commands.length; i++) {
|
||||
const cmdName = commands[i];
|
||||
cd.quiet('Cinnamon found ' + cmdName)
|
||||
out = `${out}${cmdName},\n`
|
||||
}
|
||||
return `${out}`
|
||||
case 'strawberrycheesecake':
|
||||
if (args[1] && typeof (args[1]) === 'string') {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case 'rebake':
|
||||
RebakeStrawberryCheesecake();
|
||||
return "Rebaked strawberry cheesecake!"
|
||||
case 'eat':
|
||||
client.sendMessage(roomId, {
|
||||
msgtype: "m.text",
|
||||
body: 'Eating strawberry cheesecake.'
|
||||
})
|
||||
EatStrawberryCheesecake();
|
||||
return 'Ate strawberry cheesecake.'
|
||||
case 'updaterecipe':
|
||||
client.sendMessage(roomId, {
|
||||
msgtype: "m.text",
|
||||
body: 'Updating recipe...'
|
||||
})
|
||||
StrawberryCheesecake.cake.stop()
|
||||
setTimeout(() => run('npm run quick'), 7000)
|
||||
default:
|
||||
return 'What do I do with the strawberry cheesecake?'
|
||||
}
|
||||
} else return 'Invalid arguments.'
|
||||
case 'eval':
|
||||
if (args[0].toLowerCase() === "eval") {
|
||||
args.splice(0, 1)
|
||||
var result = args.join(' ')
|
||||
const showRawOutput = result.includes(";;;raw")
|
||||
result = result.replace(';;;raw', '')
|
||||
try {
|
||||
let evaled = eval(result)
|
||||
cd.quiet(`Evaled ${evaled}`)
|
||||
if (!showRawOutput) {
|
||||
result = result.replaceAll(process.env.token, "\"[token\"").replaceAll('client.token', '\"[token]\"').replaceAll('process.env.token', '\"[token]\"');
|
||||
|
||||
//Convert evaled into a JSON String if it is an Object
|
||||
if (typeof evaled === "object") evaled = JSON.stringify(evaled);
|
||||
|
||||
//Do this if evaled is anything else other than a number, text, or true/false
|
||||
if (typeof evaled !== "number" && typeof evaled !== "string" && typeof evaled !== "boolean") evaled = `Output could not be converted to text (output was of type: ${typeof evaled}).`;
|
||||
evaled = evaled.toString().replaceAll(process.env.token.toString(), "[token]")
|
||||
result = result.toString().replaceAll(process.env.token, "[token]").replaceAll('client.token', '[token]').replaceAll('process.env.token', '[token]');
|
||||
}
|
||||
return `${showRawOutput ? "Raw e" : "E"}valuation result:\n${evaled}`
|
||||
} catch (err) {
|
||||
return `${showRawOutput ? "Raw e" : "E"}valuation result:\n${err}`
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (!args[0]) {
|
||||
dbg.sessionIsForDebugging = true;
|
||||
dbg.targetEvent = event.event_id
|
||||
dbg.roomId = roomId
|
||||
return 'Debugging event where sob!dbg was used.'
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case 'target':
|
||||
if (args[1] && dbg.targetEvent === "none")
|
||||
dbg.targetEvent = args[1]
|
||||
break;
|
||||
case 'room':
|
||||
if (args[1] && dbg.roomId === "none")
|
||||
dbg.roomId = args[1]
|
||||
break;
|
||||
case 'reset':
|
||||
dbg.roomId = 'none'
|
||||
dbg.sessionIsForDebugging = false
|
||||
dbg.targetEvent = 'none'
|
||||
return 'Reset.'
|
||||
}
|
||||
switch (args[2]) {
|
||||
case 'target':
|
||||
if (args[3] && dbg.targetEvent === "none")
|
||||
dbg.targetEvent = args[3]
|
||||
break;
|
||||
case 'room':
|
||||
if (args[3] && dbg.roomId === "none")
|
||||
dbg.roomId = args[3]
|
||||
break;
|
||||
}
|
||||
if (dbg.roomId === 'none')
|
||||
dbg.roomId = roomId
|
||||
if (dbg.targetEvent === 'none')
|
||||
dbg.targetEvent = event.event_id
|
||||
dbg.sessionIsForDebugging = true
|
||||
return `Set ${dbg.targetEvent} as the target event and ${dbg.roomId} as the room id. Now debugging.`
|
||||
}
|
||||
}
|
||||
} else if (event.sender !== "@maki:chat.sob.moe") {
|
||||
return 'No permission to do this!'
|
||||
} else
|
||||
return 'No arguments provided!'
|
||||
}
|
||||
}
|
||||
|
||||
export default Command
|
||||
@@ -0,0 +1,62 @@
|
||||
import { MatrixClient, RoomEvent } from "matrix-bot-sdk";
|
||||
import { CommandData } from "../types/Command";
|
||||
|
||||
export const Command: CommandData = {
|
||||
name: 'delete',
|
||||
description: 'Deletes/redacts a set amount of messages.',
|
||||
usage: false,
|
||||
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
|
||||
//await client.replyNotice(roomId, event, "😭");
|
||||
userInput = userInput.replace(`sob!${Command.name} `, '')
|
||||
var args = userInput.split(' ')
|
||||
try {
|
||||
if (args[0]) {
|
||||
var reason = ""
|
||||
if (args[1])
|
||||
reason = args[1]
|
||||
var times = parseInt(args[0])
|
||||
var RecentFew = await getRecentMessages(client, roomId, times)
|
||||
|
||||
if (RecentFew.length > 1) {
|
||||
for (let i = 0; i < times; i++) {
|
||||
console.log(`Cleared ${i} times total of ${times}`)
|
||||
const event: RoomEvent = RecentFew[i];
|
||||
console.log(`This: ${event.eventId}`)
|
||||
await client.redactEvent(roomId, event.eventId, reason)
|
||||
}
|
||||
}
|
||||
return `Tried redacting ${times} time(s).`
|
||||
}
|
||||
return `Invalid usage of command. ${userInput}`
|
||||
} catch (err) {
|
||||
return `${err}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getRecentMessages(client: MatrixClient, roomId: string, count: number) {
|
||||
const messages = [];
|
||||
let fromToken = (await client.doRequest("GET", "/_matrix/client/v3/sync?timeout=0")).next_batch;
|
||||
|
||||
while (messages.length < count) {
|
||||
const res = await client.doRequest("GET", `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/messages`, {
|
||||
dir: "b",
|
||||
from: fromToken,
|
||||
limit: 50, // Can adjust this
|
||||
filter: JSON.stringify({ types: ["m.room.message"] }),
|
||||
});
|
||||
// @ts-ignore
|
||||
const filtered = res.chunk.filter(e => e.type === "m.room.message");
|
||||
for (const msg of filtered) {
|
||||
messages.push(msg);
|
||||
if (messages.length === count) return messages; // ✅ Return immediately
|
||||
}
|
||||
|
||||
if (!res.end || res.chunk.length === 0) break; // No more messages to paginate
|
||||
fromToken = res.end;
|
||||
}
|
||||
|
||||
return messages; // May contain fewer than `count` if not enough messages
|
||||
}
|
||||
|
||||
export default Command
|
||||
@@ -0,0 +1,35 @@
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { CommandData } from "../types/Command";
|
||||
import Logger from "../util/Logger";
|
||||
import { cd } from "..";
|
||||
|
||||
export const Command: CommandData = {
|
||||
name: 'repeat',
|
||||
description: 'w...',
|
||||
usage: false,
|
||||
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
|
||||
//await client.replyNotice(roomId, event, "😭");
|
||||
userInput = userInput.replace('sob!repeat ', '')
|
||||
var initial: string[] = userInput.split(';;;') // initial[0]: text to spam
|
||||
|
||||
try {
|
||||
if (initial[1] === "@") {
|
||||
var times = parseInt(initial[2])
|
||||
cd.quiet(`Times: ${times.toString()}`)
|
||||
for (let i = 0; i < times; i++) {
|
||||
if (i != (times - 1))
|
||||
await client.sendMessage(roomId, {
|
||||
msgtype: "m.text",
|
||||
body: initial[0],
|
||||
})
|
||||
}
|
||||
return initial[0]
|
||||
}
|
||||
return initial[0]
|
||||
} catch (err) {
|
||||
return err.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Command
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { CommandData } from "../types/Command";
|
||||
|
||||
export const Command: CommandData = {
|
||||
name: 'sob',
|
||||
description: 'sob...',
|
||||
usage: false,
|
||||
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
|
||||
//await client.replyNotice(roomId, event, "😭");
|
||||
return "😭"
|
||||
}
|
||||
}
|
||||
|
||||
export default Command
|
||||
Reference in New Issue
Block a user