Commit b1f08ee2 authored by nanahira's avatar nanahira

handle some ocr things

parent 492ce261
......@@ -60,7 +60,12 @@ export default class HisoutensokuJammerPlugin
@UseMiddleware()
async onMessage(session: Session, next: Next) {
this.parseMessage(session.content, session.userId).then();
this.parseMessage(
session.content,
session.channelId
? `${session.channelId}:${session.userId}`
: session.userId,
).then();
return next();
}
......@@ -115,8 +120,10 @@ export default class HisoutensokuJammerPlugin
private async workForOcr(imageUrls: string[], sender: string) {
const text = (
await Promise.all(imageUrls.map((imageUrl) => this.recognize(imageUrl)))
).join('');
return this.handleMessage(text, sender, false);
).join('\n');
return Promise.all(
text.split('\n').map((line) => this.handleMessage(line, sender, false)),
);
}
private async getTargetsFromMessage(
......@@ -124,13 +131,21 @@ export default class HisoutensokuJammerPlugin
sender: string,
useCache = true,
) {
let receivedMessage = message.split('\n').join(' ').toLowerCase();
let receivedMessage = message
.split('\n')
.join(' ')
.toLowerCase()
.replace(/\s{2,}/g, ' ');
for (const chineseCharacter of chineseCharacterList) {
receivedMessage = receivedMessage.replace(
chineseCharacter.characterRegExp,
chineseCharacter.value,
);
}
if (!receivedMessage.match(/\d/)) {
// must be 1 number to match
return;
}
this.log.info(`Parsing message from ${sender}: ${receivedMessage}`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment