Skip to content

ptsgrn/patsabot

This branch is up to date with main.

Folders and files

NameName
Last commit message
Last commit date
Apr 14, 2023
Jan 2, 2025
Mar 14, 2024
Jan 22, 2025
Mar 25, 2024
Jan 22, 2025
Jan 2, 2025
Jan 8, 2025
Mar 25, 2024
Jan 8, 2025
Apr 12, 2023
Apr 12, 2023
Jan 6, 2022
Jan 22, 2025
Mar 5, 2025
Jan 8, 2025
Mar 5, 2025
Jan 6, 2025

Repository files navigation

PatsaBot

Bot flags status

ผู้ใช้:PatsaBot (คุย | ส่วนร่วม)

A Wikipedia bot operated by Patsagorn Y..

Status

task description status previous/next
#1 สร้างหน้าหมวดหมู่สำหรับ AfC แบบรายวัน afccat afccat last run
afccat next run

Setup

Prerequisites

  • bun for running the bot
mv example.toml config.toml
bun i

Edit config.toml to add your bot credentials and other configurations. Then try running the bot with bun . run login to see if it works.

Bot logs

ไฟล์ log ของบอตถูกจัดการโดย สามารถเข้าถึงได้ที่ https://tools-static.wmflabs.org/patsabot/logs/ ความหมายแต่ละไฟล์คือดังนี้

error.jsonl                - ถ้ามี error ที่ไม่ร้ายแรงมากจะถูกบันทึกไว้ที่นี่
exceptions.jsonl           - ถ้ามี error ที่ร้ายแรงจะถูกบันทึกไว้ที่นี่
rejections.jsonl           - Unhandled rejections จะถูกบันทึกไว้ที่นี่
output-20250108.jsonl.gz   - ไฟล์ log ของการทำงานในวันที่ 8 มกราคม 2025 ถูกบีบอัดด้วย gzip (เพราะไม่ใช่ไฟล์ปัจจุบัน)
output-20250109.jsonl      - ไฟล์ log ของการทำงานในวันที่ 9 มกราคม 2025 (ไฟล์ปัจจุบันไม่ถูกบีบอัด)

(ให้วันนี้เป็นวันที่ 9 มกราคม 2025)

อ่านและค้นหา Logs

ไฟล์ log เป็นไฟล์ jsonlines ซึ่งสามารถใช้คำสั่ง jq ในการค้นหาข้อมูลได้ง่าย ๆ โดยแต่ละบรรทัดประกอบด้วยข้อมูลคคร่าว ๆ ดังนี้:

{
  // ระดับของข้อความ (error, warn, info, debug)
  "level":"info",
  // ข้อความ
  "message":"Scheduled afccat (@daily)",
  // รหัสการรัน (อ่านเพิ่มด้านล่าง)
  "rid":"uhpbka4gq77s7gflxmewqtrc",
  // ชื่อของ script ที่ทำงาน
  "script":"afccat",
  // เวลาที่เกิดเหตุการณ์
  "timestamp":"2025-01-08T16:19:50.013Z"
}

คำอธิบายเพิ่มเติม:

  • rid เป็นรหัสการรันเฉพาะแต่ละครั้ง เช่นสคริปต์ afccat รันวันนี้อาจเป็นรหัสนี้ แต่หากรันใหม่อีกครั้งจะเป็นรหัสอื่น แต่การันตีว่ารหัสเดียวกันจะมีที่มาจากสคริปต์เดียวกัน
  • script คือชื่อของสคริปต์ที่ทำงาน สามารถใช้ bun . run <script name> และใช้ค่าจากฟิลด์นี้ได้

ใช้ jq และ gunzip ในการค้นหาข้อมูลในไฟล์ log ได้ดังนี้

$ curl https://tools-static.wmflabs.org/patsabot/logs/output-20250109.jsonl | jq '"\\(.timestamp) \\(.rid) \\(.level): \\(.message)"'
# Outputs:
# > "2025-01-08T17:00:00.954Z oud5v38ftzotx5j0tzww4e6e info: done"
# > "2025-01-08T17:01:45.670Z m45s34rgfg890p1id86x75mk info: Scheduled update-status (@daily)"

กรณีที่ไฟล์ log ถูกบีบอัดด้วย gzip ให้ใช้ gunzip ก่อนจึงจะใช้ jq ได้

$ curl https://tools-static.wmflabs.org/patsabot/logs/output-20250108.jsonl.gz | gunzip | jq '"\\(.timestamp) \\(.rid) \\(.level): \\(.message)"'
# Outputs:
# > "2025-01-08T16:19:50.013Z uhpbka4gq77s7gflxmewqtrc info: Scheduled afccat (@daily)"
# > "2025-01-08T16:19:50.204Z s7d32ito7amy68e35obscljh info: Scheduled linked-user-ns0 (@weekly)"

สำหรับดูเฉพาะ log ที่มี rid = oud5v38ftzotx5j0tzww4e6e

curl https://tools-static.wmflabs.org/patsabot/logs/output-20250109.jsonl | jq 'select(.rid == "oud5v38ftzotx5j0tzww4e6e") | "\\(.timestamp) \\(.rid) \\(.level): \\(.message)"'
# Outputs:
# > "2025-01-08T17:00:00.265Z oud5v38ftzotx5j0tzww4e6e info: Creating categories for categories [\"หมวดหมู่:ฉบับร่างเรียงตามวันที่ส่ง/09 มกราคม 2025\",\"หมวดหมู่:ฉบับร่างเรียงตามวันที่ส่ง/มกราคม 2025\",\"หมวดหมู่:ฉบับร่างเรียงตามวันที่ส่ง/2025\"]"
# > "2025-01-08T17:00:00.416Z oud5v38ftzotx5j0tzww4e6e error: articleexists: The page you tried to create has been created already. หมวดหมู่:ฉบับร่างเรียงตามวันที่ส่ง/มกราคม 2025"
curl https://tools-static.wmflabs.org/patsabot/logs/output-20250108.jsonl.gz | gunzip | jq 'select(.rid == "oud5v38ftzotx5j0tzww4e6e") | "\\(.timestamp) \\(.rid) \\(.level): \\(.message)"'
# Outputs:
# > "2025-01-08T16:48:32.323Z oud5v38ftzotx5j0tzww4e6e info: Scheduled linked-email-ns0 (@weekly)"

Deploy

ssh toolforge -t "become patsabot -- git -C www/js/ pull"
ssh toolforge -t "become patsabot -- toolforge webservice node18 restart"