Skip to content

Commit

Permalink
update serenity
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 8, 2024
1 parent 642e4b2 commit 4adf8c5
Show file tree
Hide file tree
Showing 54 changed files with 1,563 additions and 1,628 deletions.
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ members = [
]

[workspace.dependencies]
anyhow = "1.0.75"
anyhow = "1.0.79"
# arma-rs = "1.9.3"
arma-rs = { git = "https://github.com/brettmayson/arma-rs", features = ["uuid", "serde_json"] }
async-trait = "0.1.74"
axum = "0.6.20"
async-trait = "0.1.77"
axum = "0.7.3"
nats = { version = "0.24.1" }
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
serenity = { git = "https://github.com/serenity-rs/serenity", rev = "45e2599e2cf90b76d38b8d9f1402b4e93bda6680", default-features = false, features = ["rustls_backend"] }
serde_json = "1.0.111"
serenity = { git = "https://github.com/serenity-rs/serenity", rev = "6ae86f66e6c78a0b3490eff52557a115f863690c", default-features = false, features = ["rustls_backend"] }
# sqlx = { version = "0.7.1" }
sqlx = { git = "https://github.com/launchbadge/sqlx", ref = "e1ac3881734293cb33674a8b0b1d983132b9c2b1"}
strum = "0.25.0"
time = "0.3.30"
tokio = "1.34.0"
time = "0.3.31"
tokio = "1.35.1"
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = "0.3.17"
uuid = "1.5.0"
reqwest = { version = "0.11.22", features = ["rustls-tls"] }
tracing-subscriber = "0.3.18"
uuid = "1.6.1"
reqwest = { version = "0.11.23", features = ["rustls-tls"] }
2 changes: 1 addition & 1 deletion arma/server/src/commands/certifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn auto(discord: String, certification: Uuid, passed: bool) {
synixe_events::certifications::db,
Certify {
instructor: BRODSKY,
trainee: UserId(discord),
trainee: UserId::new(discord),
certification,
notes: "Automated certification".to_string(),
passed
Expand Down
4 changes: 2 additions & 2 deletions arma/server/src/commands/discord/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn command_get(steam: String, name: String) {
bootstrap::NC::get().await,
synixe_events::discord::info,
MemberRoles {
user: UserId(discord_id_u64),
user: UserId::new(discord_id_u64),
}
)
.await
Expand Down Expand Up @@ -168,7 +168,7 @@ fn command_save_dlc(discord: String, dlc: Vec<u32>) {
bootstrap::NC::get().await,
synixe_events::discord::db,
SaveDLC {
member: UserId(discord_u64),
member: UserId::new(discord_u64),
dlc,
}
)
Expand Down
2 changes: 1 addition & 1 deletion arma/server/src/commands/garage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn store(ctx: Context, plate: String, state: HashMap<String, Value>, discord: St
synixe_events::garage::db,
StoreVehicle {
plate: plate.to_string(),
member: UserId(discord),
member: UserId::new(discord),
state: serde_json::Value::Object(
state.into_iter().map(|(k, v)| (k, v.to_json())).collect()
),
Expand Down
2 changes: 1 addition & 1 deletion arma/server/src/commands/gear/bodybag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn command_store(
bootstrap::NC::get().await,
synixe_events::gear::db,
LockerStore {
member: UserId(discord),
member: UserId::new(discord),
items,
reason: "bodybag".to_string(),
}
Expand Down
4 changes: 2 additions & 2 deletions arma/server/src/commands/gear/loadout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn command_get(discord: String, steam: String) {
bootstrap::NC::get().await,
synixe_events::gear::db,
LoadoutGet {
member: UserId(discord),
member: UserId::new(discord),
}
)
.await
Expand Down Expand Up @@ -69,7 +69,7 @@ fn command_store(discord: String, steam: String, loadout: String) {
bootstrap::NC::get().await,
synixe_events::gear::db,
LoadoutStore {
member: UserId(discord),
member: UserId::new(discord),
loadout: loadout.replace("\"\"", "\""),
}
)
Expand Down
6 changes: 3 additions & 3 deletions arma/server/src/commands/gear/shop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn command_enter(discord: String, steam: String, mut items: HashMap<String, i32>
bootstrap::NC::get().await,
synixe_events::gear::db,
ShopEnter {
member: UserId(discord),
member: UserId::new(discord),
items,
}
)
Expand Down Expand Up @@ -120,7 +120,7 @@ fn command_leave(discord: String, steam: String, loadout: String, mut items: Has
bootstrap::NC::get().await,
synixe_events::gear::db,
ShopLeave {
member: UserId(discord),
member: UserId::new(discord),
loadout: loadout.replace("\"\"", "\""),
items,
}
Expand Down Expand Up @@ -158,7 +158,7 @@ fn command_purchase(discord: String, steam: String, mut items: HashMap<String, i
bootstrap::NC::get().await,
synixe_events::gear::db,
ShopPurchase {
member: UserId(discord),
member: UserId::new(discord),
items,
}
)
Expand Down
20 changes: 10 additions & 10 deletions arma/server/src/commands/reputation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn command_friendly_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
FriendlyShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -58,7 +58,7 @@ fn command_civilian_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
CivilianShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -84,7 +84,7 @@ fn command_unarmed_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
UnarmedShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -110,7 +110,7 @@ fn command_surrendering_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
SurrenderingShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -136,7 +136,7 @@ fn command_captive_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
CaptiveShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -162,7 +162,7 @@ fn command_unconscious_shot(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
UnconsciousShot {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -188,7 +188,7 @@ fn command_building_damaged(member: String, target: String, weapon: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
BuildingDamaged {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
weapon: weapon.to_string(),
}
Expand All @@ -214,7 +214,7 @@ fn command_friendly_healed(member: String, target: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
FriendlyHealed {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
}
)
Expand All @@ -239,7 +239,7 @@ fn command_unfriendly_healed(member: String, target: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
FriendlyHealed {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
}
)
Expand All @@ -264,7 +264,7 @@ fn command_civilian_healed(member: String, target: String) {
bootstrap::NC::get().await,
synixe_events::reputation::db,
CivilianHealed {
member: UserId(discord),
member: UserId::new(discord),
target: target.to_string(),
}
)
Expand Down
15 changes: 9 additions & 6 deletions bin/api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::net::SocketAddr;

use axum::{extract::Path, response::IntoResponse, routing::get, Router, Server};
use axum::{extract::Path, response::IntoResponse, routing::get, Router};
use synixe_events::gear::db::Response;
use synixe_proc::events_request_5;
use tokio::net::TcpListener;

#[macro_use]
extern crate tracing;
Expand All @@ -15,18 +16,20 @@ async fn main() {

let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
debug!("Listening on {}", addr);
Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
axum::serve(
TcpListener::bind(&addr).await.expect("bind to addr :3000"),
app.into_make_service(),
)
.await
.unwrap();
}

async fn balance(Path(id): Path<u64>) -> impl IntoResponse {
let Ok(Ok((Response::BankBalance(Ok(Some(balance))), _))) = events_request_5!(
bootstrap::NC::get().await,
synixe_events::gear::db,
BankBalance {
member: serenity::model::prelude::UserId(id),
member: serenity::model::prelude::UserId::new(id),
}
)
.await
Expand Down
2 changes: 1 addition & 1 deletion bin/bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async-trait = { workspace = true }
nats = { workspace = true }
rand = "0.8.5"
regex = "1.10.2"
reqwest = { version = "0.11.22", features = ["json"] }
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serenity = { workspace = true, features = ["builder", "cache", "client", "collector", "gateway", "http", "model", "utils", "rustls_backend"] }
Expand Down
2 changes: 1 addition & 1 deletion bin/bot/src/bot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{mem::MaybeUninit, sync::Arc};

use serenity::client::bridge::gateway::ShardMessenger;
use serenity::gateway::ShardMessenger;

pub struct Bot();

Expand Down
10 changes: 6 additions & 4 deletions bin/bot/src/cache_http.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use std::{mem::MaybeUninit, sync::Arc};
use std::mem::MaybeUninit;

use crate::ArcCacheAndHttp;

pub struct CacheAndHttp();

static mut SINGLETON: MaybeUninit<Arc<serenity::CacheAndHttp>> = MaybeUninit::uninit();
static mut SINGLETON: MaybeUninit<ArcCacheAndHttp> = MaybeUninit::uninit();

impl CacheAndHttp {
/// Gets a reference to the Bot cache and http
///
/// # Panics
///
/// Panics if the bot does not exists
pub fn get() -> Arc<serenity::CacheAndHttp> {
pub fn get() -> ArcCacheAndHttp {
unsafe { SINGLETON.assume_init_ref().clone() }
}

/// Initializes the Bot cache and http
pub fn init(bot: Arc<serenity::CacheAndHttp>) {
pub fn init(bot: ArcCacheAndHttp) {
unsafe {
SINGLETON = MaybeUninit::new(bot);
}
Expand Down
25 changes: 15 additions & 10 deletions bin/bot/src/discord/handler/brain/functions/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ impl BrainFunction for GetBalance {
}

async fn run(&self, _ctx: &Context, args: serde_json::Value) -> Option<serde_json::Value> {
let members = args["members"]
let members = match args["members"]
.as_array()?
.iter()
.map(|v| {
let id = v.as_str().unwrap_or_default();
let mut member = if id.trim().is_empty() {
UserId(0)
if id.trim().is_empty() {
Ok(BRODSKY)
} else {
UserId(id.parse().expect("invalid id"))
};
if member == BRODSKY {
member = UserId(0);
let Ok(id) = id.parse() else {
return Err(serde_json::Value::String(
"invalid id, only accepts IDS, not names".to_string(),
));
};
Ok(UserId::new(id))
}
member
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>, serde_json::Value>>()
{
Ok(members) => members,
Err(e) => return Some(e),
};

let mut responses = Vec::new();

Expand All @@ -65,7 +70,7 @@ impl BrainFunction for GetBalance {
return None;
};

if member == UserId(0) {
if member == BRODSKY {
responses.push(json!({
"company": bootstrap::format::money(balance, false),
}));
Expand Down
2 changes: 1 addition & 1 deletion bin/bot/src/discord/handler/brain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Brain {
};
match self.client.chat().create(request).await {
Ok(response) => {
let response = response.choices.get(0)?.message.clone();
let response = response.choices.first()?.message.clone();
if let Some(function_call) = response.function_call {
println!("ask function_call: {function_call:?}");
let Some(function) = self
Expand Down
6 changes: 6 additions & 0 deletions bin/bot/src/discord/handler/brain/prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ There is no `python` function, or any other non-provided function.
You can lookup data, but do not have the ability to change it.

If you are showing a table, be sure to use ``` ``` around it, and use the `md` language tag.
Like:
```md
| Header 1 | Header 2 |
|----------|----------|
| Data 1 | Data 2 |
```
Loading

0 comments on commit 4adf8c5

Please sign in to comment.