Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
HOStudio123 committed Aug 3, 2024
1 parent 336684d commit 2e5e138
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 237 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.9.8] - 2024-07-17
## [1.9.9] - 2024-08-03
### Fixed
- Fixed some known issues

### Added
- Added some new commands

### Removed
- Removed some commands

## [1.9.7] - 2024-07-17
### Fixed
- Fixed some known issues
Expand Down
57 changes: 33 additions & 24 deletions hopybox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
from .mail import email

# translate library
from .translate import langdet
from .translate import translate

# command library
from .command import command_gather
from .command import command_help
from .command import command_data
from .command import command_data_add
Expand Down Expand Up @@ -97,12 +97,12 @@
_windows = 0

# version
_version_code = '1.9.8'
_version_code = '2.0.0'
_version_number = int(''.join(_version_code.split('.')))
_version_type = 'default'
_version_info = f'* HOPYBOX Version {_version_code}\n* Python Version {python_version()}'
_version_update_content = '* Fixed some known issues\n* Add some new commands'
_version_update_time = 'Jul 20 2024 15:15:00'
_version_update_time = 'Aug 03 2024 12:03:00'

# command
command_data_add()
Expand Down Expand Up @@ -160,11 +160,12 @@ def __init__(self):


# command process
def _process(command:str):
def _analysis(command:str) -> list:
split_list = command.split()

if len(split_list) <= 2:
return command.split()
return split_list

command = split_list[0]
parameter = split_list[1]

Expand All @@ -177,33 +178,42 @@ def _process(command:str):
content = split_list[1:]
return [command, content]


# interpreter
def analysis(mode, command):
global _command
if len(_process(command)) == 1:
exec(command_data[mode][_command]['code'])
else:
if _process(command)[1].startswith('-'):
if len(_process(command)) == 3:
command_data[mode][_command]['run'] = _process(command)[2]
exec(command_data[mode][_command]['code'][_process(command)[1]])
else:
command_data[mode][_command]['run'] = _process(command)[1]
exec(command_data[mode][_command]['code'])
def _interpreter(mode, command):
result = _analysis(command)
length = len(result)
if length == 0:
pass
else:
head = result[0]
if length == 1:
exec(command_data[mode][head]['code'])
else:
if result[1].startswith(''):
if length == 3:
command_data[mode][head]['run'] = result[2]
exec(command_data[mode][head]['code'][result[1]])
else:
command_data[mode][head]['run'] = result[1]
exec(command_data[mode][head]['code'])


def run(command):
global _command
_command = _process(command)[0] if command else ''
if len(_analysis(command)) > 0:
_command = _analysis(command)[0]
else:
_command = ''
try:
if _command in command_data['Global']:
analysis('Global', command)
_interpreter('Global', command)
try:
del command_data['Global'][_command]['run']
except:
pass
elif _command in command_data[_mode]:
analysis(_mode, command)
_interpreter(_mode, command)
try:
del command_data[_mode][_command]['run']
except:
Expand Down Expand Up @@ -244,7 +254,6 @@ def _format_command():

# start
def start():
os.system('')
global _command, _store, _windows, completer
mouse_support = True if os.name == 'nt' else False
times = 0
Expand All @@ -257,8 +266,8 @@ def start():
('class:body', f"HOPYBOX {_version_code} ({_version_type}, {' '.join(_version_update_time.split()[:3])}, {_version_update_time.split()[3]})\n[Python {python_version()}] on {system()}\nType \"help\" , \"copyright\" , \"version\" ,\"feedback\" or \"license\" for more information")
]
style = {
'title': '#00ffff',
'head': '#00ff00',
'title': '#00FFFF',
'head': '#00FF00',
}
color_print(text,style,single=False)
style = Style.from_dict({'prompt': 'yellow'})
Expand All @@ -267,7 +276,7 @@ def start():
while True:
_windows += 1
try:
_command = session.prompt(f'[{_windows}]HOPYBOX/{_mode}:',completer=completer,style=style,mouse_support=mouse_support,auto_suggest=AutoSuggestFromHistory())
_command = session.prompt(f'[{_windows}]HOPYBOX/{_mode}:$',completer=completer,style=style,mouse_support=mouse_support,auto_suggest=AutoSuggestFromHistory())
if not _command.strip():
continue
except EOFError:
Expand Down
19 changes: 17 additions & 2 deletions hopybox/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .prompt import getpass
from .prompt import color_input
from .prompt import color_print
from .prompt import error_cross_simple

class CoralAI:
Expand All @@ -10,9 +11,10 @@ def _chat(self):
self.api_key = getpass('Please enter the secret key (See <u>https://dashboard.cohere.com/api-keys</u> for more details)\n','#00ABFF',html=True)
self.co = cohere.Client(api_key=self.api_key)
self.chat_history = list()
color_print('Welcome to chat with Coral AI ! (Continue:^C) (Exit:^D)','#49D07D')
while True:
try:
message = color_input('(Coral) ','#FFD142')
message = color_input('(You) ','#EB7A16')
self._process(message)
except EOFError:
break
Expand All @@ -29,9 +31,22 @@ def _process(self,message):
data_user['message'] = message
data_bot['role'] = 'CHATBOT'
res_message = list()
is_output = 0
for event in stream:
if event.event_type == "text-generation":
print(event.text,end='')
if is_output == 0:
text = [
('class:head','(Bot)'),
('',' '),
('class:text',event.text)
]
style = {
'head':'#FFD142'
}
color_print(text,style,single=False,end='')
is_output = 1
else:
print(event.text,end='')
res_message.append(event.text)
data_bot['message'] = ''.join(res_message)
self.chat_history.append(data_user)
Expand Down
8 changes: 4 additions & 4 deletions hopybox/cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def pin_verify(self,pin):
def _set_pin(self):
if not self.detect_pin_set:
while True:
pin = getpass('Please set the PIN code (at least 6 digits)\n','#00FF00')
pin = getpass('Set a PIN (at least 6-digit)\n','#00FF00')
if len(pin) >= 6:
self.pin_set(cipher(pin).en_sha256)
del pin
tip_tick('Succeeded in setting the PIN code, please remember this PIN code well, which cannot be reset')
tip_tick('Succeeded in setting the PIN, please remember this PIN well, which cannot be reset')
break
else:
error_cross_simple('This is an unreasonable input')
Expand All @@ -118,7 +118,7 @@ def _set_pin(self):

@property
def _verify_pin(self):
pin = getpass('Please enter the PIN code\n','#00FF00')
pin = getpass('Enter PIN\n','#00FF00')
return self.pin_verify(pin)

@property
Expand All @@ -139,7 +139,7 @@ def _add_factor(self):
else:
error_cross_simple('This is an unreasonable input')
else:
error_cross_simple('The entered PIN code is incorrect')
error_cross_simple('The entered PIN is incorrect')

def otp_pro(self, secret):
return pyotp.TOTP(secret).now()
Expand Down
20 changes: 12 additions & 8 deletions hopybox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

command_data = dict()


def command_gather(text:list) -> str:
return ' '.join(text)

def _command_add(mode, name, code, operate, details):
if mode in command_data:
command_data[mode][name] = {
Expand Down Expand Up @@ -32,7 +36,7 @@ def command_data_add():

# Global
Global = [
("help","command_help()",'help [command]','To get the help about all commands'),
("help","command_help()",'help','To get the help about all commands'),

("switch","_switch(command_data['Global']['switch']['run'])","switch [program|device|file|calculate]","To switch running mode"),

Expand Down Expand Up @@ -95,17 +99,17 @@ def command_data_add():
},"tf -[p|a|v|d]",{
"-p": "To set the PIN code to protect the two-factor",
"-a": "To add the two-factor pin",
"-v": "To view the two-factor token",
"-v": "To view the TOTP token",
"-d": "To delete the two-factor key"
}
),

("translate",{
"-y": "translate.YouDao().output(translate.YouDao().trans(' '.join(command_data['Program']['translate']['run']),langdet(' '.join(command_data['Program']['translate']['run']))[1]))",
"-g": "print(translate.Google().trans(command_data['Program']['translate']['run'],langdet(command_data['Program']['translate']['run'])[1]))"
},"translate [-(y|g) text]",{
"-y":"To translate the word into Chinese/English by YouDao",
"-g":"To translate the word into Chinese/English by Google",
"-y": "translate.YouDao().output(translate.YouDao().trans(command_gather(command_data['Program']['translate']['run'][1:]),command_data['Program']['translate']['run'][0]))",
"-g": "print(translate.Google().trans(command_gather(command_data['Program']['translate']['run'][1:]),command_data['Program']['translate']['run'][0]))"
},"translate [-(y|g) lang text]",{
"-y":"To translate the word into other language by YouDao",
"-g":"To translate the word into other language by Google",
}
),

Expand Down Expand Up @@ -240,7 +244,7 @@ def command_data_add():

("info","filetool(command_data['File']['info']['run']).info","info {path}","To view the information of file"),

("scan","print(scanner(command_data['File']['scan']['run'][0],command_data['File']['scan']['run'][1]).scan_extension)","scan {path} {extension}","Scanning the path"),
("scan","scanner(command_data['File']['scan']['run'][0],command_data['File']['scan']['run'][1]).scan_extension","scan {path} {extension}","Scanning the path"),

("chdir","os.chdir(command_data['File']['chdir']['run'])\ntip_tick('The working directory is switched successfully')","chdir [path]","To switch the work path"),

Expand Down
3 changes: 2 additions & 1 deletion hopybox/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self):

def main(self, url):
self.time(True)
with Console().status('\033[96mLoading URL …'):
os,system('')
with Console().status('[bright_cyan]Loading URL …[/bright_cyan]'):
res = self.content(url)
if res.status_code == requests.codes.ok:
self.total_time = self.time(False)
Expand Down
Loading

0 comments on commit 2e5e138

Please sign in to comment.