跳转到内容

User:Welcomebot/code

维基百科,自由的百科全书

这是本页的一个历史版本,由Shizhao留言 | 贡献2007年10月1日 (一) 13:38 新頁面,內容: <code lang="python"> #!/usr/bin/python # -*- coding: utf-8 -*- """ ATTENTION! THIS SCRIPT *REQUIRES* PYTHON 2.5 Script to welcome new users. This script works ...)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-

"""

ATTENTION! THIS SCRIPT *REQUIRES* PYTHON 2.5

Script to welcome new users. This script works out of the box for Wikis that have been defined in the script. It is currently used on the Dutch, Norwegian, Arabian, Albanian, Italian Wikipedia, Wikimedia Commons and English Wikiquote.

Note: You can download the latest version available from here: http://botwiki.sno.cc/wiki/Python:Welcome.py

Ensure you have community support before running this bot!

URLs to current implementations:

Everything that needs customisation to support additional projects is indicated by comments.

Description of basic functionality:

  • Request a list of new users every period (default: 3600 seconds)
 You can choose to break the script after the first check (see arguments)
  • Check if new user has passed a threshold for a number of edits
 (default: 1 edit)
  • Optional: check username for bad words in the username or if the username
 consists solely of numbers; log this somewhere on the wiki (default: False)
 Update: Added a whitelist (explanation below).
  • If user has made enough edits (it can be also 0), check if user has an empty
 talk page
  • If user has an empty talk page, add a welcome message.
  • Optional: Once the set number of users have been welcomed, add this to the
 configured log page, one for each day (default: True)
  • If no log page exists, create a header for the log page first.

This script (by default not yet implemented) uses two templates that need to be on the local wiki:

  • |--

|[[User:{{{user}}}|{{{user}}}]] ( [[User talk:{{{user}}}|留言]] | [[Special:Contributions/{{{user}}}|贡献]] | 画廊 | PFC画廊 ) || {{{contribs}}}: contains mark up code for log entries (just copy it from Commons)

  • == 欢迎加入维基百科! ==

您好,Welcomebot!
感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡,也請您了解以下重要文章:

有疑问?需要帮助?欢迎到互助客棧IRC频道詢問。
祝您编辑愉快!

Welcome! If you can't understand Chinese, please feel free to ask or request anything here. Thank you for visiting!

歡迎您的維基人是:~~~~: contains the information for new users

This script understands the following command-line arguments:

   -edit[:#]      Define how many edits a new user needs to be welcomed
                  (default: 1)
   -time[:#]      Define how many seconds the bot sleeps before restart
                  (default: 3600)
   -break         Use it if you don't want that the Bot restart at the end
                  (it will break) (default: False)
   -nlog          Use this parameter if you do not want the bot to log all
                  welcomed users (default: False)
   -limit[:#]     Use this parameter to define how may users should be
                  checked (default:50)
   -offset[:#]    Skip the latest # new users to give interactive users
                  a chance to welcome the new user (default: 0)
   -numberlog[:#] The number of users to welcome before refreshing the
                  welcome log (default: 4)
   -filter        Enable the username checks for bad names (default: False)
   -ask           Use this parameter if you want to confirm each possible
                  bad username (default: False)
   -random        Use a random signature, taking the signatures from a wiki
                  page (for istruction, see below).
   -file[:#]      Use a file instead of a wikipage to take the random sign.
                  N.B. If you use this parameter, you don't need to use -random.
   -savedata      This feature saves the random signature index to allow to
                  continue to welcome with the last signature used.
                                                                  • GUIDE ***********************************

Report, Bad and white list guide:

1) Set in the code which page it will use to load the badword, the

   whitelist and the report

2) In these page you have to add a "tuple" with the names that you want to

   add in the two list. For example: ('cat', 'mouse', 'dog')
   You can write also other text in the page, it will work without problem.

3) What will do the two pages? Well, the Bot will check if a badword is in

   the username and set the "warning" as True. Then the Bot check if a word
   of the whitelist is in the username. If yes it remove the word and
   recheck in the bad word list to see if there are other badword in the
   username.
   Example:
       * dio is a badword
       * Claudio is a normal name
       * The username is "Claudio90 fuck!"
       * The Bot find dio and set "warning"
       * The Bot find Claudio and set "ok"
       * The Bot find fuck at the end and set "warning"
       * Result: The username is reported.

4) When a user is reported you have to check him and do:

       * If he's ok, put the == 欢迎加入维基百科! ==

您好,Welcomebot!
感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡,也請您了解以下重要文章:

有疑问?需要帮助?欢迎到互助客棧IRC频道詢問。
祝您编辑愉快!

Welcome! If you can't understand Chinese, please feel free to ask or request anything here. Thank you for visiting!

歡迎您的維基人是:~~~~

       * If he's not, block him
       * You can decide to put a "you are blocked, change another username"
         template or not.
       * Delete the username from the page.
       IMPORTANT : The Bot check the user in this order:
           * Search if he has a talkpage (if yes, skip)
           * Search if he's blocked, if yes he will be skipped
           * Search if he's in the report page, if yes he will be skipped
           * If no, he will be reported.

Random signature guide:

Some welcomed users will answer to the one who has signed the welcome message. When you welcome many new users, you might be overwhelmed with such answers. Therefore you can define usernames of other users who are willing to receive some of these messages from newbies.

1) Set the page that the bot will load 2) Add the signatures in this way:

  • <SPACE>SIGNATURE

<NEW LINE>

Example:

* [[User:Filnik|Filnik]]
* [[User:Rock|Rock]]

NOTE: The white space and

aren't required but I suggest you to

     use them.
                                                      • Known issues/FIXMEs ****************************
  • use default pages if a wiki is not configured, so no configuration of
 the script would be required at all. Suggestion: use English language
 defaults.
  • The regex to load the user might be slightly different from project to project.
 (in this case, write to Filnik for help...)
  • Understand if it's the case to use a class to group toghether the functions used.
                                                                • Badwords ***********************************

The list of Badwords of the code is opened. If you think that a word is international and it must be blocked in all the projects feel free to add it. If also you think that a word isn't so international, feel free to delete it.

However, there is a dinamic-wikipage to load that badwords of your project or you can add them directly in the source code that you are using without adding or deleting.

Some words, like "Administrator" or "Dio" (God in italian) or "Jimbo" aren't badword at all but can be used to some bad-nickname. """

  1. (C) Alfio, 2005
  2. (C) Kyle/Orgullomoore, 2006-2007
  3. (C) Siebrand Mazeland, 2006-2007
  4. (C) Filnik, 2007
  5. (C) Daniel Herding, 2007
  6. Distributed under the terms of the MIT license.

