nodebb-plugin-niki-loyalty 1.5.1 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/library.js CHANGED
@@ -84,7 +84,7 @@ async function awardDailyAction(uid, actionKey) {
84
84
  const rule = ACTIONS[actionKey];
85
85
 
86
86
  if (!rule) {
87
- console.log(`[Niki-Loyalty] Bilinmeyen aksiyon: ${actionKey}`);
87
+
88
88
  return { success: false, reason: 'unknown_action' };
89
89
  }
90
90
 
@@ -92,7 +92,7 @@ async function awardDailyAction(uid, actionKey) {
92
92
  const dailyScoreKey = `niki:daily:${uid}:${today}`;
93
93
  const currentDailyScore = parseFloat((await db.getObjectField(dailyScoreKey, 'score')) || 0);
94
94
  if (currentDailyScore >= SETTINGS.dailyCap) {
95
- console.log(`[Niki-Loyalty] Günlük limit doldu. UID: ${uid}, Score: ${currentDailyScore}`);
95
+
96
96
  return { success: false, reason: 'daily_cap_reached' };
97
97
  }
98
98
 
@@ -100,7 +100,7 @@ async function awardDailyAction(uid, actionKey) {
100
100
  const actionCountKey = `niki:daily:${uid}:${today}:counts`;
101
101
  const currentActionCount = parseInt((await db.getObjectField(actionCountKey, actionKey)) || 0, 10);
102
102
  if (currentActionCount >= rule.limit) {
103
- console.log(`[Niki-Loyalty] Aksiyon limiti doldu. UID: ${uid}, Action: ${actionKey}, Count: ${currentActionCount}/${rule.limit}`);
103
+
104
104
  return { success: false, reason: 'action_limit_reached' };
105
105
  }
106
106
 
@@ -125,9 +125,7 @@ async function awardDailyAction(uid, actionKey) {
125
125
  // Logla
126
126
  await addUserLog(uid, 'earn', pointsToGive, rule.name);
127
127
 
128
- console.log(`[Niki-Loyalty] PUAN VERİLDİ! UID: ${uid}, Action: ${actionKey}, Points: +${pointsToGive}`);
129
-
130
- // ✅ Kullanıcıya Bildirim Gönder (Socket Emit) - Güçlendirilmiş
128
+ // Kullanıcıya Bildirim Gönder (Socket Emit)
131
129
  try {
132
130
  if (socketHelpers && socketHelpers.server && socketHelpers.server.sockets) {
133
131
  const newTotal = parseFloat((await user.getUserField(uid, 'niki_points')) || 0);
@@ -136,18 +134,14 @@ async function awardDailyAction(uid, actionKey) {
136
134
  message: `${rule.name} işleminden <strong style="color:#ffd700">+${pointsToGive} Puan</strong> kazandın!`,
137
135
  newTotal: newTotal
138
136
  });
139
- console.log(`[Niki-Loyalty] 📢 Socket bildirim gönderildi. UID: ${uid}`);
140
- } else {
141
- console.log(`[Niki-Loyalty] ⚠️ Socket server hazır değil, bildirim gönderilemedi.`);
142
137
  }
143
138
  } catch (socketErr) {
144
- console.error(`[Niki-Loyalty] Socket emit hatası:`, socketErr.message);
145
139
  }
146
140
 
147
141
  return { success: true, points: pointsToGive };
148
142
 
149
143
  } catch (err) {
150
- console.error(`[Niki-Loyalty] Error awarding points for ${actionKey}:`, err);
144
+
151
145
  return { success: false, reason: 'error', error: err.message };
152
146
  }
153
147
  }
@@ -185,67 +179,41 @@ Plugin.onPostCreate = async function (data) {
185
179
  // 4. BEĞENİ (Like Atma ve Alma) - Spam Korumalı + Debug Loglı
186
180
  // NodeBB upvote hook'u { pid, uid, ... } formatında data gönderir (post nesnesi değil!)
187
181
  Plugin.onUpvote = async function (data) {
188
- console.log('[Niki-Loyalty] 👍 Upvote hook tetiklendi. Raw Data:', JSON.stringify(data));
189
-
190
- // NodeBB bazen farklı formatlar gönderebilir, hepsini kontrol et
191
182
  const pid = data.pid || (data.post && data.post.pid);
192
183
  const voterUid = data.uid || (data.current && data.current.uid);
193
184
 
194
- if (!pid) {
195
- console.log('[Niki-Loyalty] ⚠️ Post PID bulunamadı, işlem iptal.');
196
- return;
197
- }
185
+ if (!pid || !voterUid) return;
198
186
 
199
- if (!voterUid) {
200
- console.log('[Niki-Loyalty] ⚠️ Voter UID bulunamadı, işlem iptal.');
201
- return;
202
- }
203
-
204
- // Post sahibini bul (NodeBB upvote hook'u post sahibini göndermez!)
205
187
  let postOwnerUid;
206
188
  try {
207
189
  postOwnerUid = await posts.getPostField(pid, 'uid');
208
- console.log(`[Niki-Loyalty] Post sahibi bulundu: PID=${pid}, Owner UID=${postOwnerUid}`);
209
190
  } catch (err) {
210
- console.log('[Niki-Loyalty] ⚠️ Post sahibi bulunamadı:', err.message);
211
- return;
212
- }
213
-
214
- if (!postOwnerUid) {
215
- console.log('[Niki-Loyalty] ⚠️ Post sahibi UID boş, işlem iptal.');
216
191
  return;
217
192
  }
193
+ if (!postOwnerUid) return;
218
194
 
219
195
  const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
220
196
 
221
- // Like Atan Kazanır:
197
+ // Like Atan Kazanır
222
198
  const likeGivenKey = `niki:liked:${voterUid}:${today}`;
223
199
  const alreadyLiked = await db.isSetMember(likeGivenKey, pid.toString());
224
200
 
225
- console.log(`[Niki-Loyalty] Like Atan: UID=${voterUid}, PID=${pid}, Daha önce beğenmiş mi=${alreadyLiked}`);
226
-
227
201
  if (!alreadyLiked) {
228
- const result = await awardDailyAction(voterUid, 'like_given');
229
- console.log('[Niki-Loyalty] like_given sonuç:', result);
202
+ await awardDailyAction(voterUid, 'like_given');
230
203
  await db.setAdd(likeGivenKey, pid.toString());
231
204
  await db.expire(likeGivenKey, 86400);
232
205
  }
233
206
 
234
- // Like Alan Kazanır (Post sahibi - kendine beğeni atamaz):
207
+ // Like Alan Kazanır (kendine beğeni atamaz)
235
208
  if (postOwnerUid && String(postOwnerUid) !== String(voterUid)) {
236
209
  const likeTakenKey = `niki:liked_taken:${postOwnerUid}:${today}`;
237
210
  const alreadyTaken = await db.isSetMember(likeTakenKey, pid.toString());
238
211
 
239
- console.log(`[Niki-Loyalty] Like Alan: UID=${postOwnerUid}, PID=${pid}, Daha önce puan almış mı=${alreadyTaken}`);
240
-
241
212
  if (!alreadyTaken) {
242
- const result = await awardDailyAction(postOwnerUid, 'like_taken');
243
- console.log('[Niki-Loyalty] like_taken sonuç:', result);
213
+ await awardDailyAction(postOwnerUid, 'like_taken');
244
214
  await db.setAdd(likeTakenKey, pid.toString());
245
215
  await db.expire(likeTakenKey, 86400);
246
216
  }
247
- } else {
248
- console.log('[Niki-Loyalty] ⚠️ Kullanıcı kendi postunu beğenmiş veya post sahibi bulunamadı. Post owner:', postOwnerUid, 'Voter:', voterUid);
249
217
  }
250
218
  };
251
219
 
@@ -264,7 +232,6 @@ Plugin.onGroupJoin = async function (data) {
264
232
  const flagKey = `niki:group_bonus:${uid}:${groupName}`;
265
233
  const alreadyClaimed = await db.get(flagKey);
266
234
  if (alreadyClaimed) {
267
- console.log(`[Niki-Loyalty] Grup bonusu zaten alınmış. UID: ${uid}, Group: ${groupName}`);
268
235
  return;
269
236
  }
270
237
 
@@ -272,8 +239,6 @@ Plugin.onGroupJoin = async function (data) {
272
239
  await db.set(flagKey, '1');
273
240
  await addUserLog(uid, 'earn', bonus, `${groupName} Grubu Katılım Bonusu 🎉`);
274
241
 
275
- console.log(`[Niki-Loyalty] ✅ GRUP BONUSU! UID: ${uid}, Group: ${groupName}, Points: +${bonus}`);
276
-
277
242
  // Socket bildirimi
278
243
  try {
279
244
  if (socketHelpers && socketHelpers.server && socketHelpers.server.sockets) {
@@ -283,10 +248,8 @@ Plugin.onGroupJoin = async function (data) {
283
248
  });
284
249
  }
285
250
  } catch (socketErr) {
286
- console.error('[Niki-Loyalty] Socket emit hatası:', socketErr.message);
287
251
  }
288
252
  } catch (err) {
289
- console.error('[Niki-Loyalty] Grup bonus hatası:', err);
290
253
  }
291
254
  };
292
255
 
@@ -485,7 +448,6 @@ Plugin.init = async function (params) {
485
448
  hasMore: enriched.length > 100
486
449
  });
487
450
  } catch (e) {
488
- console.error('[Niki-Loyalty] Kasa history error:', e);
489
451
  return res.status(500).json({ error: 'Sunucu hatası' });
490
452
  }
491
453
  });
@@ -609,13 +571,11 @@ Plugin.adminGetUsers = async function (socket, data) {
609
571
 
610
572
  // TÜM kullanıcıları al (limit yok: -1)
611
573
  const uids = await db.getSortedSetRevRange('users:joindate', 0, -1);
612
- console.log('[Niki-Admin] Çekilen UID sayısı:', uids ? uids.length : 0);
613
574
 
614
575
  if (!uids || uids.length === 0) return [];
615
576
 
616
577
  // Kullanıcı bilgilerini al
617
578
  const usersData = await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'niki_points', 'icon:bgColor']);
618
- console.log('[Niki-Admin] Kullanıcı verisi alındı:', usersData ? usersData.length : 0);
619
579
 
620
580
  // Puanları işle ve sırala (puanı yüksek olan önce)
621
581
  const result = usersData
@@ -630,10 +590,8 @@ Plugin.adminGetUsers = async function (socket, data) {
630
590
  }))
631
591
  .sort((a, b) => b.points - a.points); // Yüksekten düşüğe sırala
632
592
 
633
- console.log('[Niki-Admin] Döndürülen kullanıcı sayısı:', result.length);
634
593
  return result;
