示例#1
0
    def run(self, args, conn):
        if conn.user.is_muted:
            conn.write(_('You are muted.\n'))
            return
        u2 = yield find_user.by_prefix_for_user(args[0], conn)
        # XXX maybe this check should be combined with the one in 'message'
        if u2:
            u2censor = yield u2.get_censor()
            if conn.user.name in u2censor and not conn.user.is_admin():
                conn.write(_('%s is censoring you.\n') % u2.name)
                return
            msgs = yield db.get_messages_range(conn.user.id_, args[1], args[1])
            if msgs:
                msg = msgs[0]
                message_id = msg['message_id']
                msg['forwarder_name'] = conn.user.name
                yield db.forward_message(conn.user.id_, u2.id_, message_id)
                msg_str_u2 = self._format_msg(msg,
                                              u2)  # localized for receiver

                if u2.vars_['mailmess']:
                    email.send_mail(conn.user, u2, msg_str_u2)
                    conn.write(
                        _('The following message was forwarded and emailed to %s:\n'
                          ) % u2.name)
                else:
                    conn.write(
                        _('The following message was forwarded to %s:\n') %
                        u2.name)
                if u2.is_online:
                    u2.write_('The following message was received:\n')
                    u2.write(msg_str_u2)
                self._write_msg(msg, conn.user)
            else:
                conn.write(_('There is no such message.\n'))
示例#2
0
    def run(self, args, conn):
        if args[0] is None:
            conn.write(
                _('Use "clearmessages *" to clear all your messages.\n'))
            return

        if args[0] == '*':
            count = yield db.clear_messages_all(conn.user.id_)
        elif isinstance(args[0], (int, long)):
            i = int(args[0])
            count = yield db.clear_messages_range(conn.user.id_, i, i)
            if count == 0:
                conn.write(_('There is no such message.\n'))
                return
        else:
            m = self.range_re.match(args[0])
            if m:
                (start, end) = (int(m.group(1)), int(m.group(2)))
                # sanity checks
                if start < 1 or start > end or end > 9999:
                    conn.write(_('Invalid message range.\n'))
                    return
                count = yield db.clear_messages_range(conn.user.id_, start,
                                                      end)
            else:
                sender = yield find_user.by_prefix_for_user(args[0], conn)
                if not sender:
                    return
                count = yield db.clear_messages_from_to(
                    sender.id_, conn.user.id_)

        conn.write(
            ngettext('Cleared %d message.\n', 'Cleared %d messages.\n', count)
            % count)
示例#3
0
 def sub(self, item, conn):
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.name not in conn.user.noplay:
             raise ListError(_('%s is not on your noplay list.\n') % u.name)
         yield conn.user.remove_noplay(u)
         conn.write(_('%s removed from your noplay list.\n') % (u.name))
示例#4
0
 def run(self, args, conn):
     u = None
     if args[0] is not None:
         u = yield find_user.by_prefix_for_user(args[0], conn)
     else:
         u = conn.user
     if u:
         yield history.show_for_user(u, conn)
示例#5
0
 def add(self, item, conn):
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.name in conn.user.noplay:
             raise ListError(
                 _('%s is already on your noplay list.\n') % u.name)
         yield conn.user.add_noplay(u)
         conn.write(_('%s added to your noplay list.\n') % u.name)
