-
Notifications
You must be signed in to change notification settings - Fork 1
/
docsgen.sh
72 lines (63 loc) · 2.08 KB
/
docsgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
{
cat <<EOF
# Documentation
note: this file was auto-generated by [docsgen.sh](./docsgen.sh)
## Getting started
Make a new file, and import minecraft.sh with the \`source\` keyword. run "start_login" and make sure to use "wait_on_login" before sending any packets. See [the documentation for start_login](#start_login()) to see the full list of options
\`\`\`bash
source src/minecraft.sh
start_login
wait_on_login
\`\`\`
And that's it! your bot will log in and do nothing. To get it to actually do something, look at the methods here or the examples in examples/
## Listening to events
minecraft.sh works on a system of "hooks", function handlers that are called whenever certain packets are recieved. scroll down for the full list
For example, to respawn and print a method whenever the bot dies, add this code to your script
\`\`\`bash
pkt_hook_combat_death() {
echo "I died! Full information: \$1"
pkt_respawn
}
\`\`\`
If you just want to play around with the methods, ./interactive will give you an interactive shell with all the methods loaded
If you need to ask any questions, feel free to ask me @coolelectronics on [discord](https://discord.gg/bAgNyGpXSx)
# List of methods and hooks
EOF
while read -r line; do
if [[ "$line" =~ \#\#\# ]]; then
desc="${line:4}<br/>${IFS}"
while read -r line && [[ "$line" =~ \#\#\# ]]; do
desc+="${line:4}${IFS}"
done
example=""
while true; do
if [[ "$line" =~ ^[^#]*\(\) ]]; then
arguments=$toadd
command=$BASH_REMATCH
break
else
example+="$toadd$IFS"
toadd=${line:2}
fi
read -r line
done
echo "## $command"
echo -n "$desc"
if [ -n "$arguments" ]; then
echo "### arguments"
echo "\`$arguments\`"
fi
if [ -n "${example:4}" ]; then
example=${example//\$0/${command/\(\)/}}
echo "### example"
echo -n "\`\`\`bash"
echo -n "$example"
echo "\`\`\`"
fi
arguments=""
toadd=""
echo
fi
done <<<"$(cat src/*.sh)"
} >docs.md