def on_msg server args nick buffer message unicode local_charset for i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def on_msg(server, args):
nick, buffer, message = [unicode(s, local_charset) for s in parse_privmsg(server, args)]
message = strip_irc_colors(message)
if buffer == '#gentoo-ru':
latin = sum(1 for char in message if u'\u0041' <= char <= u'\u0080')
ascii8 = sum(1 for char in message if u'\u0080' <= char <= u'\u00FF')
cyrillic = sum(1 for char in message if u'\u0400' <= char <= u'\u04FF')
if cyrillic == 0:
if ascii8 >= 0.25 * len(message):
global send_queue, badnicks
if not nick in badnicks:
send_queue.append((u"%s, please, speak English or Russian in UTF-8", buffer, server))
badnicks[nick] = NOW()
return weechat.PLUGIN_RC_OK