-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TgBot++: Make command modules into a list
- Using python, we can achieve a clean config list instead of hardcode
- Loading branch information
Showing
8 changed files
with
140 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
about.html.in | ||
about.html.in | ||
commands_list.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Used by command_modules_helper.py | ||
# Syntax: commandname ([!win32]) ([infile <filename>]) | ||
|
||
alive | ||
flash | ||
possibility | ||
decide | ||
delay | ||
decho | ||
randsticker | ||
fileid | ||
clone | ||
spam | ||
cmd | ||
ibash [!win32] | ||
restart [!win32] | ||
bash [infile bash_impl] | ||
ubash [infile bash_impl] | ||
starttimer [infile timer_impl] | ||
stoptimer [infile timer_impl] | ||
database [infile database_impl] | ||
saveid [infile database_impl] | ||
start [infile alive] | ||
c [infile compilers_impl] | ||
cpp [infile compilers_impl] | ||
go [infile compilers_impl] | ||
python [infile compilers_impl] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import sys | ||
|
||
""" | ||
Just a utility script to support dynamic list of commands compiled into. | ||
""" | ||
|
||
if len(sys.argv) < 3: | ||
print('Usage: %s gen_decl|gen_ptr|get_cmd_filenames|get_cmd_commands args...' % sys.argv[0], file=sys.stderr) | ||
sys.exit(1) | ||
|
||
command = sys.argv[1] | ||
libs = sys.argv[2:] | ||
|
||
def parse_command_list(file): | ||
filenames = [] | ||
commands = [] | ||
with open(file, 'r') as f: | ||
for line in f.readlines(): | ||
if line.startswith('#'): | ||
continue | ||
if line.strip() == '': | ||
continue | ||
if len(line.split('[')) > 2 or len(line.split(']')) > 2: | ||
print('Invalid line "%s", Two options in one line:' % line, file=sys.stderr) | ||
continue | ||
command = line.split('[')[0].strip() | ||
if command in commands: | ||
print('Duplicate command: %s' % command, file=sys.stderr) | ||
continue | ||
commands.append(command) | ||
if '[' and ']' in line: | ||
opt = line.split('[')[1].split(']')[0].strip() | ||
# Parse options | ||
if opt.startswith('!'): | ||
# NOT platform declaration | ||
match line[1:]: | ||
case 'win32': | ||
if sys.platform in ['win32', 'cygwin', 'msys']: | ||
print('Ignore command: %s (Not Win32)' % command) | ||
# TODO: Add more platforms | ||
elif opt.startswith('infile'): | ||
if opt.find(' ') == -1: | ||
print('Invalid option: %s' % opt, file=sys.stderr) | ||
continue | ||
str = opt.split(' ')[1] | ||
if str not in filenames: | ||
filenames.append(str) | ||
continue | ||
else: | ||
print('Invalid option: %s' % opt, file=sys.stderr) | ||
continue | ||
filenames.append(command) | ||
return filenames, commands | ||
|
||
if command == 'gen_decl': | ||
""" Generate command module loader functions' forward declarations. """ | ||
decls = '' | ||
for lib in libs: | ||
decls += f"extern void loadcmd_{lib}(CommandModule &cmd);\n" | ||
print(decls) | ||
elif command == 'gen_ptr': | ||
""" Generate command module loader functions' pointers. """ | ||
ptrs = '' | ||
for lib in libs: | ||
ptrs += ' ' * 8 + f"&loadcmd_{lib},\n" | ||
print(ptrs) | ||
elif command == 'get_cmd_filenames': | ||
""" Get list of command module filenames. """ | ||
filenames, _ = parse_command_list(sys.argv[2]) | ||
for filename in filenames: | ||
print(filename, end=';') | ||
elif command == 'get_cmd_names': | ||
""" Get list of command module name lists. """ | ||
_, commands = parse_command_list(sys.argv[2]) | ||
for command in commands: | ||
print(command, end=';') | ||
else: | ||
print(f"Unknown command: {command}", file=sys.stderr) | ||
sys.exit(1) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.