Skip to content

Commit

Permalink
use pretty usernames, predictable !help ordering (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbatalha authored Apr 1, 2024
1 parent 568884f commit d2e2fb3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions animal_crossing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def stalk_market(cmd):
- !stalks buy <value>: will add a new offer listed at <value> bells.
- !stalks sell: will list all currently available sell offers.
- !stalks sell <value>: will add a new offer listed at <value> bells.
- !stalks trigger <value>: will ping you if a new offer is listed above <value> bells.
- !stalks trigger <value>: will ping you if a new offer is listed above <value> bells.
''') # noqa: E501
return

Expand Down Expand Up @@ -88,7 +88,7 @@ def _stalk_list_buy_prices(cmd):
current_time = datetime.datetime.now(datetime.timezone.utc)
sunday = _date_to_sunday(current_time)
cur = db.execute('''
SELECT username, expiration, price FROM price
SELECT username, expiration, price FROM price
JOIN user ON user_id = user.id
WHERE week_local = ? AND week_index = 0
''', (str(sunday),))
Expand Down Expand Up @@ -182,7 +182,7 @@ def _stalk_check_sell_triggers(cmd, price, expires_in):
if triggers:
msg = ' '.join(['<@!%s>' % (x) for x in triggers])
msg += (': %s has reported a sell price of %s, above your configured trigger. Their offer will expire in %s.' %
(cmd.sender['username'], price, expires_in))
(cmd.sender['pretty_name'], price, expires_in))
cmd.reply(msg)

def _stalk_list_sale_prices(cmd):
Expand Down
3 changes: 3 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ def handle_message_create(self, d):
if len(lines) == 2:
arg += '\n' + lines[1]
cmd = CommandEvent(d, arg, self)
cmd.sender['pretty_name'] = cmd.d['member']['nick'] or \
cmd.sender['global_name'] or \
cmd.sender['username']
handler(cmd)

def handle_interaction_create(self, d):
Expand Down
6 changes: 3 additions & 3 deletions canned.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ def canned(cmd):
try:
name, text = split[1].split(' ', 1)
except IndexError:
cmd.reply('%s: missing args to `set`; %s' % (cmd.sender['username'], can_usage))
cmd.reply('%s: missing args to `set`; %s' % (cmd.sender['pretty_name'], can_usage))
return
except ValueError:
cmd.reply('%s: must specify can name and text' % cmd.sender['username'])
cmd.reply('%s: must specify can name and text' % cmd.sender['pretty_name'])
return
_can_set(cmd, name, text)
elif subcmd == 'del':
try:
name = split[1]
except IndexError:
cmd.reply('%s: missing args to `del`; %s' % (cmd.sender['username'], can_usage))
cmd.reply('%s: missing args to `del`; %s' % (cmd.sender['pretty_name'], can_usage))
return
_can_del(cmd, name)
else:
Expand Down
2 changes: 1 addition & 1 deletion code_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def reply(cmd, output):
output = output[:500]
if len(split) == 11:
output += '\n(too many output lines)'
message = cmd.sender['username'] + ':'
message = cmd.sender['pretty_name'] + ':'
output = '```\n%s```' % output
embed = {'description': output}
cmd.reply(message, embed)
6 changes: 3 additions & 3 deletions eve.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ def get_group_actives(entity_id, entity_type):
json=[cmd.args])
r.raise_for_status()
except requests.exceptions.HTTPError:
cmd.reply('{}: esi error'.format(cmd.sender['username']))
cmd.reply('{}: esi error'.format(cmd.sender['pretty_name']))
return

initial_id = r.json()
if len(initial_id) == 0:
cmd.reply("%s: couldn't find your sleazebag" % cmd.sender['username'])
cmd.reply("%s: couldn't find your sleazebag" % cmd.sender['pretty_name'])
return

corp_id = alliance_id = None
Expand All @@ -258,7 +258,7 @@ def get_group_actives(entity_id, entity_type):
try:
char_info, killed, lost = get_char_info(initial_id['characters'][0]['id'])
except requests.exceptions.HTTPError:
cmd.reply("%s: couldn't find your sleazebag" % cmd.sender['username'])
cmd.reply("%s: couldn't find your sleazebag" % cmd.sender['pretty_name'])

corp_id = char_info['corporation_id']
output += '{name} ({security:.2f}) [{killed}/{lost}]\n'.format(
Expand Down
2 changes: 1 addition & 1 deletion friend_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ def _user_remove(cmd):
''', (cmd.sender['id'],))