__version__ = '$Id: welcome.py,v 1.4 2007/04/14 18:05:42 siebrand Exp$'

import wikipedia, config, string, locale import time, re, cPickle, os, urllib import codecs

locale.setlocale(locale.LC_ALL, )

  1. Script users the class wikipedia.translate() to find the right
  2. page/user/summary/etc so the need to specify language and project have
  3. been eliminated.
  4. FIXME: Not all language/project combinations have been defined yet.
  5. Add the following strings to customise for a language:
  6. logbook, talk_page, summary, netext, summary2, user, con, report_page
  7. comment, bad_pag, report_text, logt, random_sign and whitelist_pg.
  1. The text below are dictionaries. Copy the 'en' line, change 'en' in your
  2. language (e.g. 'de') and modify/translate the text.
  1. The page where the bot will save the log (e.g. Wikipedia:Welcome log).

logbook = {

   'commons': u'Project:Welcome log',
   'ar': u'Project:سجل الترحيب',
   'de': None, # no welcome log on de.wiki
   'en': u'Project:Welcome log',
   'fa': u'Project:سیاهه خوشامد',
   'it': u'Project:Benvenuto log',
   'nl': u'Project:Logboek welkom',
   'no': u'Project:Velkomstlogg',
   'sq': u'Project:Tung log',

'zh': u'user:Welcomebot/欢迎日志',

   }
  1. The edit summary for the welcome message (e.g. Welcome!).

