]> git.0d.be Git - botaradio.git/commitdiff
feat: tag current song
authorTerry Geng <gengyanda@gmail.com>
Mon, 9 Mar 2020 02:14:12 +0000 (10:14 +0800)
committerTerry Geng <gengyanda@gmail.com>
Mon, 9 Mar 2020 02:14:12 +0000 (10:14 +0800)
command.py
configuration.default.ini

index 30d5e23847330b786543fe06320320d6a921cf70..7c97eccb7767e5d450b7231dc3693720b6200e1a 100644 (file)
@@ -828,10 +828,19 @@ def cmd_add_tag(bot, user, text, command, parameter):
     global log
 
     params = parameter.split()
+    index = ""
+    tags = []
     if len(params) == 2:
         index = params[0]
         tags = list(map(lambda t: t.strip(), params[1].split(",")))
+    elif len(params) == 1:
+        index = str(var.playlist.current_index + 1)
+        tags = list(map(lambda t: t.strip(), params[0].split(",")))
+    else:
+        bot.send_msg(constants.strings('bad_parameter', command=command), text)
+        return
 
+    if tags[0]:
         if index.isdigit() and 1 <= int(index) <= len(var.playlist):
             var.playlist[int(index) - 1].add_tags(tags)
             log.info("cmd: add tags %s to song %s" % (", ".join(tags),
@@ -839,26 +848,39 @@ def cmd_add_tag(bot, user, text, command, parameter):
             bot.send_msg(constants.strings("added_tags",
                                            tags=", ".join(tags),
                                            song=var.playlist[int(index) - 1].format_short_string()), text)
+            return
+
         elif index == "*":
             for item in var.playlist:
                 item.add_tags(tags)
                 log.info("cmd: add tags %s to song %s" % (", ".join(tags),
                                                           item.format_debug_string()))
             bot.send_msg(constants.strings("added_tags_to_all", tags=", ".join(tags)), text)
-        else:
-            bot.send_msg(constants.strings('bad_parameter', command=command), text)
+            return
+
+    bot.send_msg(constants.strings('bad_parameter', command=command), text)
 
 
 def cmd_remove_tag(bot, user, text, command, parameter):
     global log
 
     params = parameter.split()
-    if len(params) == 2 and params[1]:
+
+    index = ""
+    tags = []
+    if len(params) == 2:
         index = params[0]
+        tags = list(map(lambda t: t.strip(), params[1].split(",")))
+    elif len(params) == 1:
+        index = str(var.playlist.current_index + 1)
+        tags = list(map(lambda t: t.strip(), params[0].split(",")))
+    else:
+        bot.send_msg(constants.strings('bad_parameter', command=command), text)
+        return
 
+    if tags[0]:
         if index.isdigit() and 1 <= int(index) <= len(var.playlist):
-            if params[1] != "*":
-                tags = list(map(lambda t: t.strip(), params[1].split(",")))
+            if tags[0] != "*":
                 var.playlist[int(index) - 1].remove_tags(tags)
                 log.info("cmd: remove tags %s from song %s" % (", ".join(tags),
                                                           var.playlist[int(index) - 1].format_debug_string()))
@@ -874,8 +896,7 @@ def cmd_remove_tag(bot, user, text, command, parameter):
                 return
 
         elif index == "*":
-            if params[1] != "*":
-                tags = list(map(lambda t: t.strip(), params[1].split(",")))
+            if tags[0] != "*":
                 for item in var.playlist:
                     item.remove_tags(tags)
                     log.info("cmd: remove tags %s from song %s" % (", ".join(tags),
index d349dd5862f28475ab0727215ffddf018b719429..0e0a6fd5a54084082a3a4eb82f2242c91721a3b7 100644 (file)
@@ -285,10 +285,9 @@ help = <h3>Commands</h3>
        <b>Music Library</b>
        <ul>
        <li> <b>!<u>se</u>arch </b> {keywords} - find item with {keywords} in the music library, keywords separated by space.</li>
-       <li> <b>!<u>addt</u>ag </b> {index} {tags} - add {tags} to {index}-th item on the playlist, tags separated by ",". </li>
+       <li> <b>!<u>addt</u>ag </b> [{index}] {tags} - add {tags} to {index}-th(current song if {index} is omitted) item on the playlist, tags separated by ",". </li>
        <li> <b>!<u>addt</u>ag </b> * {tags} - add {tags} to all items on the playlist. </li>
-       <li> <b>!<u>un</u>tag </b> {index/*} {tags} - remove {tags} from {index}-th item on the playlist. </li>
-       <li> <b>!<u>un</u>tag </b> {index/*} * - remove all tags from {index}-th item on the playlist. </li>
+       <li> <b>!<u>un</u>tag </b> [{index/*}] {tags}/* - remove {tags}/all tags from {index}-th(current song if {index} is omitted) item on the playlist. </li>
        <li> <b>!<u>fin</u>dtagged </b> (or <b>!ft</b>) {tags} - find item with {tags} in the music library. </li>
        <li> <b>!<u>del</u>ete </b> {index} - delete {index}-th item on the shortlist from the music library. </li>
        </ul>