if cur.rowcount:
cmd.reply('Successfully removed friend code for %s.' % (cmd.sender['username']))
cmd.reply('Successfully removed friend code for %s.' % (cmd.sender['pretty_name']))
else:
cmd.reply('No friend code removed. Have you registered?')
2 changes: 1 addition & 1 deletion reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def headpat(cmd):
'image': {'url': image_url, 'width': image['width'], 'height': image['height']},
}
except Exception:
cmd.reply('%s: error getting an /r/headpat image' % cmd.sender['username'])
cmd.reply('%s: error getting an /r/headpat image' % cmd.sender['pretty_name'])
else:
cmd.reply('', embed)

Expand Down
14 changes: 7 additions & 7 deletions timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def timer(cmd):
name = options[0]['options'][0]['value']
_timer_del(cmd, name)
else:
raise AssertionError('unexpeced timer sub-command: %r' % subcmd)
raise AssertionError('unexpected timer sub-command: %r' % subcmd)
else:
if not cmd.args:
cmd.reply(timer_usage)
Expand All @@ -68,17 +68,17 @@ def timer(cmd):
try:
name, arg = split[1].rsplit(' in ', 1)
except IndexError:
cmd.reply('%s: missing args to `add`; %s' % (cmd.sender['username'], timer_usage))
cmd.reply('%s: missing args to `add`; %s' % (cmd.sender['pretty_name'], timer_usage))
return
except ValueError:
cmd.reply('%s: must specify timer name and time delta' % cmd.sender['username'])
cmd.reply('%s: must specify timer name and time delta' % cmd.sender['pretty_name'])
return
_timer_add(cmd, name, arg)
elif subcmd == 'del':
try:
name = split[1]
except IndexError:
cmd.reply('%s: missing args to `del`; %s' % (cmd.sender['username'], timer_usage))
cmd.reply('%s: missing args to `del`; %s' % (cmd.sender['pretty_name'], timer_usage))
return
_timer_del(cmd, name)
else:
Expand All @@ -98,7 +98,7 @@ def _timer_add(cmd, name, arg):
timers = config.state.timers.get(cmd.channel_id, {})
if name in timers:
time_str = format_dt(timers[name].replace(tzinfo=datetime.timezone.utc))
cmd.reply('%s: "%s" already set for %s' % (cmd.sender['username'], name, time_str))
cmd.reply('%s: "%s" already set for %s' % (cmd.sender['pretty_name'], name, time_str))
return

try: # parse as timestamp (981173106)
Expand All @@ -108,7 +108,7 @@ def _timer_add(cmd, name, arg):
try:
dt = parse_rel(arg)
except RelativeTimeParsingException as e:
cmd.reply('%s: %s' % (cmd.sender['username'], e.message))
cmd.reply('%s: %s' % (cmd.sender['pretty_name'], e.message))
return
dt = dt.replace(tzinfo=datetime.timezone.utc)

Expand All @@ -125,7 +125,7 @@ def _timer_del(cmd, name):
config.state.save()
cmd.reply('deleted "%s"' % name)
except KeyError:
cmd.reply('%s: couldn\'t find "%s" in this channel' % (cmd.sender['username'], name))
cmd.reply('%s: couldn\'t find "%s" in this channel' % (cmd.sender['pretty_name'], name))

def format_dt(dt):
ts = dt.timestamp()
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def help(cmd):
if cmd.args: # only reply on "!help"
return
commands = set(cmd.bot.commands.keys())
commands = list(cmd.bot.commands.keys())
guild_id = cmd.bot.channels[cmd.channel_id]
if config.bot.roles is None or guild_id != config.bot.roles['server']:
for name, func in cmd.bot.commands.items():
Expand Down Expand Up @@ -128,7 +128,7 @@ def roll(cmd):
result = split[1].split('=', 1)[1]
cmd.reply('%s %s' % (result, details))
except IndexError:
cmd.reply('%s: error rolling' % cmd.sender['username'])
cmd.reply('%s: error rolling' % cmd.sender['pretty_name'])

tzinfos = {
'PST': dateutil.tz.gettz('America/Los_Angeles'),
Expand Down Expand Up @@ -174,7 +174,7 @@ def weather(cmd):
response = rs.get(url)
response.raise_for_status()
except Exception:
cmd.reply('%s: error getting weather at %s' % (cmd.sender['username'], url),
cmd.reply('%s: error getting weather at %s' % (cmd.sender['pretty_name'], url),
{'description': '```%s```' % traceback.format_exc()[-500:]})
return
cmd.reply(None, files={'weather.png': response.content})
Expand Down

0 comments on commit d2e2fb3

Please sign in to comment.