635
594
  } catch (err) {
636
- console.error('[Niki-Admin] adminGetUsers HATA:', err.message);
637
595
  throw err;
638
596
  }
639
597
  };
@@ -770,6 +728,7 @@ Plugin.adminManagePoints = async function (socket, data) {
770
728
  // Denetim Logu
771
729
  const auditLog = { ts: Date.now(), adminUid: uid, adminName: adminUserData.username, targetUid: targetUid, action: action, amount: amount, reason: reason };
772
730
  await db.listAppend('niki:audit:admin_points', JSON.stringify(auditLog));
731
+ await db.listTrim('niki:audit:admin_points', -500, -1);
773
732
 
774
733
  const newPoints = await user.getUserField(targetUid, 'niki_points');
775
734
  return { success: true, newPoints: parseFloat(newPoints) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-niki-loyalty",
3
- "version": "1.5.1",
3
+ "version": "1.5.5",
4
4
  "description": "Niki The Cat Coffee Loyalty System - Earn points while studying on IEU Forum.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -82,7 +82,6 @@ $(document).ready(function () {
82
82
  }, 300);
83
83
  }
84
84
 
85
- console.log('[Niki-Loyalty] Toast gösterildi:', message);
86
85
  }
87
86
 
88
87
  // Fonksiyonu global yap (Konsoldan test için)
