-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrantext.py
More file actions
51 lines (36 loc) · 1.47 KB
/
rantext.py
File metadata and controls
51 lines (36 loc) · 1.47 KB
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
from random import choice
import plugin
defaults = {
'rantext_sources': [],
'rantext_frames': {},
}
class Plugin(plugin.Plugin):
"""
Retrieve a random line from a text file. Can be directed at individuals.
"""
def register_commands(self):
self.commands = []
self.sources = {}
for source in self.conf['rantext_sources']:
filename = '%s/rantext/%s.txt' % (self.conf['content_dir'],
source)
file = open(filename, encoding="utf-8")
line_list = []
for line in file:
line_list.append(line)
self.sources[source] = line_list
for source in self.sources:
everyone_func = lambda message, args: self.rantext(message, args)
everyone_func.__doc__ = '>%s' % choice(self.sources[source])
targetted_func = lambda message, args: self.rantext(message, args)
self.commands.append((source, everyone_func))
self.commands.append(('%s <<nick>>' % source, targetted_func))
def rantext(self, message, args):
sourcename = args['_command'].split(' ')[0]
source = self.sources[sourcename]
line = choice(source)
if sourcename in self.conf['rantext_frames']:
line = self.conf['rantext_frames'][sourcename] % line
if 'nick' in args:
line = '%s: %s' % (args['nick'], line)
self.irc.privmsg(message.source, line)