tangled
alpha
login
or
join now
crashkeys.dev
/
audquotes
0
fork
atom
Source code for my personal quote bot project.
0
fork
atom
overview
issues
pulls
pipelines
Set up bot for hourly posting of regular quotes.
ironballista
1 year ago
be1ff351
c797b3f4
+30
-23
1 changed file
expand all
collapse all
unified
split
src
main.rs
+30
-23
src/main.rs
reviewed
···
19
19
const DEFAULT_QUEUE: &str = "queue:default";
20
20
const EVENT_QUEUE: &str = "queue:event";
21
21
22
22
+
// See https://cron.help for what these strings mean
23
23
+
const POSTING_INTERVAL_CRON: &str = "00,30 * * * * * *";
24
24
+
const EVENT_UPDATE_INTERVAL: &str = "55 23 * * *";
25
25
+
22
26
fn prepare_post<I: Into<String>>(text: I) -> post::RecordData {
23
27
post::RecordData {
24
28
text: text.into(),
···
122
126
std::env::var("BLUESKY_USERNAME").unwrap_or_default(),
123
127
std::env::var("BLUESKY_PASSWORD").unwrap_or_default(),
124
128
)
125
125
-
.await;
129
129
+
.await?;
126
130
127
131
let sched = JobScheduler::new().await?;
128
132
let agent = Arc::new(Mutex::new(agent));
129
129
-
let event_filter = Arc::new(QuoteFilter {
130
130
-
content: r"\b(?i:mother|mommy|mama|mom)\b".to_string(),
131
131
-
path: "quotes/**/*.txt".to_string(),
132
132
-
dates: vec![],
133
133
-
});
133
133
+
134
134
+
/*
135
135
+
let event_filter = Arc::new(QuoteFilter {
136
136
+
content: r"\b(?i:mother|mommy|mama|mom)\b".to_string(),
137
137
+
path: "test/**/*.txt".to_string(),
138
138
+
dates: vec![],
139
139
+
});
140
140
+
*/
134
141
135
142
let regular_filter = Arc::new(QuoteFilter {
136
143
content: r".*".to_string(),
137
137
-
path: "test/**/*.txt".to_string(),
144
144
+
path: "quotes/**/*.txt".to_string(),
138
145
dates: vec![],
139
146
});
140
147
···
143
150
144
151
// Add async job
145
152
sched
146
146
-
.add(Job::new_async("0/10,5/10 * * * * *", move |_uuid, _| {
153
153
+
.add(Job::new_async(POSTING_INTERVAL_CRON, move |_uuid, _| {
147
154
let filter = regular_filter.clone();
148
155
let con = con_poster.clone();
149
156
let agent = agent_poster.clone();
···
152
159
let text: String = get_quote(&filter, con).await.unwrap();
153
160
let post = prepare_post(text.as_str());
154
161
let agent = agent.lock().await;
155
155
-
if let Err(_) = agent.create_record(post).await {
156
156
-
println!("{}\n", text)
162
162
+
if let Err(e) = agent.create_record(post).await {
163
163
+
eprintln!("Could not post quote: {e}")
157
164
}
158
165
})
159
166
})?)
160
167
.await?;
161
168
162
162
-
sched
163
163
-
.add(Job::new_async("32 * * * * *", move |_uuid, _| {
164
164
-
let filter = event_filter.clone();
165
165
-
let con = con_event_monitor.clone();
166
166
-
let _agent = agent_event_monitor.clone(); // Can be used later to e.g. update profile
169
169
+
// sched
170
170
+
// .add(Job::new_async(EVENT_UPDATE_INTERVAL, move |_uuid, _| {
171
171
+
// let filter = event_filter.clone();
172
172
+
// let con = con_event_monitor.clone();
173
173
+
// let _agent = agent_event_monitor.clone(); // Can be used later to e.g. update profile
167
174
168
168
-
Box::pin(async move {
169
169
-
// For testing purposes, let's always upload events
170
170
-
reshuffle_quotes(&filter, con.clone(), EVENT_QUEUE)
171
171
-
.await
172
172
-
.unwrap();
173
173
-
})
174
174
-
})?)
175
175
-
.await?;
175
175
+
// Box::pin(async move {
176
176
+
// // For testing purposes, let's always upload events
177
177
+
// reshuffle_quotes(&filter, con.clone(), EVENT_QUEUE)
178
178
+
// .await
179
179
+
// .unwrap();
180
180
+
// })
181
181
+
// })?)
182
182
+
// .await?;
176
183
177
184
sched.start().await.unwrap();
178
185
loop {