This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
ai.py
155 lines (120 loc) · 4.3 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
"""
ai.py - Artificial Intelligence Module
Copyright 2009-2011, Michael Yanovich, yanovich.net
Licensed under the Eiffel Forum License 2.
http://sopel.chat
"""
from sopel.module import rule, priority, rate
import random
import time
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|gtg|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).*(sopel|$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).*(sopel|$nickname).*')
@rate(40)
def ty4(bot, trigger):
ty(bot, trigger)
@rule('(sopel|$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|sopel)\:\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)((sopel|$nickname)\[,:]\s*i.*love|i.*love.*(sopel|$nickname).*)')
@rate(30)
def love(bot, trigger):
bot.reply("I love you too.")
@rule('\s*([Xx]+[dD]+|([Hh]+[Aa]+)+)')
@rate(30)
def xd(bot, trigger):
respond = ['xDDDDD', 'XD', 'XDDDD', 'haha']
randtime = random.uniform(0, 3)
time.sleep(randtime)
bot.say(random.choice(respond))
@rule('(haha!?|lol!?)$')
@priority('high')
def f_lol(bot, trigger):
if decide(bot):
respond = ['haha', 'lol', 'rofl', 'hm', 'hmmmm...']
randtime = random.uniform(0, 9)
time.sleep(randtime)
bot.say(random.choice(respond))
@rule('^\s*(([Bb]+([Yy]+[Ee]+(\s*[Bb]+[Yy]+[Ee]+)?)|[Ss]+[Ee]{2,}\s*[Yy]+[Aa]+|[Oo]+[Uu]+)|cya|ttyl|[Gg](2[Gg]|[Tt][Gg]|([Oo]{2,}[Dd]+\s*([Bb]+[Yy]+[Ee]+|[Nn]+[Ii]+[Gg]+[Hh]+[Tt]+)))\s*(!|~|.)*)$')
@priority('high')
def f_bye(bot, trigger):
set1 = ['bye', 'byebye', 'see you', 'see ya', 'Good bye', 'have a nice day']
set2 = ['~', '~~~', '!', ' :)', ':D', '(Y)', '(y)', ':P', ':-D', ';)', '(wave)', '(flee)']
respond = [ str1 + ' ' + str2 for str1 in set1 for str2 in set2]
bot.say(random.choice(respond))
@rule('^\s*(([Hh]+([AaEe]+[Ll]+[Oo]+|[Ii]+)+\s*(all)?)|[Yy]+[Oo]+|[Aa]+[Ll]+|[Aa]nybody)\s*(!+|\?+|~+|.+|[:;][)DPp]+)*$')
@priority('high')
def f_hello(bot, trigger):
randtime = random.uniform(0, 7)
time.sleep(randtime)
set1 = ['yo', 'hey', 'hi', 'Hi', 'hello', 'Hello', 'Welcome']
set2 = ['~', '~~~', '!', '?', ' :)', ':D', 'xD', '(Y)', '(y)', ':P', ':-D', ';)', ', How do you do?']
respond = [ str1 + ' ' + str2 for str1 in set1 for str2 in set2]
bot.say(random.choice(respond))
@rule('(heh!?)$')
@priority('high')
def f_heh(bot, trigger):
if decide(bot):
respond = ['hm', 'hmmmmmm...', 'heh?']
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('^\s*[Ww]([Bb]|elcome\s*back)[\s:,].*$nickname')
def wb(bot, trigger):
set1 = ['Thank you', 'thanks']
set2 = ['!', ' :)', ' :D']
respond = [ str1 + str2 for str1 in set1 for str2 in set2]
randtime = random.uniform(0, 7)
time.sleep(randtime)
bot.reply(random.choice(respond))
if __name__ == '__main__':
print(__doc__.strip())