add scpt cron
This commit is contained in:
		@@ -96,3 +96,11 @@ $ cp -rf ~/.config/ai ./.config/
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$ docker compose up
 | 
					$ docker compose up
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### cron
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					$ sudo pacman -S fcron
 | 
				
			||||||
 | 
					$ fcrontab -e
 | 
				
			||||||
 | 
					* * * * * $HOME/bot/test/ai.zsh c
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,11 +8,13 @@ case $OSTYPE in
 | 
				
			|||||||
		;;
 | 
							;;
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
d=${0:a:h}
 | 
					d=${0:a:h}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
source $d/env
 | 
					source $d/env
 | 
				
			||||||
source $d/refresh.zsh
 | 
					source $d/refresh.zsh
 | 
				
			||||||
source $d/token.zsh
 | 
					source $d/token.zsh
 | 
				
			||||||
source $d/reply.zsh
 | 
					source $d/reply.zsh
 | 
				
			||||||
source $d/notify.zsh
 | 
					source $d/notify.zsh
 | 
				
			||||||
 | 
					source $d/cron.zsh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
case $1 in
 | 
					case $1 in
 | 
				
			||||||
	refresh|r)
 | 
						refresh|r)
 | 
				
			||||||
@@ -27,4 +29,7 @@ case $1 in
 | 
				
			|||||||
	notify|n)
 | 
						notify|n)
 | 
				
			||||||
		notify
 | 
							notify
 | 
				
			||||||
		;;
 | 
							;;
 | 
				
			||||||
 | 
						cron|c)
 | 
				
			||||||
 | 
							cron
 | 
				
			||||||
 | 
							;;
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								test/cron.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								test/cron.zsh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					function cron() {
 | 
				
			||||||
 | 
						t=`docker ps |grep "ai bot"`
 | 
				
			||||||
 | 
						if [ -z "$t" ];then
 | 
				
			||||||
 | 
							docker compose up -d
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
						exit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										26
									
								
								test/env
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								test/env
									
									
									
									
									
								
							@@ -1,26 +1,10 @@
 | 
				
			|||||||
cfg=~/.config/ai/test.json
 | 
					cfg=~/.config/ai/test.json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ ! -f $cfg ] || ! cat $cfg|jq . || [ "`cat $cfg|jq .host`" = "null" ] || [ -z "`cat $cfg`" ];then
 | 
					if [ -f $cfg ];then
 | 
				
			||||||
	mkdir -p ~/.config/ai
 | 
						host=`cat $cfg|jq -r .host`
 | 
				
			||||||
	echo server:
 | 
						handle=`cat $cfg|jq -r .handle`
 | 
				
			||||||
	read host
 | 
						pass=`cat $cfg|jq -r .password`
 | 
				
			||||||
 | 
						date=`date --iso-8601=seconds`
 | 
				
			||||||
	echo password:
 | 
					 | 
				
			||||||
	read pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	echo handle:
 | 
					 | 
				
			||||||
	read handle
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
host=`cat $cfg|jq -r .host`
 | 
					 | 
				
			||||||
handle=`cat $cfg|jq -r .handle`
 | 
					 | 
				
			||||||
pass=`cat $cfg|jq -r .password`
 | 
					 | 
				
			||||||
date=`date --iso-8601=seconds`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ ! -f $cfg.t ];then
 | 
					 | 
				
			||||||
	$d/token.zsh
 | 
					 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -f $cfg.t ];then
 | 
					if [ -f $cfg.t ];then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,16 @@
 | 
				
			|||||||
function token() {
 | 
					function token() {
 | 
				
			||||||
 | 
							mkdir -p ~/.config/ai
 | 
				
			||||||
 | 
							echo server:
 | 
				
			||||||
 | 
							read host
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							echo password:
 | 
				
			||||||
 | 
							read pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							echo handle:
 | 
				
			||||||
 | 
							read handle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	url=https://$host/xrpc/com.atproto.server.createSession
 | 
						url=https://$host/xrpc/com.atproto.server.createSession
 | 
				
			||||||
	j=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url`
 | 
						j=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url`
 | 
				
			||||||
	echo $j
 | 
						echo $j
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user