@@ -58,7 +58,7 @@ def has_expected_mode(path, mode):
58
58
59
59
configFile = os .path .expanduser ("~" ) + '/.rhonrhonrc'
60
60
if not has_expected_mode (configFile , 0o600 ):
61
- print ("err: invalid mode on configFile" , configFile )
61
+ print ("err: invalid mode on configFile, should be 600 " , configFile )
62
62
sys .exit (2 )
63
63
64
64
exec (open (configFile ).read ())
@@ -283,14 +283,8 @@ def on_pubmsg(self, serv, ev):
283
283
urls = re .findall ('(https?://[^\s]+)' , pl )
284
284
urls_copy = list (urls )
285
285
for url in urls_copy :
286
- urlbody = {
287
- 'query' : {
288
- 'match_phrase' : {'urls' : url }
289
- },
290
- 'size' : 1
291
- }
292
- res = es .search (index = es_idx , doc_type = channel , body = urlbody )
293
- for rep in res ['hits' ]['hits' ]:
286
+ (vieille , rep ) = self .vieille (url , channel )
287
+ if vieille :
294
288
try :
295
289
msg = '{0}: VIEUX ! The URL [ {1} ] has been posted '
296
290
msg = msg + 'by {2} the {3} at {4}.'
@@ -311,7 +305,6 @@ def on_pubmsg(self, serv, ev):
311
305
pass
312
306
313
307
urls .remove (url )
314
- break
315
308
316
309
has_nick = False
317
310
tonick = []
@@ -350,13 +343,39 @@ def handle_noauth_privcmd(self, serv, ev, s):
350
343
self .showrage (serv , ev , 'priv' )
351
344
return True
352
345
346
+ # Ask rhonrhon weither a list of URLs are old or not.
347
+ # Syntax: urls?:? (#channel)? text containing URLs.
348
+ # The default channel is #gcu.
349
+ # Ex: url: #gcu c'est bon la rhonrhon ? https://www.google.com
350
+ # Ex: urls http://www.bonjourmadame.fr ou alors
351
+ # http://bonjourlesroux.tumblr.com
352
+ if re .match ('^urls?:?$' , s [0 ]):
353
+ i = 1
354
+ if re .match ('^#.*$' , s [1 ]):
355
+ channel = s [1 ].replace ('#' , '' )
356
+ i += 1
357
+ else :
358
+ channel = 'gcu'
359
+
360
+ for url in [x for x in s [i :] if re .match ('(https?://[^\s]+)' , x )]:
361
+ if len (url ) > 262 :
362
+ msg = 'SAYTROPLONG [ {0} ]'
363
+ else :
364
+ (vieille , rep ) = self .vieille (url , channel )
365
+ if vieille :
366
+ msg = 'VIEUX ! [ {0} ]'
367
+ else :
368
+ msg = 'SAYBON [ {0} ]'
369
+ serv .privmsg (ev .source .nick , msg .format (url ))
370
+ return True
371
+
353
372
return False
354
373
355
374
def on_privmsg (self , serv , ev ):
356
375
pl = ev .arguments [0 ]
357
376
s = pl .split (' ' )
358
377
if not s :
359
- return # no command passed (is it even possible ? :)
378
+ return # no command passed (is it even possible ? :) )
360
379
if self .handle_noauth_privcmd (serv , ev , s ) is True :
361
380
return # a publicly accessible command was provided
362
381
if not ev .source .nick in auth .keys ():
@@ -461,6 +480,23 @@ def on_quit(self, serv, ev):
461
480
self ._refresh_all_chans () # quit doesn't set any target
462
481
self ._user_unregister (ev .source )
463
482
483
+ def vieille (self , url , channel ):
484
+ urlbody = {
485
+ 'query' : {
486
+ 'match_phrase' : {'urls' : url }
487
+ },
488
+ 'size' : 1
489
+ }
490
+ try :
491
+ res = es .search (index = es_idx , doc_type = channel , body = urlbody )
492
+ for rep in res ['hits' ]['hits' ]:
493
+ return (True , rep )
494
+ except Exception as e :
495
+ logger .warn (e )
496
+ pass
497
+ return (False , [])
498
+
499
+
464
500
465
501
foreground = False
466
502
0 commit comments