summary = {

   'commons':u'Welcome!',
   'ar':u'مرحبا!',
   'de':u'Herzlich willkommen!',
   'en':u'Welcome!',
   'fa':u'خوش آمدید!',
   'it':u'Benvenuto!',
   'nl':u'Welkom!',
   'no':u'Velkommen!',
   'sq':u'Tung',

'zh':u'欢迎!',

   }
  1. The text for the welcome message (e.g. == 欢迎加入维基百科! ==

您好,Welcomebot!
感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡,也請您了解以下重要文章:

有疑问?需要帮助?欢迎到互助客棧IRC频道詢問。
祝您编辑愉快!

Welcome! If you can't understand Chinese, please feel free to ask or request anything here. Thank you for visiting!

歡迎您的維基人是:~~~~) and %s at the end

  1. that is your signature (the bot has a random parameter to add different
  2. sign, so in this way it will change according to your parameters).

netext = {

   'commons':u'
您好,Welcomebot!欢迎加入维基百科!

感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡。除了歡迎辭外,也請您了解以下重要文章:

政策
政策
GNU
GNU
版權問題解答
貢獻內容必须是您所著或獲得授權、同意在GFDL條款下發布
手冊
手冊
問號
問號
有问题?請到互助客栈询问,或在我的对话页提出。別忘記:討論後要簽名,可使用編輯工具條上的Signature icon.png按鈕。
If you have any questions about the Chinese Wikipedia, please leave a message here. Thank you for visiting!

希望您能享受编写人類共有之自由百科的快乐,成为一名快樂的维基百科人我是欢迎您的维基百科人:百無一用是書生 () 2007年10月1日 (一) 13:38 (UTC) %s',

   'ar':u'Template:نسخ:مستخدم:Alnokta/ترحيب %s',
   'de':u'{{subst:Hallo}} %s',
   'en':u'
您好,Welcomebot!欢迎加入维基百科!

感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡。除了歡迎辭外,也請您了解以下重要文章:

政策
政策
GNU
GNU
版權問題解答
貢獻內容必须是您所著或獲得授權、同意在GFDL條款下發布
手冊
手冊
問號
問號
有问题?請到互助客栈询问,或在我的对话页提出。別忘記:討論後要簽名,可使用編輯工具條上的Signature icon.png按鈕。
If you have any questions about the Chinese Wikipedia, please leave a message here. Thank you for visiting!

希望您能享受编写人類共有之自由百科的快乐,成为一名快樂的维基百科人我是欢迎您的维基百科人:百無一用是書生 () 2007年10月1日 (一) 13:38 (UTC) %s',

   'fa':u'Template:جا:خوشامد %s',
   'it':u'Template:Benvebot %s',
   'nl':u'Template:Welkomstbericht %s',
   'no':u'{{subst:bruker:jhs/vk}} %s',
   'sq':u'{{subst:tung}} %s',

'zh':u'

您好,Welcomebot!欢迎加入维基百科!

感謝您對維基百科的興趣與貢獻,希望您會喜歡這裡。除了歡迎辭外,也請您了解以下重要文章:

政策
政策
GNU
GNU
版權問題解答
貢獻內容必须是您所著或獲得授權、同意在GFDL條款下發布
手冊
手冊
問號
問號
有问题?請到互助客栈询问,或在我的对话页提出。別忘記:討論後要簽名,可使用編輯工具條上的Signature icon.png按鈕。
If you have any questions about the Chinese Wikipedia, please leave a message here. Thank you for visiting!

希望您能享受编写人類共有之自由百科的快乐,成为一名快樂的维基百科人我是欢迎您的维基百科人:百無一用是書生 () 2007年10月1日 (一) 13:38 (UTC) %s',

   }
  1. The edit summary for updating the welcome log (e.g. Updating log).

