forked from DarkMio/RedditRoverPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MioMarkov.py
61 lines (48 loc) · 1.8 KB
/
MioMarkov.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding=utf-8
from misc.brain import Brain
from core.baseclass import PluginBase
from random import random, choice
from pkg_resources import resource_filename
class MioMarkov(PluginBase):
def __init__(self, database, handler):
super().__init__(database, handler, 'MioMarkov')
self.brain = Brain(resource_filename('misc', 'dota2_cobe.sql'))
def execute_titlepost(self, title_only):
pass
def on_new_message(self, message):
pass
def update_procedure(self, thing, created, lifetime, last_updated, interval):
pass
def execute_link(self, link_submission):
pass
def execute_submission(self, submission):
if submission.subreddit.display_name.lower() == 'dota2' and random() <= 0.001:
reply = self.produce_dank_maymays(submission.selftext)
if reply:
self.add_comment(submission.name, reply)
return True
def execute_comment(self, comment):
if comment.subreddit.display_name.lower() == 'dota2' or random() <= 0.001:
reply = self.produce_dank_maymays(comment.body)
if reply:
self.add_comment(comment.name, reply)
return True
def produce_dank_maymays(self, message):
msg = ''
i = 0
while(not (10 < len(msg) < 210)):
if i > 4:
msg = ''
break
msg = self.brain.reply(message)
i += 1
return msg
def init(database, handler):
return MioMarkov(database, handler)
if __name__ == '__main__':
from core.logprovider import setup_logging
from core.handlers import RoverHandler
from core.database import Database
logger = setup_logging('DEBUG')
mm = MioMarkov(Database(), RoverHandler())
mm.test_single_comment('cvfmf9e')