1
0
Fork 1
mirror of https://example.com synced 2024-11-25 23:56:39 +09:00

feat: randomly add miao at end of the post in Chinese cat mode

This commit is contained in:
naskya 2023-12-29 00:28:45 +09:00
parent 2fe35019c8
commit abcaed23d4
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
3 changed files with 28 additions and 3 deletions

View file

@ -38,6 +38,7 @@
## 細かい変更点 ## 細かい変更点
- 中国語の猫モードでは 0.1 の確率で投稿の末尾に「喵」を追加するように
- 設定のバックアップファイルに `misskeyVersion` の値が含まれていなくても警告しないように変更 - 設定のバックアップファイルに `misskeyVersion` の値が含まれていなくても警告しないように変更
- マージされていない本家版へのプルリクエストを独断でマージ - マージされていない本家版へのプルリクエストを独断でマージ
- RTL Layout Support ([!10452](https://git.joinfirefish.org/firefish/firefish/-/merge_requests/10452)) - RTL Layout Support ([!10452](https://git.joinfirefish.org/firefish/firefish/-/merge_requests/10452))

View file

@ -1,4 +1,8 @@
export function nyaize(text: string, lang?: string): string { export function nyaize(
text: string,
lang: string | undefined,
appendMiao: boolean,
): string {
text = text text = text
// ja-JP // ja-JP
.replaceAll("な", "にゃ") .replaceAll("な", "にゃ")
@ -26,6 +30,7 @@ export function nyaize(text: string, lang?: string): string {
// zh-CN, zh-TW // zh-CN, zh-TW
if (lang === "zh") text = text.replace(/(妙|庙|描|渺|瞄|秒|苗|藐|廟)/g, "喵"); if (lang === "zh") text = text.replace(/(妙|庙|描|渺|瞄|秒|苗|藐|廟)/g, "喵");
if (appendMiao) text += "喵";
return text; return text;
} }

View file

@ -23,6 +23,7 @@ import {
} from "@/misc/populate-emojis.js"; } from "@/misc/populate-emojis.js";
import { db } from "@/db/postgre.js"; import { db } from "@/db/postgre.js";
import { IdentifiableError } from "@/misc/identifiable-error.js"; import { IdentifiableError } from "@/misc/identifiable-error.js";
import rng from "random-seed";
export async function populatePoll(note: Note, meId: User["id"] | null) { export async function populatePoll(note: Note, meId: User["id"] | null) {
const poll = await Polls.findOneByOrFail({ noteId: note.id }); const poll = await Polls.findOneByOrFail({ noteId: note.id });
@ -260,12 +261,30 @@ export const NoteRepository = db.getRepository(Note).extend({
lang: note.lang, lang: note.lang,
}); });
if (packed.user.isCat && packed.user.speakAsCat && packed.text) { const CHINESE_APPEND_MIAO_PROBABILITY = 0.1;
const shouldAppendMiao = (() => {
if (packed.lang?.startsWith("zh")) {
let seed: string | null = null;
if (packed.url != null) seed = packed.url.split("/").pop() ?? null;
if (packed.uri != null) seed = packed.uri.split("/").pop() ?? null;
if (seed == null) seed = packed.id;
const rand = rng.create(seed);
return rand.random() <= CHINESE_APPEND_MIAO_PROBABILITY;
}
return false;
})();
if (packed.user.isCat && packed.user.speakAsCat && packed.text != null) {
const tokens = packed.text ? mfm.parse(packed.text) : []; const tokens = packed.text ? mfm.parse(packed.text) : [];
function nyaizeNode(node: mfm.MfmNode) { function nyaizeNode(node: mfm.MfmNode) {
if (node.type === "quote") return; if (node.type === "quote") return;
if (node.type === "text") if (node.type === "text")
node.props.text = nyaize(node.props.text, packed.lang); node.props.text = nyaize(
node.props.text,
packed.lang,
shouldAppendMiao,
);
if (node.children) { if (node.children) {
for (const child of node.children) { for (const child of node.children) {