Skip to content

Commit 5904a6e

Browse files
committed
feat(discord): add configuration for internal Discord token management and enhance date handling in exports
1 parent 56c4f9c commit 5904a6e

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

config/test_settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@
108108

109109
# Tests patch a single subprocess.Popen for DiscordChatExporter.
110110
DISCORD_CHAT_EXPORTER_SEQUENTIAL_EXPORT = False
111+
112+
# Tests set DISCORD_USER_TOKEN via monkeypatch; do not inherit internal-token mode
113+
# from developer .env (get_or_load_discord_user_token would ignore env token).
114+
ALLOW_INTERNAL_DISCORD_TOKENS = False
115+
DISCORD_USER_TOKEN = ""

discord_activity_tracker/management/commands/run_discord_activity_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def task_discord_sync(
223223
user_token=user_token,
224224
guild_id=guild_id,
225225
output_dir=staging,
226-
after_date=after_date,
226+
after_date=after_date if not per_channel_incremental else None,
227227
before_date=before_date,
228228
channel_ids=channel_ids or None,
229229
per_channel_incremental=per_channel_incremental,

discord_activity_tracker/sync/chat_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def _export_guild_by_channel_day(
549549
"--channels filter, token access, or INCLUDE_VC if you need voice channels)."
550550
)
551551

552-
explicit_after = after_date if not per_channel_incremental else None
552+
explicit_after = after_date
553553
results: List[ChannelDayExport] = []
554554
for ch_id in ids:
555555
ch_after = resolve_channel_export_after(

discord_activity_tracker/sync/exporter_window.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ def iter_channel_export_days(
9999
else:
100100
now = now.astimezone(timezone.utc)
101101

102-
upper = before.astimezone(timezone.utc) if before is not None else now
102+
upper = now
103+
if before is not None:
104+
upper = (
105+
before.astimezone(timezone.utc)
106+
if before.tzinfo is not None
107+
else before.replace(tzinfo=timezone.utc)
108+
)
103109

104110
if after is None:
105111
first_day = utc_day_start(now)

discord_activity_tracker/tests/test_exporter_window.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ def test_resolve_channel_export_after_honors_explicit_since():
195195
assert resolve_channel_export_after(1, 2, explicit_after=explicit) == explicit
196196

197197

198+
def test_iter_channel_export_days_naive_before_treated_as_utc():
199+
after = datetime(2026, 6, 1, 10, 0, 0, tzinfo=timezone.utc)
200+
before_naive = datetime(2026, 6, 3, 8, 0, 0)
201+
before_aware = datetime(2026, 6, 3, 8, 0, 0, tzinfo=timezone.utc)
202+
naive_days = iter_channel_export_days(
203+
after=after, before=before_naive, now=before_aware
204+
)
205+
aware_days = iter_channel_export_days(
206+
after=after, before=before_aware, now=before_aware
207+
)
208+
assert naive_days == aware_days
209+
assert [d[0] for d in naive_days] == ["2026-06-01", "2026-06-02", "2026-06-03"]
210+
211+
198212
def test_iter_channel_export_days_clips_partial_last_day():
199213
after = datetime(2026, 6, 2, 22, 0, 0, tzinfo=timezone.utc)
200214
now = datetime(2026, 6, 2, 23, 30, 0, tzinfo=timezone.utc)

0 commit comments

Comments
 (0)