diff --git a/animal_crossing.py b/animal_crossing.py index a9e0108..75c938c 100644 --- a/animal_crossing.py +++ b/animal_crossing.py @@ -22,7 +22,7 @@ def stalk_market(cmd): - !stalks buy : will add a new offer listed at bells. - !stalks sell: will list all currently available sell offers. - !stalks sell : will add a new offer listed at bells. -- !stalks trigger : will ping you if a new offer is listed above bells. +- !stalks trigger : will ping you if a new offer is listed above bells. ''') # noqa: E501 return @@ -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),)) @@ -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): diff --git a/bot.py b/bot.py index 84214f0..5605624 100644 --- a/bot.py +++ b/bot.py @@ -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): diff --git a/canned.py b/canned.py index 1b9f43b..a8086c3 100644 --- a/canned.py +++ b/canned.py @@ -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: diff --git a/code_eval.py b/code_eval.py index c24db85..8b6f33b 100644 --- a/code_eval.py +++ b/code_eval.py @@ -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) diff --git a/eve.py b/eve.py index 40821a1..f6edfcb 100644 --- a/eve.py +++ b/eve.py @@ -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 @@ -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( diff --git a/friend_code.py b/friend_code.py index d11690f..ebd83f2 100644 --- a/friend_code.py +++ b/friend_code.py @@ -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?') diff --git a/reddit.py b/reddit.py index 5ad85ae..d10b79b 100644 --- a/reddit.py +++ b/reddit.py @@ -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) diff --git a/timer.py b/timer.py index 07b0266..f872a36 100644 --- a/timer.py +++ b/timer.py @@ -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) @@ -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: @@ -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) @@ -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) @@ -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() diff --git a/utils.py b/utils.py index 3ca31ac..b669b6b 100644 --- a/utils.py +++ b/utils.py @@ -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(): @@ -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'), @@ -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})