summary2 = {

   'commons':u'Updating log',
   'ar':u'تحديث السجل',
   'de':u'Aktualisiere Logdatei',
   'en':u'Updating log',
   'fa':u'به روز رسانی سیاهه',
   'it':u'Aggiorno il log',
   'nl':u'Logboek bijwerken',
   'no':u'Oppdaterer logg',
   'sq':u'Rifreskoj log',

'zh':u'更新日志',

   }
  1. The page where the bot will report users with a possibly bad username.

report_page = {

   'commons': u'Project:Administrators\' noticeboard/User problems/Usernames to be checked',
   'ar': 'Project:إخطار الإداريين/أسماء مستخدمين للفحص',
   'de': u'Benutzer:Filnik/Report',
   'en': u'Project:Administrator intervention against vandalism',
   'fa': u'Project:تابلوی اعلانات مدیران/گزارش ربات',
   'it': u'Utente:Filbot/Report',
   'nl': u'Project:Verzoekpagina voor moderatoren/RegBlok/Te controleren gebruikersnamen',
   'no': u'Bruker:JhsBot II/Rapport',
   'sq': u'User:EagleBot/Report',
   }
  1. The edit summary for reporting a possibly bad username.

comment = {

   'commons':u'Adding a username that needs to be checked',
   'ar':u'إضافة اسم مستخدم يحتاج للفحص',
   'de':u'Ergänze zu überprüfenden Benutzernamen',
   'en':u'Adding a username that needs to be checked',
   'fa':u'افزودن حساب کاربری نیازمند بررسی',
   'it':u'Aggiunto utente da controllare',
   'nl':u'Te controleren gebruikersnaam toegevoegd',
   'no':u'Legger til et brukernavn som m? sjekkes',
   'sq':u'Added username to be checked',
   }
  1. The page where the bot reads the real-time bad words page
  2. (this parameter is optional).

bad_pag = {

   'commons': u'Project:Welcome log/Bad_names',
   'ar': u'Project:سجل الترحيب/أسماء سيئة',
   'en': u'Project:Welcome log/Bad_names',
   'fa': u'Project:سیاهه خوشامد/نام بد',
   'it': u'Utente:Filbot/Bad_words',
   'nl': u'Project:Logboek_welkom/Bad_names',
   'no': u'Bruker:JhsBot/Daarlige ord',
   'sq': u'User:Eagleal/Bad_names',
   }
  1. The text for reporting a possibly bad username (e.g. *Username).

