Compare commits
	
		
			2 commits
		
	
	
		
			b0f616fd32
			...
			7e8b53a207
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7e8b53a207 | |||
| 17f1727be1 | 
					 6 changed files with 1989 additions and 6 deletions
				
			
		
							
								
								
									
										101
									
								
								etc/utf8.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								etc/utf8.lua
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,101 @@ | ||||||
|  | -- Unicode library | ||||||
|  | 
 | ||||||
|  | local pattern = '[%z\1-\127\194-\244][\128-\191]*' | ||||||
|  | 
 | ||||||
|  | -- helper function | ||||||
|  | local function posrelat(pos, len) | ||||||
|  |   if pos < 0 then | ||||||
|  |     pos = len + pos + 1 | ||||||
|  |   end | ||||||
|  |   return pos | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | local utf8 = {} | ||||||
|  | 
 | ||||||
|  | -- THE MEAT | ||||||
|  | 
 | ||||||
|  | function utf8.map(s, f, no_subs) | ||||||
|  |   local i = 0 | ||||||
|  | 
 | ||||||
|  |   if no_subs then | ||||||
|  |     for b, e in s:gmatch('()' .. pattern .. '()') do | ||||||
|  |       i = i + 1 | ||||||
|  |       local c = e - b | ||||||
|  |       f(i, c, b) | ||||||
|  |     end | ||||||
|  |   else | ||||||
|  |     for b, c in s:gmatch('()(' .. pattern .. ')') do | ||||||
|  |       i = i + 1 | ||||||
|  |       f(i, c, b) | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | -- THE REST | ||||||
|  | 
 | ||||||
|  | function utf8.chars(s, no_subs) | ||||||
|  |   return coroutine.wrap(function() | ||||||
|  |     return utf8.map(s, coroutine.yield, no_subs) | ||||||
|  |   end) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.len(s) | ||||||
|  |   return select(2, s:gsub('[^\128-\193]', '')) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.replace(s, map) | ||||||
|  |   return s:gsub(pattern, map) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.reverse(s) | ||||||
|  |   s = s:gsub(pattern, function(c) | ||||||
|  |     return #c > 1 and c:reverse() | ||||||
|  |   end) | ||||||
|  |   return s:reverse() | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.strip(s) | ||||||
|  |   return s:gsub(pattern, function(c) | ||||||
|  |     return #c > 1 and '' | ||||||
|  |   end) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.sub(s, i, j) | ||||||
|  |   local l = utf8.len(s) | ||||||
|  | 
 | ||||||
|  |   i = posrelat(i, l) | ||||||
|  |   j = j and posrelat(j, l) or l | ||||||
|  | 
 | ||||||
|  |   if i < 1 then i = 1 end | ||||||
|  |   if j > l then j = l end | ||||||
|  |   if i > j then return '' end | ||||||
|  | 
 | ||||||
|  |   local diff = j - i | ||||||
|  |   local iter = utf8.chars(s, true) | ||||||
|  | 
 | ||||||
|  |   for _ = 1, i - 1 do iter() end | ||||||
|  |   local c, b = select(2, iter()) | ||||||
|  | 
 | ||||||
|  |   if diff == 0 | ||||||
|  |   then return s:sub(b, b + c - 1) end | ||||||
|  | 
 | ||||||
|  |   i = b | ||||||
|  |   for _ = 1, diff - 1 do iter() end | ||||||
|  |   local c, b = select(2, iter()) | ||||||
|  | 
 | ||||||
|  |   return s:sub(i, b + c - 1) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | -- ADDITION | ||||||
|  | 
 | ||||||
|  | require 'etc.utf8data' | ||||||
|  | 
 | ||||||
|  | function utf8.upper(s) | ||||||
|  |   return utf8.replace(s, utf8_lc_uc) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function utf8.lower(s) | ||||||
|  |   return utf8.replace(s, utf8_uc_lc) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | return utf8 | ||||||
							
								
								
									
										1860
									
								
								etc/utf8data.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1860
									
								
								etc/utf8data.lua
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -1,9 +1,25 @@ | ||||||
|  | local reg = { | ||||||
|  |   {'эх',         'хуех'}, -- надоели эхать | ||||||
|  |   {'мета',       'хуета'}, | ||||||
|  |   {'meta',       'xueta'}, | ||||||
|  |   {'цукерберг',  'цукерхуй'}, | ||||||
|  |   {'zuckerberg', 'zuckerhui'}, | ||||||
|  |   {'whatsapp',   'вадзад'}, | ||||||
|  |   {'tiktok',     'деградация'}, | ||||||
|  |   {'.*че%?*$',   'пиши ё, грамотей'}, | ||||||
|  |   {'.*чё%?*$',   'ничё'} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| return function(C, api, msg) | return function(C, api, msg) | ||||||
|   -- надоели эхать |   if msg.text then | ||||||
|   if msg.text |     msg.text = utf8.lower(msg.text) | ||||||
|   and msg.text:match '[Ээ]+[Хх]+' then |     local t = '' | ||||||
|     C.api:reply(msg, msg.text |     for _, v in pairs(reg) do | ||||||
|       :gsub('[Ээ]+[Хх]+', 'хуех') |       if msg.text:match(v[1]) | ||||||
|     ,nil) |       then t = t.. v[2] ..' ' | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  |     if t ~= '' | ||||||
|  |     then api:reply(msg, t) end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -28,6 +28,8 @@ | ||||||
|       "prov": "\nData provided from central bank of Russia." |       "prov": "\nData provided from central bank of Russia." | ||||||
|     }, |     }, | ||||||
|     "start": { |     "start": { | ||||||
|  |       "desc": "getting started", | ||||||
|  | 
 | ||||||
|       "msg": "Hi! I'm Computer - an open-source bot.\nIf you looking for source code: https://gitdab.com/er2/comp-tg" |       "msg": "Hi! I'm Computer - an open-source bot.\nIf you looking for source code: https://gitdab.com/er2/comp-tg" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -28,6 +28,8 @@ | ||||||
|       "prov": "\nДанные предоставлены центральным банком России." |       "prov": "\nДанные предоставлены центральным банком России." | ||||||
|     }, |     }, | ||||||
|     "start": { |     "start": { | ||||||
|  |       "desc": "начало работы", | ||||||
|  | 
 | ||||||
|       "msg": "Привет! Я Computer - бот с открытым исходным кодом.\nЕсли ты ищешь исходники: https://gitdab.com/er2/comp-tg" |       "msg": "Привет! Я Computer - бот с открытым исходным кодом.\nЕсли ты ищешь исходники: https://gitdab.com/er2/comp-tg" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -42,6 +42,8 @@ end | ||||||
| function Core:init() | function Core:init() | ||||||
|   self:load 'parts' |   self:load 'parts' | ||||||
| 
 | 
 | ||||||
|  |   utf8 = require 'etc.utf8' | ||||||
|  | 
 | ||||||
|   print 'Done!' |   print 'Done!' | ||||||
|   self:emit 'ready' |   self:emit 'ready' | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue