Skip to content

Commit

Permalink
port to latest library versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Dec 2, 2023
1 parent 65cc127 commit 9e0ec36
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 268 deletions.
661 changes: 428 additions & 233 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ tempfile = "3.4.0"
# TODO
[dependencies.poise]
git = "https://github.com/serenity-rs/poise"
branch = "serenity-next"
branch = "current"

[dependencies.songbird]
git = "https://github.com/serenity-rs/songbird.git"
branch = "next"
version = "0.4.0"
features = [ "builtin-queue" ]

[dependencies.serenity]
git = "https://github.com/serenity-rs/serenity"
branch = "next"
version = "0.12.0"
default-features = false
features = ["client", "model", "cache", "voice", "rustls_backend"]

Expand Down
7 changes: 3 additions & 4 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,18 @@ async fn queue(
let text = retrieve_queue(&hlock, page).await;
let msg = ctx
.send(
CreateReply::new()
CreateReply::default()
.content(text)
.components(vec![make_buttons(page, len)]),
)
.await?;

drop(hlock);

let discord = ctx.discord();
let msg = msg.into_message().await?;

let rxns = msg.await_component_interaction(ctx.discord());
start_pagination(msg, discord.clone(), handler, rxns);
let rxns = msg.await_component_interaction(ctx);
start_pagination(msg, ctx.serenity_context().clone(), handler, rxns);

Ok(())
})
Expand Down
34 changes: 16 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;

use reqwest::Client;
use restart::CallData;
use serenity::client::ClientBuilder;
use serenity::gateway::ActivityData;
use serenity::model::prelude::UserId;
use serenity::prelude::GatewayIntents;
Expand Down Expand Up @@ -135,14 +136,17 @@ async fn main_inner() {
.init();

let bot_owner = env::var("BOT_OWNER_ID").expect("Please set BOT_OWNER_ID");
let bot_owner = UserId(
NonZeroU64::new(bot_owner.parse().expect("bot owner id not correctly set")).unwrap(),
let bot_owner = UserId::from(
NonZeroU64::new(bot_owner.parse().expect("bot owner id not correctly set")).expect("bot owner ID should be non-zero"),
);

poise::FrameworkBuilder::default()
.client_settings(|c| {
c.register_songbird()
.activity(ActivityData::watching("you"))
let framework = poise::FrameworkBuilder::default()
.setup(|ctx, _ready, _framework| {
Box::pin(async move {
let client = reqwest::Client::new();
maybe_recover(ctx, client.clone()).await;
Ok(Data { client })
})
})
.options(poise::FrameworkOptions {
commands: all_commands(),
Expand All @@ -153,16 +157,10 @@ async fn main_inner() {
},
..Default::default()
})
.token(env::var("DISCORD_TOKEN").expect("Expected a token in the environment"))
.intents(GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT)
.user_data_setup(|ctx, _ready, _framework| {
Box::pin(async move {
let client = reqwest::Client::new();
maybe_recover(ctx, client.clone()).await;
Ok(Data { client })
})
})
.run()
.await
.unwrap();
.build();

let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
let client = ClientBuilder::new(token, intents).register_songbird().activity(ActivityData::watching("you")).framework(framework).await;
client.unwrap().start().await.unwrap();
}
2 changes: 1 addition & 1 deletion src/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async fn maybe_edit<'a>(
msg: String,
) -> Result<ReplyHandle<'a>, Error> {
if let Some(m) = prev {
m.edit(ctx, CreateReply::new().content(msg)).await?;
m.edit(ctx, CreateReply::default().content(msg)).await?;
Ok(m)
} else {
Ok(ctx.say(msg).await?)
Expand Down
2 changes: 1 addition & 1 deletion src/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn restart(ctx: Context<'_>) -> CommandResult {
return Ok(());
}

let songbird = songbird::get(ctx.discord()).await.unwrap();
let songbird = songbird::get(ctx.serenity_context()).await.unwrap();
let mut calls = Vec::new();
for (guild, call) in songbird.iter() {
let mut handler = call.lock().await;
Expand Down
4 changes: 2 additions & 2 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;
use std::time::Duration;

use poise::serenity_prelude::{
CacheHttp, ComponentInteractionCollector, ComponentInteractionDataKind, CreateActionRow,
ComponentInteractionCollector, ComponentInteractionDataKind, CreateActionRow,
CreateInteractionResponse, CreateSelectMenu, CreateSelectMenuKind, CreateSelectMenuOption,
EditMessage, Message,
};
Expand Down Expand Up @@ -112,7 +112,7 @@ pub async fn search(
.into_message()
.await?;

let collector = msg.await_component_interactions(ctx.discord());
let collector = msg.await_component_interactions(ctx);

enter_vc(ctx, true, move |handler, ctx| async move {
handle_search_responses(msg, ctx, handler, collector, results).await
Expand Down
8 changes: 4 additions & 4 deletions src/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl songbird::EventHandler for ErrorHandler {
pub async fn try_join(ctx: Context<'_>, must_join: bool) -> Result<Arc<Mutex<Call>>, &'static str> {
let guild = ctx.guild_id().unwrap();
let user = ctx.author().id;
let manager = songbird::get(ctx.discord())
let manager = songbird::get(ctx.serenity_context())
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
Expand All @@ -44,7 +44,7 @@ pub async fn try_join(ctx: Context<'_>, must_join: bool) -> Result<Arc<Mutex<Cal
}

let channel_id = guild
.to_guild_cached(ctx.discord())
.to_guild_cached(&ctx)
.unwrap()
.voice_states
.get(&user)
Expand Down Expand Up @@ -84,7 +84,7 @@ pub async fn enter_vc<
) -> CommandResult {
let guild_id = ctx.guild_id().unwrap();

let manager = songbird::get(ctx.discord())
let manager = songbird::get(ctx.serenity_context())
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn join(ctx: Context<'_>) -> CommandResult {
async fn leave(ctx: Context<'_>) -> CommandResult {
let guild_id = ctx.guild_id().unwrap();

let manager = songbird::get(ctx.discord())
let manager = songbird::get(ctx.serenity_context())
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
Expand Down

0 comments on commit 9e0ec36

Please sign in to comment.