mirror of
https://github.com/pacnpal/markov-discord.git
synced 2025-12-20 03:01:04 -05:00
Update to markov-strings-db 4.1
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -14,7 +14,8 @@
|
|||||||
],
|
],
|
||||||
"args": [
|
"args": [
|
||||||
"${workspaceFolder}/src/index.ts"
|
"${workspaceFolder}/src/index.ts"
|
||||||
]
|
],
|
||||||
|
"outputCapture": "std",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,8 @@ RUN npm run build
|
|||||||
########
|
########
|
||||||
FROM base as deploy
|
FROM base as deploy
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
# Steal node_modules from base image
|
# Steal node_modules from base image
|
||||||
COPY --from=build /usr/app/node_modules node_modules
|
COPY --from=build /usr/app/node_modules node_modules
|
||||||
|
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -23,7 +23,7 @@
|
|||||||
"erlpack": "github:discord/erlpack",
|
"erlpack": "github:discord/erlpack",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"json5": "^2.2.0",
|
"json5": "^2.2.0",
|
||||||
"markov-strings-db": "^4.0.1",
|
"markov-strings-db": "^4.1.1",
|
||||||
"pino": "^7.5.1",
|
"pino": "^7.5.1",
|
||||||
"pino-pretty": "^7.3.0",
|
"pino-pretty": "^7.3.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
@@ -2681,9 +2681,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/markov-strings-db": {
|
"node_modules/markov-strings-db": {
|
||||||
"version": "4.0.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/markov-strings-db/-/markov-strings-db-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/markov-strings-db/-/markov-strings-db-4.1.1.tgz",
|
||||||
"integrity": "sha512-i7GANb+/6Ppm8DAEO6jp3dxso28Z1LQRW2B+KgJFgvN0dRS9L9r5Dh5zNwW3txye8AYIFhPbXo5zdmP1UknXMQ==",
|
"integrity": "sha512-IRfqGlq8VajKXY2+CYvuLIOwHWSLoIWfruyYK8WP96fJ17UqqXLRO959jJLp5Yy+9JJuwGHfbvVt7fBd1xHxjw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"typeorm": "^0.2.41"
|
"typeorm": "^0.2.41"
|
||||||
@@ -6431,9 +6431,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"markov-strings-db": {
|
"markov-strings-db": {
|
||||||
"version": "4.0.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/markov-strings-db/-/markov-strings-db-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/markov-strings-db/-/markov-strings-db-4.1.1.tgz",
|
||||||
"integrity": "sha512-i7GANb+/6Ppm8DAEO6jp3dxso28Z1LQRW2B+KgJFgvN0dRS9L9r5Dh5zNwW3txye8AYIFhPbXo5zdmP1UknXMQ==",
|
"integrity": "sha512-IRfqGlq8VajKXY2+CYvuLIOwHWSLoIWfruyYK8WP96fJ17UqqXLRO959jJLp5Yy+9JJuwGHfbvVt7fBd1xHxjw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"typeorm": "^0.2.41"
|
"typeorm": "^0.2.41"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"erlpack": "github:discord/erlpack",
|
"erlpack": "github:discord/erlpack",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"json5": "^2.2.0",
|
"json5": "^2.2.0",
|
||||||
"markov-strings-db": "^4.0.1",
|
"markov-strings-db": "^4.1.1",
|
||||||
"pino": "^7.5.1",
|
"pino": "^7.5.1",
|
||||||
"pino-pretty": "^7.3.0",
|
"pino-pretty": "^7.3.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
|||||||
26
src/index.ts
26
src/index.ts
@@ -189,9 +189,13 @@ function messageToData(message: Discord.Message): AddDataProps {
|
|||||||
const attachmentUrls = message.attachments.map((a) => a.url);
|
const attachmentUrls = message.attachments.map((a) => a.url);
|
||||||
let custom: MarkovDataCustom | undefined;
|
let custom: MarkovDataCustom | undefined;
|
||||||
if (attachmentUrls.length) custom = { attachments: attachmentUrls };
|
if (attachmentUrls.length) custom = { attachments: attachmentUrls };
|
||||||
|
const tags: string[] = [message.id];
|
||||||
|
if (message.channelId) tags.push(message.channelId);
|
||||||
|
if (message.guildId) tags.push(message.guildId);
|
||||||
return {
|
return {
|
||||||
string: message.content,
|
string: message.content,
|
||||||
custom,
|
custom,
|
||||||
|
tags,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +217,7 @@ async function saveGuildMessageHistory(
|
|||||||
|
|
||||||
L.debug('Deleting old data');
|
L.debug('Deleting old data');
|
||||||
await markov.delete();
|
await markov.delete();
|
||||||
|
await markov.setup(); // TODO: temp fix until new markov-strings-db version
|
||||||
|
|
||||||
const channelIds = channels.map((c) => c.id);
|
const channelIds = channels.map((c) => c.id);
|
||||||
L.debug({ channelIds }, `Training from text channels`);
|
L.debug({ channelIds }, `Training from text channels`);
|
||||||
@@ -365,7 +370,7 @@ async function generateResponse(
|
|||||||
const messageOpts: Discord.MessageOptions = { tts };
|
const messageOpts: Discord.MessageOptions = { tts };
|
||||||
const attachmentUrls = response.refs
|
const attachmentUrls = response.refs
|
||||||
.filter((ref) => ref.custom && 'attachments' in ref.custom)
|
.filter((ref) => ref.custom && 'attachments' in ref.custom)
|
||||||
.flatMap((ref) => ref.custom.attachments);
|
.flatMap((ref) => (ref.custom as MarkovDataCustom).attachments);
|
||||||
if (attachmentUrls.length > 0) {
|
if (attachmentUrls.length > 0) {
|
||||||
const randomRefAttachment = getRandomElement(attachmentUrls);
|
const randomRefAttachment = getRandomElement(attachmentUrls);
|
||||||
messageOpts.files = [randomRefAttachment];
|
messageOpts.files = [randomRefAttachment];
|
||||||
@@ -373,19 +378,8 @@ async function generateResponse(
|
|||||||
const randomMessage = await MarkovInputData.createQueryBuilder<
|
const randomMessage = await MarkovInputData.createQueryBuilder<
|
||||||
MarkovInputData<MarkovDataCustom>
|
MarkovInputData<MarkovDataCustom>
|
||||||
>('input')
|
>('input')
|
||||||
.leftJoinAndSelect('input.fragment', 'fragment')
|
.leftJoinAndSelect('input.markov', 'markov')
|
||||||
.leftJoinAndSelect('fragment.corpusEntry', 'corpusEntry')
|
.where({ markov: markov.db })
|
||||||
.where([
|
|
||||||
{
|
|
||||||
fragment: { startWordMarkov: markov.db },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fragment: { endWordMarkov: markov.db },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fragment: { corpusEntry: { markov: markov.db } },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.orderBy('RANDOM()')
|
.orderBy('RANDOM()')
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.getOne();
|
.getOne();
|
||||||
@@ -565,7 +559,7 @@ client.on('messageDelete', async (message) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const markov = await getMarkovByGuildId(message.guildId);
|
const markov = await getMarkovByGuildId(message.guildId);
|
||||||
await markov.removeData([message.content]);
|
await markov.removeStrings([message.content]);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageUpdate', async (oldMessage, newMessage) => {
|
client.on('messageUpdate', async (oldMessage, newMessage) => {
|
||||||
@@ -575,7 +569,7 @@ client.on('messageUpdate', async (oldMessage, newMessage) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const markov = await getMarkovByGuildId(oldMessage.guildId);
|
const markov = await getMarkovByGuildId(oldMessage.guildId);
|
||||||
await markov.removeData([oldMessage.content]);
|
await markov.removeStrings([oldMessage.content]);
|
||||||
await markov.addData([newMessage.content]);
|
await markov.addData([newMessage.content]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user