Pārlūkot izejas kodu

Tweak !remind all a bit.

tags/v0.3
Ben Kurtovic pirms 9 gadiem
vecāks
revīzija
941cc2c00a
1 mainītis faili ar 22 papildinājumiem un 14 dzēšanām
  1. +22
    -14
      earwigbot/commands/remind.py

+ 22
- 14
earwigbot/commands/remind.py Parādīt failu

@@ -220,17 +220,20 @@ class Remind(Command):

def _show_reminders(self, data, user):
"""Show all of a user's current reminders."""
if user not in self.reminders:
self.reply(data, "You have no reminders. Set one with "
"\x0306!remind [time] [message]\x0F. See also: "
"\x0306!remind help\x0F.")
return

shorten = lambda s: (s[:37] + "..." if len(s) > 40 else s)
fmt = lambda robj: '\x0303{0}\x0F ("{1}", {2})'.format(
robj.id, shorten(robj.message), robj.end_time)
dest = lambda data: (
"privately" if data.is_private else "in {0}".format(data.chan))
fmt = lambda robj: '\x0303{0}\x0F ("{1}" {2}, {3})'.format(
robj.id, shorten(robj.message), dest(robj.data), robj.end_time)

if user in self.reminders:
rlist = ", ".join(fmt(robj) for robj in self.reminders[user])
msg = "Your reminders: {0}.".format(rlist)
else:
msg = ("You have no reminders. Set one with \x0306!remind [time] "
"[message]\x0F. See also: \x0306!remind help\x0F.")
self.reply(data, msg)
rlist = ", ".join(fmt(robj) for robj in self.reminders[user])
self.reply(data, "Your reminders: {0}.".format(rlist))

def _show_all_reminders(self, data):
"""Show all reminders to bot admins."""
@@ -243,14 +246,14 @@ class Remind(Command):
self.reply(data, "There are no active reminders.")
return

shorten = lambda s: (s[:37] + "..." if len(s) > 40 else s)
fmt = lambda robj, user: '\x0303{0}\x0F ("{1}" for {2}, {3})'.format(
robj.id, shorten(robj.message), user, robj.end_time)
dest = lambda data: (
"privately" if data.is_private else "in {0}".format(data.chan))
fmt = lambda robj, user: '\x0303{0}\x0F (for {1} {2}, {3})'.format(
robj.id, user, dest(robj.data), robj.end_time)

rlist = (fmt(rem, user) for user, rems in self.reminders.iteritems()
for rem in rems)
msg = "All reminders: {0}.".format(", ".join(rlist))
self.reply(data, msg)
self.reply(data, "All reminders: {0}.".format(", ".join(rlist)))

def _process_snooze_command(self, data, user):
"""Process the !snooze command."""
@@ -421,6 +424,11 @@ class _Reminder(object):
self._cmdobj.unstore_reminder(self.id)

@property
def data(self):
"""Return the IRC data object associated with this reminder."""
return self._data

@property
def end_time(self):
"""Return a string representing the end time of a reminder."""
if self.end >= time.time():


Notiek ielāde…
Atcelt
Saglabāt