แม่แบบ:Bots/doc

This is a template for pages to specify whether or not they want visits from any bots, most bots or specific bots.  This can be used to easily and explicitly opt-in or opt-out of unsolicited bot posts to user pages or to cause maintenance bots to avoid certain pages.  Explicitly opting-in has the advantage of possibly receiving useful changes or targeted posts that might otherwise be skipped by the bot assuming a default "opt-out" behavior.  These templates should be used mainly on the "User" and "User talk" namespaces and should be used carefully in other spaces.
Users should be aware that by opting-out of bot posts, they will not be notified of matters relating to material they have edited or uploaded, which are tagged or scanned by bots per policy. 
In particular, in the encyclopedia spaces:
*Avoid using the template as a blunt instrument
*Address the root problem with the bot owner or bot community
*Remove the template tag once the underlying problem has been resolved.

**Syntax:**
Ban all compliant bots (shortcut)
Allow all bots (shortcut)
Ban all compliant bots not in the list
Ban all compliant bots in the list
Where  is a comma-delimited string of bot usernames (AWB can be used for all AWB-based bots):


can also be "none" or "all" as in the following examples:
Allow all bots
Ban all compliant bots
Ban all compliant bots
Allow all bots
Bots are not bound to observe the nobots tag, it will depend on their functionality, their owners and their terms of approval. The bots which currently support exclusion are listed at exclusion compliant bots.

**Message notification opt out**
Another option is to opt out of specific types of messages for users who wish to be notified of certain problems, but not others. Users should be aware that by opting-out of specific notification posts, they will not be notified of matters relating to material they have edited or uploaded, which are tagged per policy. Actions (such as deletion) may be executed without you being notified as a result. By applying this to your own user talk page, you agree to this consequence. Applying this to a user talk page other than your own will be considered vandalism. All bots and scripts that leave messages on a user's talk page are encouraged to add this capability.
By adding this to a user's talk page, a user may still receive these messages by non-compliant bots or scripts, or humans who add the tag manually.
Opt out of all messages (see limitations below).
Opt out of no source messages.
Opt out of no license messages.
Opt out of orphaned fair use messages.
Opt out of no rationale messages.
Opt out of replaceable fair use messages.
Opt out of better source request messages.
Opt out of articles for deletion messages or variant forms.
Opt out of images for deletion messages or variant.
Opt out of prod warning messages or variant.
Items can be combined by putting a comma between options
Opt out of no source, and no license messages.
Opt out of fair use messages.

**Restrictions of messages that can be opted out**
Some message notifications are not allowed to be opted out. These include (but are not limited to):
#Copyright violation notifications
#Vandalism (and other) warning notices.
#Any message tag that isn't included as a way of opting out above. (Is there one that should be included? Leave a message on the talk page.)

**Notes**
List of some interwiki bots
SieBot,A4Bot,AlleborgoBot,Thijs!bot,YurikBot,Tsca.bot,Eskimbot

**Implementation**
Pywikipediabot supports bots and nobots since r4096. The templates may be ignored using a parameter.
*Since version 3.2.0.0 AutoWikiBrowser fully supports . Additionally, pseudo-username AWB can be specified to ban all AWB-based bots from the page. However, AWB has an option to ignore these templates.
*Opt out message notification was introduced here April 3, 2008. Individual bot/script implementation will vary and notice above of implementation may not include this feature.

**Example implementations**

**PHP**
function allowBots( $text ) {
global $user;
if (preg_match('/\{\{(nobots|bots\|allow=none|bots\|deny=all|bots\|optout=all|bots\|deny=.*?'.preg_quote($user,'/').'.*?)\}\}/iS',$text)) { return false; }
return true;
}

**Perl**
sub allowBots {
my($text, $user, $opt) = @_;
return 0 if $text =~ //;
return 1 if $text =~ //;
if($text =~ /\s*allow\s*=\s*(.*?)\s*/s){
return 1 if $1 eq 'all';
return 0 if $1 eq 'none';
my @bots = split(/\s*,\s*/, $1);
return (grep $_ eq $user, @bots)?1:0;
}
if($text =~ /\s*deny\s*=\s*(.*?)\s*/s){
return 0 if $1 eq 'all';
return 1 if $1 eq 'none';
my @bots = split(/\s*,\s*/, $1);
return (grep $_ eq $user, @bots)?0:1;
}
if(defined($opt) && $text =~ /\s*optout\s*=\s*(.*?)\s*/s){
return 0 if $1 eq 'all';
my @opt = split(/\s*,\s*/, $1);
return (grep $_ eq $opt, @opt)?0:1;
}
return 1;
}

**C#**
public static bool AllowBots(string text, string user)
{
return !Regex.Match(text, @"\{\{(nobots|bots\|(allow=none|deny=.*?" + user.Normalize() + @".*?|optout=all|deny=all))\}\}", RegexOptions.IgnoreCase).Success;
}

**Java**
public static boolean AllowBots(String text, String user)
{
return !Regex.Match(text, "\\{\\{(nobots|bots\\|(allow=none|deny=.*?" + user.Normalize() + ".*?|optout=all|deny=all))\\}\\}", RegexOptions.IgnoreCase).Success;
}

**Python**
def Allowbots(text, user):
if (re.search(r'\{\{(nobots|bots\|(allow=none|deny=.*?' + user + r'.*?|optout=all|deny=all))\}\}', text)):
return false
return true

**See also**
 Template:Bots at Meta.
cs:Šablona:Nobots
de:Vorlage:Bots
eo:Ŝablono:Bots
fr:Modèle:Nobots
hu:Sablon:Bots
it:Template:Bots
ja:Template:Bots
nl:sjabloon:Bots
no:Mal:Bots
pl:Szablon:Bots
ru:Шаблон:Bots
fi:Malline:Bots
zh:Template:Bots
zh-yue:Template:Bots