forked from colons/pyfoot-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrantext.py
More file actions
42 lines (30 loc) · 1.27 KB
/
Copy pathrantext.py
File metadata and controls
42 lines (30 loc) · 1.27 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
from random import choice
from copy import copy
import plugin
defaults = {
'rantext_sources': [],
}
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.conf['rantext_sources']:
filename = self.conf.conf['content_dir']+source+'.txt'
file = open(filename)
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__ = '$<comchar>%s\n>%s' % (source, 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):
source = self.sources[args['_command'].split(' ')[0]]
line = choice(source)
if 'nick' in args:
line = '%s: %s' % (args['nick'], line)
self.irc.privmsg(message.source, line)