timeselected = u' 13:38, 1 10月 2007 (UTC).' report_text = {

   'commons':u"\n*%s (討論 · 貢獻 · 日誌)" + timeselected,
   'ar':u"\n*Template:User13" + timeselected,
   'de':u'\n*Benutzer Diskussion:%s ' + timeselected,
   'en':u'\n*%s 討論 · 貢獻 · 刪除貢獻 · 日誌 · 過濾器日誌 · 封禁 · 封禁日誌 ' + timeselected,
   'fa':u'\n*Template:کاربر' + timeselected,
   'it':u"\nTemplate:Reported'
                       break
                   else:
                       final_rep = rep_text
           # Checking in the whitelist...
           for xy in whitelist:
               if xy.lower() in username.lower():
                   username.replace(xy, )
                   for word in elenco:
                       if word.lower() in username.lower():
                           baduser = True
                       else:
                           baduser = False
           # He has a badusername, trying to report him...
           if baduser == True:
               while 1:
                   if ask == True:
                       wikipedia.output(u'%s may have an unwanted username, what shall i do?' % username )
                       answer = wikipedia.input(u'[B]lock or [W]elcome?')
                       for w in block:
                           if w in answer:
                               if not usertalkpage.exists():
                                   # Check if the user has been already blocked (second check).
                                   ki = blocked(wsite, username)
                                   if ki == True:
                                       wikipedia.output(u'%s has been blocked! Skipping him...' % username)
                                       continue
                                   report(wsite, rep_page, username, com, final_rep)
                                   break
                               else:
                                   wikipedia.output(u'The discussion page of the bad-user already exist...')
                                   running = False
                       for w in say_hi:
                           if w in answer:
                               baduser = False
                               break
                   elif ask == False:
                       wikipedia.output(u'%s is possibly an unwanted username. He will be reported.' % username)
                       if not usertalkpage.exists():
                           report(wsite, rep_page, username, com, final_rep)
                           break
                       else:
                           wikipedia.output(u'The discussion page of the bad-user already exist...')
                           break
           # He has a good username, welcome!
           elif baduser == False:
               if not usertalkpage.exists():
                   # Tring to put the welcome...
                   try:
                       # make non-minor edit to trigger new talk page message.
                       usertalkpage.put(welcom, summ, minorEdit = False)
                       welcomed_users.append(found_result)
                       if random == True:
                           number_user += 1
                           yield number_user
                   except wikipedia.EditConflict:
                       wikipedia.output(u'An edit conflict has occured, skipping this user.')
                       continue
               else:
                   wikipedia.output(u'%s has been already welcomed when i was loading all the users... skipping' % username)
                   continue
           # That's the log
           if log_variable == True and logg:
               if len(welcomed_users) == 1:
                   wikipedia.output(u'One user has been welcomed.')
               elif len(welcomed_users) == 0:
                   wikipedia.output(u'No users have been welcomed.')
               else:
                   wikipedia.output(u'%s users have been welcomed.' % str(len(welcomed_users)) )
               if len(welcomed_users) < numberlog:
                   continue
               # Update the welcome log each fifth welcome message.
               elif len(welcomed_users) >= numberlog:
                   logresult = logmaker(wsite, welcomed_users, logg, summ2, usernam, contrib)
                   welcomed_users = list()
                   if logresult == False:
                       continue
           # If we haven't to report, do nothing.
           elif log_variable == False:
               pass
       if log_variable == True and logg and len(welcomed_users) != 0:
           if len(welcomed_users) == 1:
               wikipedia.output(u'Putting the log of the latest user...')
           else:
               wikipedia.output(u'Putting the log of the latest %d users...' % len(welcomed_users))
           logresult2 = logmaker(wsite, welcomed_users, logg, summ2, usernam, contrib)
           welcomed_users = list()
           if logresult2 == False:
               continue
       # If recursive, don't exit, repeat after one hour.
       if recursive == True:
           waitstr = unicode(time_variable)
           if locale.getlocale()[1]:
               strfstr = unicode(time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime()), locale.getlocale()[1])
           else:
               strfstr = unicode(time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime()))
           wikipedia.output(u'Sleeping %s seconds before rerun. %s' % (waitstr, strfstr))
           time.sleep(time_variable)
       # If not recursive, break.
       elif recursive == False:
           yield [number_user, 'STOP']

if __name__ == "__main__":

   # Use try and finally, to put the wikipedia.stopme() always at the end of the code.
   try:
       number_user = None
       settingsBot = mainSettings()
       # Take two settings for the "finally" block.
       filename = settingsBot[2]
       random = settingsBot[11]
       savedata = settingsBot[13]
       # I need to know what is the number_user, in this way I get it.
       for x in main(settingsBot):
           try:
               number_user = x[0]
           except TypeError:
               number_user = x
           else:
               break
   except wikipedia.BadTitle:
       wikipedia.output(u"Wikidown or server's problem. Quit.")
       wikipedia.stopme()
   # finally:
       # If there is the savedata, the script must save the number_user.
       if random == True and savedata == True and number_user != None:
           f = file(filename, 'w')
           cPickle.dump(number_user, f)
           f.close()
       wikipedia.stopme()