Skip to content

Commit e3bba6e

Browse files
committed
Switch attacks.py to new nick checks
1 parent f16352a commit e3bba6e

1 file changed

Lines changed: 29 additions & 34 deletions

File tree

plugins/attacks.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1+
import asyncio
12
import codecs
23
import json
34
import os
45
import random
5-
import asyncio
66
import re
77

88
from cloudbot import hook
99
from cloudbot.util import textgen
1010

11-
nick_re = re.compile("^[A-Za-z0-9_|.\-\]\[\{\}]*$", re.I)
12-
13-
14-
def is_valid(target):
15-
""" Checks if a string is a valid IRC nick. """
16-
if nick_re.match(target):
17-
return True
18-
else:
19-
return False
20-
2111

2212
def is_self(conn, target):
2313
""" Checks if a string is "****self" or contains conn.name. """
@@ -64,11 +54,11 @@ def load_attacks(bot):
6454

6555
@asyncio.coroutine
6656
@hook.command
67-
def lart(text, conn, nick, action):
57+
def lart(text, conn, nick, action, is_nick_valid):
6858
"""<user> - LARTs <user>"""
6959
target = text.strip()
7060

71-
if not is_valid(target):
61+
if not is_nick_valid(target):
7262
return "I can't lart that."
7363

7464
if is_self(conn, target):
@@ -83,11 +73,11 @@ def lart(text, conn, nick, action):
8373

8474
@asyncio.coroutine
8575
@hook.command("flirt", "sexup", "jackmeoff")
86-
def flirt(text, conn, nick, message):
76+
def flirt(text, conn, nick, message, is_nick_valid):
8777
"""<user> - flirts with <user>"""
8878
target = text.strip()
8979

90-
if not is_valid(target):
80+
if not is_nick_valid(target):
9181
return "I can't flirt with that."
9282

9383
if is_self(conn, target):
@@ -99,11 +89,11 @@ def flirt(text, conn, nick, message):
9989

10090
@asyncio.coroutine
10191
@hook.command("kill", "end")
102-
def kill(text, conn, nick, action):
92+
def kill(text, conn, nick, action, is_nick_valid):
10393
"""<user> - kills <user>"""
10494
target = text.strip()
10595

106-
if not is_valid(target):
96+
if not is_nick_valid(target):
10797
return "I can't attack that."
10898

10999
if is_self(conn, target):
@@ -118,11 +108,11 @@ def kill(text, conn, nick, action):
118108

119109
@asyncio.coroutine
120110
@hook.command
121-
def slap(text, action, nick, conn):
111+
def slap(text, action, nick, conn, is_nick_valid):
122112
"""<user> -- Makes the bot slap <user>."""
123113
target = text.strip()
124114

125-
if not is_valid(target):
115+
if not is_nick_valid(target):
126116
return "I can't slap that."
127117

128118
if is_self(conn, target):
@@ -140,11 +130,11 @@ def slap(text, action, nick, conn):
140130

141131
@asyncio.coroutine
142132
@hook.command
143-
def compliment(text, action, nick, conn):
133+
def compliment(text, action, nick, conn, is_nick_valid):
144134
"""<user> -- Makes the bot compliment <user>."""
145135
target = text.strip()
146136

147-
if not is_valid(target):
137+
if not is_nick_valid(target):
148138
return "I can't compliment that."
149139

150140
if is_self(conn, target):
@@ -159,20 +149,21 @@ def compliment(text, action, nick, conn):
159149
# act out the message
160150
action(generator.generate_string())
161151

152+
162153
@hook.command(autohelp=False)
163-
def strax(text, conn, message, nick):
154+
def strax(text, conn, message, nick, is_nick_valid):
164155
"""Strax quote."""
165156

166157
if text:
167158
target = text.strip()
168-
if not is_valid(target):
169-
return "I can't do that."
159+
if not is_nick_valid(target):
160+
return "I can't do that."
170161

171162
if is_self(conn, target):
172-
# user is trying to make the bot attack itself!
173-
target = nick
163+
# user is trying to make the bot attack itself!
164+
target = nick
174165
variables = {
175-
"user": target
166+
"user": target
176167
}
177168

178169
generator = textgen.TextGenerator(strax["target_template"], strax["parts"], variables=variables)
@@ -182,24 +173,26 @@ def strax(text, conn, message, nick):
182173
# Become Strax
183174
message(generator.generate_string())
184175

176+
185177
@hook.command(autohelp=False)
186178
def nk(chan, message):
187179
"""outputs a random North Korea propoganda slogan"""
188-
index = random.randint(0,len(north_korea)-1)
180+
index = random.randint(0, len(north_korea) - 1)
189181
slogan = north_korea[index]
190182
message(slogan, chan)
191183

184+
192185
@asyncio.coroutine
193186
@hook.command()
194-
def insult(text, conn, nick, notice, message):
187+
def insult(text, conn, nick, notice, message, is_nick_valid):
195188
"""<user> - insults <user>
196189
:type text: str
197190
:type conn: cloudbot.client.Client
198191
:type nick: str
199192
"""
200193
target = text.strip()
201194

202-
if " " in target:
195+
if not is_nick_valid(target):
203196
notice("Invalid username!")
204197
return
205198

@@ -209,20 +202,22 @@ def insult(text, conn, nick, notice, message):
209202

210203
message("{}, {}".format(target, random.choice(insults)))
211204

205+
212206
@asyncio.coroutine
213207
@hook.command("present", "gift")
214-
def present(text, conn, nick, action):
208+
def present(text, conn, nick, action, is_nick_valid):
215209
"""<user> - gives gift to <user>"""
216210
target = text.strip()
217211

218-
if not is_valid(target):
212+
if not is_nick_valid(target):
219213
return "I can't gift that."
220214

221215
if is_self(conn, target):
222-
#user is trying to make the bot gift itself!
216+
# user is trying to make the bot gift itself!
223217
target = nick
218+
224219
variables = {
225-
"user": target
220+
"user": target
226221
}
227222

228223
generator = textgen.TextGenerator(presents["templates"], presents["parts"], variables=variables)

0 commit comments

Comments
 (0)