示例#6
0
    def run(self, args, conn):
        if conn.user.session.game:
            if conn.user.session.game.gtype == EXAMINED:
                conn.write(_("You are already examining a game.\n"))
            else:
                conn.write(_("You are playing a game.\n"))
            return

        if args[0] is None:
            conn.write(_("Starting a game in examine (scratch) mode.\n"))
            e = examine.ExaminedGame(conn.user)
            yield e.finish_init(conn.user)
            return

        if args[0] == 'b':
            conn.write('TODO: EXAMINE SCRATCH BOARD\n')
            return

        u = yield find_user.by_prefix_for_user(args[0], conn)
        if not u:
            return

        if args[1] is None:
            conn.write('TODO: EXAMINE ADJOURNED GAME\n')
            return

        try:
            num = int(args[1])
            # history game
            h = u.get_history_game(num, conn)
            if h:
                e = examine.ExaminedGame(conn.user, h)
                yield e.finish_init(conn.user)
            return
        except ValueError:
            m = re.match(r'%(\d\d?)', args[1])
            if m:
                num = int(m.group(1))
                conn.write('TODO: EXAMINE JOURNAL GAME\n')
                return

            u2 = yield find_user.by_prefix_for_user(args[1], conn)
            if not u2:
                return
            conn.write('TODO: EXAMINE ADJOURNED GAME\n')
