Compare commits
3 Commits
98bfba6bfe
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
e780283e5b
|
|||
|
6876fb741c
|
|||
|
a4020c1f43
|
Submodule .config/ai/scpt deleted from 7a4d642e41
5
.env.example
Normal file
5
.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Admin handle (bot will respond to admin commands from this user)
|
||||||
|
ADMIN=syui.ai
|
||||||
|
|
||||||
|
# Bluesky host (optional, default: bsky.social)
|
||||||
|
HOST=syu.is
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -17,3 +17,5 @@ pnpm-lock.yaml
|
|||||||
**Cargo.lock
|
**Cargo.lock
|
||||||
*/target/
|
*/target/
|
||||||
*/**/*.rs.bk
|
*/**/*.rs.bk
|
||||||
|
.claude
|
||||||
|
.config
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
FROM syui/aios
|
FROM syui/aios
|
||||||
|
|
||||||
WORKDIR /root
|
COPY ./target/release/aibot /usr/sbin/aibot
|
||||||
ADD ./test/entrypoint.sh .
|
|
||||||
RUN chmod +x /root/entrypoint.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["/root/entrypoint.sh"]
|
WORKDIR /root
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<img src="./icon/avatar.png" width="100">
|
<img src="./icon/avatar.png" width="100">
|
||||||
|
|
||||||
- name : ai bot
|
- name : aibot
|
||||||
- base : [ai os](https://git.syui.ai/ai/os)
|
- base : [aios](https://git.syui.ai/ai/os)
|
||||||
- host : [yui.syui.ai](https://bsky.app/profile/yui.syui.ai), [ai.syu.is](https://web.syu.is/profile/ai.syu.is)
|
- host : [yui.syui.ai](https://bsky.app/profile/yui.syui.ai), [ai.syu.is](https://syu.is/profile/did:plc:6qyecktefllvenje24fcxnie)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ aibot
|
$ aibot
|
||||||
@@ -28,14 +28,14 @@ $ aibot ai -t avatar
|
|||||||
### login
|
### login
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# ai login $handle -p $password
|
# aibot login $handle -p $password
|
||||||
$ aibot l yui.syui.ai -p password
|
$ aibot l yui.syui.ai -p password
|
||||||
|
|
||||||
$ cat ~/.config/ai/token.toml
|
$ cat ~/.config/ai/token.toml
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# ai l $handle -p $password -s $server
|
# aibot l $handle -p $password -s $server
|
||||||
$ aibot l ai.syu.is -p password -s syu.is
|
$ aibot l ai.syu.is -p password -s syu.is
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
19
compose.yml
19
compose.yml
@@ -1,11 +1,16 @@
|
|||||||
services:
|
services:
|
||||||
aios:
|
bot:
|
||||||
#image: syui/aios
|
|
||||||
#command: ai bot -a syui.syu.is
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
restart: always
|
dockerfile: Dockerfile
|
||||||
env_file:
|
image: syui/aios:custom
|
||||||
- .env
|
container_name: aibot
|
||||||
|
restart: unless-stopped
|
||||||
|
command: ["aibot", "bot", "-a", "${ADMIN:-syui.ai}"]
|
||||||
volumes:
|
volumes:
|
||||||
- ./.config:/root/.config
|
- ./.config/syui/ai/bot:/root/.config/syui/ai/bot
|
||||||
|
logging:
|
||||||
|
driver: json-file
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|||||||
86
src/bot.rs
86
src/bot.rs
@@ -167,7 +167,9 @@ pub fn c_bot(c: &Context) {
|
|||||||
|| com.contains("うらない") == true
|
|| com.contains("うらない") == true
|
||||||
|| com.contains("うらなって") == true
|
|| com.contains("うらなって") == true
|
||||||
{
|
{
|
||||||
let _output = Command::new(data_scpt(&"ai"))
|
let script_path = data_scpt(&"ai");
|
||||||
|
println!("[fortune] script: {}", script_path);
|
||||||
|
let output = Command::new(&script_path)
|
||||||
.arg(&"atproto").arg(&"fortune")
|
.arg(&"atproto").arg(&"fortune")
|
||||||
.arg(&handle)
|
.arg(&handle)
|
||||||
.arg(&did)
|
.arg(&did)
|
||||||
@@ -178,11 +180,25 @@ pub fn c_bot(c: &Context) {
|
|||||||
.arg(&host)
|
.arg(&host)
|
||||||
.arg(&prompt)
|
.arg(&prompt)
|
||||||
.arg(&prompt_sub)
|
.arg(&prompt_sub)
|
||||||
.output()
|
.output();
|
||||||
.expect("zsh");
|
match output {
|
||||||
|
Ok(out) => {
|
||||||
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
|
println!("[fortune] stdout: {}", stdout);
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
println!("[fortune] stderr: {}", stderr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("[fortune] error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
} else if com == "card" || com == "/card" {
|
} else if com == "card" || com == "/card" {
|
||||||
let output = Command::new(data_scpt(&"ai"))
|
let script_path = data_scpt(&"ai");
|
||||||
|
println!("[card] script: {}", script_path);
|
||||||
|
let output = Command::new(&script_path)
|
||||||
.arg(&"atproto").arg(&"card")
|
.arg(&"atproto").arg(&"card")
|
||||||
.arg(&handle)
|
.arg(&handle)
|
||||||
.arg(&did)
|
.arg(&did)
|
||||||
@@ -193,14 +209,26 @@ pub fn c_bot(c: &Context) {
|
|||||||
.arg(&host)
|
.arg(&host)
|
||||||
.arg(&prompt)
|
.arg(&prompt)
|
||||||
.arg(&prompt_sub)
|
.arg(&prompt_sub)
|
||||||
.output()
|
.output();
|
||||||
.expect("zsh");
|
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
match output {
|
||||||
|
Ok(out) => {
|
||||||
|
let d = String::from_utf8_lossy(&out.stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
|
println!("[card] stdout: {}", d);
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
println!("[card] stderr: {}", stderr);
|
||||||
|
}
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
let text_limit = c_char(dd);
|
let text_limit = c_char(dd);
|
||||||
if text_limit.len() > 3 {
|
if text_limit.len() > 3 {
|
||||||
//handlev = handle.replace(".", "-").to_string();
|
let lines: Vec<&str> = d.lines().collect();
|
||||||
handlev = d.lines().collect::<Vec<_>>()[0].to_string();
|
handlev = lines.get(0).unwrap_or(&"").trim().to_string();
|
||||||
|
// 空白を含む場合や空の場合はhandleから生成
|
||||||
|
if handlev.is_empty() || handlev.contains(' ') {
|
||||||
|
handlev = handle.split('.').next().unwrap_or("").to_string();
|
||||||
|
}
|
||||||
|
if !handlev.is_empty() {
|
||||||
link = "https://card.syui.ai/".to_owned() + &handlev;
|
link = "https://card.syui.ai/".to_owned() + &handlev;
|
||||||
e = link.chars().count();
|
e = link.chars().count();
|
||||||
let str_rep = reply_link::post_request(
|
let str_rep = reply_link::post_request(
|
||||||
@@ -217,6 +245,13 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("[card] script error: {}", e);
|
||||||
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if com == "fav" || com == "/fav" {
|
} else if com == "fav" || com == "/fav" {
|
||||||
let output = Command::new(data_scpt(&"ai"))
|
let output = Command::new(data_scpt(&"ai"))
|
||||||
.arg(&"atproto").arg(&"fav")
|
.arg(&"atproto").arg(&"fav")
|
||||||
@@ -814,7 +849,9 @@ pub fn c_bot_feed(c: &Context) {
|
|||||||
}
|
}
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
} else if com == "card" || com == "/card" {
|
} else if com == "card" || com == "/card" {
|
||||||
let output = Command::new(data_scpt(&"ai"))
|
let script_path = data_scpt(&"ai");
|
||||||
|
println!("[card] script: {}", script_path);
|
||||||
|
let output = Command::new(&script_path)
|
||||||
.arg(&"atproto").arg(&"card")
|
.arg(&"atproto").arg(&"card")
|
||||||
.arg(&handle)
|
.arg(&handle)
|
||||||
.arg(&did)
|
.arg(&did)
|
||||||
@@ -825,14 +862,26 @@ pub fn c_bot_feed(c: &Context) {
|
|||||||
.arg(&host)
|
.arg(&host)
|
||||||
.arg(&prompt)
|
.arg(&prompt)
|
||||||
.arg(&prompt_sub)
|
.arg(&prompt_sub)
|
||||||
.output()
|
.output();
|
||||||
.expect("zsh");
|
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
match output {
|
||||||
|
Ok(out) => {
|
||||||
|
let d = String::from_utf8_lossy(&out.stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
|
println!("[card] stdout: {}", d);
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
println!("[card] stderr: {}", stderr);
|
||||||
|
}
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
let text_limit = c_char(dd);
|
let text_limit = c_char(dd);
|
||||||
if text_limit.len() > 3 {
|
if text_limit.len() > 3 {
|
||||||
//handlev = handle.replace(".", "-").to_string();
|
let lines: Vec<&str> = d.lines().collect();
|
||||||
handlev = d.lines().collect::<Vec<_>>()[0].to_string();
|
handlev = lines.get(0).unwrap_or(&"").trim().to_string();
|
||||||
|
// 空白を含む場合や空の場合はhandleから生成
|
||||||
|
if handlev.is_empty() || handlev.contains(' ') {
|
||||||
|
handlev = handle.split('.').next().unwrap_or("").to_string();
|
||||||
|
}
|
||||||
|
if !handlev.is_empty() {
|
||||||
link = "https://card.syui.ai/".to_owned() + &handlev;
|
link = "https://card.syui.ai/".to_owned() + &handlev;
|
||||||
e = link.chars().count();
|
e = link.chars().count();
|
||||||
let str_rep = reply_link::post_request(
|
let str_rep = reply_link::post_request(
|
||||||
@@ -849,6 +898,13 @@ pub fn c_bot_feed(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("[card] script error: {}", e);
|
||||||
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if com == "fav" || com == "/fav" {
|
} else if com == "fav" || com == "/fav" {
|
||||||
let output = Command::new(data_scpt(&"ai"))
|
let output = Command::new(data_scpt(&"ai"))
|
||||||
.arg(&"atproto").arg(&"fav")
|
.arg(&"atproto").arg(&"fav")
|
||||||
|
|||||||
12
src/data.rs
12
src/data.rs
@@ -8,7 +8,7 @@ use std::io::Write;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn data_file(s: &str) -> String {
|
pub fn data_file(s: &str) -> String {
|
||||||
let file = "/.config/ai/";
|
let file = "/.config/syui/ai/bot/";
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
let mut f = shellexpand::tilde("~").to_string();
|
||||||
f.push_str(&file);
|
f.push_str(&file);
|
||||||
let path = Path::new(&f);
|
let path = Path::new(&f);
|
||||||
@@ -24,7 +24,7 @@ pub fn data_file(s: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_file(s: &str) -> String {
|
pub fn log_file(s: &str) -> String {
|
||||||
let file = "/.config/ai/txt/";
|
let file = "/.config/syui/ai/bot/txt/";
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
let mut f = shellexpand::tilde("~").to_string();
|
||||||
f.push_str(&file);
|
f.push_str(&file);
|
||||||
let path = Path::new(&f);
|
let path = Path::new(&f);
|
||||||
@@ -263,7 +263,7 @@ pub fn data_refresh(s: &str) -> String {
|
|||||||
|
|
||||||
pub fn data_scpt(s: &str) -> String {
|
pub fn data_scpt(s: &str) -> String {
|
||||||
let s = String::from(s);
|
let s = String::from(s);
|
||||||
let file = "/.config/ai/scpt/".to_owned() + &s + &".zsh";
|
let file = "/.config/syui/ai/bot/scpt/".to_owned() + &s + &".zsh";
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
let mut f = shellexpand::tilde("~").to_string();
|
||||||
f.push_str(&file);
|
f.push_str(&file);
|
||||||
return f;
|
return f;
|
||||||
@@ -603,7 +603,7 @@ pub fn w_cid(cid: String, file: String, t: bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn c_follow_all() {
|
pub fn c_follow_all() {
|
||||||
let file = "/.config/ai/scpt/follow_all.zsh";
|
let file = "/.config/syui/ai/bot/scpt/follow_all.zsh";
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
let mut f = shellexpand::tilde("~").to_string();
|
||||||
f.push_str(&file);
|
f.push_str(&file);
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
@@ -617,7 +617,7 @@ pub fn c_openai_key(c: &Context) {
|
|||||||
let api = c.args[0].to_string();
|
let api = c.args[0].to_string();
|
||||||
let o = "api='".to_owned() + &api.to_string() + &"'".to_owned();
|
let o = "api='".to_owned() + &api.to_string() + &"'".to_owned();
|
||||||
let o = o.to_string();
|
let o = o.to_string();
|
||||||
let l = shellexpand::tilde("~") + "/.config/ai/openai.toml";
|
let l = shellexpand::tilde("~") + "/.config/syui/ai/bot/openai.toml";
|
||||||
let l = l.to_string();
|
let l = l.to_string();
|
||||||
let mut l = fs::File::create(l).unwrap();
|
let mut l = fs::File::create(l).unwrap();
|
||||||
if o != "" {
|
if o != "" {
|
||||||
@@ -628,7 +628,7 @@ pub fn c_openai_key(c: &Context) {
|
|||||||
|
|
||||||
impl Open {
|
impl Open {
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
let d = shellexpand::tilde("~") + "/.config/ai/openai.toml";
|
let d = shellexpand::tilde("~") + "/.config/syui/ai/bot/openai.toml";
|
||||||
let s = Config::builder()
|
let s = Config::builder()
|
||||||
.add_source(File::with_name(&d))
|
.add_source(File::with_name(&d))
|
||||||
.add_source(config::Environment::with_prefix("APP"))
|
.add_source(config::Environment::with_prefix("APP"))
|
||||||
|
|||||||
@@ -480,6 +480,8 @@ fn bot(c: &Context) {
|
|||||||
loop {
|
loop {
|
||||||
c_bot(c);
|
c_bot(c);
|
||||||
c_bot_feed(c);
|
c_bot_feed(c);
|
||||||
|
// 10秒待機してCPU使用率を抑制
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,6 +489,7 @@ fn feed_watch(c: &Context) {
|
|||||||
refresh(c);
|
refresh(c);
|
||||||
loop {
|
loop {
|
||||||
c_feed_watch(c);
|
c_feed_watch(c);
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
#ai l $HANDLE -p $PASSWORD -s $HOST
|
|
||||||
ai bot -a $ADMIN
|
|
||||||
Reference in New Issue
Block a user