forked from naskya/firefish
feat: randomly add miao at end of the post in Chinese cat mode
This commit is contained in:
parent
2fe35019c8
commit
abcaed23d4
3 changed files with 28 additions and 3 deletions
|
@ -38,6 +38,7 @@
|
|||
|
||||
## 細かい変更点
|
||||
|
||||
- 中国語の猫モードでは 0.1 の確率で投稿の末尾に「喵」を追加するように
|
||||
- 設定のバックアップファイルに `misskeyVersion` の値が含まれていなくても警告しないように変更
|
||||
- マージされていない本家版へのプルリクエストを独断でマージ
|
||||
- RTL Layout Support ([!10452](https://git.joinfirefish.org/firefish/firefish/-/merge_requests/10452))
|
||||
|
|
|
@ -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
|
||||
// ja-JP
|
||||
.replaceAll("な", "にゃ")
|
||||
|
@ -26,6 +30,7 @@ export function nyaize(text: string, lang?: string): string {
|
|||
|
||||
// zh-CN, zh-TW
|
||||
if (lang === "zh") text = text.replace(/(妙|庙|描|渺|瞄|秒|苗|藐|廟)/g, "喵");
|
||||
if (appendMiao) text += "喵";
|
||||
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
} from "@/misc/populate-emojis.js";
|
||||
import { db } from "@/db/postgre.js";
|
||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||
import rng from "random-seed";
|
||||
|
||||
export async function populatePoll(note: Note, meId: User["id"] | null) {
|
||||
const poll = await Polls.findOneByOrFail({ noteId: note.id });
|
||||
|
@ -260,12 +261,30 @@ export const NoteRepository = db.getRepository(Note).extend({
|
|||
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) : [];
|
||||
function nyaizeNode(node: mfm.MfmNode) {
|
||||
if (node.type === "quote") return;
|
||||
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) {
|
||||
for (const child of node.children) {
|
||||
|
|
Loading…
Reference in a new issue