forked from sopel-irc/sopel-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.py
156 lines (118 loc) · 3.78 KB
/
ai.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
ai.py - Artificial Intelligence Module
Copyright 2009-2011, Michael Yanovich, yanovich.net
Licensed under the Eiffel Forum License 2.
http://willie.dftba.net
"""
from willie.module import rule, priority, rate
import random
import time
def configure(config):
"""
| [ai] | example | purpose |
| ---------- | ------- | ------- |
| frequency | 3 | How often Willie participates in the conversation (0-10) |
"""
if config.option('Configure ai module', False):
if not config.has_section('ai'):
config.add_section('ai')
config.interactive_add('ai', 'frequency',
"How often do you want Willie to participate in the conversation? (0-10)",
3)
config.save()
def setup(bot):
# Set value to 3 if not configured
if bot.config.ai and bot.config.ai.frequency:
bot.memory['frequency'] = bot.config.ai.frequency
else:
bot.memory['frequency'] = 3
random.seed()
def decide(bot):
return 0 < random.random() < float(bot.memory['frequency']) / 10
@rule('(?i)$nickname\:\s+(bye|goodbye|seeya|cya|ttyl|g2g|gnight|goodnight)')
@rate(30)
def goodbye(bot, trigger):
byemsg = random.choice(('Bye', 'Goodbye', 'Seeya', 'Auf Wiedersehen', 'Au revoir', 'Ttyl'))
punctuation = random.choice(('!', ' '))
bot.say(byemsg + ' ' + trigger.nick + punctuation)
@rule('(?i).*(thank).*(you).*(willie|$nickname).*$')
@rate(30)
@priority('high')
def ty(bot, trigger):
human = random.uniform(0, 9)
time.sleep(human)
mystr = trigger.group()
mystr = str(mystr)
if (mystr.find(" no ") == -1) and (mystr.find("no ") == -1) and (mystr.find(" no") == -1):
bot.reply("You're welcome.")
@rule('(?i)$nickname\:\s+(thank).*(you).*')
@rate(30)
def ty2(bot, trigger):
ty(bot, trigger)
@rule('(?i).*(thanks).*(willie|$nickname).*')
@rate(40)
def ty4(bot, trigger):
ty(bot, trigger)
@rule('(willie|$nickname)\:\s+(yes|no)$')
@rate(15)
def yesno(bot, trigger):
rand = random.uniform(0, 5)
text = trigger.group()
text = text.split(":")
text = text[1].split()
time.sleep(rand)
if text[0] == 'yes':
bot.reply("no")
elif text[0] == 'no':
bot.reply("yes")
@rule('(?i)($nickname|willie)\:\s+(ping)\s*')
@rate(30)
def ping_reply(bot, trigger):
text = trigger.group().split(":")
text = text[1].split()
if text[0] == 'PING' or text[0] == 'ping':
bot.reply("PONG")
@rule('(?i)i.*love.*(willie|$nickname).*')
@rate(30)
def love(bot, trigger):
bot.reply("I love you too.")
@rule('(?i)(willie|$nickname)\:\si.*love.*')
@rate(30)
def love2(bot, trigger):
bot.reply("I love you too.")
@rule('(?i)(willie|$nickname)\,\si.*love.*')
@rate(30)
def love3(bot, trigger):
bot.reply("I love you too.")
@rule('(haha!?|lol!?)$')
@priority('high')
def f_lol(bot, trigger):
if decide(bot):
respond = ['haha', 'lol', 'rofl']
randtime = random.uniform(0, 9)
time.sleep(randtime)
bot.say(random.choice(respond))
@rule('(g2g!?|bye!?)$')
@priority('high')
def f_bye(bot, trigger):
respond = ['bye!', 'bye', 'see ya', 'see ya!']
bot.say(random.choice(respond))
@rule('(heh!?)$')
@priority('high')
def f_heh(bot, trigger):
if decide(bot):
respond = ['hm']
randtime = random.uniform(0, 7)
time.sleep(randtime)
bot.say(random.choice(respond))
@rule('(?i)$nickname\:\s+(really!?)')
@priority('high')
def f_really(bot, trigger):
randtime = random.uniform(10, 45)
time.sleep(randtime)
bot.say(str(trigger.nick) + ": " + "Yes, really.")
@rule('^(wb|welcome\sback).*$nickname\s')
def wb(bot, trigger):
bot.reply("Thank you!")
if __name__ == '__main__':
print __doc__.strip()