// İzleyici kayıtları ve puanlar.
export function normalizeText(s) {
return String(s || '')
.toLocaleLowerCase('tr')
.replace(/ı/g, 'i').replace(/ş/g, 's').replace(/ğ/g, 'g')
.replace(/ü/g, 'u').replace(/ö/g, 'o').replace(/ç/g, 'c')
.normalize('NFD').replace(/[̀-ͯ]/g, '');
}
/** Yorumdaki komutu bul: kelimelerden biri komut listesinde varsa onu döner. */
export function findCommand(text, commands) {
const words = normalizeText(text).split(/[^a-z0-9]+/).filter(Boolean);
for (const [cmd, aliases] of Object.entries(commands || {})) {
for (const a of aliases) {
const na = normalizeText(a);
if (words.includes(na)) return cmd;
}
}
return null;
}
const GENDER_DEFAULT = {
f: ['kadın', 'kadin', 'kız', 'kadınım', 'kızım', 'bayan'],
m: ['erkek', 'erkeğim', 'adam', 'bay'],
toggle: ['değiş', 'değiştir', 'cinsiyet'],
};
/** Cinsiyet komutu: yorum sadece komut kelimesi (ya da "kadın ol" gibi) ise 'f' | 'm' | 'toggle', yoksa null.
* Cümle içinde geçen "kız", "erkek" karakteri değiştirmesin diye tam eşleşme. */
export function genderCommand(text, aliases) {
const words = normalizeText(text).split(/[^a-z0-9]+/).filter(Boolean);
if (!words.length || words.length > 2) return null;
if (words.length === 2 && !['ol', 'olayim', 'olsun', 'yap'].includes(words[1])) return null;
for (const [g, list] of Object.entries(aliases || GENDER_DEFAULT)) {
if (list.some((a) => normalizeText(a) === words[0])) return g;
}
return null;
}
const BYE_DEFAULT = ['görüşürüz', 'iyi geceler', 'hoşça kal', 'hoşçakal', 'gidiyorum', 'kaçtım', 'kaçar', 'bay bay', 'bye', 'bb'];
/** Vedalaşma: yorumda geçerse karakter el sallayıp mekandan çıkar. */
export function isFarewell(text, phrases) {
const line = ' ' + normalizeText(text).split(/[^a-z0-9]+/).filter(Boolean).join(' ') + ' ';
return (phrases || BYE_DEFAULT).some((p) => line.includes(' ' + normalizeText(p) + ' '));
}
export class Viewers {
constructor() {
this.map = new Map();
}
get(id) {
return this.map.get(id);
}
add(user) {
const v = {
id: user.id,
name: user.name,
avatar: null,
zone: null, // normal | diva | loca | dans | leaving
spot: null,
lastActive: performance.now(),
zoneSince: performance.now(),
comments: 0,
likes: 0,
coins: 0,
};
this.map.set(user.id, v);
return v;
}
remove(id) {
this.map.delete(id);
}
all() {
return [...this.map.values()];
}
get size() {
return this.map.size;
}
}
/** Kalıcı skor tablosu (karakter mekandan çıksa bile puan kalır). */
export class Scores {
constructor() {
this.map = new Map();
}
bump(user, { comments = 0, likes = 0, coins = 0 }) {
let s = this.map.get(user.id);
if (!s) {
s = { name: user.name, comments: 0, likes: 0, coins: 0 };
this.map.set(user.id, s);
}
s.comments += comments;
s.likes += likes;
s.coins += coins;
}
top(n, freeMode) {
const score = (s) => (freeMode ? s.comments * 5 + s.likes : s.coins);
return [...this.map.values()]
.map((s) => ({ name: s.name, score: score(s) }))
.filter((s) => s.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, n);
}
clear() {
this.map.clear();
}
}
Lisans bilgisi projenin LICENSE dosyasında.