示例#7
0
 def sub(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if not u.is_muted:
             raise ListError(_('%s is not on the mute list.\n') % u.name)
         yield u.set_muted(False)
         if not u.is_guest:
             yield db.add_comment(conn.user.id_, u.id_, 'Unmuted.')
         self._notify_removed(conn, u)
示例#8
0
 def sub(self, item, conn):
     if conn.user.is_guest:
         raise ListError(
             _('Only registered players can have notify lists.\n'))
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.name not in conn.user.notifiers:
             raise ListError(_('%s is not on your notify list.\n') % u.name)
         yield conn.user.remove_notification(u)
         conn.write(_('%s removed from your notify list.\n') % u.name)
示例#9
0
 def run(self, args, conn):
     if args[0] is not None:
         u2 = yield find_user.by_prefix_for_user(args[0], conn)
     else:
         u2 = conn.user
     if u2:
         log = yield u2.get_log()
         if not log:
             conn.write('%s has not logged on.\n' % u2.name)
         else:
             self._display_log(log, conn)
示例#10
0
 def sub(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_guest:
             raise ListError(A_('Only registered players can be banned.\n'))
         if not u.is_banned:
             raise ListError(_('%s is not on the ban list.\n') % u.name)
         yield u.set_banned(False)
         yield db.add_comment(conn.user.id_, u.id_, 'Unbanned.')
         self._notify_removed(conn, u)
示例#11
0
 def run(self, args, conn):
     (chid, name) = args
     u = yield find_user.by_prefix_for_user(name, conn)
     if not u:
         return
     try:
         ch = yield global_.channels.get(chid)
     except KeyError:
         conn.write(_('Invalid channel number.\n'))
         return
     yield ch.kick(u, conn.user)
示例#12
0
 def add(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_admin():
             raise ListError(A_('Admins cannot be playbanned.\n'))
         if u.is_playbanned:
             raise ListError(
                 _('%s is already on the playban list.\n') % u.name)
         yield u.set_playbanned(True)
         if not u.is_guest:
             yield db.add_comment(conn.user.id_, u.id_, 'Playbanned.')
         self._notify_added(conn, u)
示例#13
0
 def sub(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_guest:
             raise ListError(_("Only registered users may have titles.\n"))
         if not u.has_title(self.name):
             raise ListError(
                 _('%(uname)s is not on the %(lname)s list.\n') % {
                     'uname': u.name,
                     'lname': self.name
                 })
         yield u.remove_title(self.id_)
         self._notify_removed(conn, u)
示例#14
0
    def run(self, args, conn):
        u = None

        if args[0] is not None:
            u = yield find_user.by_prefix_for_user(args[0], conn)
        else:
            u = conn.user
        if u:

            if u.is_guest:
                conn.write(_('Only registered players may have stored games.\n'))
            else:
                adjourned = yield u.get_adjourned()

                if not adjourned:
                    conn.write(_('%s has no adjourned games.\n') % u.name)
                    return

                conn.write(_('Stored games for %s:\n') % u.name)
                conn.write(_('    C Opponent       On Type          Str  M    ECO Date\n'))

                i = 1

                for entry in adjourned:
                    entry['id'] = i

                    is_white = entry['white_user_id'] == u.id_
                    entry['user_color'] = is_white and 'W' or 'B'

                    opp_name = (entry['black_name'] if is_white
                        else entry['white_name'])
                    entry['opp_str'] = opp_name[:15]

                    entry['online'] = "Y" if global_.online.is_online(opp_name) else "N"

                    flags = entry['speed_abbrev'] + entry['variant_abbrev']
                    entry['flags'] = flags + 'r' if entry['is_rated'] else 'u'

                    half_moves = entry['movetext'].count(' ') + 1
                    next_move_color = "B" if half_moves % 2 else "W"
                    next_move_number = half_moves // 2 + 1
                    entry['next_move'] = "%s%d" % (next_move_color,
                        next_move_number)

                    entry['eco'] = entry['eco'][:3]
                    entry['when_adjourned_str'] = u.format_datetime(entry['when_ended'])
                    conn.write('%(id)2d: %(user_color)1s %(opp_str)-15s %(online)s [%(flags)3s%(time)3s %(inc)3s] %(white_material)2s-%(black_material)-2s %(next_move)-4s %(eco)s %(when_adjourned_str)-s\n' %
                        entry)
                    i = i + 1
示例#15
0
 def add(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_guest:
             raise ListError(
                 A_('Only registered players can be c-muzzled.\n'))
         if u.is_admin():
             raise ListError(A_('Admins cannot be c-muzzled.\n'))
         if u.is_cmuzzled:
             raise ListError(
                 _('%s is already on the cmuzzle list.\n') % u.name)
         yield u.set_cmuzzled(True)
         yield db.add_comment(conn.user.id_, u.id_, 'C-muzzled.')
         self._notify_added(conn, u)
示例#16
0
    def add(self, item, conn):
        self._require_admin(conn.user)
        u = yield find_user.by_prefix_for_user(item, conn)
        if u:
            if u.is_guest:
                raise ListError(_("Only registered users may have titles.\n"))

            try:
                yield u.add_title(self.id_)
            except db.DuplicateKeyError:
                raise ListError(
                    _('%(uname)s is already on the %(lname)s list.\n') % {
                        'uname': u.name,
                        'lname': self.name
                    })
            self._notify_added(conn, u)
示例#17
0
 def add(self, item, conn):
     if conn.user.is_guest:
         raise ListError(
             _('Only registered players can have gnotify lists.\n'))
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u == conn.user:
             raise ListError(_('You cannot gnotify yourself.\n'))
         if u.is_guest:
             raise ListError(
                 _('You cannot add an unregistered user to your gnotify list.\n'
                   ))
         if u.name in conn.user.gnotifiers:
             raise ListError(
                 _('[%s] is already on your gnotify list.\n') % u.name)
         yield conn.user.add_gnotification(u)
         conn.write(_('[%s] added to your gnotify list.\n') % u.name)
示例#18
0
 def add(self, item, conn):
     if conn.user.is_guest:
         raise ListError(
             _('Only registered players can have notify lists.\n'))
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u == conn.user:
             raise ListError(_('You cannot notify yourself.\n'))
         if u.is_guest:
             raise ListError(
                 _('You cannot add an unregistered user to your notify list.\n'
                   ))
         if u.name in conn.user.notifiers:
             raise ListError(
                 _('%s is already on your notify list.\n') % u.name)
         yield conn.user.add_notification(u)
         conn.write(_('%s added to your notify list.\n') % u.name)
         if u.is_online and u.vars_['notifiedby']:
             # new feature: inform the added user
             u.write_('\nYou have been added to the notify list of %s.\n',
                      (conn.user.name, ))
示例#19
0
    def run(self, args, conn):
        if args[0] is None:
            u = conn.user
        else:
            u = yield find_user.by_prefix_for_user(args[0], conn)

        if not u:
            return

        u.vars_['disp_tzone'] = u.vars_['tzone'][0:8] if (
            u == conn.user or conn.user.is_admin()) else '???'

        conn.write(_("Variable settings of %s:\n\n") % u.name)
        conn.write(
            'time=%(time)d       private=?     shout=%(shout)d         pin=%(pin)d           style=%(style)d \n'
            % u.vars_)
        conn.write(
            'inc=%(inc)d       jprivate=?    cshout=%(cshout)d        notifiedby=%(notifiedby)d    flip=?\n'
            % u.vars_)
        conn.write(
            'rated=?                    kibitz=%(kibitz)d        availinfo=?     highlight=?\n'
            % u.vars_)
        conn.write(
            'open=%(open)d       automail=?    kiblevel=?      availmin=?      bell=%(bell)d\n'
            % u.vars_)
        conn.write(
            'pgn=?        tell=%(tell)d        availmax=?      width=%(width)d \n'
            % u.vars_)
        conn.write(
            'bugopen=%(bugopen)d                  ctell=%(ctell)d         gin=%(gin)d           height=%(height)d \n'
            % u.vars_)
        conn.write(
            'mailmess=%(mailmess)d                 seek=%(seek)d          ptime=%(ptime)d\n'
            % u.vars_)
        conn.write(
            'tourney=?    messreply=?   chanoff=%(chanoff)d       showownseek=%(showownseek)d   tzone=%(disp_tzone)s\n'
            % u.vars_)
        conn.write(
            'provshow=?                 silence=%(silence)d                       Lang=%(lang)s\n'
            % u.vars_)
        conn.write(
            'autoflag=%(autoflag)d   unobserve=?   echo=?          examine=%(examine)d\n'
            % u.vars_)
        conn.write(
            'minmovetime=%(minmovetime)d              tolerance=?     noescape=%(noescape)d      notakeback=%(notakeback)d\n'
            % u.vars_)

        if u.is_online:
            conn.write(_('\nPrompt: %s\n') % u.vars_['prompt'])
            if u.vars_['interface']:
                conn.write(_('Interface: %s\n') % u.vars_['interface'])
            if u.session.partner:
                conn.write(
                    _('Bughouse partner: %s\n') % u.session.partner.name)
            if u.session.following:
                if u.session.pfollow:
                    conn.write(
                        _("Following: %s's partner\n") % u.session.following)
                else:
                    conn.write(_("Following: %s\n") % u.session.following)

        for i in range(1, 10):
            fname = 'f' + str(i)
            if u.vars_[fname]:
                conn.write(' %s: %s\n' % (fname, u.vars_[fname]))
        if u.vars_['formula']:
            conn.write('Formula: %s\n' % u.vars_['formula'])
        conn.write("\n")
示例#20
0
    def run(self, args, conn):
        out = []

        # defaults
        show_notes = True
        show_ratings = True
        show_comments = False
        rating_variants = None

        if args[0] is None:
            u = conn.user
        else:
            u = yield find_user.by_prefix_for_user(args[0], conn)
            if u:
                if args[1] and args[1][0] == '/':
                    # original FICS excepts things like 'b' here for blitz,
                    # but since we separate the speed and variant
                    # we only allow specifying the variant
                    try:
                        rating_variants = [speed_variant.variant_abbrevs[c] for c in args[1][1:]]
                    except KeyError:
                        # unknown variant
                        raise BadCommandError

                    flags = args[2]
                else:
                    flags = args[1]
                    if flags:
                        flags = flags.lower()

                if flags:
                    # specify notes, ratings, or comments
                    show_ratings = False
                    show_notes = False
                    show_comments = False
                    for f in flags:
                        if f == 'r':
                            show_ratings = True
                        elif f == 'n':
                            show_notes = True
                        elif f == 'c' and conn.user.is_admin():
                            show_comments = True
                        else:
                            raise BadCommandError

        if u:
            show_admin_info = (conn.user.is_admin() and
                not conn.user.vars_['hideinfo'])
            out.append(_('Finger of %s:\n\n') % u.get_display_name())

            if u.is_online:
                out.append(_('On for: %s   Idle: %s\n')
                    % (time_format.hms_words(u.session.get_online_time()),
                        time_format.hms_words(u.session.get_idle_time())))
                if u.vars_['busy']:
                    out.append(_('(%(name)s %(busy)s)\n' % {
                        'name': u.name, 'busy': u.vars_['busy']}))
                if u.vars_['silence']:
                    out.append(_('%s is in silence mode.\n') % u.name)

                if u.session.game:
                    g = u.session.game
                    if g.gtype == PLAYED:
                        out.append(_('(playing game %d: %s vs. %s)\n') % (g.number, g.white.name, g.black.name))
                    elif g.gtype == EXAMINED:
                        out.append(_('(examining game %d)\n') % (g.number))
                    else:
                        assert(False)
            else:
                assert(not u.is_guest)
                if u.last_logout is None:
                    out.append(_('%s has never connected.\n') % u.name)
                else:
                    out.append(_('Last disconnected: %s\n') %
                        u.last_logout.replace(tzinfo=pytz.utc).astimezone(conn.user.tz).strftime('%Y-%m-%d %H:%M %Z'))

            out.append('\n')

            if u.is_guest:
                # The open source release of FICS, Lasker, and BICS print
                # this message, but more recent versions of FICS do not.
                out.append(_('%s is NOT a registered player.\n') % u.name)
            if show_ratings and not u.is_guest:
                ratings = yield rating.show_ratings(u, conn, rating_variants)
                out.extend(ratings)
            if u.admin_level > admin.Level.user:
                out.append(A_('Admin level: %s\n') % admin.level.to_str(u.admin_level))
            if show_admin_info:
                if not u.is_guest:
                    out.append(A_('Real name:   %s\n') % u.real_name)
                if u.is_online:
                    out.append(A_('Host:        %s\n') % u.session.conn.ip)
                if not u.is_guest:
                    count = yield db.count_comments(u.id_)
                    out.append(A_('Comments:    %s\n') % count)

            if u == conn.user or show_admin_info:
                if not u.is_guest:
                    out.append(_('Email:       %s\n\n') % u.email)
                    if u.first_login:
                        total = u.get_total_time_online()
                        first = calendar.timegm(u.first_login.timetuple()) + (
                            1e-6 * u.first_login.microsecond)
                        perc = round(100 * total // (time.time() - first), 1)
                        out.append(_('Total time online: %s\n') % time_format.hms_words(total, round_secs=True))
                        since = time.strftime("%a %b %e, %H:%M %Z %Y", time.gmtime(first))
                        # should be equivalent: since = u.first_login.replace(tzinfo=pytz.utc).astimezone(conn.user.tz).strftime('%a %b %e, %H:%M %Z %Y')
                        out.append(_('%% of life online:  %3.1f (since %s)\n\n') % (perc, since))

            if u.is_online:
                if u.session.use_zipseal:
                    out.append(_('Zipseal:     On\n'))
                elif u.session.use_timeseal:
                    if u.session.timeseal_version == 1:
                        out.append(_('Timeseal 1:  On\n'))
                    elif u.session.timeseal_version == 2:
                        out.append(_('Timeseal 2:  On\n'))
                else:
                    out.append(_('Zipseal:     Off\n'))
                if show_admin_info and (u.session.use_timeseal or
                        u.session.use_zipseal):
                    out.append(A_('Acc:         %s\n') % u.session.timeseal_acc)
                    out.append(A_('System:      %s\n') % u.session.timeseal_system)

            notes = u.notes
            if (not u.is_guest and u.is_notebanned and u != conn.user
                    and not show_admin_info):
                # hide notes
                notes = []
            if notes and show_notes:
                out.append('\n')
                prev_max = 0
                for (num, txt) in sorted(notes.iteritems()):
                    num = int(num)
                    assert(num >= prev_max + 1)
                    assert(num <= 10)
                    if num > prev_max + 1:
                        # fill in blank lines
                        for j in range(prev_max + 1, num):
                            out.append(_("%2d: %s\n") % (j, ''))
                    out.append(_("%2d: %s\n") % (num, txt))
                    prev_max = num
                out.append('\n')

            conn.write(''.join(out))

            if show_comments:
                yield admin_command.show_comments(conn, u)
示例#21
0
    def run(self, args, conn):
        if args[0] is None:
            # display all messages
            msgs = yield db.get_messages_all(conn.user.id_)
            if not msgs:
                conn.write(_('You have no messages.\n'))
            else:
                conn.write(_('Messages:\n'))
                for msg in msgs:
                    conn.write(_('%d. ') % (msg['num']))
                    self._write_msg(msg, conn.user)
                yield db.set_messages_read_all(conn.user.id_)
        elif args[0] == 'u':
            if args[1] is not None:
                raise BadCommandError
            msgs = yield db.get_messages_unread(conn.user.id_)
            if not msgs:
                conn.write(_('You have no unread messages.\n'))
            else:
                conn.write(_('Unread messages:\n'))
                for msg in msgs:
                    conn.write(_('%d. ') % (msg['num']))
                    self._write_msg(msg, conn.user)
                yield db.set_messages_read_all(conn.user.id_)
        elif args[1] is None:
            # display some messages
            try:
                i = int(args[0])
                msgs = yield db.get_messages_range(conn.user.id_, i, i)
                if not msgs:
                    conn.write(_('There is no such message.\n'))
                    return
            except ValueError:
                m = self.range_re.match(args[0])
                if m:
                    (start, end) = (int(m.group(1)), int(m.group(2)))
                    # sanity checks
                    if start < 1 or start > end or end > 9999:
                        conn.write(_('Invalid message range.\n'))
                        return
                    msgs = yield db.get_messages_range(conn.user.id_, start,
                                                       end)
                else:
                    u2 = yield find_user.by_prefix_for_user(args[0], conn)
                    if not u2:
                        return
                    if u2.is_guest:
                        conn.write(
                            _('Only registered players can have messages.\n'))
                        return
                    msgs = yield db.get_messages_from_to(conn.user.id_, u2.id_)
                    if not msgs:
                        conn.write(
                            _('You have no messages to %s.\n') % u2.name)
                    else:
                        conn.write(_('Messages to %s:\n') % u2.name)
                        for msg in msgs:
                            self._write_msg(msg, conn.user)
                    conn.write('\n')

                    msgs = yield db.get_messages_from_to(u2.id_, conn.user.id_)
                    if not msgs:
                        conn.write(
                            _('You have no messages from %s.\n') % u2.name)
                        return
                    else:
                        conn.write(_('Messages from %s:\n') % u2.name)

            for msg in msgs:
                conn.write(_('%d. ') % (msg['num']))
                self._write_msg(msg, conn.user)
                if msg['unread']:
                    yield db.set_message_read(msg['message_id'])
        else:
            """ Send a message.  Note that the message may be localized
            differently for the sender and receiver. """
            to = yield find_user.by_prefix_for_user(args[0], conn)
            if to:
                if conn.user.is_muted:
                    conn.write(_('You are muted.\n'))
                    return
                if to.is_guest:
                    conn.write(
                        _('Only registered players can have messages.\n'))
                    return
                tocensor = yield to.get_censor()
                if conn.user.name in tocensor and not conn.user.is_admin():
                    conn.write(_('%s is censoring you.\n') % to.name)
                    return
                message_id = yield db.send_message(conn.user.id_, to.id_,
                                                   args[1])
                msg = yield db.get_message(message_id)
                msg_str_to = self._format_msg(msg,
                                              to)  # localized for receiver

                if to.vars_['mailmess']:
                    email.send_mail(conn.user, to, msg_str_to)
                    conn.write(
                        _('The following message was sent and emailed to %s:\n'
                          ) % to.name)
                else:
                    conn.write(
                        _('The following message was sent to %s:\n') % to.name)
                self._write_msg(msg, conn.user)

                if to.is_online:
                    to.write_('The following message was received:\n')
                    to.write(msg_str_to)