Files
SaveAny-Bot/en/usage/rules/index.html
2026-06-28 10:00:28 +00:00

42 lines
11 KiB
HTML

<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
Storage Rules
#
Storage rules allow you to define redirection rules when the bot uploads files to storage, so that saved files are automatically organized.
See: #28
Currently supported rule types:
FILENAME-REGEX
MESSAGE-REGEX
IS-ALBUM
Basic syntax for adding rules:
&ldquo;RuleType RuleContent StorageName Path&rdquo;
Pay attention to spaces; the bot can only parse correctly formatted syntax. Below is an example of a valid rule command:
/rule add FILENAME-REGEX (?i)\.(mp4|mkv|ts|avi|flv)$ MyAlist /videos
In addition, if CHOSEN is used as the storage name in the rule, it means files will be stored under the path of the storage you selected by clicking the inline button."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://sabot.unv.app/en/usage/rules/"><meta property="og:site_name" content="Save Any Bot"><meta property="og:title" content="Storage Rules"><meta property="og:description" content="Storage Rules # Storage rules allow you to define redirection rules when the bot uploads files to storage, so that saved files are automatically organized.
See: #28
Currently supported rule types:
FILENAME-REGEX MESSAGE-REGEX IS-ALBUM Basic syntax for adding rules:
“RuleType RuleContent StorageName Path”
Pay attention to spaces; the bot can only parse correctly formatted syntax. Below is an example of a valid rule command:
/rule add FILENAME-REGEX (?i)\.(mp4|mkv|ts|avi|flv)$ MyAlist /videos In addition, if CHOSEN is used as the storage name in the rule, it means files will be stored under the path of the storage you selected by clicking the inline button."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="usage"><meta property="article:modified_time" content="2026-06-28T18:00:02+08:00"><title>Storage Rules | Save Any Bot</title><link rel=icon href=/favicon.png><link rel=manifest href=/manifest.json><link rel=canonical href=https://sabot.unv.app/en/usage/rules/><link rel=alternate hreflang=zh href=https://sabot.unv.app/usage/rules/ title=存储规则><link rel=stylesheet href=/book.min.a22f4c7d8c2bdc5e3d6e34ba11cb59ab50ea5772594e71305bfd5a595dc78b7e.css integrity="sha256-oi9MfYwr3F49bjS6EctZq1DqV3JZTnEwW/1aWV3Hi34=" crossorigin=anonymous></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/en/><img src=/logo.png alt=Logo class=book-icon><span>Save Any Bot</span></a></h2><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
<label for=languages class=flex><a role=button class="flex flex-auto"><img src=/svg/translate.svg class=book-icon alt=Languages>
English</a></label><ul><li><a href=/usage/rules/>简体中文</a></li></ul></li></ul><ul><li><a href=https://github.com/krau/SaveAny-Bot target=_blank rel=noopener>🔗 GitHub</a></li></ul><ul><li><span>Deployment Guide</span><ul><li><a href=/en/deployment/configuration/>Configuration Guide</a><ul><li><a href=/en/deployment/configuration/storages/>Storage Configuration</a></li></ul></li><li><a href=/en/deployment/installation/>Installation and Updates</a></li></ul></li><li><a href=/en/usage/>Usage</a><ul><li><a href=/en/usage/silent/>Silent Mode</a></li><li><a href=/en/usage/rules/ class=active>Storage Rules</a></li><li><a href=/en/usage/watch/>Watch Chats</a></li><li><a href=/en/usage/directlinks/>Direct Download Links</a></li><li><a href=/en/usage/aria2/>Aria2 Download</a></li><li><a href=/en/usage/ytdlp/>yt-dlp Video Download</a></li><li><a href=/en/usage/transfer/>Storage Transfer</a></li><li><a href=/en/usage/parsers/>Save Files Outside Telegram</a></li><li><a href=/en/usage/config/>File Naming & Conflict Strategies</a></li><li><a href=/en/usage/api/>HTTP API</a></li><li><a href=/en/usage/cli/>CLI Subcommands</a></li></ul></li><li><a href=/en/help/>Frequently Asked Questions</a><ul></ul></li><li><a href=/en/contribute/>Contributing</a><ul></ul></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/svg/menu.svg class=book-icon alt=Menu></label><h3>Storage Rules</h3><label for=toc-control><img src=/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#preset-rules>Preset Rules</a></li><li><a href=#filename-regex>FILENAME-REGEX</a></li><li><a href=#message-regex>MESSAGE-REGEX</a></li><li><a href=#is-album>IS-ALBUM</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=storage-rules>Storage Rules
<a class=anchor href=#storage-rules>#</a></h1><p>Storage rules allow you to define redirection rules when the bot uploads files to storage, so that saved files are automatically organized.</p><p>See: <a href=https://github.com/krau/SaveAny-Bot/issues/28 target=_blank>#28</a></p><p>Currently supported rule types:</p><ol><li>FILENAME-REGEX</li><li>MESSAGE-REGEX</li><li>IS-ALBUM</li></ol><p>Basic syntax for adding rules:</p><p>&ldquo;RuleType RuleContent StorageName Path&rdquo;</p><p>Pay attention to spaces; the bot can only parse correctly formatted syntax. Below is an example of a valid rule command:</p><pre tabindex=0><code>/rule add FILENAME-REGEX (?i)\.(mp4|mkv|ts|avi|flv)$ MyAlist /videos
</code></pre><p>In addition, if <code>CHOSEN</code> is used as the storage name in the rule, it means files will be stored under the path of the storage you selected by clicking the inline button.</p><p>You can also toggle whether rules are applied with <code>/rule switch</code>. When rule mode is off, all files go to the default storage.</p><h2 id=preset-rules>Preset Rules
<a class=anchor href=#preset-rules>#</a></h2><p>Manually writing regex rules for common file types is tedious, so the bot ships a built-in set of preset categories (video, image, audio, document, archive) that you can import in one command:</p><pre tabindex=0><code>/rule preset &lt;storage&gt; [base_path]
</code></pre><p>Parameters:</p><ul><li><code>storage</code>: Target storage name (must exist and be accessible to you)</li><li><code>base_path</code>: Optional. Each preset category&rsquo;s subdirectory is created under this path. If omitted, the default category directory names are used directly.</li></ul><p>Examples:</p><pre tabindex=0><code># Import preset rules into &#34;MyAlist&#34; with the default directory layout
/rule preset MyAlist
# Import preset rules with a custom base path &#34;downloads/sorted&#34;
/rule preset MyAlist downloads/sorted
</code></pre><p>This will create <code>FILENAME-REGEX</code> rules for each category, routing matched files to the corresponding subdirectory under <code>base_path</code>:</p><table><thead><tr><th>Category</th><th>Matched extensions</th><th>Default directory</th></tr></thead><tbody><tr><td>video</td><td>mp4, mkv, ts, avi, flv, mov, webm, wmv, rmvb, m2ts</td><td><code>视频</code></td></tr><tr><td>image</td><td>jpg, jpeg, png, gif, webp, bmp</td><td><code>图片</code></td></tr><tr><td>audio</td><td>mp3, flac, wav, aac, m4a, ogg</td><td><code>音频</code></td></tr><tr><td>document</td><td>pdf, doc, docx, xls, xlsx, ppt, pptx, txt, md, csv, epub, mobi, azw3, chm</td><td><code>文档</code></td></tr><tr><td>archive</td><td>zip, rar, 7z, tar, gz, bz2, xz, &mldr;</td><td><code>压缩包</code></td></tr></tbody></table><blockquote class="book-hint info">Preset rules are regular `FILENAME-REGEX` rules once imported. You can view, edit, or delete them individually with `/rule` and `/rule del <id>` like any other rule.</blockquote><p>Rule types:</p><h2 id=filename-regex>FILENAME-REGEX
<a class=anchor href=#filename-regex>#</a></h2><p>Matches based on filename regex. The rule content must be a valid regular expression, such as:</p><pre tabindex=0><code>FILENAME-REGEX (?i)\.(mp4|mkv|ts|avi|flv)$ MyAlist /videos
</code></pre><p>This means files with extensions mp4, mkv, ts, avi, flv will be saved to the <code>/videos</code> directory in the storage named <code>MyAlist</code> (also affected by the <code>base_path</code> in the configuration file).</p><h2 id=message-regex>MESSAGE-REGEX
<a class=anchor href=#message-regex>#</a></h2><p>Similar to the above, but matches based on the text content of the message itself.</p><h2 id=is-album>IS-ALBUM
<a class=anchor href=#is-album>#</a></h2><p>Matches album messages (media groups). Rule content can only be <code>true</code> or <code>false</code>.</p><p>If the path in the rule uses <code>NEW-FOR-ALBUM</code>, the bot will create a new folder for each media group and store all files of that group there. See: <a href=https://github.com/krau/SaveAny-Bot/issues/87>https://github.com/krau/SaveAny-Bot/issues/87</a></p><p>For example:</p><pre tabindex=0><code>IS-ALBUM true MyWebdav NEW-FOR-ALBUM
</code></pre><p>This will save media-group messages to the storage named <code>MyWebdav</code>, creating a new folder (generated from the first file) for each album.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"><div><a class="flex align-center" href=https://github.com/krau/saveany-bot/commit/c9bb6c9e3c325c83ffef5bbe4fa54a58b82de2df title='Last modified by krau | 2026/06/28' target=_blank rel=noopener><img src=/svg/calendar.svg class=book-icon alt>
<span>2026/06/28</span></a></div><div><a class="flex align-center" href=https://github.com/krau/saveany-bot/edit/main/docs/content/en/usage/rules.md target=_blank rel=noopener><img src=/svg/edit.svg class=book-icon alt>
<span>Edit this page</span></a></div></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><div class=book-comments></div><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#preset-rules>Preset Rules</a></li><li><a href=#filename-regex>FILENAME-REGEX</a></li><li><a href=#message-regex>MESSAGE-REGEX</a></li><li><a href=#is-album>IS-ALBUM</a></li></ul></nav></div></aside></main></body></html>