# Path: bnw/handlers/command_post.py
# def _(s, user):
# def normalize_format(fmt):
# def postMessage(request, tags, clubs, text, anon=False, anoncomments=False,
#                 format=None):
# def cmd_post(request, tags="", clubs="", anonymous="", anoncomments="", format="", text=""):
# def cmd_post_simple(request, text, tag1=None, tag2=None, tag3=None, tag4=None, tag5=None):
# def cmd_comment(request, message="", anonymous="", format="", text=""):
# def cmd_recommend(request, message="", comment="", unrecommend=""):


from base import *
from bnw.core.post import renderPostOrComment
from twisted.internet import defer
from bnw.handlers import command_post
import bnw.core.bnw_objects as objs



def _(s, user):
    return s


@defer.inlineCallbacks
def update_internal(message, what, delete, text):
    action = '$pull' if delete else '$addToSet'
    defer.returnValue((yield objs.Message.mupdate({'id': message}, {action: {what: text}})))


@defer.inlineCallbacks
def update_message_internal(request, message='', text='', club=False,
            tag=False, delete=False, clubs=None, tags=None, api=False,
            format=None):
    """Update message's clubs and tags."""
    message = canonic_message(message).upper()
    if (not message or not ((text and (club or tag)) or
                            (clubs is not None) or
                            (tags is not None) or api or format)):
        defer.returnValue(dict(
            ok=False,
            desc='Usage: <update|u> -m <message> <--club|--tag> '
                 '[--delete] <tag|club> [--clubs=club1,club2] '
                 '[--tags=tag1,tag2] '
                 '[--format=<markdown|md|moinmoin|mm|plaintext>]'))

    if format and not format in command_post.acceptable_formats:

# Path: bnw/handlers/command_post.py
# def _(s, user):
# def normalize_format(fmt):
# def postMessage(request, tags, clubs, text, anon=False, anoncomments=False,
#                 format=None):
# def cmd_post(request, tags="", clubs="", anonymous="", anoncomments="", format="", text=""):
# def cmd_post_simple(request, text, tag1=None, tag2=None, tag3=None, tag4=None, tag5=None):
# def cmd_comment(request, message="", anonymous="", format="", text=""):
# def cmd_recommend(request, message="", comment="", unrecommend=""):


# Path: bnw/handlers/command_update.py
from base import *
from bnw.core.post import renderPostOrComment
from twisted.internet import defer
from bnw.handlers import command_post
import bnw.core.bnw_objects as objs




def _(s, user):
    return s


@defer.inlineCallbacks
def update_internal(message, what, delete, text):
    action = '$pull' if delete else '$addToSet'
    defer.returnValue((yield objs.Message.mupdate({'id': message}, {action: {what: text}})))


@defer.inlineCallbacks
def update_message_internal(request, message='', text='', club=False,
            tag=False, delete=False, clubs=None, tags=None, api=False,
            format=None):
    """Update message's clubs and tags."""
    message = canonic_message(message).upper()
    if (not message or not ((text and (club or tag)) or
                            (clubs is not None) or
                            (tags is not None) or api or format)):
        defer.returnValue(dict(
            ok=False,
            desc='Usage: <update|u> -m <message> <--club|--tag> '
                 '[--delete] <tag|club> [--clubs=club1,club2] '
                 '[--tags=tag1,tag2] '
                 '[--format=<markdown|md|moinmoin|mm|plaintext>]'))

    if format and not format in command_post.acceptable_formats:

        defer.returnValue(dict(ok=False, desc=u"'%s' is not a valid format! Choose one of: %s" % (format, command_post.acceptable_formats_str)))