-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathattacks.py
More file actions
159 lines (114 loc) · 4.13 KB
/
attacks.py
File metadata and controls
159 lines (114 loc) · 4.13 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
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
157
158
159
import codecs
import json
import os
import random
import asyncio
import re
from cloudbot import hook
from cloudbot.util import textgen
nick_re = re.compile("^[A-Za-z0-9_|.\-\]\[\{\}]*$", re.I)
def is_valid(target):
""" Checks if a string is a valid IRC nick. """
if nick_re.match(target):
return True
else:
return False
def is_self(conn, target):
""" Checks if a string is "****self" or contains conn.name. """
if re.search("(^..?.?.?self|{})".format(re.escape(conn.nick)), target, re.I):
return True
else:
return False
@hook.on_start()
def load_attacks(bot):
"""
:type bot: cloudbot.bot.CloudBot
"""
global larts, flirts, kills, slaps, rekts, flick
with codecs.open(os.path.join(bot.data_dir, "larts.txt"), encoding="utf-8") as f:
larts = [line.strip() for line in f.readlines() if not line.startswith("//")]
with codecs.open(os.path.join(bot.data_dir, "flirts.txt"), encoding="utf-8") as f:
flirts = [line.strip() for line in f.readlines() if not line.startswith("//")]
with codecs.open(os.path.join(bot.data_dir, "rekts.txt"), encoding="utf-8") as f:
rekts = [line.strip() for line in f.readlines() if not line.startswith("//")]
with codecs.open(os.path.join(bot.data_dir, "flicks.txt"), encoding="utf-8") as f:
rekts = [line.strip() for line in f.readlines() if not line.startswith("//")]
with codecs.open(os.path.join(bot.data_dir, "kills.json"), encoding="utf-8") as f:
kills = json.load(f)
with codecs.open(os.path.join(bot.data_dir, "slaps.json"), encoding="utf-8") as f:
slaps = json.load(f)
@asyncio.coroutine
@hook.command
def lart(text, conn, nick, action):
"""<user> - LARTs <user>"""
target = text.strip()
if not is_valid(target):
return "I can't attack that."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
phrase = random.choice(larts)
# act out the message
action(phrase.format(user=target))
@asyncio.coroutine
@hook.command
def flirt(text, conn, nick, message):
"""<user> - flirts with <user>"""
target = text.strip()
if not is_valid(target):
return "I can't attack that."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
message('{}, {}'.format(target, random.choice(flirts)))
@asyncio.coroutine
@hook.command
def flick(text, conn, nick, message):
"""<user> - flick <user> nipple"""
target = text.strip()
if not is_valid(target):
return "I can't flick that person's nipple."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
message('{}, {}'.format(target, random.choice(flicks)))
@asyncio.coroutine
@hook.command
def rekt(text, conn, nick, message):
"""<user> - rekts <user>"""
target = text.strip()
if not is_valid(target):
return "I can't attack that."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
message('{}, {}'.format(target, random.choice(rekts)))
@asyncio.coroutine
@hook.command
def kill(text, conn, nick, action):
"""<user> - kills <user>"""
target = text.strip()
if not is_valid(target):
return "I can't attack that."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
generator = textgen.TextGenerator(kills["templates"], kills["parts"], variables={"user": target})
# act out the message
action(generator.generate_string())
@asyncio.coroutine
@hook.command
def slap(text, action, nick, conn):
"""<user> -- Makes the bot slap <user>."""
target = text.strip()
if not is_valid(target):
return "I can't attack that."
if is_self(conn, target):
# user is trying to make the bot attack itself!
target = nick
variables = {
"user": target
}
generator = textgen.TextGenerator(slaps["templates"], slaps["parts"], variables=variables)
# act out the message
action(generator.generate_string())