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

View File

@@ -1,7 +1,7 @@
{ lib, rustPlatform, pkg-config, autoconf, alsa-lib, automake, libopus, ffmpeg, makeWrapper }:
let manifest = (lib.importTOML ./Cargo.toml).package;
in rustPlatform.buildRustPackage rec {
in rustPlatform.buildRustPackage {
pname = manifest.name;
version = manifest.version;
@@ -13,7 +13,7 @@ in rustPlatform.buildRustPackage rec {
cargoLock = {
lockFile = ./Cargo.lock;
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; {
description = manifest.desciption;
description = manifest.description;
homepage = manifest.homepage;
license = licenses.agpl3Plus;
platforms = platforms.all;

34
flake.lock generated
View File

@@ -2,16 +2,16 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1642104392,
"narHash": "sha256-m71b7MgMh9FDv4MnI5sg9MiBVW6DhE1zq+d/KlLWSC8=",
"lastModified": 1686331006,
"narHash": "sha256-hElRDWUNG655aqF0awu+h5cmDN+I/dQcChRt2tGuGGU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5aaed40d22f0d9376330b6fa413223435ad6fee5",
"rev": "85bcb95aa83be667e562e781e9d186c57a07d757",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
@@ -22,13 +22,31 @@
"utils": "utils"
}
},
"utils": {
"systems": {
"locked": {
"lastModified": 1638122382,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"lastModified": 1681028828,
"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",
"repo": "flake-utils",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {

View File

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

View File

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

View File

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

View File

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