Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/isida/4.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiSabler <dissy@ya.ru>2014-05-04 19:12:36 +0400
committerdiSabler <dissy@ya.ru>2014-05-04 19:12:36 +0400
commit7d0791fc886223762accf20b3fff69af936faa83 (patch)
treefa1a8a57ea2b55edf20020654bd6edd23a2e8324
parentb63c2f9cc40307360cfa5cdc7e46a8aec9d634ca (diff)
add: command `drink` in AI
-rw-r--r--data/ai/ru.txt1
-rw-r--r--plugins/ai.py60
-rw-r--r--plugins/drink.py48
3 files changed, 71 insertions, 38 deletions
diff --git a/data/ai/ru.txt b/data/ai/ru.txt
index eb5e406..edaaec4 100644
--- a/data/ai/ru.txt
+++ b/data/ai/ru.txt
@@ -31,5 +31,6 @@ uptime {PAR} ?|сколько|работает|аптайм|какой||мой|
anek ?|анекд|расска
calend ?|праздник|какой|что|сегодня
calend {TOMORROW} ?|праздник|какой|что|завтра
+!ai_drink {RAW} ?|повод|выпить|бухать|за|бухнуть|наибенит|наибенет|наибенец|наибениц|когда|какой|пиво|пива|водка|водки|водяра|вино
oboobs сиськи|сиську|титьки|титьку|покажи|покаж
obutts попу|попку|зад|жопу|покажи|покаж
diff --git a/plugins/ai.py b/plugins/ai.py
index c770703..cb56138 100644
--- a/plugins/ai.py
+++ b/plugins/ai.py
@@ -23,6 +23,8 @@
# [u'devel@conference.jabber.ru', u'sulci', u'moderator', u'admin', u'sulci@jabber.ru/Ocaml']
+AI_PREFIX = '!ai_'
+
AI_PREV = {}
AI_PHRASES_FOLDER = data_folder % 'ai/%s'
AI_PHRASES_FILES = [t for t in os.listdir(AI_PHRASES_FOLDER % '') if t.endswith('.txt') and os.path.isfile(AI_PHRASES_FOLDER % t)]
@@ -36,6 +38,33 @@ for PH_LANG in AI_PHRASES_FILES:
if not AI_PHRASES.has_key(PH_L): AI_PHRASES[PH_L] = [LINE.split('\t',1)]
else: AI_PHRASES[PH_L].append(LINE.split('\t',1))
+def AI_UNIQUE(M):
+ m = []
+ for t in M:
+ if t not in m: m.append(t)
+ return m
+
+def AI_RAW(CMD, RAW, RN):
+ CMD = CMD.replace(AI_PREFIX,'',1)
+ if CMD.startswith('drink') and os.path.isfile(date_file):
+ RAW_SPLIT = RAW.lower().replace('?','').strip().split()
+ DRINK = drink_dmas + drink_mmas1 + drink_mmas2 + drink_wday + drink_lday
+ INIT_DRINK = re.findall('[0-9]+', RAW, re.S)
+ if INIT_DRINK: INIT_DRINK = ['.'.join(INIT_DRINK)]
+ for t in DRINK:
+ DRINK_LOCALE = L(t, RN).lower()
+ if DRINK_LOCALE in RAW_SPLIT: INIT_DRINK.append(DRINK_LOCALE)
+ if len(INIT_DRINK) >= 2: return CMD.replace('{RAW}', ' '.join(AI_UNIQUE(INIT_DRINK))), True
+ else:
+ ddate = readfile(date_file).decode('UTF').lower().split('\n')
+ for DATE in ddate:
+ DATE_SPLIT = DATE.split()
+ for R in RAW_SPLIT:
+ if R in DATE_SPLIT:
+ INIT_DRINK.append(R)
+ if INIT_DRINK: return CMD.replace('{RAW}', ' '.join(AI_UNIQUE(INIT_DRINK))), True
+ return '', False
+
def AI_PARSE(room, jid, nick, type, text):
if not get_config(room,'ai'): return
LOC = get_L_('%s/%s' % (room,nick))
@@ -64,6 +93,7 @@ def AI_PARSE(room, jid, nick, type, text):
if 'nick' in ptype and '||' in CMD[1]:
for t in CMD[1].split('||')[1].split('|'):
text = text.replace(t,nick)
+
PRM = AI_PARAMETER(text, ptype, room)
if 'nick' in ptype:
@@ -75,17 +105,27 @@ def AI_PARSE(room, jid, nick, type, text):
if not PP: PRM.append(nick)
COMMAND = CMD[0]
- COMMAND = COMMAND.replace('{TOMORROW}',time.strftime('%d.%m', time.localtime(time.time()+86400)))
- WAS_PARAM = False
- for PARAM in PRM:
- if PARAM:
+ if COMMAND.startswith(AI_PREFIX):
+ for PHRASES in AI_PHRASES[LOC]:
+ if PHRASES[0] == COMMAND:
+ for t in PHRASES[1].split('||')[0].lower().split('|'):
+ TEXT = TEXT.lower().replace(t,'')
+ COMMAND, IS_PARSED = AI_RAW(COMMAND, TEXT, '%s/%s'%(jid,nick))
+ if IS_PARSED:
+ com_parser(access_mode, nowname, type, room, nick, COMMAND, jid)
+ return True
+ else:
+ COMMAND = COMMAND.replace('{TOMORROW}',time.strftime('%d.%m', time.localtime(time.time()+86400)))
+ WAS_PARAM = False
+ for PARAM in PRM:
+ if PARAM:
+ if time_nolimit: time.sleep(time_nolimit)
+ com_parser(access_mode, nowname, type, room, nick, COMMAND.replace('{PAR}',PARAM), jid)
+ WAS_PARAM = True
+ if not WAS_PARAM:
if time_nolimit: time.sleep(time_nolimit)
- com_parser(access_mode, nowname, type, room, nick, COMMAND.replace('{PAR}',PARAM), jid)
- WAS_PARAM = True
- if not WAS_PARAM:
- if time_nolimit: time.sleep(time_nolimit)
- com_parser(access_mode, nowname, type, room, nick, COMMAND, jid)
- return True
+ com_parser(access_mode, nowname, type, room, nick, COMMAND, jid)
+ return True
def AI_RATING(s, text, room):
r,s = 0.0,s.split('|')
diff --git a/plugins/drink.py b/plugins/drink.py
index 51c30f8..5993df5 100644
--- a/plugins/drink.py
+++ b/plugins/drink.py
@@ -21,25 +21,18 @@
# #
# --------------------------------------------------------------------------- #
+# translate: first,second,third,fourth,fifth,sixth,seventh,eighth,nineth,tenth,eleventh,twelveth,thirteenth,fourteenth,fivteenth,sixteenth,seventeenth,eighteenth,nineteenth,twentieth,twenty-first,twenty-second,twenty-third,twenty-fourth,twenty-fifth,twenty-sixth,twenty-seventh,twenty-eighth,twenty-nineth,thirtieth,thirty-first,january,february,march,april,may,june,july,august,september,october,november,december,January,February,March,April,May,June,July,August,September,October,November,December,monday,tuesday,wendesday,thirsday,friday,saturday,sunday,last,last,Last,last,Last,Last,lAst
+
+drink_dmas = ['first','second','third','fourth','fifth','sixth','seventh','eighth','nineth','tenth','eleventh','twelveth',
+ 'thirteenth','fourteenth','fivteenth','sixteenth','seventeenth','eighteenth','nineteenth','twentieth',
+ 'twenty-first','twenty-second','twenty-third','twenty-fourth','twenty-fifth','twenty-sixth','twenty-seventh',
+ 'twenty-eighth','twenty-nineth','thirtieth','thirty-first']
+drink_mmas1 = ['january','february','march','april','may','june','july','august','september','october','november','december']
+drink_mmas2 = ['January','February','March','April','May','June','July','August','September','October','November','December']
+drink_wday = ['monday','tuesday','wendesday','thirsday','friday','saturday','sunday']
+drink_lday = ['last','last','Last','last','Last','Last','lAst']
+
def to_drink(type, jid, nick, text):
- dmas = [L('first','%s/%s'%(jid,nick)),L('second','%s/%s'%(jid,nick)),L('third','%s/%s'%(jid,nick)),L('fourth','%s/%s'%(jid,nick)),
- L('fifth','%s/%s'%(jid,nick)),L('sixth','%s/%s'%(jid,nick)),L('seventh','%s/%s'%(jid,nick)),L('eighth','%s/%s'%(jid,nick)),
- L('nineth','%s/%s'%(jid,nick)),L('tenth','%s/%s'%(jid,nick)),L('eleventh','%s/%s'%(jid,nick)),L('twelveth','%s/%s'%(jid,nick)),
- L('thirteenth','%s/%s'%(jid,nick)),L('fourteenth','%s/%s'%(jid,nick)),L('fivteenth','%s/%s'%(jid,nick)),L('sixteenth','%s/%s'%(jid,nick)),
- L('seventeenth','%s/%s'%(jid,nick)),L('eighteenth','%s/%s'%(jid,nick)),L('nineteenth','%s/%s'%(jid,nick)),('twentieth'),
- L('twenty-first','%s/%s'%(jid,nick)),L('twenty-second','%s/%s'%(jid,nick)),L('twenty-third','%s/%s'%(jid,nick)),
- L('twenty-fourth','%s/%s'%(jid,nick)),L('twenty-fifth','%s/%s'%(jid,nick)),L('twenty-sixth','%s/%s'%(jid,nick)),L('twenty-seventh','%s/%s'%(jid,nick)),
- L('twenty-eighth','%s/%s'%(jid,nick)),L('twenty-nineth','%s/%s'%(jid,nick)),L('thirtieth','%s/%s'%(jid,nick)),L('thirty-first','%s/%s'%(jid,nick))]
- mmas1 = [L('january','%s/%s'%(jid,nick)),L('february','%s/%s'%(jid,nick)),L('march','%s/%s'%(jid,nick)),L('april','%s/%s'%(jid,nick)),
- L('may','%s/%s'%(jid,nick)),L('june','%s/%s'%(jid,nick)),L('july','%s/%s'%(jid,nick)),L('august','%s/%s'%(jid,nick)),
- L('september','%s/%s'%(jid,nick)),L('october','%s/%s'%(jid,nick)),L('november','%s/%s'%(jid,nick)),L('december','%s/%s'%(jid,nick))]
- mmas2 = [L('January','%s/%s'%(jid,nick)),L('February','%s/%s'%(jid,nick)),L('March','%s/%s'%(jid,nick)),L('April','%s/%s'%(jid,nick)),
- L('May','%s/%s'%(jid,nick)),L('June','%s/%s'%(jid,nick)),L('July','%s/%s'%(jid,nick)),L('August','%s/%s'%(jid,nick)),
- L('September','%s/%s'%(jid,nick)),L('October','%s/%s'%(jid,nick)),L('November','%s/%s'%(jid,nick)),L('December','%s/%s'%(jid,nick))]
- wday = [L('monday','%s/%s'%(jid,nick)),L('tuesday','%s/%s'%(jid,nick)),L('wendesday','%s/%s'%(jid,nick)),L('thirsday','%s/%s'%(jid,nick)),
- L('friday','%s/%s'%(jid,nick)),L('saturday','%s/%s'%(jid,nick)),L('sunday','%s/%s'%(jid,nick))]
- lday = [L('last','%s/%s'%(jid,nick)),L('last','%s/%s'%(jid,nick)),L('Last','%s/%s'%(jid,nick)),L('last','%s/%s'%(jid,nick)),
- L('Last','%s/%s'%(jid,nick)),L('Last','%s/%s'%(jid,nick)),L('lAst','%s/%s'%(jid,nick))]
if os.path.isfile(date_file):
ddate = readfile(date_file).decode('UTF')
week1 = ''
@@ -48,16 +41,15 @@ def to_drink(type, jid, nick, text):
else:
if len(text) <= 2:
ltim = tuple(time.localtime())
- text = '%s %s' % (ltim[2], mmas2[ltim[1]-1])
- week1 = '%s %s %s' % (ltim[2]/7+(ltim[2]%7 > 0), wday[ltim[6]], mmas2[ltim[1]-1])
- if ltim[2]+7 > calendar.monthrange(ltim[0], ltim[1])[1]: week2 = '%s %s %s' % (lday[ltim[6]].lower(), wday[ltim[6]], mmas2[ltim[1]-1])
+ text = '%s %s' % (ltim[2], L(drink_mmas2[ltim[1]-1],'%s/%s'%(jid,nick)))
+ week1 = '%s %s %s' % (ltim[2]/7+(ltim[2]%7 > 0), L(drink_wday[ltim[6]],'%s/%s'%(jid,nick)), L(drink_mmas2[ltim[1]-1],'%s/%s'%(jid,nick)))
+ if ltim[2]+7 > calendar.monthrange(ltim[0], ltim[1])[1]: week2 = '%s %s %s' % (L(drink_lday[ltim[6]].lower(),'%s/%s'%(jid,nick)), L(drink_wday[ltim[6]],'%s/%s'%(jid,nick)), L(drink_mmas2[ltim[1]-1],'%s/%s'%(jid,nick)))
or_text = text
if text.count('.')==1: text = text.split('.')
elif text.count(' ')==1: text = text.split(' ')
else: text = [text]
msg = ''
ddate = ddate.split('\n')
- ltxt = len(text)
for tmp in ddate:
if or_text.lower() in tmp.lower(): msg += '\n'+tmp
elif week1.lower() in tmp.lower() and week1 != '': msg += '\n'+tmp
@@ -66,13 +58,13 @@ def to_drink(type, jid, nick, text):
try:
ttmp = tmp.split(' ')[0].split('.')
tday = [ttmp[0]]
- tday.append(dmas[int(ttmp[0])-1])
+ tday.append(L(drink_dmas[int(ttmp[0])-1],'%s/%s'%(jid,nick)))
tmonth = [ttmp[1]]
- tmonth.append(mmas1[int(ttmp[1])-1])
- tmonth.append(mmas2[int(ttmp[1])-1])
+ tmonth.append(L(drink_mmas1[int(ttmp[1])-1],'%s/%s'%(jid,nick)))
+ tmonth.append(L(drink_mmas2[int(ttmp[1])-1],'%s/%s'%(jid,nick)))
tmonth.append(str(int(ttmp[1])))
- t = tday.index(text[0])
- t = tmonth.index(text[1])
+ t = tday.index(L(text[0],'%s/%s'%(jid,nick)))
+ t = tmonth.index(L(text[1],'%s/%s'%(jid,nick)))
msg += '\n'+tmp
except: pass
if msg == '': msg = L('Holiday: %s not found.','%s/%s'%(jid,nick)) % or_text
@@ -106,5 +98,5 @@ def calend(type, jid, nick, text):
global execute
-execute = [(3, 'drink', to_drink, 2, 'Find holiday\ndrink [name_holiday/date]'),
+execute = [(3, 'drink', to_drink, 2, 'Find holiday\ndrink [name_holiday/date]',['raw']),
(3, 'calend', calend, 2, 'Find holiday\ncalend [name_holiday/date]')] \ No newline at end of file