Changeset 2475 for lang/python

Show
Ignore:
Timestamp:
12/05/07 15:33:34 (7 years ago)
Author:
nishio
Message:

/lang/python/81kun/ ランダムに返すのをやめてハッシュ値で選ぶようにした

Location:
lang/python/81kun
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/python/81kun/actions/http.py

    r2473 r2475  
    11# -*- coding: utf-8 -*- 
    2 # http return codeをランダムに答える 
     2# http return codeを適当に答える 
    33CODES = """ 
    44100     Continue 
     
    4141""".strip().split("\n") 
    4242 
    43 def say(self, e): 
    44     from random import choice 
    45     self.say(choice(CODES)) 
     43N = len(CODES) 
     44 
     45def say(self, e, msg): 
     46    self.say(CODES[hash(msg) % N]) 
  • lang/python/81kun/rules.py

    r2473 r2475  
    77    ("81reload", actions.reload), 
    88    ("bad_words \+= (?P<words>.*)", actions.register_bad_word), 
    9     ("81http", actions.http.say), 
     9    ("81http (?P<msg>.*)", actions.http.say), 
    1010 
    1111    ("regexp /(?P<regexp>.+)/ => (?P<result>.+)",