|
|
|
|
@ -27,7 +27,7 @@
|
|
|
|
|
# dm_send <conv_id> <text> send DM text message |
|
|
|
|
# listen interactive event listener |
|
|
|
|
|
|
|
|
|
import sys, os, json, socket, struct |
|
|
|
|
import sys, os, json, socket, struct, argparse |
|
|
|
|
|
|
|
|
|
DEFAULT_HOST = os.environ.get("CHATCLI_HOST", "127.0.0.1") |
|
|
|
|
DEFAULT_PORT = int(os.environ.get("CHATCLI_PORT", "9999")) |
|
|
|
|
@ -148,6 +148,41 @@ def cmd_dm_messages(conv_id, count=None):
|
|
|
|
|
def cmd_dm_send(conv_id, text): |
|
|
|
|
_req("dm_send", conv_id=conv_id, data=text) |
|
|
|
|
|
|
|
|
|
def cmd_interaction(cmd, args): |
|
|
|
|
parser = argparse.ArgumentParser(prog="chatcli " + cmd) |
|
|
|
|
if cmd == "reactions": |
|
|
|
|
parser.parse_args(args) |
|
|
|
|
_req("reaction_catalog") |
|
|
|
|
return |
|
|
|
|
parser.add_argument("ch") |
|
|
|
|
if cmd == "poll": |
|
|
|
|
parser.add_argument("question") |
|
|
|
|
parser.add_argument("options", nargs="+") |
|
|
|
|
parser.add_argument("--multiple", action="store_true") |
|
|
|
|
parser.add_argument("--custom", action="store_true") |
|
|
|
|
else: |
|
|
|
|
parser.add_argument("message_id") |
|
|
|
|
if cmd == "vote": |
|
|
|
|
parser.add_argument("choices", nargs="*", type=int, help="option IDs from feedback (start at 0)") |
|
|
|
|
parser.add_argument("--custom", default="") |
|
|
|
|
elif cmd == "react": |
|
|
|
|
parser.add_argument("emoji", nargs="?") |
|
|
|
|
parser.add_argument("--off", action="store_true") |
|
|
|
|
parser.add_argument("--clear", action="store_true") |
|
|
|
|
values = parser.parse_args(args) |
|
|
|
|
if cmd == "poll": |
|
|
|
|
_req("poll_create", ch=values.ch, question=values.question, options=values.options, |
|
|
|
|
mode="multiple" if values.multiple else "single", allow_custom_answer=values.custom) |
|
|
|
|
elif cmd == "vote": |
|
|
|
|
_req("vote", ch=values.ch, message_id=values.message_id, choices=values.choices, custom=values.custom) |
|
|
|
|
elif cmd == "react": |
|
|
|
|
if not values.clear and values.emoji is None: |
|
|
|
|
parser.error("specify an emoji or --clear") |
|
|
|
|
emoji = int(values.emoji) if values.emoji and values.emoji.isdigit() else values.emoji |
|
|
|
|
_req("react", ch=values.ch, message_id=values.message_id, emoji=emoji, on=not values.off, clear=values.clear) |
|
|
|
|
else: |
|
|
|
|
_req("feedback", ch=values.ch, message_id=values.message_id) |
|
|
|
|
|
|
|
|
|
def cmd_listen(): |
|
|
|
|
print(f"Listening on {DEFAULT_HOST}:{DEFAULT_PORT} (Ctrl+C to quit)") |
|
|
|
|
s = _connect() |
|
|
|
|
@ -201,6 +236,7 @@ def main():
|
|
|
|
|
cmd = args[0] |
|
|
|
|
try: |
|
|
|
|
if cmd == "ping": cmd_ping() |
|
|
|
|
elif cmd in ("poll", "vote", "react", "feedback", "reactions"): cmd_interaction(cmd, args[1:]) |
|
|
|
|
elif cmd == "status": cmd_status() |
|
|
|
|
elif cmd == "channels": cmd_channels() |
|
|
|
|
elif cmd == "members": cmd_members(*args[1:2] if len(args) > 1 else (_die("usage: members <ch_id>"),)) |
|
|
|
|
|