update rust deps and nixpkgs

This commit is contained in:
Gabriel Fontes
2023-06-11 00:40:00 -03:00
parent d48c1c2a9f
commit ef77a54805
8 changed files with 788 additions and 1241 deletions

1922
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,10 +7,11 @@ edition = "2018"
homepage = "https://misterio.me" homepage = "https://misterio.me"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[dependencies.serenity] [dependencies.log]
version = "0.10" version = "0.4"
default-features = false
features = [ "default_no_backend", "rustls_backend" ] [dependencies.env_logger]
version = "0.9"
[dependencies.reqwest] [dependencies.reqwest]
version = "0.11" version = "0.11"
@@ -23,8 +24,12 @@ git = "https://github.com/Misterio77/sunk"
default-features = false default-features = false
features = [ "rustls-tls" ] features = [ "rustls-tls" ]
[dependencies.serenity]
version = "0.11"
features = [ "voice" ]
[dependencies.songbird] [dependencies.songbird]
version = "0.2" version = "0.3"
default-features = false default-features = false
features = [ "serenity-rustls", "driver", "gateway", "builtin-queue" ] features = [ "serenity-rustls", "driver", "gateway", "builtin-queue" ]

View File

@@ -1,7 +1,7 @@
{ lib, rustPlatform, pkg-config, autoconf, alsa-lib, automake, libopus, ffmpeg, makeWrapper }: { lib, rustPlatform, pkg-config, autoconf, alsa-lib, automake, libopus, ffmpeg, makeWrapper }:
let manifest = (lib.importTOML ./Cargo.toml).package; let manifest = (lib.importTOML ./Cargo.toml).package;
in rustPlatform.buildRustPackage rec { in rustPlatform.buildRustPackage {
pname = manifest.name; pname = manifest.name;
version = manifest.version; version = manifest.version;
@@ -13,7 +13,7 @@ in rustPlatform.buildRustPackage rec {
cargoLock = { cargoLock = {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
outputHashes = { outputHashes = {
"sunk-0.1.2" = "sha256-VruqNDbWbjdarXiyR1OHcXsR1MvTmCM5j+v2ZpcG5IA="; "sunk-0.1.2" = "sha256-edipTPS8d6D2Rf6WFwutycI93YjuWK/Z5GQR2HHIxAU=";
}; };
}; };
@@ -22,7 +22,7 @@ in rustPlatform.buildRustPackage rec {
''; '';
meta = with lib; { meta = with lib; {
description = manifest.desciption; description = manifest.description;
homepage = manifest.homepage; homepage = manifest.homepage;
license = licenses.agpl3Plus; license = licenses.agpl3Plus;
platforms = platforms.all; platforms = platforms.all;

34
flake.lock generated
View File

@@ -2,16 +2,16 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1642104392, "lastModified": 1686331006,
"narHash": "sha256-m71b7MgMh9FDv4MnI5sg9MiBVW6DhE1zq+d/KlLWSC8=", "narHash": "sha256-hElRDWUNG655aqF0awu+h5cmDN+I/dQcChRt2tGuGGU=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5aaed40d22f0d9376330b6fa413223435ad6fee5", "rev": "85bcb95aa83be667e562e781e9d186c57a07d757",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixos-23.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@@ -22,13 +22,31 @@
"utils": "utils" "utils": "utils"
} }
}, },
"utils": { "systems": {
"locked": { "locked": {
"lastModified": 1638122382, "lastModified": 1681028828,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b", "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -2,7 +2,7 @@
description = "Discord bot for interacting with subsonic music libraries"; description = "Discord bot for interacting with subsonic music libraries";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
}; };

View File

@@ -1,13 +1,15 @@
use anyhow::Result; use anyhow::Result;
use serenity::{ use serenity::{
client::Client as DiscordClient, framework::standard::StandardFramework, prelude::TypeMapKey, client::Client as DiscordClient,
framework::standard::StandardFramework,
prelude::{GatewayIntents, TypeMapKey},
}; };
use songbird::SerenityInit; use songbird::SerenityInit;
use sunk::Client as SubsonicClient; use sunk::Client as SubsonicClient;
use std::{env, fs, io}; use std::{env, fs, io};
use crate::discord::{Handler, GENERAL_GROUP, after_hook}; use crate::discord::{after_hook, Handler, GENERAL_GROUP};
pub struct Client { pub struct Client {
ss_url: String, ss_url: String,
@@ -45,17 +47,19 @@ impl Client {
} }
pub async fn discord(&self, ss: SubsonicClient) -> Result<DiscordClient> { pub async fn discord(&self, ss: SubsonicClient) -> Result<DiscordClient> {
Ok(DiscordClient::builder(&self.discord_token) Ok(
.event_handler(Handler) DiscordClient::builder(&self.discord_token, GatewayIntents::default())
.framework( .event_handler(Handler)
StandardFramework::new() .framework(
.configure(|c| c.prefix("~")) StandardFramework::new()
.group(&GENERAL_GROUP) .configure(|c| c.prefix("~"))
.after(after_hook) .group(&GENERAL_GROUP)
) .after(after_hook),
.type_map_insert::<MusicClient>(ss) )
.register_songbird() .type_map_insert::<MusicClient>(ss)
.await?) .register_songbird()
.await?,
)
} }
pub async fn subsonic(&self) -> Result<SubsonicClient> { pub async fn subsonic(&self) -> Result<SubsonicClient> {

View File

@@ -1,4 +1,5 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use log::warn;
use serenity::{ use serenity::{
async_trait, async_trait,
client::{Context, EventHandler}, client::{Context, EventHandler},
@@ -6,7 +7,7 @@ use serenity::{
macros::{command, group, hook}, macros::{command, group, hook},
Args, CommandResult, Args, CommandResult,
}, },
model::channel::Message, model::{channel::Message, gateway::Ready},
prelude::Mutex, prelude::Mutex,
utils::MessageBuilder, utils::MessageBuilder,
}; };
@@ -33,7 +34,11 @@ pub struct General;
pub struct Handler; pub struct Handler;
#[async_trait] #[async_trait]
impl EventHandler for Handler {} impl EventHandler for Handler {
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
}
}
#[hook] #[hook]
pub async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: CommandResult) { pub async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: CommandResult) {
@@ -45,7 +50,7 @@ pub async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Com
#[command] #[command]
async fn leave(ctx: &Context, msg: &Message) -> CommandResult { async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap(); let guild = msg.guild(&ctx.cache).unwrap();
let guild_id = guild.id; let guild_id = guild.id;
let manager = songbird::get(ctx) let manager = songbird::get(ctx)
@@ -58,7 +63,7 @@ async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
#[command] #[command]
async fn join(ctx: &Context, msg: &Message) -> CommandResult { async fn join(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap(); let guild = msg.guild(&ctx.cache).unwrap();
let guild_id = guild.id; let guild_id = guild.id;
let channel = guild let channel = guild
@@ -306,7 +311,6 @@ async fn queue_song(
) -> Result<()> { ) -> Result<()> {
let guild = msg let guild = msg
.guild(&ctx.cache) .guild(&ctx.cache)
.await
.ok_or_else(|| anyhow!("Couldn't get guild id"))?; .ok_or_else(|| anyhow!("Couldn't get guild id"))?;
let manager = songbird::get(ctx) let manager = songbird::get(ctx)
.await .await
@@ -343,7 +347,6 @@ async fn queue_song(
async fn get_handler(ctx: &Context, msg: &Message) -> Result<Arc<Mutex<Call>>> { async fn get_handler(ctx: &Context, msg: &Message) -> Result<Arc<Mutex<Call>>> {
let guild = msg let guild = msg
.guild(&ctx.cache) .guild(&ctx.cache)
.await
.ok_or_else(|| anyhow!("Couldn't get guild id"))?; .ok_or_else(|| anyhow!("Couldn't get guild id"))?;
let manager = songbird::get(ctx) let manager = songbird::get(ctx)
.await .await

View File

@@ -1,14 +1,19 @@
use anyhow::Result; use anyhow::Result;
use log::warn;
use disconic::Client; use disconic::Client;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
dotenv::dotenv().ok(); dotenv::dotenv().ok();
env_logger::init();
let client = Client::from_env().await?; let client = Client::from_env().await?;
warn!("Initialized disconic client.");
let subsonic = client.subsonic().await?; let subsonic = client.subsonic().await?;
warn!("Initialized subsonic client.");
let mut discord = client.discord(subsonic).await?; let mut discord = client.discord(subsonic).await?;
warn!("Initialized discord client.");
discord.start().await?; discord.start().await?;