You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.6 KiB
133 lines
4.6 KiB
3 years ago
|
// ao-cli includes an AO client that makes calls to a locla or remote AO server.
|
||
|
// The ao-cli client has no store so it makes frequent (hopefully very quick) calls to get exactly the information it needs.
|
||
|
// This requires us to make sure the AO API server's REST API is concise and efficient.
|
||
|
// The only places ao-cli should call out to an AO server (i.e., use the API in api.js) are in this Use AO menu and in the Tests menu.
|
||
|
import inquirer from 'inquirer'
|
||
|
import { aoEnv } from './settings.js'
|
||
|
import { isLoggedIn, loginPrompt, logout } from './session.js'
|
||
|
import { getTopPriorityText } from './priority.js'
|
||
|
import { startPublicBootstrap } from './bootstrap.js'
|
||
|
import { AO_DEFAULT_HOSTNAME } from './api.js'
|
||
|
import { cardMenu } from './cards.js'
|
||
|
import { connectMenu } from './connect.js'
|
||
|
import { headerStyle } from './styles.js'
|
||
|
|
||
|
// Prints the Use AO Menu and executes the user's choice. Using the AO as a client occurs only under this menu item (except Tests menu).
|
||
|
export default async function useAoMenu() {
|
||
|
const loggedIn = isLoggedIn()
|
||
|
console.log(`\n${headerStyle('AO')}\n`)
|
||
|
if(loggedIn) {
|
||
|
console.log('Logged in as:', aoEnv('AO_CLI_SESSION_USERNAME'))
|
||
|
const topPriority = await getTopPriorityText()
|
||
|
if(topPriority) {
|
||
|
console.log('Top priority:', topPriority)
|
||
|
} else {
|
||
|
console.log('Error contacting server, is your AO server running? AO features might not work.')
|
||
|
}
|
||
|
}
|
||
|
let aoMenuChoices = []
|
||
|
if(loggedIn) {
|
||
|
aoMenuChoices.push(
|
||
|
'Deck',
|
||
|
'Chat',
|
||
|
'Connect',
|
||
|
)
|
||
|
}
|
||
|
aoMenuChoices.push(
|
||
|
loggedIn ? 'Log Out' : 'Log In',
|
||
|
'Back to Main Menu'
|
||
|
)
|
||
|
let answer
|
||
|
try {
|
||
|
answer = await inquirer.prompt({
|
||
|
name: 'ao_menu',
|
||
|
type: 'list',
|
||
|
message: 'Please choose:',
|
||
|
choices: aoMenuChoices,
|
||
|
pageSize: aoMenuChoices.length
|
||
|
})
|
||
|
} catch(error) {
|
||
|
if (error === 'EVENT_INTERRUPTED') {
|
||
|
console.log('\nESC')
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
switch(answer.ao_menu) {
|
||
|
case 'Deck':
|
||
|
//await todoList('My Todo List', ['Add full AO install process to ao-cli in convenient format', 'Add AO server unit tests to ao-cli', 'Get groceries', 'Play music every day'])
|
||
|
while(await cardMenu()) {}
|
||
|
break
|
||
|
case 'Connect':
|
||
|
while(await connectMenu()) {}
|
||
|
break
|
||
|
case 'Chat':
|
||
|
while(await chatMenu()) {}
|
||
|
break
|
||
|
case 'Log In':
|
||
|
console.log('\nao-cli will use the AO API to log into the AO server at', (aoEnv('AO_CLI_TARGET_HOSTNAME') || AO_DEFAULT_HOSTNAME) + '.')
|
||
|
await loginPrompt()
|
||
|
break
|
||
|
case 'Log Out':
|
||
|
await logout()
|
||
|
//await spinnerWait('Logging out...')
|
||
|
break
|
||
|
case 'Back to Main Menu':
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// Prints a menu that allows you to join the global AO chatrooms
|
||
|
async function chatMenu() {
|
||
|
let answers = {}
|
||
|
const PUBLIC_BOOTSTRAP_ENABLED = aoEnv('PUBLIC_BOOTSTRAP_ENABLED')
|
||
|
if(PUBLIC_BOOTSTRAP_ENABLED) {
|
||
|
// They previously enabled public bootstrapping, so check to make sure it is working and then hide the option
|
||
|
// todo: start and then verify functioning of p2p boostrap method here
|
||
|
// if it's already started don't start it again
|
||
|
if(!publicBootstrapStarted) {
|
||
|
console.log("\nBootstrapping public AO swarm...")
|
||
|
startPublicBootstrap()
|
||
|
console.log("Bootstrapped (just kidding)")
|
||
|
}
|
||
|
//answers['chat_menu'] = 'Enable p2p bootstrap'
|
||
|
}
|
||
|
const chatChoices = [
|
||
|
{ name: 'Join public chatroom', value: 'browse_chatrooms', short: 'public chatrooms' },
|
||
|
{ name: 'Join chatroom', value: 'join_chat', short: 'join chat' },
|
||
|
'Address Book',
|
||
|
'Back to AO Menu',
|
||
|
]
|
||
|
console.log(`\n${headerStyle('AO Public Chatrooms')}\n`)
|
||
|
let answer
|
||
|
try {
|
||
|
answer = await inquirer.prompt({
|
||
|
name: 'chat_menu',
|
||
|
type: 'list',
|
||
|
message: 'Please choose:',
|
||
|
choices: chatChoices
|
||
|
})
|
||
|
} catch(error) {
|
||
|
if (error === 'EVENT_INTERRUPTED') {
|
||
|
console.log('\nESC')
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
switch(answer.chat_menu) {
|
||
|
case 'browse_chatrooms':
|
||
|
console.log('Not yet implemented')
|
||
|
break
|
||
|
case 'join_chat':
|
||
|
console.log('Not yet implemented')
|
||
|
break
|
||
|
case 'Address Book':
|
||
|
console.log('The point of this address book is to make it possible to type short, one-word names and have them resolve to tor addresses.')
|
||
|
console.log('Name a piece of data by saying name=data. For example, doge=5uc41o1...onion. Then \'doge\' will return the .onion address.')
|
||
|
console.log('Querying with any synonym in a chain will return the final meanings they all point to.')
|
||
|
console.log('Keys can have multiple values.')
|
||
|
break
|
||
|
case 'Back to AO Menu':
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|