def cli(fp, acc): with LedgerServer(fp) as server: print(f"{_name} ver {_ver}") print("run help for a list of commands") print("or exit to leave the cli") while True: try: cmd = input(ps1(acc)) except KeyboardInterrupt: print() cmd = '' except EOFError: print('exit') cmd = 'exit' if cmd == '': continue if cmd.split()[0] in cant_run: print(f"Can't execute {cmd.split()[0]} from cli") elif cmd.startswith('login'): split = cmd.split() acc_id = parse_account_id(split[1]) acc = acc_id elif cmd.startswith('exit'): break else: print(run_command(acc, cmd, server))
async def on_message(message: discord.Message): if message.author == discord_client.user: return global config_prefix content = message.content.lstrip() prefixes = ( '<@%s>' % discord_client.user.id, '<@!%s>' % discord_client.user.id) if config_prefix is not None: if isinstance(config_prefix, (list, tuple)): prefixes += tuple(config_prefix) elif isinstance(config_prefix, str): prefixes += (config_prefix.lower(),) if content.lower().startswith(prefixes): # Checking all messages that start with the prefix. prefix = [prefix for prefix in prefixes if content.lower().startswith(prefix)][0] command_content = content[len(prefix):].lstrip() response = discord_postprocess( run_command( DiscordAccountId(str(message.author.id)), command_content, server)) chunks = split_into_chunks(response.encode('utf-8'), 1024) title = command_content.split()[0] if len(command_content.split()) > 0 else 'Empty Message' message_obj = DiscordMessage(message.author, chunks, title) await message_obj.send(message.channel) messages[message_obj.message.id] = message_obj
def parse(cmd, account, fp): acc = parse_account_id(account) if cmd is not None: server = LedgerServer(fp) cmds = cmd.split(';') for cmd in cmds: print(run_command(acc, cmd, server)) server.close() elif cmd is None: cli(fp, account)
def parse(cmd, account, fp): acc = parse_account_id(account) if cmd is not None: server = LedgerServer(fp) cmds = cmd.split(';') for cmd in cmds: if cmd.startswith("shoot"): print("Can't execute shoot from cli") else: print(run_command(acc, cmd, server)) server.close() elif cmd is None: cli(fp, account)
async def on_message(message: discord.Message): if message.guild.id != primary_guild_id: return if message.author == discord_client.user: return global config_prefix content = message.content.lstrip() prefixes = ('<@%s>' % discord_client.user.id, '<@!%s>' % discord_client.user.id) if config_prefix is not None: if isinstance(config_prefix, (list, tuple)): prefixes += tuple(config_prefix) elif isinstance(config_prefix, str): prefixes += (config_prefix.lower(), ) if content.lower().startswith( prefixes): # Checking all messages that start with the prefix. prefix = [ prefix for prefix in prefixes if content.lower().startswith(prefix) ][0] command_content = content[len(prefix):].lstrip() response = run_command(DiscordAccountId(str(message.author.id)), command_content, server) if isinstance(response, dict): params = response response = params["response"] if "to_be_muted" in params: user_id = int(params["to_be_muted"].discord_id) guild = primary_guild member = guild.get_member(user_id) role = guild.get_role(muted_role_id) if role not in member.roles: await member.add_roles(role) response = discord_postprocess(response) chunks = split_into_chunks(response.encode('utf-8'), 1024) title = command_content.split()[0] if len( command_content.split()) > 0 else 'Empty Message' message_obj = DiscordMessage(message.author, chunks, title) await message_obj.send(message.channel) messages[message_obj.message.id] = message_obj
def run_command_stream(server, *commands): """Runs a sequence of commands (formatted as author, command pairs) on a server.""" responses = [] for (author, cmd) in commands: responses.append(run_command(author, cmd, server)) return responses
def process_comment(comment, server): """Processes a comment with the proper prefix.""" author = RedditAccountId(comment.author.name) comment.reply(run_command(author, comment.body[len(prefix):], server))
def process_message(message, server): """Processes a message sent to the bot.""" reply( message, run_command(RedditAccountId(message.author.name), message.body, server))