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

turn.py « plugins - github.com/isida/3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b20511862f27ed09f8604099e510b7774ee0ba1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
# -*- coding: utf-8 -*-

# --------------------------------------------------------------------------- #
#                                                                             #
#    Plugin for iSida Jabber Bot                                              #
#    Copyright (C) diSabler <dsy@dsy.name>                                    #
#    Copyright (C) Vit@liy <vitaliy@root.ua>                                  #
#                                                                             #
#    This program is free software: you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation, either version 3 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
#                                                                             #
# --------------------------------------------------------------------------- #

turn_base = []

def turner_raw(text,jid,nick):
	global turn_base
	rtab = L('qwertyuiop[]asdfghjkl;\'zxcvbnm,.`QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>~','%s/%s'%(jid,nick))
	ltab = L('QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>~qwertyuiop[]asdfghjkl;\'zxcvbnm,.`','%s/%s'%(jid,nick))
	to_turn = text
	if not text:
		for tmp in turn_base:
			if tmp[0] == jid and tmp[1] == nick:
				turn_base.remove(tmp)
				to_turn = tmp[2]
				break
	if to_turn:
		if to_turn[:3] == '/me': msg, to_turn = '*%s' % nick, to_turn[3:]
		elif ': ' in to_turn: msg, to_turn = '%s:' % to_turn.split(': ',1)[0], to_turn.split(': ',1)[1]
		else: msg = ''
		for tt in re.findall('\s+[^\s]*', ' ' + to_turn,re.I+re.U):
			if re.findall('\s+(((svn|http[s]?|ftp)(://))|(magnet:\?))',tt,re.I+re.S+re.U): msg += tt
			else: msg += ''.join([ltab[rtab.find(x)] if x in rtab else x for x in tt])
		msg = msg.strip()
		if get_config(getRoom(jid),'censor'): msg = to_censore(msg,jid)
		return msg
	else: return None

def turner(type, jid, nick, text):
	if not text and type != 'groupchat':
		send_msg(type, jid, nick, L('Not allowed in private!','%s/%s'%(jid,nick)))
		return
	to_turn = turner_raw(text,jid,nick)
	if to_turn: send_msg(type, jid, [nick,''][type=='groupchat'], to_turn)
	else: send_msg(type, jid, nick, L('What?','%s/%s'%(jid,nick)))

def append_to_turner(room,jid,nick,type,text):
	global turn_base
	for tmp in turn_base:
		if tmp[0] == room and tmp[1] == nick:
			try: turn_base.remove(tmp)
			except: pass
			break
	turn_base.append((room,nick,text))

def remove_from_turner(room,jid,nick,type,text):
	global turn_base
	if type == 'unavailable':
		for tmp in turn_base:
			if tmp[0] == room and tmp[1] == nick:
				try: turn_base.remove(tmp)
				except: pass
				break

def autoturn(room,jid,nick,type,text):
	if get_config(room,'autoturn') and type == 'groupchat':
		if cur_execute_fetchone('select * from commonoff where room=%s and cmd=%s',(room,'turn')): return
		nowname = get_xnick(room)
		if nick == nowname: return
		text = re.sub('^%s[,:]\ ' % re.escape(nowname), '', text.strip())
		tmp = text.lower()
		if ': ' in tmp: tmp = tmp.split(': ',1)[1]
		count_two = 0
		if not sum([int(ord(t)>127) for t in tmp]):
			for tt in re.findall('\s+[^\s]*', ' ' + tmp):
				if not re.findall('(svn|http[s]?|ftp)(://)',tt,re.S+re.U) and not re.findall(u'\s+[A-ZА-Я\d\']{2,}$',tt,re.U): count_two += sum([1 for k in two_en if k in tt])
			if len(tmp.split()) < count_two - 1:
				to_turn = turner_raw(text,room,nick)
				if to_turn and to_turn != text:
					pprint('Autoturn text: %s/%s [%s] %s > %s' % (room,nick,jid,text,to_turn),'dark_gray')
					send_msg(type, room, '', to_turn)
				return True

global execute, message_act_control

message_control = [append_to_turner]
presence_control = [remove_from_turner]
message_act_control = [autoturn]

execute = [(3, 'turn', turner, 2, 'Turn text from one layout to another.')]