@@ -105,10 +104,8 @@ $(document).ready(function () {
105
104
  if (data && typeof data.points !== 'undefined') {
106
105
  var points = Math.floor(data.points);
107
106
  $('#widget-user-points').text(points);
108
- console.log('[Niki-Loyalty] Widget puanı güncellendi:', points);
109
107
  }
110
108
  }).fail(function () {
111
- console.log('[Niki-Loyalty] Widget puanı yüklenemedi.');
112
109
  });
113
110
  }
114
111
  // Fonksiyonu global yap
@@ -147,7 +144,6 @@ $(document).ready(function () {
147
144
  if (response && response.success) {
148
145
  // Puan kazanıldı! Bildirim göster
149
146
  showNikiToast('Günlük giriş için <strong style="color:#ffd700">+' + response.earned + ' Puan</strong> kazandın! 👋');
150
- console.log('[Niki-Loyalty] Günlük giriş puanı alındı. Yeni Toplam:', response.total);
151
147
 
152
148
  // Widget'ı güncelle
153
149
  if (typeof updateSidebarWidget === 'function') {
@@ -158,7 +154,6 @@ $(document).ready(function () {
158
154
  localStorage.setItem(storageKey, today);
159
155
  }).fail(function () {
160
156
  // Hata durumunda sessizce devam et
161
- console.log('[Niki-Loyalty] Günlük giriş kontrolü başarısız.');
162
157
  });
163
158
  }
164
159
 
@@ -177,13 +172,11 @@ $(document).ready(function () {
177
172
  // ============================================================
178
173
  // Sadece 'topic' (konu) sayfasındaysak sayaç çalışsın.
179
174
  if (ajaxify.data && ajaxify.data.template && ajaxify.data.template.name === 'topic') {
180
- console.log('[Niki-Loyalty] Konu sayfası algılandı, sayaç başlatılıyor...');
181
175
 
182
176
  // 10 Dakikada bir tetikle (Günde 10 limit var backendde)
183
177
  heartbeatInterval = setInterval(function () {
184
178
  if (document.hidden) return; // Sekme aktif değilse sayma
185
179
 
186
- console.log('[Niki-Loyalty] 10dk doldu. Puan isteniyor...');
187
180
 
188
181
  $.post('/api/niki-loyalty/heartbeat', { _csrf: config.csrf_token }, function (response) {
189
182
  if (response && response.earned) {
@@ -191,11 +184,9 @@ $(document).ready(function () {
191
184
  if (typeof showNikiToast === 'function') {
192
185
  showNikiToast('Konu okuduğun için <strong style="color:#ffd700">+1 Puan</strong> kazandın! 🐈');
193
186
  }
194
- console.log('[Niki-Loyalty] Heartbeat başarılı. Yeni Puan:', response.total);
195
187
  // Widget'ı hemen güncelle
196
188
  updateSidebarWidget();
197
189
  } else {
198
- console.log('[Niki-Loyalty] Puan gelmedi (Günlük okuma limiti dolmuş olabilir).');
199
190
  }
200
191
  });
201
192
  }, 600000); // 10 Dakika = 600.000 ms
@@ -389,7 +380,6 @@ $(document).ready(function () {
389
380
  });
390
381
  });
391
382
  }).fail(function () {
392
- console.log('[Niki-Loyalty] Cüzdan verileri yüklenemedi.');
393
383
  });
394
384
  }
395
385