Skip to content

Commit 70e8151

Browse files
committed
Update mcuser to have dashes in UUIDs, add limit to remind.py, remove dead code from correction. Closes #85
1 parent 67ce9b3 commit 70e8151

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

plugins/correction.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,3 @@ def correction(match, conn, chan, message):
3939
return
4040
else:
4141
continue
42-
return "Did not find {} in any recent messages.".format(to_find)
43-

plugins/minecraft_user.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import requests
3+
import uuid
34

45
from cloudbot import hook
56

@@ -12,46 +13,47 @@ def get_name(uuid):
1213
# submit the profile request
1314
request = requests.get(UUID_API.format(uuid))
1415
data = request.json()
15-
return data[uuid] or None
16+
return data[uuid]
1617

1718

1819
@hook.command("mcuser", "mcpaid", "haspaid")
1920
def mcuser(text, bot):
2021
"""<username> - gets information about the Minecraft user <account>"""
2122
headers = {'User-Agent': bot.user_agent}
22-
user = text.strip()
23+
text = text.strip()
2324

24-
cleaned = user.replace('-', '')
25-
if re.search(r'[0-9a-f]{32}\Z', cleaned, re.I):
25+
# check if we are looking up a UUID
26+
cleaned = text.replace('-', '')
27+
if re.search(r'^[0-9a-f]{32}\Z$', cleaned, re.I):
28+
# we are looking up a UUID, get a name.
2629
try:
2730
name = get_name(cleaned)
28-
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
31+
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, KeyError) as e:
2932
return "Could not get username from UUID: {}".format(e)
3033
else:
31-
name = user
34+
name = text
3235

33-
if not name:
34-
return "The account \x02{}\x02 does not exist.".format(user)
35-
36-
# submit the profile request
36+
# get user data from fishbans
3737
try:
3838
request = requests.get(HIST_API.format(requests.utils.quote(name)), headers=headers)
3939
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
4040
return "Could not get profile status: {}".format(e)
4141

42-
# get the fishbans data
42+
# read the fishbans data
4343
try:
4444
results = request.json()
4545
except ValueError:
4646
return "Could not parse profile status"
4747

48-
# handle errors
48+
# check for errors from fishbans and handle them
4949
if not results['success']:
5050
if results['error'] == "User is not premium.":
51-
return "The account \x02{}\x02 is not premium or does not exist.".format(user)
51+
return "The account \x02{}\x02 is not premium or does not exist.".format(text)
5252
else:
5353
return results['error']
54-
user = results["data"]
5554

56-
return 'The account \x02{username}\x02 ({uuid}) exists. It is a \x02paid\x02' \
57-
' account.'.format(**user)
55+
username = results['data']['username']
56+
id = uuid.UUID(results['data']['uuid'])
57+
58+
return 'The account \x02{}\x02 ({}) exists. It is a \x02paid\x02' \
59+
' account.'.format(username, id)

plugins/remind.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def delete_reminder(async, db, network, remind_time, added_user):
5252
def add_reminder(async, db, network, added_user, added_chan, message, remind_time, added_time):
5353
query = table.insert().values(
5454
network=network,
55-
added_user=added_user,
55+
added_user=added_user.lower(),
5656
added_time=added_time,
5757
added_chan=added_chan,
5858
message=message,
@@ -126,6 +126,8 @@ def remind(text, nick, chan, db, conn, notice, async):
126126
notice(remind.__doc__)
127127
return
128128

129+
count = [x for x in reminder_cache if x[0] == conn.name and x[3] == nick.lower()].count()
130+
129131
time_string = parts[0].strip()
130132
message = colors.strip_all(parts[1].strip())
131133

@@ -136,7 +138,10 @@ def remind(text, nick, chan, db, conn, notice, async):
136138
# parse the time input, return error if invalid
137139
seconds = time_parse(time_string)
138140
if not seconds:
139-
return "Invalid input"
141+
return "Invalid input."
142+
143+
if seconds > 2764800:
144+
return "I can't remind you of something more than (approximately) a month from now."
140145

141146
# work out the time to remind the user, and check if that time is in the past
142147
remind_time = datetime.fromtimestamp(current_epoch + seconds)

0 commit comments

Comments
 (0)