Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 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. logUser = False
  24.  
  25. logpath = os.path.join('config','picturelogs','picturelog-%s'%complete.channel())
  26. words_channel = dict()
  27.  
  28. if os.path.exists(logpath):
  29. with open(logpath) as logFile:
  30. words_channel = pickle.load(logFile)
  31.  
  32. if logUser:
  33. logpath_u = os.path.join('config','picturelogs','picturelog-%s-%s'%(complete.channel(),complete.user()))
  34. words_user = dict()
  35.  
  36. if os.path.exists(logpath_u):
  37. with open(logpath_u) as logFile:
  38. words_user = pickle.load(logFile)
  39.  
  40.  
  41. words = complete.fullMessage().split()
  42.  
  43. first = True
  44. for word in words:
  45. if first and word[0] == '\x01':
  46. first = False
  47. continue
  48.  
  49. word = word.lower()
  50.  
  51. if word in self.exceptions:
  52. for cwords in [words_channel] + ([words_user] if logUser else []):
  53. if word in cwords:
  54. cwords[word] += 1
  55. else:
  56. cwords[word] = 1
  57. continue
  58.  
  59. #remove text coloring characters
  60. word = re.sub("\x03\d\d?(,\d\d?)?", '', word)
  61.  
  62. word = word.lstrip(self.charIgnore).rstrip(self.charIgnore)
  63. for cwords in [words_channel] + ([words_user] if logUser else []):
  64. if word in cwords:
  65. cwords[word] += 1
  66. else:
  67. cwords[word] = 1
  68.  
  69. with open(logpath,"w") as logFile:
  70. pickle.dump(words_channel,logFile)
  71. if logUser:
  72. with open(logpath_u,"w") as logFile:
  73. pickle.dump(words_user,logFile)
  74.  
  75. return [""]
  76.  
  77. def describe(self, complete):
  78. 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