Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from plugins import plugin
  3. import globalv
  4. import pickle
  5. import sys
  6. import os
  7. import re
  8.  
  9. class pluginClass(plugin):
  10. def __init__(self):
  11. self.charIgnore = '!#*()"\'?,.\x01\x02\x03\x04\x05\x06\x07\x08\x16\xff\t\r\n'
  12. self.exceptions = [':)',':(','=)','=(',':|','>:(','>:)','._.',':\'(']
  13.  
  14. def gettype(self):
  15. return "realtime"
  16.  
  17. def action(self,complete):
  18. logUser = True
  19. if complete.channel()[0] != '#'
  20. return [""]
  21.  
  22. if not ".*!"+complete.userMask().split('!',1)[1] in [x[0] for x in globalv.miscVars[2]]:
  23. print '(pictured)', complete.user(), 'is not registered'
  24. logUser = False
  25. else:
  26. print '(pictured)', complete.user(), 'is registered'
  27.  
  28. logpath = os.path.join('config','picturelogs','picturelog-%s'%complete.channel())
  29. words_channel = dict()
  30.  
  31. if os.path.exists(logpath):
  32. with open(logpath) as logFile:
  33. words_channel = pickle.load(logFile)
  34.  
  35. if logUser:
  36. logpath_u = os.path.join('config','picturelogs','picturelog-%s-%s'%(complete.channel(),complete.user()))
  37. words_user = dict()
  38.  
  39. if os.path.exists(logpath_u):
  40. with open(logpath_u) as logFile:
  41. words_user = pickle.load(logFile)
  42.  
  43.  
  44. words = complete.fullMessage().split()
  45.  
  46. first = True
  47. for word in words:
  48. if first and word[0] == '\x01':
  49. first = False
  50. continue
  51.  
  52. word = word.lower()
  53.  
  54. if word in self.exceptions:
  55. for cwords in [words_channel] + ([words_user] if logUser else []):
  56. if word in cwords:
  57. cwords[word] += 1
  58. else:
  59. cwords[word] = 1
  60. continue
  61.  
  62. #remove text coloring characters
  63. word = re.sub("\x03\d\d?(,\d\d?)?", '', word)
  64.  
  65. word = word.lstrip(self.charIgnore).rstrip(self.charIgnore)
  66. for cwords in [words_channel] + ([words_user] if logUser else []):
  67. if word in cwords:
  68. cwords[word] += 1
  69. else:
  70. cwords[word] = 1
  71.  
  72. with open(logpath,"w") as logFile:
  73. pickle.dump(words_channel,logFile)
  74. if logUser:
  75. with open(logpath_u,"w") as logFile:
  76. pickle.dump(words_user,logFile)
  77. print 'the log for', complete.user(), 'was updated'
  78.  
  79. return [""]
  80.  
  81. def describe(self, complete):
  82. return ["PRIVMSG $C$ :I am the picture module! Say !picture to see a piece of art made by you talking!"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement