Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6368a93
added run as dev script for windows in package.json
Xevrrer May 27, 2024
ac3b0df
Fix pnpm dev on windows
Xevrrer May 28, 2024
0bc7ed6
Merge branch 'nghtw:main' into main
Xevrrer Jul 21, 2024
0664b78
template unstyled table
Xevrrer Jul 29, 2024
8b13d04
fix multi select
Xevrrer Aug 11, 2024
643de8c
reedit template
Xevrrer Aug 16, 2024
eb46c06
preapre safe action
Xevrrer Aug 17, 2024
3ac5f07
cleanup
Xevrrer Sep 1, 2024
1d92ee3
fixed filters by tag
Xevrrer Sep 1, 2024
c2c28fa
added channel reading
Xevrrer Sep 3, 2024
6319128
test: show author
Xevrrer Sep 3, 2024
ebc667d
fix
Xevrrer Sep 3, 2024
3121ab2
added properly working fetch from api and action
Xevrrer Sep 4, 2024
0f603f5
added listeners and some functions
Xevrrer Oct 8, 2024
baa0dbb
Loading content tags from channel
Xevrrer Oct 8, 2024
b5c70e6
more listeners, fixed bugs, added comment preview
Xevrrer Oct 14, 2024
e968d5c
update to next 15
Xevrrer Oct 24, 2024
1ee95b6
fixes hydration error after next 15 update
Xevrrer Oct 24, 2024
aa99512
added auth system
Xevrrer Oct 24, 2024
082ddf1
oauth github (temporary)
Xevrrer Oct 24, 2024
6c42db8
fix session promise
Xevrrer Oct 25, 2024
050020b
fixed types, authed routes, login/ logout/ roles
Xevrrer Oct 25, 2024
0d207b8
return null instead of string when unauthorized
Xevrrer Oct 25, 2024
d61cd57
Fix tsx errors
Xevrrer Oct 25, 2024
431573a
fixed upsert comments order date
Xevrrer Oct 25, 2024
93e0ed9
added canary note system
Xevrrer Oct 26, 2024
33d83da
added notes
Xevrrer Oct 26, 2024
6522e33
added fetching attachemnt to bot
Xevrrer Oct 26, 2024
df6c67a
added attachments to view, fix discord url issue
Xevrrer Oct 26, 2024
30c71e7
main table ui update
Xevrrer Oct 28, 2024
d375309
dialog ui
Xevrrer Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/bot/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class MistSapphireClient extends SapphireClient {
this.stores.registerPath(join(this.rootData.root, "modules/debug"));
this.stores.registerPath(join(this.rootData.root, "modules/managed-roles"));
this.stores.registerPath(join(this.rootData.root, "modules/tickets"));
this.stores.registerPath(join(this.rootData.root, "modules/content"));
}

public override async login(token?: string) {
Expand Down
2 changes: 2 additions & 0 deletions apps/bot/src/modules/boards/listeners/thread-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class BoardsThreadCreateListener extends Listener<"threadCreate"> {
"Channel is not a board channel"
);



const status = config.tags.find(
(tag) =>
tag.isStatus &&
Expand Down
18 changes: 18 additions & 0 deletions apps/bot/src/modules/content/functions/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { container } from "@sapphire/pieces";



// obecne obslugiwany jest tylko jeden kanał
export async function getChannelWithEnabledContentFetching() {
const config = await container.db.contentChannelConfig.findFirst({
where: {
enabled: true,
},
select: {
channelId: true,
},
});

return config

}
15 changes: 15 additions & 0 deletions apps/bot/src/modules/content/functions/deleteAllAttachments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { container } from "@sapphire/pieces";
import type { Message } from "discord.js";

export async function deleteAllAttachments(message: Message) {
try {
await container.db.contentCommentAttachment.deleteMany({
where: {
commentId: BigInt(message.id),
},
});
console.log('Wszystkie załączniki dla komentarza usunięte.');
} catch (error) {
console.error('Błąd podczas usuwania załączników:', error);
}
}
18 changes: 18 additions & 0 deletions apps/bot/src/modules/content/functions/deleteAllReactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { container } from '@sapphire/pieces';
import type { Message } from 'discord.js';

export async function deleteAllReactions(message: Message) {
const messageId = BigInt(message.id);

try {
await container.db.contentCommentReactions.deleteMany({
where: {
commentId: messageId,
},
});

console.log(`Wszystkie reakcje dla wiadomości o ID ${message.id} zostały usunięte.`);
} catch (error) {
console.error('Błąd podczas usuwania reakcji:', error);
}
}
16 changes: 16 additions & 0 deletions apps/bot/src/modules/content/functions/deleteAllThreadTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// deleteAllThreadTags.ts
import { container } from "@sapphire/pieces";


export async function deleteAllThreadTags(threadId: bigint): Promise<void> {
try {
await container.db.threadTag.deleteMany({
where: {
threadId: threadId,
},
});
console.log(`Usunięto wszystkie tagi dla wątku ID: ${threadId}`);
} catch (error) {
console.error(`Błąd podczas usuwania tagów dla wątku ID: ${threadId}:`, error);
}
}
26 changes: 26 additions & 0 deletions apps/bot/src/modules/content/functions/getThreadAuthorUsername.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ThreadChannel } from "discord.js";



export async function getThreadAuthorUsername(thread: ThreadChannel): Promise<string | null> {

if (!thread.ownerId) {
console.error("Wątek nie ma przypisanego właściciela (ownerId).");
return null;
}

try {

const owner = thread.client.users.cache.get(thread.ownerId);

if (owner) {
return owner.username;
}

const fetchedOwner = await thread.client.users.fetch(thread.ownerId);
return fetchedOwner.username;
} catch (error) {
console.error("Błąd podczas pobierania autora wątku:", error);
return null;
}
}
27 changes: 27 additions & 0 deletions apps/bot/src/modules/content/functions/upsertAttachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { container } from "@sapphire/pieces";
import type { Attachment, Message } from "discord.js";

export async function upsertAttachment(attachment: Attachment, message: Message) {
try {
await container.db.contentCommentAttachment.upsert({
where: { id: BigInt(attachment.id) },
update: {
commentId: BigInt(message.id),
url: attachment.url,
filename: attachment.name,
updatedAt: new Date(),
},
create: {
id: BigInt(attachment.id),
commentId: BigInt(message.id),
url: attachment.url,
filename: attachment.name,
createdAt: new Date(),
updatedAt: new Date(),
},
});
console.log('Załącznik upsertowany:');
} catch (error) {
console.error('Błąd podczas upsertowania załącznika:', error);
}
}
34 changes: 34 additions & 0 deletions apps/bot/src/modules/content/functions/upsertComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { container } from "@sapphire/pieces";
import type { Message, ThreadChannel } from "discord.js";
//import { getThreadAuthorUsername } from "./getThreadAuthorUsername.js";

export async function upsertComment(message: Message, thread: ThreadChannel) {

const author = message.author.username;

if (!author) {
throw new Error("Wątek nie ma przypisanego właściciela (ownerId) lub ten nie znajduje się w cache.");
}

try {
await container.db.contentComments.upsert({
where: { id: BigInt(message.id) },
update: {
content: message.content,
author,
updatedAt: new Date(),
},
create: {
id: BigInt(message.id),
threadId: BigInt(thread.id),
content: message.content,
author,
createdAt: message.createdAt ?? new Date(),
updatedAt: new Date(),
},
});
console.log('Wątek upsertowany:');
} catch (error) {
console.error('Błąd podczas upsertowania wątku', error);
}
}
57 changes: 57 additions & 0 deletions apps/bot/src/modules/content/functions/upsertReactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { container } from '@sapphire/pieces';
import type { MessageReaction, User, ThreadChannel } from 'discord.js';

export async function upsertReaction(
reaction: MessageReaction,
user: User,
thread: ThreadChannel,
action: 'add' | 'remove'
) {
const message = reaction.message;
const emoji = reaction.emoji.identifier;

if (!emoji) {
console.error('Nie udało się uzyskać identyfikatora emoji.');
return;
}

try {


if (action === 'add') {
await container.db.contentCommentReactions.upsert({
where: {
commentId_emoji_userId: {
commentId: BigInt(message.id),
emoji,
userId: BigInt(user.id),
},
},
update: {
updatedAt: new Date(),
},
create: {
commentId: BigInt(message.id),
emoji,
userId: BigInt(user.id),
createdAt: new Date(),
updatedAt: new Date(),
},
});
console.log('Reakcja dodana do bazy danych.');
} else if (action === 'remove') {
await container.db.contentCommentReactions.delete({
where: {
commentId_emoji_userId: {
commentId: BigInt(message.id),
emoji,
userId: BigInt(user.id),
},
},
});
console.log('Reakcja usunięta z bazy danych.');
}
} catch (error) {
console.error('Błąd podczas upsertowania reakcji', error);
}
}
35 changes: 35 additions & 0 deletions apps/bot/src/modules/content/functions/upsertTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// upsertTag.ts
import { container } from "@sapphire/pieces";
import type { GuildForumTag } from "discord.js";
import { assert } from "../../../utils/assert.js";

interface UpsertTagParams {
tag: GuildForumTag;
channelId: bigint;
}

export async function upsertTag({ tag, channelId }: UpsertTagParams) {
try {
await container.db.contentTag.upsert({
where: {
id: tag.id,
},
update: {
name: tag.name,
emoji: tag.emoji ? tag.emoji.name : null,
updatedAt: new Date(),
},
create: {
id: tag.id,
channelId: channelId,
name: tag.name,
emoji: tag.emoji ? tag.emoji.name : null,
createdAt: new Date(),
updatedAt: new Date(),
},
});
console.log(`Tag upsertowany: ${tag.name}`);
} catch (error) {
console.error(`Błąd podczas upsertowania tagu "${tag.name}":`, error);
}
}
28 changes: 28 additions & 0 deletions apps/bot/src/modules/content/functions/upsertTagsForThread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// upsertTagsForThread.ts
import { container } from "@sapphire/pieces";

interface AssignTagsToThreadParams {
threadId: bigint;
tagIds: string[];
}


export async function upsertTagsForThread({ threadId, tagIds }: AssignTagsToThreadParams): Promise<void> {
try {
const createThreadTags = tagIds.map((tagId) => ({
threadId: threadId,
tagId: tagId,
}));

if (createThreadTags.length > 0) {
await container.db.threadTag.createMany({
data: createThreadTags,
});
console.log(`Przypisano ${createThreadTags.length} tagi do wątku ID: ${threadId}`);
} else {
//console.log(`Nie przypisano żadnych tagów do wątku ID: ${threadId}`);
}
} catch (error) {
console.error(`Błąd podczas przypisywania tagów do wątku ID: ${threadId}:`, error);
}
}
33 changes: 33 additions & 0 deletions apps/bot/src/modules/content/functions/upsertThread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { container } from "@sapphire/pieces";
import type { ThreadChannel } from "discord.js";
import { getThreadAuthorUsername } from "./getThreadAuthorUsername.js";

export async function upsertThread(thread: ThreadChannel) {

const author = await getThreadAuthorUsername(thread);

if (!author) {
throw new Error("Wątek nie ma przypisanego właściciela (ownerId) lub ten nie znajduje się w cache.");
}

try {
await container.db.contentThreads.upsert({
where: { id: BigInt(thread.id) },
update: {
content: thread.name,
author,
updatedAt: new Date(),
},
create: {
id: BigInt(thread.id),
content: thread.name,
author,
createdAt: new Date(),
updatedAt: new Date(),
},
});
console.log(`Wątek upsertowany: ${thread.name}`);
} catch (error) {
console.error(`Błąd podczas upsertowania wątku "${thread.name}":`, error);
}
}
38 changes: 38 additions & 0 deletions apps/bot/src/modules/content/listeners/message-create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Listener } from '@sapphire/framework';
import type { Message, ThreadChannel } from 'discord.js';
import { getChannelWithEnabledContentFetching } from '../functions/config.js';
import { upsertComment } from '../functions/upsertComment.js';

export class MessageCreateListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
event: 'messageCreate',
});
}

public async run(message: Message) {
if (message.partial) await message.fetch();

if (!message.channel.isThread()) return;

const thread = message.channel as ThreadChannel;

const result = await getChannelWithEnabledContentFetching();

if (!result) {
console.error('Nie znaleziono konfiguracji kanału.');
return;
}

const channelId = result.channelId;

if (thread.parentId !== channelId.toString()){
return;
}

console.log('message was created', message.content);

await upsertComment(message, thread);
}
}
Loading