def prompt_tags(msg): """ Prompt for and return tags wished for message. """ # pylint: disable=R0914,W0603 # Too many local variables # Using the global statement from x84.bbs import DBProxy, echo, getterminal, getsession from x84.bbs import Ansi, LineEditor session, term = getsession(), getterminal() tagdb = DBProxy('tags') msg_onlymods = (u"\r\nONlY MEMbERS Of thE '%s' OR '%s' " "GROUP MAY CREAtE NEW tAGS." % ( term.bold_yellow('sysop'), term.bold_blue('moderator'),)) msg_invalidtag = u"\r\n'%s' is not a valid tag." prompt_tags1 = u"ENtER %s, COMMA-dEliMitEd. " % ( term.bold_red('TAG(s)'),) prompt_tags2 = u"OR '/list', %s:quit\r\n : " % ( term.bold_yellow_underline('Escape'),) while True: # Accept user input for multiple 'tag's, or /list command echo(u'\r\n\r\n') echo(prompt_tags1) echo(prompt_tags2) width = term.width - 6 sel_tags = u', '.join(msg.tags) inp_tags = LineEditor(width, sel_tags).read() if inp_tags is not None and 0 == len(inp_tags.strip()): # no tags must be (private ..) msg.tags = set() return True if inp_tags is None or inp_tags.strip().lower() == '/quit': return False elif inp_tags.strip().lower() == '/list': # list all available tags, and number of messages echo(u'\r\n\r\nTags: \r\n') all_tags = sorted(tagdb.items()) if 0 == len(all_tags): echo(u'None !'.center(term.width / 2)) else: echo(Ansi(u', '.join(([u'%s(%d)' % (_key, len(_value),) for (_key, _value) in all_tags])) ).wrap(term.width - 2)) continue echo(u'\r\n') # search input as valid tag(s) tags = set([inp.strip().lower() for inp in inp_tags.split(',')]) err = False for tag in tags.copy(): if not tag in tagdb and not ( 'sysop' in session.user.groups or 'moderator' in session.user.groups): tags.remove(tag) echo(msg_invalidtag % (term.bold_red(tag),)) err = True if err: echo(msg_onlymods) continue msg.tags = tags return True
def prompt_tags(session, term, msg, colors, public=True): xpos = max(0, (term.width // 2) - (80 // 2)) # conditionally enforce tag moderation moderated = get_ini("msg", "moderated_tags", getter="getboolean") tag_moderators = set(get_ini("msg", "tag_moderators", split=True)) # enforce 'public' tag if public and "public" not in msg.tags: msg.tags.add("public") elif not public and "public" in msg.tags: msg.tags.remove("public") # describe all available tags, as we oft want to do. do_describe_available_tags(term, colors) # and remind ourselves of the available network tags, description = get_network_tag_description(term, colors) if description: show_description(term=term, color=None, description=description) echo( u"".join( (term.move_x(xpos), term.clear_eos, u"Enter tags, separated by commas.\r\n", term.move_x(xpos), u":: ") ) ) all_tags = list_tags() while True: inp = LineEditor( subject_max_length, u", ".join(sorted(msg.tags)), colors={"highlight": colors["backlight"]} ).read() if inp is None: echo(u"".join((term.move_x(xpos), colors["highlight"]("Message canceled."), term.clear_eol))) term.inkey(1) return False msg.tags = set(filter(None, set(map(unicode.strip, inp.split(","))))) if moderated and not (tag_moderators | session.user.groups): cannot_tag = [_tag for _tag in msg.tags if _tag not in all_tags] if cannot_tag: echo( u"".join( ( u"\r\n", term.move_x(xpos), u", ".join((quote(tag, colors) for tag in cannot_tag)), u": not allowed; this system is moderated.", ) ) ) term.inkey(2) echo(term.move_up) map(msg.tags.remove, cannot_tag) continue return True
def prompt_tags(session, term, msg, colors, public=True): xpos = max(0, (term.width // 2) - (80 // 2)) # conditionally enforce tag moderation moderated = get_ini('msg', 'moderated_tags', getter='getboolean') tag_moderators = set(get_ini('msg', 'tag_moderators', split=True)) # enforce 'public' tag if public and 'public' not in msg.tags: msg.tags.add('public') elif not public and 'public' in msg.tags: msg.tags.remove('public') # describe all available tags, as we oft want to do. do_describe_available_tags(term, colors) # and remind ourselves of the available network tags, description = get_network_tag_description(term, colors) if description: show_description(term=term, color=None, description=description) echo(u''.join( (term.move_x(xpos), term.clear_eos, u'Enter tags, separated by commas.\r\n', term.move_x(xpos), u':: '))) all_tags = list_tags() while True: inp = LineEditor(subject_max_length, u', '.join(sorted(msg.tags)), colors={ 'highlight': colors['backlight'] }).read() if inp is None: echo(u''.join( (term.move_x(xpos), colors['highlight']('Message canceled.'), term.clear_eol))) term.inkey(1) return False msg.tags = set(filter(None, set(map(unicode.strip, inp.split(','))))) if moderated and not (tag_moderators | session.user.groups): cannot_tag = [_tag for _tag in msg.tags if _tag not in all_tags] if cannot_tag: echo(u''.join((u'\r\n', term.move_x(xpos), u', '.join( (quote(tag, colors) for tag in cannot_tag)), u': not allowed; this system is moderated.'))) term.inkey(2) echo(term.move_up) map(msg.tags.remove, cannot_tag) continue return True
def prompt_tags(msg): """ Prompt for and return tags wished for message. """ # pylint: disable=R0914,W0603 # Too many local variables # Using the global statement from x84.bbs import DBProxy, echo, getterminal, getsession from x84.bbs import LineEditor, ini session, term = getsession(), getterminal() tagdb = DBProxy('tags') # version 1.0.9 introduced new ini option; set defaults for # those missing it from 1.0.8 upgrades. import ConfigParser try: moderated_tags = ini.CFG.getboolean('msg', 'moderated_tags') except ConfigParser.NoOptionError: moderated_tags = False try: moderated_groups = set(ini.CFG.get('msg', 'tag_moderator_groups' ).split()) except ConfigParser.NoOptionError: moderated_groups = ('sysop', 'moderator',) msg_onlymods = (u"\r\nONlY MEMbERS Of GROUPS %s MAY CREAtE NEW tAGS." % ( ", ".join(["'%s'".format(term.bold_yellow(grp) for grp in moderated_groups)]))) msg_invalidtag = u"\r\n'%s' is not a valid tag." prompt_tags1 = u"ENtER %s, COMMA-dEliMitEd. " % (term.bold_red('TAG(s)'),) prompt_tags2 = u"OR '/list', %s:quit\r\n : " % ( term.bold_yellow_underline('Escape'),) while True: # Accept user input for multiple 'tag's, or /list command echo(u'\r\n\r\n') echo(prompt_tags1) echo(prompt_tags2) width = term.width - 6 sel_tags = u', '.join(msg.tags) inp_tags = LineEditor(width, sel_tags).read() if inp_tags is not None and 0 == len(inp_tags.strip()): # no tags must be (private ..) msg.tags = set() return True if inp_tags is None or inp_tags.strip().lower() == '/quit': return False elif inp_tags.strip().lower() == '/list': # list all available tags, and number of messages echo(u'\r\n\r\nTags: \r\n') all_tags = sorted(tagdb.items()) if 0 == len(all_tags): echo(u'None !'.center(term.width / 2)) else: echo(u', '.join((term.wrap([u'%s(%d)' % (_key, len(_value),) for (_key, _value) in all_tags])) ), term.width - 2) continue echo(u'\r\n') # search input as valid tag(s) tags = set([inp.strip().lower() for inp in inp_tags.split(',')]) # if the tag is new, and the user's group is not in # tag_moderator_groups, then dissallow such tag if # 'moderated_tags = yes' in ini cfg if moderated_tags: err = False for tag in tags.copy(): if not tag in tagdb and not ( session.users.groups & moderated_groups): tags.remove(tag) echo(msg_invalidtag % (term.bold_red(tag),)) err = True if err: echo(msg_onlymods) continue msg.tags = tags return True
def prompt_tags(msg): """ Prompt for and return tags wished for message. """ # pylint: disable=R0914,W0603 # Too many local variables # Using the global statement from x84.bbs import DBProxy, echo, getterminal, getsession from x84.bbs import Ansi, LineEditor, ini session, term = getsession(), getterminal() tagdb = DBProxy('tags') # version 1.0.9 introduced new ini option; set defaults for # those missing it from 1.0.8 upgrades. import ConfigParser try: moderated_tags = ini.CFG.getboolean('msg', 'moderated_tags') except ConfigParser.NoOptionError: moderated_tags = False try: moderated_groups = set( ini.CFG.get('msg', 'tag_moderator_groups').split()) except ConfigParser.NoOptionError: moderated_groups = ( 'sysop', 'moderator', ) msg_onlymods = ( u"\r\nONlY MEMbERS Of GROUPS %s MAY CREAtE NEW tAGS." % (", ".join( ["'%s'".format(term.bold_yellow(grp) for grp in moderated_groups)]))) msg_invalidtag = u"\r\n'%s' is not a valid tag." prompt_tags1 = u"ENtER %s, COMMA-dEliMitEd. " % (term.bold_red('TAG(s)'), ) prompt_tags2 = u"OR '/list', %s:quit\r\n : " % ( term.bold_yellow_underline('Escape'), ) while True: # Accept user input for multiple 'tag's, or /list command echo(u'\r\n\r\n') echo(prompt_tags1) echo(prompt_tags2) width = term.width - 6 sel_tags = u', '.join(msg.tags) inp_tags = LineEditor(width, sel_tags).read() if inp_tags is not None and 0 == len(inp_tags.strip()): # no tags must be (private ..) msg.tags = set() return True if inp_tags is None or inp_tags.strip().lower() == '/quit': return False elif inp_tags.strip().lower() == '/list': # list all available tags, and number of messages echo(u'\r\n\r\nTags: \r\n') all_tags = sorted(tagdb.items()) if 0 == len(all_tags): echo(u'None !'.center(term.width / 2)) else: echo( Ansi(u', '.join(([ u'%s(%d)' % ( _key, len(_value), ) for (_key, _value) in all_tags ]))).wrap(term.width - 2)) continue echo(u'\r\n') # search input as valid tag(s) tags = set([inp.strip().lower() for inp in inp_tags.split(',')]) # if the tag is new, and the user's group is not in # tag_moderator_groups, then dissallow such tag if # 'moderated_tags = yes' in ini cfg if moderated_tags: err = False for tag in tags.copy(): if not tag in tagdb and not (session.users.groups & moderated_groups): tags.remove(tag) echo(msg_invalidtag % (term.bold_red(tag), )) err = True if err: echo(msg_onlymods) continue msg.tags = tags return True